58 #ifndef ACG_GLSTATE_HH
59 #define ACG_GLSTATE_HH
66 #include "../Math/GLMatrixT.hh"
67 #include "../Math/VectorT.hh"
68 #include "../Config/ACGDefines.hh"
69 #include "ColorStack.hh"
77 #pragma warning(disable:4251)
133 std::bitset<0xFFFF+1> glStateEnabled_;
136 GLenum blendFuncState_[4];
138 GLenum blendEquationState_;
140 GLclampf blendColorState_[4];
142 GLenum alphaFuncState_;
143 GLclampf alphaRefState_;
151 GLuint glBufferTargetState_[4];
155 GLenum activeTexture_;
177 GLclampd depthRange_[2];
187 const GLvoid* pointer;
189 bool equals(GLint _size, GLenum _type, GLsizei _stride,
const GLvoid* _ptr)
191 return (size == _size && _type == type && _stride == stride && pointer == _ptr);
194 void set(GLint _size, GLenum _type, GLsizei _stride,
const GLvoid* _ptr)
196 size = _size; type = _type; stride = _stride, pointer = _ptr;
207 GLenum drawBufferSingle_;
208 GLenum drawBufferState_[16];
209 int activeDrawBuffer_;
213 GLuint framebuffers_[2];
225 GLState(
bool _updateGL =
true,
bool _compatibilityProfile =
true );
234 static void syncFromGL();
254 void clearBuffers ();
261 void setCompatibilityProfile(
bool _compatibility );
263 bool compatibilityProfile()
const;
267 bool compatibilityProfile_;
279 static void enable(GLenum _cap);
282 static void disable(GLenum _cap);
285 static void lockState(GLenum _cap);
288 static void unlockState(GLenum _cap);
291 static bool isStateLocked(GLenum _cap);
294 static bool isStateEnabled(GLenum _cap);
298 static void enableClientState(GLenum _cap);
300 static void disableClientState(GLenum _cap);
303 static void lockClientState(GLenum _cap);
305 static void unlockClientState(GLenum _cap);
308 static bool isClientStateEnabled(GLenum _cap);
310 static bool isClientStateLocked(GLenum _cap);
314 static void blendFunc(GLenum _sfactor, GLenum _dfactor) { blendFuncSeparate(_sfactor, _dfactor, _sfactor, _dfactor); }
317 static void getBlendFunc(GLenum* _sfactor, GLenum* _dfactor) { getBlendFuncSeparate(_sfactor, _dfactor, 0, 0); }
329 static void blendFuncSeparate(GLenum _srcRGB, GLenum _dstRGB, GLenum _srcAlpha, GLenum _dstAlpha);
332 static void getBlendFuncSeparate(GLenum* _srcRGB, GLenum* _dstRGB, GLenum* _srcAlpha, GLenum* _dstAlpha);
335 static void lockBlendFuncSeparate(
bool _rgb =
true,
bool _alpha =
true) { blendFuncSeparateLock_[0] = _rgb; blendFuncSeparateLock_[1] = _alpha; }
345 static void blendEquation(GLenum _mode);
358 static void blendColor(GLclampf _red, GLclampf _green, GLclampf _blue, GLclampf _alpha);
361 static void getBlendColor(GLclampf* _col);
372 static void alphaFunc(GLenum _func, GLclampf _ref);
375 static void getAlphaFunc(GLenum* _func, GLclampf* _ref);
386 static void shadeModel(GLenum _mode);
398 static void cullFace(GLenum _mode);
400 static GLenum
getCullFace() {
return stateStack_.back().cullFace_;}
409 static void depthRange(GLclampd _zNear, GLclampd _zFar);
411 static void getDepthRange(GLclampd* _zNearOut, GLclampd* _zFarOut);
427 static void vertexPointer(GLint _size, GLenum _type, GLsizei _stride,
const GLvoid* _pointer);
429 static void getVertexPointer(GLint* _size, GLenum* _type, GLsizei* _stride,
const GLvoid** _pointer);
452 static void normalPointer(GLenum _type, GLsizei _stride,
const GLvoid* _pointer);
454 static void getNormalPointer(GLenum* _type, GLsizei* _stride,
const GLvoid** _pointer);
470 static void colorPointer(GLint _size, GLenum _type, GLsizei _stride,
const GLvoid* _pointer);
472 static void getColorPointer(GLint* _size, GLenum* _type, GLsizei* _stride,
const GLvoid** _pointer);
492 static void texcoordPointer(GLint _size, GLenum _type, GLsizei _stride,
const GLvoid* _pointer);
494 static void getTexcoordPointer(GLint* _size, GLenum* _type, GLsizei* _stride,
const GLvoid** _pointer);
533 static void genBuffersARB(GLsizei n, GLuint* buffers);
539 static void genBuffers(GLsizei n, GLuint* buffers);
545 static void bufferDataARB(
546 GLenum target, GLsizeiptrARB size,
const GLvoid *data, GLenum usage);
552 static void bufferData(
553 GLenum target, GLsizeiptr size,
const GLvoid* data, GLenum usage);
559 static GLvoid* mapBuffer (GLenum target, GLenum access);
565 static GLboolean unmapBuffer (GLenum target);
571 static void deleteBuffers(GLsizei n,
const GLuint* buffers);
574 static void bindBuffer(GLenum _target, GLuint _buffer);
576 static void bindBufferARB(GLenum _target, GLuint _buffer) {bindBuffer(_target, _buffer);}
579 static void lockBufferTarget(GLenum _target);
582 static void unlockBufferTarget(GLenum _target);
585 static bool isBufferTargetLocked(GLenum _target);
588 static GLuint getBoundBuf(GLenum _target);
592 static void drawBuffer(GLenum _mode);
594 static void drawBuffers(GLsizei _n,
const GLenum* _bufs);
605 static void bindFramebuffer(GLenum _target, GLuint _framebuffer);
607 static GLuint getFramebufferDraw();
609 static GLuint getFramebufferRead();
612 static void lockFramebuffer(GLenum _target);
614 static void unlockFramebuffer(GLenum _target);
616 static bool isFramebufferLocked(GLenum _target);
627 static void useProgram(GLuint _program);
629 static GLuint
getProgram() {
return stateStack_.back().program_;}
644 static int getBufferTargetIndex(GLenum _target);
654 static void activeTexture(GLenum _texunit);
665 static void bindTexture(GLenum _target, GLuint _buffer);
668 static void lockTextureStage();
671 static void unlockTextureStage();
674 static bool isTextureTargetLocked();
677 static GLuint getBoundTextureBuffer();
679 static GLenum getBoundTextureTarget();
691 void reset_projection();
701 void ortho(
double _left,
double _right,
702 double _bottom,
double _top,
703 double _near_plane,
double _far_plane );
706 void frustum(
double _left,
double _right,
707 double _bottom,
double _top,
708 double _near_plane,
double _far_plane );
711 void perspective(
double _fovY,
double _aspect,
712 double _near_plane,
double _far_plane );
715 void viewport(
int _left,
int _bottom,
int _width,
int _height,
716 int _glwidth = 0,
int _glheight = 0);
728 void reset_modelview();
738 void lookAt(
const Vec3d& _eye,
const Vec3d& _center,
const Vec3d& _up );
741 void translate(
double _x,
double _y,
double _z,
745 void translate(
Vec3d _vector,
749 void rotate(
double _angle,
double _x,
double _y,
double _z,
754 { scale(_s, _s, _s); }
759 { scale(_s, _s, _s); }
762 void scale(
double _sx,
double _sy,
double _sz,
771 void push_projection_matrix();
773 void pop_projection_matrix();
776 void push_modelview_matrix();
778 void pop_modelview_matrix();
800 return window2viewport_;
805 return window2viewport_ * projection_ * modelview_;
810 return inverse_projection_;
815 return inverse_modelview_;
820 int& _width,
int& _height )
const {
821 _left = left_; _bottom = bottom_; _width = width_; _height = height_;
845 double aspect()
const;
852 return viewing_direction(width_>>1, height_>>1);
856 Vec3d viewing_direction(
int _x,
int _y)
const;
867 void viewing_ray(
int _x,
int _y,
Vec3d& _origin,
Vec3d& _direction)
const;
872 const GLenum& depthFunc()
const;
875 void set_depthFunc(
const GLenum& _depth_func);
879 static void depthFunc(GLenum _depthFunc);
881 inline static void lockDepthFunc() {depthFuncLock_ =
true;}
882 inline static void unlockDepthFunc() {depthFuncLock_ =
false;}
883 inline static bool isDepthFuncLocked() {
return depthFuncLock_;}
892 Vec3d unproject(
const Vec3d& _winPoint)
const;
916 void set_color(
const Vec4f& _col);
922 void set_clear_color(
const Vec4f& _col);
927 void set_base_color(
const Vec4f& _col);
932 void set_ambient_color(
const Vec4f& _col);
937 void set_diffuse_color(
const Vec4f& _col);
942 void set_specular_color(
const Vec4f& _col);
951 void set_overlay_color(
const Vec4f& _col);
961 void set_shininess(
float _shininess);
971 void set_point_size(
float _f);
976 void set_line_width(
float _f);
1041 void set_twosided_lighting(
bool _b);
1048 void set_multisampling(
bool _b );
1086 void pick_init (
bool _color);
1098 bool pick_set_maximum (
unsigned int _idx);
1110 void pick_set_name (
unsigned int _idx);
1115 Vec4uc pick_get_name_color (
unsigned int _idx);
1118 void pick_push_name (
unsigned int _idx);
1121 void pick_pop_name ();
1125 std::vector<unsigned int> pick_color_to_stack (
Vec4uc _rgba)
const;
1128 unsigned int pick_free_indicies ()
const;
1132 bool pick_error ()
const;
1143 unsigned int pick_current_index ()
const;
1146 bool color_picking ()
const;
1152 std::stack<GLMatrixd> stack_projection_,
1154 stack_inverse_projection_,
1155 stack_inverse_modelview_;
1159 inverse_projection_,
1163 inverse_window2viewport_;
1166 int left_, bottom_, width_, height_;
1169 int glwidth_, glheight_;
1172 double near_plane_, far_plane_;
1178 Vec4f ambient_color_;
1179 Vec4f diffuse_color_;
1180 Vec4f specular_color_;
1181 Vec4f overlay_color_;
1187 float point_size_, line_width_;
1190 bool twosided_lighting_;
1193 bool multisampling_;
1194 bool allow_multisampling_;
1196 static int num_texture_units_;
1208 unsigned int msSinceLastRedraw_;
1218 static bool depthFuncLock_;
1225 static std::deque <GLStateContext> stateStack_;
1228 static GLenum glStateCaps[95];
1232 static std::bitset<0xFFFF+1> glStateLock_;
1234 static bool blendFuncSeparateLock_[2];
1235 static bool blendEquationLock_;
1236 static bool blendColorLock_;
1237 static bool alphaFuncLock_;
1239 static bool depthRangeLock_;
1244 static int glBufferTargetLock_[4];
1247 static int glTextureStageLock_[16];
1250 static bool shadeModelLock_;
1253 static bool cullFaceLock_;
1255 static bool vertexPointerLock_;
1256 static bool normalPointerLock_;
1257 static bool texcoordPointerLock_;
1258 static bool colorPointerLock_;
1262 static bool drawBufferLock_;
1266 static bool framebufferLock_[2];
1269 static bool programLock_;
1273 static int maxTextureCoords_;
1274 static int maxCombinedTextureImageUnits_;
1275 static int maxDrawBuffers_;
1438 #pragma warning(push)
1444 #endif // ACG_GLSTATE_HH defined
void scale(double _s)
scale by (_s, _s, _s)
static void unlockBlendColor()
unlock blend color
float shininess() const
get specular shininess (must be in [0, 128])
static void vertexPointer(const Vec4d *_p)
Wrapper: glVertexPointer for Vec4d.
static int getActiveTextureIndex()
get active texture as zero based index
static void vertexPointer(const Vec4f *_p)
Wrapper: glVertexPointer for Vec4f.
bool multisampling_allowed()
Check if Multisampling is globally disabled.
static const Vec4f default_clear_color
default value for clear color
static const Vec4f default_ambient_color
default value for ambient color
Namespace providing different geometric functions concerning angles.
void allow_mipmapping(bool _b)
Allow mipmapping globally.
static void lockBlendFunc()
lock blend func
static bool isVertexPointerLocked()
get vertex pointer lock state
int context_height() const
get gl context height
double far_plane() const
get far clipping distance
unsigned int msSinceLastRedraw() const
time passed since last redraw in milliseconds
static void lockBlendEquation()
lock blend equation
static void unlockAlphaFunc()
unlock alpha func
bool blending()
get whether transparenet or solid objects should be drawn
static void vertexPointer(const Vec3d *_p)
Wrapper: glVertexPointer for Vec3d.
const Vec4f & clear_color() const
get background color
unsigned int render_pass() const
get current render pass counter
void next_render_pass()
increment render pass counter
static GLenum getActiveTexture()
get active GL texture
static void texcoordPointer(const Vec2d *_p)
Wrapper: glTexcoordPointer for Vec2d.
static GLenum getBlendEquation()
get blend equation
static void lockAlphaFunc()
lock alpha func
bool multisampling()
Get current multisampling state.
static void unlockVertexPointer()
unlock vertex pointer
static bool isColorPointerLocked()
get vertex pointer lock state
static void lockColorPointer()
lock color pointer
static void colorPointer(const Vec4uc *_p)
Wrapper: glColorPointer for Vec4uc.
static void texcoordPointer(const float *_p)
Wrapper: glTexcoordPointer for float.
static GLuint getProgram()
get bound program
VectorT< double, 3 > Vec3d
const GLMatrixd & modelview() const
get modelview matrix
static GLenum getCullFace()
get current cull face
const GLMatrixd & projection() const
get projection matrix
static void lockShadeModel()
lock shade model
static bool isBlendFuncSeparateAlphaLocked()
replaces glEnable, but supports locking
static bool isBlendColorLocked()
get blend color locking state
void reset_render_pass()
reset render pass counter
static void unlockBlendFuncSeparate()
unlock blend func
const GLMatrixd & inverse_projection() const
get inverse projection matrix
static void colorPointer(const Vec3f *_p)
Wrapper: glColorPointer for Vec3f.
const Vec4f & overlay_color() const
Get overlay color.
static bool isTexcoordPointerLocked()
get vertex pointer lock state
void set_blending(bool _b)
set whether transparent or solid objects should be drawn
static bool isDepthRangeLocked()
get depth range locking state
static void texcoordPointer(const Vec4d *_p)
Wrapper: glTexcoordPointer for Vec4d.
void makeCurrent()
does nothing
static bool isBlendFuncLocked()
get blend func locking state
static const Vec4f default_diffuse_color
default value for diffuse color
static bool isProgramLocked()
get program locking state
static void unlockTexcoordPointer()
unlock vertex pointer
void scale(double _s, MultiplyFrom)
scale by (_s, _s, _s)
static GLenum getShadeModel()
get current shade model
void set_max_render_passes(const unsigned int _max)
set maximum number of render passes
const Vec4f & color()
set color
static void lockVertexPointer()
lock vertex pointer
static void lockTexcoordPointer()
lock color pointer
int viewport_width() const
get viewport width
static void lockCullFace()
lock cull face
static void unlockDepthRange()
unlock depth range
static void lockBlendFuncSeparate(bool _rgb=true, bool _alpha=true)
lock blend func
static void blendFunc(GLenum _sfactor, GLenum _dfactor)
replaces glBlendFunc, supports locking
const Vec4f & specular_color() const
get specular color
const GLMatrixd & inverse_modelview() const
get inverse modelview matrix
static void activeTextureARB(GLenum _texunit)
same functiona as activeTexture
static void vertexPointer(const Vec3f *_p)
Wrapper: glVertexPointer for Vec3f.
float line_width() const
get line width
static void unlockProgram()
unlock the program
static const Vec4f default_base_color
default value for base color
static void colorPointer(const Vec3uc *_p)
Wrapper: glColorPointer for Vec3uc.
double near_plane() const
get near clipping distance
float point_size() const
get point size
bool mipmapping_allowed() const
Get current global mipmapping state.
static void texcoordPointer(const Vec3d *_p)
Wrapper: glTexcoordPointer for Vec3d.
static void unlockShadeModel()
unlock shade model
static bool isNormalPointerLocked()
get normal pointer lock state
static const Vec4f default_overlay_color
default value for overlay color
unsigned int max_render_passes_
static void vertexPointer(const Vec2f *_p)
Wrapper: glVertexPointer for Vec2f.
void set_updateGL(bool _b)
should GL matrices be updated after each matrix operation
static void colorPointer(const Vec4f *_p)
Wrapper: glColorPointer for Vec4f.
Vec3d viewing_direction() const
get viewing ray
unsigned int max_render_passes() const
get maximum number of render passes
static bool isBlendEquationLocked()
get blend equation locking state
void get_viewport(int &_left, int &_bottom, int &_width, int &_height) const
get viewport
const GLMatrixd & viewport() const
get viewport matrix
static bool isBlendFuncSeparateLocked()
get blend func locking state
static void unlockBlendFunc()
unlock blend func
static void normalPointer(const Vec3f *_p)
Wrapper: glNormalPointer for Vec3f.
static void texcoordPointer(const double *_p)
Wrapper: glTexcoordPointer for double.
static void lockNormalPointer()
lock normal pointer
static const float default_shininess
default value for shininess
static void lockDepthRange()
lock depth range
static void lockProgram()
lock the program
bool twosided_lighting()
get whether transparenet or solid objects should be drawn
static bool isShadeModelLocked()
get shade model locking state
static void vertexPointer(const Vec2d *_p)
Wrapper: glVertexPointer for Vec2d.
static bool isBlendFuncSeparateColorLocked()
replaces glEnable, but supports locking
void set_modelview(const GLMatrixd &_m)
set modelview
static void texcoordPointer(const Vec2f *_p)
Wrapper: glTexcoordPointer for Vec2f.
static void lockBlendColor()
lock blend color
static void lockDrawBuffer()
lock draw buffer state, applies to drawBuffer and drawBuffers
void set_msSinceLastRedraw(unsigned int _ms)
set time passed since last redraw in milliseconds
static void normalPointer(const Vec3d *_p)
Wrapper: glNormalPointer for Vec3d.
unsigned int render_pass_
const Vec4f & ambient_color() const
get ambient color
static bool isDrawBufferLocked()
get draw buffer lock state
static void bindBufferARB(GLenum _target, GLuint _buffer)
same function as bindBuffer
static void unlockDrawBuffer()
unlock draw buffer state
static bool isAlphaFuncLocked()
get alpha func locking state
void set_projection(const GLMatrixd &_m)
set projection
GLMatrixd forward_projection() const
get forward projection matrix
bool invert()
matrix inversion (returns true on success)
static bool isCullFaceLocked()
get cull face locking state
const Vec4f & base_color() const
get base color (used when lighting is off)
static void unlockBlendEquation()
unlock blend equation
static void unlockNormalPointer()
unlock normal pointer
int context_width() const
get gl context width
static void texcoordPointer(const Vec3f *_p)
Wrapper: glTexcoordPointer for Vec3f.
int viewport_height() const
get viewport height
static const Vec4f default_specular_color
default value for specular color
static void getBlendFunc(GLenum *_sfactor, GLenum *_dfactor)
get blend function, null-ptr safe
static void unlockCullFace()
unlock cull face
static void unlockColorPointer()
unlock vertex pointer
void allow_multisampling(bool _b)
Disable multisampling globally.
const Vec4f & diffuse_color() const
get diffuse color
bool updateGL() const
should GL matrices be updated after each matrix operation
static void texcoordPointer(const Vec4f *_p)
Wrapper: glTexcoordPointer for Vec4f.
int max_texture_units() const
Get max number of available texture units.