66 #include <ACG/GL/gl.hh>
67 #include <ACG/GL/GLState.hh>
109 void call() {
if (valid) glCallList(dlist); }
111 void new_list(GLenum mode) {
if(!valid) gen(); glNewList(dlist, mode); }
113 void end_list() { glEndList(); }
115 void del() {
if(valid) glDeleteLists(dlist, 1); valid =
false; }
117 bool is_valid()
const {
return valid; }
121 void gen() { dlist = glGenLists(1); valid=
true; }
131 #if defined(GL_ARB_vertex_buffer_object)
133 class ACGDLLEXPORT VertexBufferObject
137 VertexBufferObject(GLenum _target) : target(_target), valid(false), vbo(0u) {}
139 virtual ~VertexBufferObject() { del(); }
142 bool is_valid()
const {
return valid; }
147 void upload(GLsizeiptr size,
const GLvoid* data, GLenum usage);
150 void uploadSubData(GLuint _offset, GLuint _size,
const GLvoid* _data );
152 char* offset(
unsigned int _offset)
const
154 return ((
char*)NULL + _offset);
157 GLuint id()
const {
return vbo;}
172 class GeometryBuffer :
public VertexBufferObject
175 GeometryBuffer() : VertexBufferObject(GL_ARRAY_BUFFER_ARB) {}
179 class IndexBuffer :
public VertexBufferObject
182 IndexBuffer() : VertexBufferObject(GL_ELEMENT_ARRAY_BUFFER_ARB) {}
217 static bool isSupported();
226 GLuint id()
const {
return id_;}
228 bool is_valid()
const {
return id_ != 0;}
230 operator GLuint()
const {
return id_;}
235 static int supportStatus_;
247 Texture(GLenum tgt, GLenum _unit=GL_NONE);
252 void bind(GLenum _unit)
259 void activate(GLenum _unit)
266 void activate() { activate(unit); }
268 void parameter(GLenum pname, GLint i)
271 glTexParameteri(target, pname, i);
274 void parameter(GLenum pname, GLfloat f)
277 glTexParameterf(target, pname, f);
280 void parameter(GLenum pname, GLint * ip)
283 glTexParameteriv(target, pname, ip);
286 void parameter(GLenum pname, GLfloat * fp)
289 glTexParameterfv(target, pname, fp);
306 if(valid) glDeleteTextures(1, &texture);
310 void gen() { glGenTextures(1, &texture); valid = (texture > 0u ?
true : valid); }
312 bool is_valid()
const {
return valid; }
314 GLuint id()
const {
return texture; }
316 void setUnit(GLenum u) {unit = u;}
317 GLenum getUnit()
const {
return unit; }
318 GLenum getTarget()
const {
return target;}
321 GLint getInternalFormat();
341 void bindAsImage(GLuint _index, GLenum _access);
344 static bool supportsImageLoadStore();
347 static bool supportsTextureBuffer();
350 static bool supportsClearTexture();
353 static bool supportsGenerateMipmap();
362 GLint internalFormat_;
375 void setData(GLint _level, GLint _internalFormat, GLsizei _width, GLenum _format, GLenum _type,
const GLvoid* _data);
379 void setStorage(GLsizei _levels, GLenum _internalFormat, GLsizei _width);
382 GLsizei getWidth()
const {
return width_;}
383 GLenum getFormat()
const {
return format_;}
384 GLenum getType()
const {
return type_;}
387 bool getData(GLint _level,
void* _dst);
388 bool getData(GLint _level, std::vector<char>& _dst);
393 GLenum format_, type_;
409 bool autogenerateMipMaps();
412 void disableAutogenerateMipMaps();
415 void setData(GLint _level, GLint _internalFormat, GLsizei _width, GLsizei _height, GLenum _format, GLenum _type,
const GLvoid* _data);
419 void setStorage(GLsizei _levels, GLenum _internalFormat, GLsizei _width, GLsizei _height);
424 bool loadFromFile(
const std::string& _filename, GLenum _minFilter = GL_NEAREST_MIPMAP_LINEAR, GLenum _magFilter = GL_LINEAR);
427 void loadRandom(GLint _internalFormat, GLsizei _width, GLsizei _height);
430 GLsizei getWidth()
const {
return width_;}
431 GLsizei getHeight()
const {
return height_;}
432 GLenum getFormat()
const {
return format_;}
433 GLenum getType()
const {
return type_;}
436 bool getData(GLint _level,
void* _dst);
437 bool getData(GLint _level, std::vector<char>& _dst);
440 static bool checkTextureMem(GLenum _internalFormat, GLsizei _width, GLsizei _height,
446 void buildMipMaps(GLenum _internalfmt,
455 GLsizei width_, height_;
456 GLenum format_, type_;
475 #if defined(GL_ARB_texture_cube_map)
477 class TextureCubeMap :
public Texture
480 TextureCubeMap(GLenum u=GL_NONE) :
Texture(GL_TEXTURE_CUBE_MAP_ARB, u) {}
483 #elif defined(GL_EXT_texture_cube_map)
485 class TextureCubeMap :
public Texture
488 TextureCubeMap(GLenum u=GL_NONE) :
Texture(GL_TEXTURE_CUBE_MAP_EXT, u) {}
497 #if defined(GL_EXT_texture_rectangle)
499 class TextureRectangleEXT :
public Texture
502 TextureRectangleEXT(GLenum u=GL_NONE)
503 :
Texture(GL_TEXTURE_RECTANGLE_EXT, u) {}
509 #if defined(GL_NV_texture_rectangle)
511 class TextureRectangleNV :
public Texture
514 TextureRectangleNV(GLenum u=GL_NONE)
515 :
Texture(GL_TEXTURE_RECTANGLE_NV, u) {}
533 void setBufferData(
int _size,
const void* _data, GLenum _internalFormat, GLenum _usage = GL_STATIC_DRAW);
535 int getBufferSize()
const {
return bufferSize_;}
537 GLuint getBufferId()
const {
return buffer_;}
539 GLenum getUsage()
const {
return usage_;}
541 GLenum getFormat()
const {
return fmt_;}
545 bool getBufferData(
void* _dst);
546 bool getBufferData(std::vector<char>& _dst);
566 ProgramBase(GLenum tgt) : valid(
false), target(tgt), program(0) {}
569 bool is_valid()
const {
return valid; }
570 GLuint id()
const {
return program; }
572 virtual void bind() = 0;
573 virtual void unbind() = 0;
574 virtual bool load(
const char* prog_text) = 0;
576 bool load_file(
const char* _filename)
578 std::ifstream ifs(_filename);
581 std::cerr <<
"Can't open " << _filename <<
"\n";
588 if (!ifs.getline(line, 255).bad())
590 prog += std::string(line);
595 return load(prog.c_str());
610 #if defined(GL_NV_vertex_program) || defined(GL_NV_fragment_program)
617 ~ProgramBaseNV() { del(); }
622 bool load(
const char* prog_text);
636 #if defined(GL_ARB_vertex_program) || defined(GL_ARB_fragment_program)
638 class ProgramBaseARB :
public ProgramBase
642 ProgramBaseARB(GLenum tgt) : ProgramBase(tgt) {}
643 ~ProgramBaseARB() { del(); }
648 bool load(
const char* prog_text);
663 #if defined(GL_NV_vertex_program)
665 class VertexProgramNV :
public ProgramBaseNV
668 VertexProgramNV() : ProgramBaseNV(GL_VERTEX_PROGRAM_NV) {}
672 class VertexStateProgramNV :
public ProgramBaseNV
675 VertexStateProgramNV() : ProgramBaseNV(GL_VERTEX_STATE_PROGRAM_NV) {}
684 #if defined(GL_NV_fragment_program)
686 class FragmentProgramNV :
public ProgramBaseNV
689 FragmentProgramNV() : ProgramBaseNV(GL_FRAGMENT_PROGRAM_NV) {}
699 #if defined(GL_ARB_vertex_program)
701 class VertexProgramARB :
public ProgramBaseARB
704 VertexProgramARB() : ProgramBaseARB(GL_VERTEX_PROGRAM_ARB) {}
713 #if defined(GL_ARB_fragment_program)
715 class FragmentProgramARB :
public ProgramBaseARB
718 FragmentProgramARB() : ProgramBaseARB(GL_FRAGMENT_PROGRAM_ARB) {}
760 void set(
unsigned int _value = 0);
764 void get(
unsigned int* _out);
770 void bind(GLuint _index);
776 static bool isSupported();
778 bool isValid()
const;
780 GLuint getBufferId()
const {
return buffer_;}
781 int getNumCounters()
const {
return numCounters_;}
788 static int supportStatus_;
829 bool available()
const;
832 GLuint result()
const;
869 GLuint64 elapsedNs();
872 GLuint64 elapsedMs();
878 static bool isSupported();
882 GLuint queryObjects_[2];
885 static int supportStatus_;
930 void setUniformData(
GLSL::Program* _prog,
const char* _bufferName,
const char* _uniformName,
const void* _data,
int _datasize,
bool _delay =
false);
936 void bind(GLuint _index);
939 static bool isSupported();
942 static int getMaxBindings();
943 static int getMaxBlocksize();
944 static int getMaxCombinedShaderBlocks();
945 static int getOffsetAlignment();
950 std::vector<char> data_;
952 static void queryCaps();
955 static int supportStatus_;
956 static int maxBlockSize_;
957 static int maxBindings_;
958 static int maxCombinedShaderBlocks_;
959 static int offsetAlignment_;
1001 void bind(GLuint _index);
1004 static bool isSupported();
1007 static int getMaxBindings();
1008 static int getMaxBlocksize();
1009 static int getMaxCombinedShaderBlocks();
1013 static void queryCaps();
1016 static int supportStatus_;
1017 static int maxBlockSize_;
1018 static int maxBindings_;
1019 static int maxCombinedShaderBlocks_;
1027 #endif // GL_OBJECTS_HH defined
static void enable(GLenum _cap)
replaces glEnable, but supports locking
Namespace providing different geometric functions concerning angles.
static void bindBuffer(GLenum _target, GLuint _buffer)
replaces glBindBuffer, supports locking
static void bindTexture(GLenum _target, GLuint _buffer)
replaces glBindTexture, supports locking
static void activeTexture(GLenum _texunit)
replaces glActiveTexture, no locking support
This namespace contains all the classes and functions for handling GLSL shader and program objects...
static void disable(GLenum _cap)
replaces glDisable, but supports locking
bool bind(osg::GeometryPtr &_geo, Mesh &_mesh)