49 #ifndef ACG_GLSTATE_HH 50 #define ACG_GLSTATE_HH 57 #include "../Math/GLMatrixT.hh" 58 #include "../Math/VectorT.hh" 59 #include "../Config/ACGDefines.hh" 60 #include "ColorStack.hh" 68 #pragma warning(disable:4251) 124 std::bitset<0xFFFF+1> glStateEnabled_;
127 GLenum blendFuncState_[4];
129 GLenum blendEquationState_;
131 GLclampf blendColorState_[4];
133 GLenum alphaFuncState_;
134 GLclampf alphaRefState_;
142 GLuint glBufferTargetState_[14];
146 GLenum activeTexture_;
170 GLclampd depthRange_[2];
180 const GLvoid* pointer;
182 bool equals(GLint _size, GLenum _type, GLsizei _stride,
const GLvoid* _ptr)
184 return (size == _size && _type == type && _stride == stride && pointer == _ptr);
187 void set(GLint _size, GLenum _type, GLsizei _stride,
const GLvoid* _ptr)
189 size = _size; type = _type; stride = _stride; pointer = _ptr;
200 GLenum drawBufferSingle_;
201 GLenum drawBufferState_[16];
202 int activeDrawBuffer_;
206 GLuint framebuffers_[2];
218 GLState(
bool _updateGL =
true,
bool _compatibilityProfile =
true );
227 static void syncFromGL();
247 void clearBuffers ();
254 void setCompatibilityProfile(
bool _compatibility );
260 bool compatibilityProfile_;
272 static void enable(GLenum _cap,
bool _warnRemoved =
true);
275 static void disable(GLenum _cap,
bool _warnRemoved =
true);
278 static void lockState(GLenum _cap);
281 static void unlockState(GLenum _cap);
284 static bool isStateLocked(GLenum _cap);
287 static bool isStateEnabled(GLenum _cap);
291 static void enableClientState(GLenum _cap);
293 static void disableClientState(GLenum _cap);
296 static void lockClientState(GLenum _cap);
298 static void unlockClientState(GLenum _cap);
301 static bool isClientStateEnabled(GLenum _cap);
303 static bool isClientStateLocked(GLenum _cap);
307 static void blendFunc(GLenum _sfactor, GLenum _dfactor) { blendFuncSeparate(_sfactor, _dfactor, _sfactor, _dfactor); }
310 static void getBlendFunc(GLenum* _sfactor, GLenum* _dfactor) { getBlendFuncSeparate(_sfactor, _dfactor, 0, 0); }
322 static void blendFuncSeparate(GLenum _srcRGB, GLenum _dstRGB, GLenum _srcAlpha, GLenum _dstAlpha);
325 static void getBlendFuncSeparate(GLenum* _srcRGB, GLenum* _dstRGB, GLenum* _srcAlpha, GLenum* _dstAlpha);
328 static void lockBlendFuncSeparate(
bool _rgb =
true,
bool _alpha =
true) { blendFuncSeparateLock_[0] = _rgb; blendFuncSeparateLock_[1] = _alpha; }
338 static void blendEquation(GLenum _mode);
351 static void blendColor(GLclampf _red, GLclampf _green, GLclampf _blue, GLclampf _alpha);
354 static void getBlendColor(GLclampf* _col);
365 static void alphaFunc(GLenum _func, GLclampf _ref);
368 static void getAlphaFunc(GLenum* _func, GLclampf* _ref);
379 static void shadeModel(GLenum _mode);
391 static void cullFace(GLenum _mode);
393 static GLenum
getCullFace() {
return stateStack_.back().cullFace_;}
402 static void depthRange(GLclampd _zNear, GLclampd _zFar);
404 static void getDepthRange(GLclampd* _zNearOut, GLclampd* _zFarOut);
420 static void vertexPointer(GLint _size, GLenum _type, GLsizei _stride,
const GLvoid* _pointer);
422 static void getVertexPointer(GLint* _size, GLenum* _type, GLsizei* _stride,
const GLvoid** _pointer);
445 static void normalPointer(GLenum _type, GLsizei _stride,
const GLvoid* _pointer);
447 static void getNormalPointer(GLenum* _type, GLsizei* _stride,
const GLvoid** _pointer);
463 static void colorPointer(GLint _size, GLenum _type, GLsizei _stride,
const GLvoid* _pointer);
465 static void getColorPointer(GLint* _size, GLenum* _type, GLsizei* _stride,
const GLvoid** _pointer);
485 static void texcoordPointer(GLint _size, GLenum _type, GLsizei _stride,
const GLvoid* _pointer);
487 static void getTexcoordPointer(GLint* _size, GLenum* _type, GLsizei* _stride,
const GLvoid** _pointer);
507 static void setTexGenMode(GLenum _coord, GLenum _name, GLint _param);
509 static void getTexGenMode(GLenum _coord, GLenum _name, GLint* _param);
530 static void genBuffersARB(GLsizei n, GLuint* buffers);
536 static void genBuffers(GLsizei n, GLuint* buffers);
542 static void bufferDataARB(
543 GLenum target, GLsizeiptrARB size,
const GLvoid *data, GLenum usage);
549 static void bufferData(
550 GLenum target, GLsizeiptr size,
const GLvoid* data, GLenum usage);
556 static GLvoid* mapBuffer (GLenum target, GLenum access);
562 static GLboolean unmapBuffer (GLenum target);
568 static void deleteBuffers(GLsizei n,
const GLuint* buffers);
571 static void bindBuffer(GLenum _target, GLuint _buffer);
573 static void bindBufferARB(GLenum _target, GLuint _buffer) {bindBuffer(_target, _buffer);}
576 static void lockBufferTarget(GLenum _target);
579 static void unlockBufferTarget(GLenum _target);
582 static bool isBufferTargetLocked(GLenum _target);
585 static GLuint getBoundBuf(GLenum _target);
589 static void drawBuffer(GLenum _mode);
591 static void drawBuffers(GLsizei _n,
const GLenum* _bufs);
602 static void bindFramebuffer(GLenum _target, GLuint _framebuffer);
604 static GLuint getFramebufferDraw();
606 static GLuint getFramebufferRead();
609 static void lockFramebuffer(GLenum _target);
611 static void unlockFramebuffer(GLenum _target);
613 static bool isFramebufferLocked(GLenum _target);
624 static void useProgram(GLuint _program);
626 static GLuint
getProgram() {
return stateStack_.back().program_;}
641 static int getBufferTargetIndex(GLenum _target);
651 static void activeTexture(GLenum _texunit);
662 static void bindTexture(GLenum _target, GLuint _buffer);
665 static void lockTextureStage();
668 static void unlockTextureStage();
671 static bool isTextureTargetLocked();
674 static GLuint getBoundTextureBuffer();
676 static GLenum getBoundTextureTarget();
688 void reset_projection();
698 void ortho(
double _left,
double _right,
699 double _bottom,
double _top,
700 double _near_plane,
double _far_plane );
703 void frustum(
double _left,
double _right,
704 double _bottom,
double _top,
705 double _near_plane,
double _far_plane );
708 void perspective(
double _fovY,
double _aspect,
709 double _near_plane,
double _far_plane );
712 void viewport(
int _left,
int _bottom,
int _width,
int _height,
713 int _glwidth = 0,
int _glheight = 0);
725 void reset_modelview();
735 void lookAt(
const Vec3d& _eye,
const Vec3d& _center,
const Vec3d& _up );
738 void translate(
double _x,
double _y,
double _z,
742 void translate(
Vec3d _vector,
746 void rotate(
double _angle,
double _x,
double _y,
double _z,
751 { scale(_s, _s, _s); }
756 { scale(_s, _s, _s); }
759 void scale(
double _sx,
double _sy,
double _sz,
768 void push_projection_matrix();
770 void pop_projection_matrix();
773 void push_modelview_matrix();
775 void pop_modelview_matrix();
797 return window2viewport_;
802 return window2viewport_ * projection_ * modelview_;
807 return inverse_projection_;
812 return inverse_modelview_;
817 int& _width,
int& _height )
const {
818 _left = left_; _bottom = bottom_; _width = width_; _height = height_;
842 double aspect()
const;
849 return viewing_direction(width_>>1, height_>>1);
853 Vec3d viewing_direction(
int _x,
int _y)
const;
864 void viewing_ray(
int _x,
int _y,
Vec3d& _origin,
Vec3d& _direction)
const;
869 const GLenum& depthFunc()
const;
872 void set_depthFunc(
const GLenum& _depth_func);
876 static void depthFunc(GLenum _depthFunc);
878 inline static void lockDepthFunc() {depthFuncLock_ =
true;}
879 inline static void unlockDepthFunc() {depthFuncLock_ =
false;}
880 inline static bool isDepthFuncLocked() {
return depthFuncLock_;}
889 Vec3d unproject(
const Vec3d& _winPoint)
const;
913 void set_color(
const Vec4f& _col);
919 void set_clear_color(
const Vec4f& _col);
924 void set_base_color(
const Vec4f& _col);
929 void set_ambient_color(
const Vec4f& _col);
934 void set_diffuse_color(
const Vec4f& _col);
939 void set_specular_color(
const Vec4f& _col);
948 void set_overlay_color(
const Vec4f& _col);
958 void set_shininess(
float _shininess);
968 void set_point_size(
float _f);
973 void set_line_width(
float _f);
1038 void set_twosided_lighting(
bool _b);
1045 void set_multisampling(
bool _b );
1083 void pick_init (
bool _color);
1095 bool pick_set_maximum (
size_t _idx);
1107 void pick_set_name (
size_t _idx);
1112 Vec4uc pick_get_name_color (
size_t _idx);
1115 Vec4f pick_get_name_color_norm (
unsigned int _idx);
1118 void pick_push_name (
size_t _idx);
1121 void pick_pop_name ();
1125 std::vector<size_t> pick_color_to_stack (
Vec4uc _rgba)
const;
1128 size_t pick_free_indicies ()
const;
1132 bool pick_error ()
const;
1143 size_t 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 static void colorPointer(const Vec4uc *_p)
Wrapper: glColorPointer for Vec4uc.
static void texcoordPointer(const Vec2d *_p)
Wrapper: glTexcoordPointer for Vec2d.
static bool isVertexPointerLocked()
get vertex pointer lock state
static void texcoordPointer(const double *_p)
Wrapper: glTexcoordPointer for double.
static void vertexPointer(const Vec2f *_p)
Wrapper: glVertexPointer for Vec2f.
static bool isTexcoordPointerLocked()
get vertex pointer lock state
Vec3d viewing_direction() const
get viewing ray
static void lockProgram()
lock the program
bool multisampling_allowed()
Check if Multisampling is globally disabled.
static void lockAlphaFunc()
lock alpha func
static const Vec4f default_base_color
default value for base color
static const Vec4f default_diffuse_color
default value for diffuse color
static const Vec4f default_clear_color
default value for clear color
static void unlockDrawBuffer()
unlock draw buffer state
const Vec4f & specular_color() const
get specular color
unsigned int render_pass_
float point_size() const
get point size
int viewport_width() const
get viewport width
Namespace providing different geometric functions concerning angles.
double near_plane() const
get near clipping distance
const Vec4f & overlay_color() const
Get overlay color.
static void unlockDepthRange()
unlock depth range
static void normalPointer(const Vec3f *_p)
Wrapper: glNormalPointer for Vec3f.
const Vec4f & color()
set color
static bool isNormalPointerLocked()
get normal pointer lock state
static void lockBlendFuncSeparate(bool _rgb=true, bool _alpha=true)
lock blend func
GLMatrixd forward_projection() const
get forward projection matrix
const Vec4f & base_color() const
get base color (used when lighting is off)
static bool isBlendFuncLocked()
get blend func locking state
void get_viewport(int &_left, int &_bottom, int &_width, int &_height) const
get viewport
static void normalPointer(const Vec3d *_p)
Wrapper: glNormalPointer for Vec3d.
void scale(double _s, MultiplyFrom)
scale by (_s, _s, _s)
static void unlockProgram()
unlock the program
static void texcoordPointer(const float *_p)
Wrapper: glTexcoordPointer for float.
static void colorPointer(const Vec3uc *_p)
Wrapper: glColorPointer for Vec3uc.
void scale(double _s)
scale by (_s, _s, _s)
static void unlockVertexPointer()
unlock vertex pointer
const Vec4f & diffuse_color() const
get diffuse color
static bool isColorPointerLocked()
get vertex pointer lock state
float shininess() const
get specular shininess (must be in [0, 128])
static void colorPointer(const Vec4f *_p)
Wrapper: glColorPointer for Vec4f.
static void unlockBlendColor()
unlock blend color
static GLenum getBlendEquation()
get blend equation
void set_updateGL(bool _b)
should GL matrices be updated after each matrix operation
static bool isBlendFuncSeparateAlphaLocked()
replaces glEnable, but supports locking
static void vertexPointer(const Vec3d *_p)
Wrapper: glVertexPointer for Vec3d.
static void texcoordPointer(const Vec3f *_p)
Wrapper: glTexcoordPointer for Vec3f.
static const Vec4f default_ambient_color
default value for ambient color
bool invert()
matrix inversion (returns true on success)
void set_modelview(const GLMatrixd &_m)
set modelview
bool updateGL() const
should GL matrices be updated after each matrix operation
static void lockDepthRange()
lock depth range
static void unlockBlendEquation()
unlock blend equation
void set_msSinceLastRedraw(unsigned int _ms)
set time passed since last redraw in milliseconds
void reset_render_pass()
reset render pass counter
void set_blending(bool _b)
set whether transparent or solid objects should be drawn
const GLMatrixd & inverse_modelview() const
get inverse modelview matrix
static void lockShadeModel()
lock shade model
const GLMatrixd & inverse_projection() const
get inverse projection matrix
static void unlockTexcoordPointer()
unlock vertex pointer
static void getBlendFunc(GLenum *_sfactor, GLenum *_dfactor)
get blend function, null-ptr safe
static void lockVertexPointer()
lock vertex pointer
static int getActiveTextureIndex()
get active texture as zero based index
void allow_multisampling(bool _b)
Disable multisampling globally.
static void vertexPointer(const Vec4f *_p)
Wrapper: glVertexPointer for Vec4f.
static void activeTextureARB(GLenum _texunit)
same functiona as activeTexture
static void lockColorPointer()
lock color pointer
unsigned int render_pass() const
get current render pass counter
int viewport_height() const
get viewport height
static bool isBlendEquationLocked()
get blend equation locking state
static void lockDrawBuffer()
lock draw buffer state, applies to drawBuffer and drawBuffers
static GLenum getShadeModel()
get current shade model
static bool isDrawBufferLocked()
get draw buffer lock state
static GLenum getActiveTexture()
get active GL texture
void set_max_render_passes(const unsigned int _max)
set maximum number of render passes
void next_render_pass()
increment render pass counter
static void blendFunc(GLenum _sfactor, GLenum _dfactor)
replaces glBlendFunc, supports locking
static void lockNormalPointer()
lock normal pointer
unsigned int max_render_passes_
static void lockBlendColor()
lock blend color
static void texcoordPointer(const Vec2f *_p)
Wrapper: glTexcoordPointer for Vec2f.
static const float default_shininess
default value for shininess
static void colorPointer(const Vec3f *_p)
Wrapper: glColorPointer for Vec3f.
static bool isAlphaFuncLocked()
get alpha func locking state
static void texcoordPointer(const Vec4f *_p)
Wrapper: glTexcoordPointer for Vec4f.
static bool isShadeModelLocked()
get shade model locking state
int max_texture_units() const
Get max number of available texture units.
static void lockBlendFunc()
lock blend func
static void lockCullFace()
lock cull face
const GLMatrixd & viewport() const
get viewport matrix
static bool isDepthRangeLocked()
get depth range locking state
void makeCurrent()
does nothing
static bool isProgramLocked()
get program locking state
static void unlockCullFace()
unlock cull face
static const Vec4f default_overlay_color
default value for overlay color
static void texcoordPointer(const Vec4d *_p)
Wrapper: glTexcoordPointer for Vec4d.
static const Vec4f default_specular_color
default value for specular color
static void vertexPointer(const Vec4d *_p)
Wrapper: glVertexPointer for Vec4d.
static void unlockColorPointer()
unlock vertex pointer
const GLMatrixd & modelview() const
get modelview matrix
static void bindBufferARB(GLenum _target, GLuint _buffer)
same function as bindBuffer
static void unlockShadeModel()
unlock shade model
static bool isBlendFuncSeparateColorLocked()
replaces glEnable, but supports locking
void compatibilityProfile(bool _enableCoreProfile)
Store opengl core profile setting.
void allow_mipmapping(bool _b)
Allow mipmapping globally.
void set_projection(const GLMatrixd &_m)
set projection
bool blending()
get whether transparenet or solid objects should be drawn
int context_height() const
get gl context height
static void unlockNormalPointer()
unlock normal pointer
static GLuint getProgram()
get bound program
float line_width() const
get line width
unsigned int msSinceLastRedraw() const
time passed since last redraw in milliseconds
static GLenum getCullFace()
get current cull face
unsigned int max_render_passes() const
get maximum number of render passes
static void unlockAlphaFunc()
unlock alpha func
const GLMatrixd & projection() const
get projection matrix
bool multisampling()
Get current multisampling state.
bool mipmapping_allowed() const
Get current global mipmapping state.
static bool isBlendFuncSeparateLocked()
get blend func locking state
static void unlockBlendFuncSeparate()
unlock blend func
static void vertexPointer(const Vec3f *_p)
Wrapper: glVertexPointer for Vec3f.
const Vec4f & clear_color() const
get background color
double far_plane() const
get far clipping distance
bool twosided_lighting()
get whether transparenet or solid objects should be drawn
static void unlockBlendFunc()
unlock blend func
static void texcoordPointer(const Vec3d *_p)
Wrapper: glTexcoordPointer for Vec3d.
static bool isBlendColorLocked()
get blend color locking state
static void lockTexcoordPointer()
lock color pointer
static void lockBlendEquation()
lock blend equation
const Vec4f & ambient_color() const
get ambient color
int context_width() const
get gl context width
static void vertexPointer(const Vec2d *_p)
Wrapper: glVertexPointer for Vec2d.
static bool isCullFaceLocked()
get cull face locking state