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 size_t getBufferSize(GLenum _target);
574 static void deleteBuffers(GLsizei n,
const GLuint* buffers);
577 static void bindBuffer(GLenum _target, GLuint _buffer);
579 static void bindBufferARB(GLenum _target, GLuint _buffer) {bindBuffer(_target, _buffer);}
582 static void lockBufferTarget(GLenum _target);
585 static void unlockBufferTarget(GLenum _target);
588 static bool isBufferTargetLocked(GLenum _target);
591 static GLuint getBoundBuf(GLenum _target);
595 static GLenum getShaderType(GLuint _shader);
599 static size_t getShaderSourceLength(GLuint _shader);
604 static size_t getShaderSource(GLuint _shader,
char* _buffer,
size_t _bufferSize);
611 static GLuint getAttachedShader(GLuint _program, GLenum _type);
614 static void drawBuffer(GLenum _mode);
616 static void drawBuffers(GLsizei _n,
const GLenum* _bufs);
627 static void bindFramebuffer(GLenum _target, GLuint _framebuffer);
629 static GLuint getFramebufferDraw();
631 static GLuint getFramebufferRead();
634 static void lockFramebuffer(GLenum _target);
636 static void unlockFramebuffer(GLenum _target);
638 static bool isFramebufferLocked(GLenum _target);
649 static void useProgram(GLuint _program);
651 static GLuint
getProgram() {
return stateStack_.back().program_;}
666 static int getBufferTargetIndex(GLenum _target);
676 static void activeTexture(GLenum _texunit);
687 static void bindTexture(GLenum _target, GLuint _buffer);
690 static void lockTextureStage();
693 static void unlockTextureStage();
696 static bool isTextureTargetLocked();
699 static GLuint getBoundTextureBuffer();
701 static GLenum getBoundTextureTarget();
713 void reset_projection();
723 void ortho(
double _left,
double _right,
724 double _bottom,
double _top,
725 double _near_plane,
double _far_plane );
728 void frustum(
double _left,
double _right,
729 double _bottom,
double _top,
730 double _near_plane,
double _far_plane );
733 void perspective(
double _fovY,
double _aspect,
734 double _near_plane,
double _far_plane );
737 void viewport(
int _left,
int _bottom,
int _width,
int _height,
738 int _glwidth = 0,
int _glheight = 0);
750 void reset_modelview();
760 void lookAt(
const Vec3d& _eye,
const Vec3d& _center,
const Vec3d& _up );
763 void translate(
double _x,
double _y,
double _z,
767 void translate(
Vec3d _vector,
771 void rotate(
double _angle,
double _x,
double _y,
double _z,
776 { scale(_s, _s, _s); }
781 { scale(_s, _s, _s); }
784 void scale(
double _sx,
double _sy,
double _sz,
793 void push_projection_matrix();
795 void pop_projection_matrix();
798 void push_modelview_matrix();
800 void pop_modelview_matrix();
822 return window2viewport_;
827 return window2viewport_ * projection_ * modelview_;
832 return inverse_projection_;
837 return inverse_modelview_;
842 int& _width,
int& _height )
const {
843 _left = left_; _bottom = bottom_; _width = width_; _height = height_;
867 double aspect()
const;
874 return viewing_direction(width_>>1, height_>>1);
878 Vec3d viewing_direction(
int _x,
int _y)
const;
889 void viewing_ray(
int _x,
int _y,
Vec3d& _origin,
Vec3d& _direction)
const;
894 const GLenum& depthFunc()
const;
897 void set_depthFunc(
const GLenum& _depth_func);
901 static void depthFunc(GLenum _depthFunc);
903 inline static void lockDepthFunc() {depthFuncLock_ =
true;}
904 inline static void unlockDepthFunc() {depthFuncLock_ =
false;}
905 inline static bool isDepthFuncLocked() {
return depthFuncLock_;}
914 Vec3d unproject(
const Vec3d& _winPoint)
const;
938 void set_color(
const Vec4f& _col);
944 void set_clear_color(
const Vec4f& _col);
949 void set_base_color(
const Vec4f& _col);
954 void set_ambient_color(
const Vec4f& _col);
959 void set_diffuse_color(
const Vec4f& _col);
964 void set_specular_color(
const Vec4f& _col);
973 void set_overlay_color(
const Vec4f& _col);
983 void set_shininess(
float _shininess);
993 void set_point_size(
float _f);
998 void set_line_width(
float _f);
1063 void set_twosided_lighting(
bool _b);
1070 void set_multisampling(
bool _b );
1108 void pick_init (
bool _color);
1120 bool pick_set_maximum (
size_t _idx);
1132 void pick_set_name (
size_t _idx);
1137 Vec4uc pick_get_name_color (
size_t _idx);
1140 Vec4f pick_get_name_color_norm (
unsigned int _idx);
1143 void pick_push_name (
size_t _idx);
1146 void pick_pop_name ();
1150 std::vector<size_t> pick_color_to_stack (
Vec4uc _rgba)
const;
1153 size_t pick_free_indicies ()
const;
1157 bool pick_error ()
const;
1168 size_t pick_current_index ()
const;
1171 bool color_picking ()
const;
1177 std::stack<GLMatrixd> stack_projection_,
1179 stack_inverse_projection_,
1180 stack_inverse_modelview_;
1184 inverse_projection_,
1188 inverse_window2viewport_;
1191 int left_, bottom_, width_, height_;
1194 int glwidth_, glheight_;
1197 double near_plane_, far_plane_;
1203 Vec4f ambient_color_;
1204 Vec4f diffuse_color_;
1205 Vec4f specular_color_;
1206 Vec4f overlay_color_;
1212 float point_size_, line_width_;
1215 bool twosided_lighting_;
1218 bool multisampling_;
1219 bool allow_multisampling_;
1221 static int num_texture_units_;
1233 unsigned int msSinceLastRedraw_;
1243 static bool depthFuncLock_;
1250 static std::deque <GLStateContext> stateStack_;
1253 static GLenum glStateCaps[95];
1257 static std::bitset<0xFFFF+1> glStateLock_;
1259 static bool blendFuncSeparateLock_[2];
1260 static bool blendEquationLock_;
1261 static bool blendColorLock_;
1262 static bool alphaFuncLock_;
1264 static bool depthRangeLock_;
1269 static int glBufferTargetLock_[4];
1272 static int glTextureStageLock_[16];
1275 static bool shadeModelLock_;
1278 static bool cullFaceLock_;
1280 static bool vertexPointerLock_;
1281 static bool normalPointerLock_;
1282 static bool texcoordPointerLock_;
1283 static bool colorPointerLock_;
1287 static bool drawBufferLock_;
1291 static bool framebufferLock_[2];
1294 static bool programLock_;
1298 static int maxTextureCoords_;
1299 static int maxCombinedTextureImageUnits_;
1300 static int maxDrawBuffers_;
1463 #pragma warning(push) 1469 #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