57 #include <ACG/GL/gl.hh> 58 #include <ACG/GL/GLState.hh> 100 void call() {
if (valid) glCallList(dlist); }
102 void new_list(GLenum mode) {
if(!valid) gen(); glNewList(dlist, mode); }
104 void end_list() { glEndList(); }
106 void del() {
if(valid) glDeleteLists(dlist, 1); valid =
false; }
108 bool is_valid()
const {
return valid; }
112 void gen() { dlist = glGenLists(1); valid=
true; }
122 #if defined(GL_VERSION_1_5) 124 class ACGDLLEXPORT VertexBufferObject
128 VertexBufferObject(GLenum _target) : target(_target), valid(
false), vbo(0u) {}
130 virtual ~VertexBufferObject() { del(); }
133 bool is_valid()
const {
return valid; }
138 void upload(GLsizeiptr size,
const GLvoid* data, GLenum usage);
141 void uploadSubData(GLuint _offset, GLuint _size,
const GLvoid* _data );
143 char* offset(
unsigned int _offset)
const 145 return reinterpret_cast<char*
>(_offset);
148 GLuint id()
const {
return vbo;}
163 class GeometryBuffer :
public VertexBufferObject
166 GeometryBuffer() : VertexBufferObject(GL_ARRAY_BUFFER) {}
170 class IndexBuffer :
public VertexBufferObject
173 IndexBuffer() : VertexBufferObject(GL_ELEMENT_ARRAY_BUFFER) {}
208 static bool isSupported();
217 GLuint id()
const {
return id_;}
219 bool is_valid()
const {
return id_ != 0;}
221 operator GLuint()
const {
return id_;}
226 static int supportStatus_;
238 Texture(GLenum tgt, GLenum _unit=GL_NONE);
243 void bind(GLenum _unit)
250 void activate(GLenum _unit)
257 void activate() { activate(unit); }
259 void parameter(GLenum pname, GLint i)
262 glTexParameteri(target, pname, i);
265 void parameter(GLenum pname, GLfloat f)
268 glTexParameterf(target, pname, f);
271 void parameter(GLenum pname, GLint * ip)
274 glTexParameteriv(target, pname, ip);
277 void parameter(GLenum pname, GLfloat * fp)
280 glTexParameterfv(target, pname, fp);
297 if(valid) glDeleteTextures(1, &texture);
301 void gen() { glGenTextures(1, &texture); valid = (texture > 0u ? true : valid); }
303 bool is_valid()
const {
return valid; }
305 GLuint id()
const {
return texture; }
307 void setUnit(GLenum u) {unit = u;}
308 GLenum getUnit()
const {
return unit; }
309 GLenum getTarget()
const {
return target;}
312 GLint getInternalFormat();
332 void bindAsImage(GLuint _index, GLenum _access);
335 static bool supportsImageLoadStore();
338 static bool supportsTextureBuffer();
341 static bool supportsClearTexture();
344 static bool supportsGenerateMipmap();
353 GLint internalFormat_;
366 void setData(GLint _level, GLint _internalFormat, GLsizei _width, GLenum _format, GLenum _type,
const GLvoid* _data);
370 void setStorage(GLsizei _levels, GLenum _internalFormat, GLsizei _width);
373 GLsizei getWidth()
const {
return width_;}
374 GLenum getFormat()
const {
return format_;}
375 GLenum getType()
const {
return type_;}
378 bool getData(GLint _level,
void* _dst);
379 bool getData(GLint _level, std::vector<char>& _dst);
384 GLenum format_, type_;
400 bool autogenerateMipMaps();
403 void disableAutogenerateMipMaps();
406 void setData(GLint _level, GLint _internalFormat, GLsizei _width, GLsizei _height, GLenum _format, GLenum _type,
const GLvoid* _data,
bool _mipmaps =
false);
410 void setStorage(GLsizei _levels, GLenum _internalFormat, GLsizei _width, GLsizei _height);
415 bool loadFromFile(
const std::string& _filename, GLenum _minFilter = GL_NEAREST_MIPMAP_LINEAR, GLenum _magFilter = GL_LINEAR);
418 void loadRandom(GLint _internalFormat, GLsizei _width, GLsizei _height);
421 GLsizei getWidth()
const {
return width_;}
422 GLsizei getHeight()
const {
return height_;}
423 GLenum getFormat()
const {
return format_;}
424 GLenum getType()
const {
return type_;}
427 bool getData(GLint _level,
void* _dst);
428 bool getData(GLint _level, std::vector<char>& _dst);
431 static bool checkTextureMem(GLenum _internalFormat, GLsizei _width, GLsizei _height,
437 void buildMipMaps(GLenum _internalfmt,
446 GLsizei width_, height_;
447 GLenum format_, type_;
466 #if defined(GL_ARB_texture_cube_map) 468 class TextureCubeMap :
public Texture 471 TextureCubeMap(GLenum u=GL_NONE) :
Texture(GL_TEXTURE_CUBE_MAP_ARB, u) {}
474 #elif defined(GL_EXT_texture_cube_map) 476 class TextureCubeMap :
public Texture 479 TextureCubeMap(GLenum u=GL_NONE) :
Texture(GL_TEXTURE_CUBE_MAP_EXT, u) {}
488 #if defined(GL_EXT_texture_rectangle) 490 class TextureRectangleEXT :
public Texture 493 TextureRectangleEXT(GLenum u=GL_NONE)
494 :
Texture(GL_TEXTURE_RECTANGLE_EXT, u) {}
500 #if defined(GL_NV_texture_rectangle) 502 class TextureRectangleNV :
public Texture 505 TextureRectangleNV(GLenum u=GL_NONE)
506 :
Texture(GL_TEXTURE_RECTANGLE_NV, u) {}
524 void setBufferData(
size_t _size,
const void* _data, GLenum _internalFormat, GLenum _usage = GL_STATIC_DRAW);
526 size_t getBufferSize()
const {
return bufferSize_;}
528 GLuint getBufferId()
const {
return buffer_;}
530 GLenum getUsage()
const {
return usage_;}
532 GLenum getFormat()
const {
return fmt_;}
536 bool getBufferData(
void* _dst);
537 bool getBufferData(std::vector<char>& _dst);
557 ProgramBase(GLenum tgt) : valid(
false), target(tgt), program(0) {}
560 bool is_valid()
const {
return valid; }
561 GLuint id()
const {
return program; }
563 virtual void bind() = 0;
564 virtual void unbind() = 0;
565 virtual bool load(
const char* prog_text) = 0;
567 bool load_file(
const char* _filename)
569 std::ifstream ifs(_filename);
572 std::cerr <<
"Can't open " << _filename <<
"\n";
579 if (!ifs.getline(line, 255).bad())
581 prog += std::string(line);
586 return load(prog.c_str());
601 #if defined(GL_NV_vertex_program) || defined(GL_NV_fragment_program) 608 ~ProgramBaseNV() { del(); }
613 bool load(
const char* prog_text);
627 #if defined(GL_ARB_vertex_program) || defined(GL_ARB_fragment_program) 634 ~ProgramBaseARB() { del(); }
639 bool load(
const char* prog_text);
654 #if defined(GL_NV_vertex_program) 656 class VertexProgramNV :
public ProgramBaseNV
659 VertexProgramNV() : ProgramBaseNV(GL_VERTEX_PROGRAM_NV) {}
663 class VertexStateProgramNV :
public ProgramBaseNV
666 VertexStateProgramNV() : ProgramBaseNV(GL_VERTEX_STATE_PROGRAM_NV) {}
675 #if defined(GL_NV_fragment_program) 677 class FragmentProgramNV :
public ProgramBaseNV
680 FragmentProgramNV() : ProgramBaseNV(GL_FRAGMENT_PROGRAM_NV) {}
690 #if defined(GL_ARB_vertex_program) 692 class VertexProgramARB :
public ProgramBaseARB
695 VertexProgramARB() : ProgramBaseARB(GL_VERTEX_PROGRAM_ARB) {}
704 #if defined(GL_ARB_fragment_program) 706 class FragmentProgramARB :
public ProgramBaseARB
709 FragmentProgramARB() : ProgramBaseARB(GL_FRAGMENT_PROGRAM_ARB) {}
751 void set(
unsigned int _value = 0);
755 void get(
unsigned int* _out);
761 void bind(GLuint _index);
767 static bool isSupported();
769 bool isValid()
const;
771 GLuint getBufferId()
const {
return buffer_;}
772 int getNumCounters()
const {
return numCounters_;}
779 static int supportStatus_;
820 bool available()
const;
823 GLuint result()
const;
860 GLuint64 elapsedNs();
863 GLuint64 elapsedMs();
869 static bool isSupported();
873 GLuint queryObjects_[2];
876 static int supportStatus_;
921 void setUniformData(
GLSL::Program* _prog,
const char* _bufferName,
const char* _uniformName,
const void* _data,
int _datasize,
bool _delay =
false);
927 void bind(GLuint _index);
930 static bool isSupported();
933 static int getMaxBindings();
934 static int getMaxBlocksize();
935 static int getMaxCombinedShaderBlocks();
936 static int getOffsetAlignment();
941 std::vector<char> data_;
943 static void queryCaps();
946 static int supportStatus_;
947 static int maxBlockSize_;
948 static int maxBindings_;
949 static int maxCombinedShaderBlocks_;
950 static int offsetAlignment_;
992 void bind(GLuint _index);
995 static bool isSupported();
998 static int getMaxBindings();
999 static int getMaxBlocksize();
1000 static int getMaxCombinedShaderBlocks();
1004 static void queryCaps();
1007 static int supportStatus_;
1008 static int maxBlockSize_;
1009 static int maxBindings_;
1010 static int maxCombinedShaderBlocks_;
1018 #endif // GL_OBJECTS_HH defined This namespace contains all the classes and functions for handling GLSL shader and program objects...
bool bind(osg::GeometryPtr &_geo, Mesh &_mesh)
Namespace providing different geometric functions concerning angles.
static void enable(GLenum _cap, bool _warnRemoved=true)
replaces glEnable, but supports locking
static void activeTexture(GLenum _texunit)
replaces glActiveTexture, no locking support
static void bindBuffer(GLenum _target, GLuint _buffer)
replaces glBindBuffer, supports locking
static void disable(GLenum _cap, bool _warnRemoved=true)
replaces glDisable, but supports locking
static void bindTexture(GLenum _target, GLuint _buffer)
replaces glBindTexture, supports locking