Developer Documentation
GLState.hh
1 /*===========================================================================*\
2  * *
3  * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39  * *
40 \*===========================================================================*/
41 
42 //=============================================================================
43 //
44 // CLASS GLState
45 //
46 //=============================================================================
47 
48 
49 #ifndef ACG_GLSTATE_HH
50 #define ACG_GLSTATE_HH
51 
52 
53 //== INCLUDES =================================================================
54 
55 
56 #include "gl.hh"
57 #include "../Math/GLMatrixT.hh"
58 #include "../Math/VectorT.hh"
59 #include "../Config/ACGDefines.hh"
60 #include "ColorStack.hh"
61 #include <stack>
62 #include <vector>
63 #include <bitset>
64 #include <deque>
65 
66 #ifdef _MSC_VER
67  #pragma warning(push)
68  #pragma warning(disable:4251)
69 #endif
70 
71 //== NAMESPACES ===============================================================
72 
73 
74 namespace ACG {
75 
76 
77 //== CLASS DEFINITION =========================================================
78 
79 
114 {
115  // this struct is needed for push/popAttrib operations
116  // it contains a copy of the OpenGL state machine
117 
118 public:
119  GLStateContext();
120 
121 
122  // glEnable / glDisable states
123  // iff a bit is set for a state, it is enabled in OpenGL
124  std::bitset<0xFFFF+1> glStateEnabled_;
125 
126  // element 0: sfactor, 1: dfactor, 2 : alpha_sfactor, 3 : alpha_dfactor
127  GLenum blendFuncState_[4];
128 
129  GLenum blendEquationState_;
130 
131  GLclampf blendColorState_[4];
132 
133  GLenum alphaFuncState_;
134  GLclampf alphaRefState_;
135 
136  // depth function
137  GLenum depthFunc_;
138 
139  // buffer targets available in opengl:
140  // GL_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER, GL_PIXEL_PACK_BUFFER, GL_PIXEL_UNPACK_BUFFER, GL_UNIFORM_BUFFER, GL_SHADER_STORAGE_BUFFER ...
141  // current state of a buffer target
142  GLuint glBufferTargetState_[14];
143 
144 
145  // active texture unit: GL_TEXTUREi
146  GLenum activeTexture_;
147 
148  // texture generation mode we only support one mode for all coordinates
149  GLint texGenMode_;
150 
152  {
153  TextureStage() : target_(0), buf_(0) {}
154  // current stage target
155  GLenum target_;
156  // current stage buffer
157  GLuint buf_;
158  };
159  // 16 texture stages
160  TextureStage glTextureStage_[16];
161 
162  // current shade model: GL_FLAT, GL_SMOOTH, set by glShadeModel
163  GLenum shadeModel_;
164 
165  // current cull face mode: GL_FRONT, GL_FRONT_AND_BACK
166  GLenum cullFace_;
167 
168 
169  // current depth range: zNear and zFar
170  GLclampd depthRange_[2];
171 
172  // vertex pointers, used in glVertexPointer, glTexcoordPointer..
174  {
175  GLVertexPointer() : size(0), type(0), stride(0), pointer(0) {}
176 
177  GLint size;
178  GLenum type;
179  GLsizei stride;
180  const GLvoid* pointer;
181 
182  bool equals(GLint _size, GLenum _type, GLsizei _stride, const GLvoid* _ptr)
183  {
184  return (size == _size && _type == type && _stride == stride && pointer == _ptr);
185  }
186 
187  void set(GLint _size, GLenum _type, GLsizei _stride, const GLvoid* _ptr)
188  {
189  size = _size; type = _type; stride = _stride; pointer = _ptr;
190  }
191  };
192 
193  GLVertexPointer vertexPointer_;
194  GLVertexPointer normalPointer_;
195  GLVertexPointer texcoordPointer_;
196  GLVertexPointer colorPointer_;
197 
198 
199  // draw buffers
200  GLenum drawBufferSingle_;
201  GLenum drawBufferState_[16];
202  int activeDrawBuffer_; // = 0 -> drawBufferSignle_; != 0 -> drawBufferState
203 
204  // framebuffer
205  // framebuffer id for each target: 0 - GL_DRAW_FRAMEBUFFER, 1-> GL_READ_FRAMEBUFFER
206  GLuint framebuffers_[2];
207 
208  // current gl shader program
209  GLuint program_;
210 };
211 
212 
213 class ACGDLLEXPORT GLState
214 {
215 public:
216 
218  GLState(bool _updateGL = true, bool _compatibilityProfile = true );
219 
221  ~GLState() {}
222 
224  void makeCurrent() { }
225 
227  static void syncFromGL();
228 
230  void initialize();
231 
233  bool updateGL() const { return updateGL_; }
235  void set_updateGL(bool _b) { updateGL_ = _b; }
236 
238  unsigned int msSinceLastRedraw () const { return msSinceLastRedraw_; }
239 
241  void set_msSinceLastRedraw (unsigned int _ms) { msSinceLastRedraw_ = _ms; }
242 
244  void setState ();
245 
247  void clearBuffers ();
248 
249  //===========================================================================
252  //===========================================================================
253 
254  void setCompatibilityProfile( bool _compatibility );
255 
256  bool compatibilityProfile() const;
257 
258 private:
259 
260  bool compatibilityProfile_;
261 
264  //===========================================================================
267  //===========================================================================
268 
269 public:
270 
272  static void enable(GLenum _cap, bool _warnRemoved = true);
273 
275  static void disable(GLenum _cap, bool _warnRemoved = true);
276 
278  static void lockState(GLenum _cap);
279 
281  static void unlockState(GLenum _cap);
282 
284  static bool isStateLocked(GLenum _cap);
285 
287  static bool isStateEnabled(GLenum _cap);
288 
289 
291  static void enableClientState(GLenum _cap);
293  static void disableClientState(GLenum _cap);
294 
296  static void lockClientState(GLenum _cap);
298  static void unlockClientState(GLenum _cap);
299 
301  static bool isClientStateEnabled(GLenum _cap);
303  static bool isClientStateLocked(GLenum _cap);
304 
305 
307  static void blendFunc(GLenum _sfactor, GLenum _dfactor) { blendFuncSeparate(_sfactor, _dfactor, _sfactor, _dfactor); }
308 
310  static void getBlendFunc(GLenum* _sfactor, GLenum* _dfactor) { getBlendFuncSeparate(_sfactor, _dfactor, 0, 0); }
311 
313  static void lockBlendFunc() { lockBlendFuncSeparate(); }
315  static void unlockBlendFunc() { unlockBlendFuncSeparate(); }
317  static bool isBlendFuncLocked() {return isBlendFuncSeparateLocked();}
318 
319 
320 
322  static void blendFuncSeparate(GLenum _srcRGB, GLenum _dstRGB, GLenum _srcAlpha, GLenum _dstAlpha);
323 
325  static void getBlendFuncSeparate(GLenum* _srcRGB, GLenum* _dstRGB, GLenum* _srcAlpha, GLenum* _dstAlpha);
326 
328  static void lockBlendFuncSeparate(bool _rgb = true, bool _alpha = true) { blendFuncSeparateLock_[0] = _rgb; blendFuncSeparateLock_[1] = _alpha; }
330  static void unlockBlendFuncSeparate() { lockBlendFuncSeparate(false, false); }
332  static bool isBlendFuncSeparateLocked() { return blendFuncSeparateLock_[0] || blendFuncSeparateLock_[1]; }
333  static bool isBlendFuncSeparateColorLocked() { return blendFuncSeparateLock_[0]; }
334  static bool isBlendFuncSeparateAlphaLocked() { return blendFuncSeparateLock_[1]; }
335 
336 
338  static void blendEquation(GLenum _mode);
339 
341  static GLenum getBlendEquation() {return stateStack_.back().blendEquationState_;}
342 
344  static void lockBlendEquation() {blendEquationLock_ = true;}
346  static void unlockBlendEquation() {blendEquationLock_ = false;}
348  static bool isBlendEquationLocked() {return blendEquationLock_;}
349 
351  static void blendColor(GLclampf _red, GLclampf _green, GLclampf _blue, GLclampf _alpha);
352 
354  static void getBlendColor(GLclampf* _col);
355 
357  static void lockBlendColor() {blendColorLock_ = true;}
359  static void unlockBlendColor() {blendColorLock_ = false;}
361  static bool isBlendColorLocked() {return blendColorLock_;}
362 
363 
365  static void alphaFunc(GLenum _func, GLclampf _ref);
366 
368  static void getAlphaFunc(GLenum* _func, GLclampf* _ref);
369 
371  static void lockAlphaFunc() {alphaFuncLock_ = true;}
373  static void unlockAlphaFunc() {alphaFuncLock_ = false;}
375  static bool isAlphaFuncLocked() {return alphaFuncLock_;}
376 
377 
379  static void shadeModel(GLenum _mode);
381  static GLenum getShadeModel() {return stateStack_.back().shadeModel_;}
383  static void lockShadeModel() {shadeModelLock_ = true;}
385  static void unlockShadeModel() {shadeModelLock_ = false;}
387  static bool isShadeModelLocked() {return shadeModelLock_;}
388 
389 
391  static void cullFace(GLenum _mode);
393  static GLenum getCullFace() {return stateStack_.back().cullFace_;}
395  static void lockCullFace() {cullFaceLock_ = true;}
397  static void unlockCullFace() {cullFaceLock_ = false;}
399  static bool isCullFaceLocked() {return cullFaceLock_;}
400 
402  static void depthRange(GLclampd _zNear, GLclampd _zFar);
404  static void getDepthRange(GLclampd* _zNearOut, GLclampd* _zFarOut);
406  static void lockDepthRange() {depthRangeLock_ = true;}
408  static void unlockDepthRange() {depthRangeLock_ = false;}
410  static bool isDepthRangeLocked() {return depthRangeLock_;}
411 
414  //===========================================================================
417  //===========================================================================
418 
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);
423 
425  static void vertexPointer(const Vec2f* _p) {vertexPointer(2, GL_FLOAT, 0, _p);}
427  static void vertexPointer(const Vec2d* _p) {vertexPointer(2, GL_DOUBLE, 0, _p);}
429  static void vertexPointer(const Vec3f* _p) {vertexPointer(3, GL_FLOAT, 0, _p);}
431  static void vertexPointer(const Vec3d* _p) {vertexPointer(3, GL_DOUBLE, 0, _p);}
433  static void vertexPointer(const Vec4f* _p) {vertexPointer(4, GL_FLOAT, 0, _p);}
435  static void vertexPointer(const Vec4d* _p) {vertexPointer(4, GL_DOUBLE, 0, _p);}
436 
438  static void lockVertexPointer() {vertexPointerLock_ = true;}
440  static void unlockVertexPointer() {vertexPointerLock_ = false;}
442  static bool isVertexPointerLocked() {return vertexPointerLock_;}
443 
445  static void normalPointer(GLenum _type, GLsizei _stride, const GLvoid* _pointer);
447  static void getNormalPointer(GLenum* _type, GLsizei* _stride, const GLvoid** _pointer);
448 
450  static void normalPointer(const Vec3f* _p) { glNormalPointer(GL_FLOAT, 0, _p); }
452  static void normalPointer(const Vec3d* _p) { glNormalPointer(GL_DOUBLE, 0, _p); }
453 
455  static void lockNormalPointer() {normalPointerLock_ = true;}
457  static void unlockNormalPointer() {normalPointerLock_ = false;}
459  static bool isNormalPointerLocked() {return normalPointerLock_;}
460 
461 
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);
466 
468  static void colorPointer(const Vec3uc* _p) {colorPointer(3, GL_UNSIGNED_BYTE, 0, _p);}
470  static void colorPointer(const Vec3f* _p) {colorPointer(3, GL_FLOAT, 0, _p);}
472  static void colorPointer(const Vec4uc* _p) {colorPointer(4, GL_UNSIGNED_BYTE, 0, _p);}
474  static void colorPointer(const Vec4f* _p) {colorPointer(4, GL_FLOAT, 0, _p);}
475 
477  static void lockColorPointer() {colorPointerLock_ = true;}
479  static void unlockColorPointer() {colorPointerLock_ = false;}
481  static bool isColorPointerLocked() {return colorPointerLock_;}
482 
483 
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);
488 
490  static void texcoordPointer(const float* _p) {texcoordPointer(1, GL_FLOAT, 0, _p); }
492  static void texcoordPointer(const double* _p) {texcoordPointer(1, GL_DOUBLE, 0, _p); }
494  static void texcoordPointer(const Vec2f* _p) {texcoordPointer(2, GL_FLOAT, 0, _p); }
496  static void texcoordPointer(const Vec2d* _p) {texcoordPointer(2, GL_DOUBLE, 0, _p); }
498  static void texcoordPointer(const Vec3f* _p) {texcoordPointer(3, GL_FLOAT, 0, _p); }
500  static void texcoordPointer(const Vec3d* _p) {texcoordPointer(3, GL_DOUBLE, 0, _p); }
502  static void texcoordPointer(const Vec4f* _p) {texcoordPointer(4, GL_FLOAT, 0, _p); }
504  static void texcoordPointer(const Vec4d* _p) {texcoordPointer(4, GL_DOUBLE, 0, _p); }
505 
506 
507  static void setTexGenMode(GLenum _coord, GLenum _name, GLint _param);
508 
509  static void getTexGenMode(GLenum _coord, GLenum _name, GLint* _param);
510 
512  static void lockTexcoordPointer() {colorPointerLock_ = true;}
514  static void unlockTexcoordPointer() {colorPointerLock_ = false;}
516  static bool isTexcoordPointerLocked() {return colorPointerLock_;}
517 
518 
521  //===========================================================================
524  //===========================================================================
525 
530  static void genBuffersARB(GLsizei n, GLuint* buffers);
531 
536  static void genBuffers(GLsizei n, GLuint* buffers);
537 
542  static void bufferDataARB(
543  GLenum target, GLsizeiptrARB size, const GLvoid *data, GLenum usage);
544 
549  static void bufferData(
550  GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage);
551 
556  static GLvoid* mapBuffer (GLenum target, GLenum access);
557 
562  static GLboolean unmapBuffer (GLenum target);
563 
568  static void deleteBuffers(GLsizei n, const GLuint* buffers);
569 
571  static void bindBuffer(GLenum _target, GLuint _buffer);
573  static void bindBufferARB(GLenum _target, GLuint _buffer) {bindBuffer(_target, _buffer);}
574 
576  static void lockBufferTarget(GLenum _target);
577 
579  static void unlockBufferTarget(GLenum _target);
580 
582  static bool isBufferTargetLocked(GLenum _target);
583 
585  static GLuint getBoundBuf(GLenum _target);
586 
587 
589  static void drawBuffer(GLenum _mode);
591  static void drawBuffers(GLsizei _n, const GLenum* _bufs);
592 
594  static void lockDrawBuffer() {drawBufferLock_ = true;}
596  static void unlockDrawBuffer() {drawBufferLock_ = false;}
598  static bool isDrawBufferLocked() {return drawBufferLock_;}
599 
600 
602  static void bindFramebuffer(GLenum _target, GLuint _framebuffer);
604  static GLuint getFramebufferDraw();
606  static GLuint getFramebufferRead();
607 
609  static void lockFramebuffer(GLenum _target);
611  static void unlockFramebuffer(GLenum _target);
613  static bool isFramebufferLocked(GLenum _target);
614 
615 
618  //===========================================================================
621  //===========================================================================
622 
624  static void useProgram(GLuint _program);
626  static GLuint getProgram() {return stateStack_.back().program_;}
627 
629  static void lockProgram() {programLock_ = true;}
631  static void unlockProgram() {programLock_ = false;}
633  static bool isProgramLocked() {return programLock_;}
634 
635 
638 private:
639 
641  static int getBufferTargetIndex(GLenum _target);
642 
643 public:
644 
645  //===========================================================================
648  //===========================================================================
649 
651  static void activeTexture(GLenum _texunit);
653  static void activeTextureARB(GLenum _texunit) {activeTexture(_texunit);}
654 
655 
657  inline static GLenum getActiveTexture() {return stateStack_.back().activeTexture_;}
659  inline static int getActiveTextureIndex() {return getActiveTexture() - GL_TEXTURE0;}
660 
662  static void bindTexture(GLenum _target, GLuint _buffer);
663 
665  static void lockTextureStage();
666 
668  static void unlockTextureStage();
669 
671  static bool isTextureTargetLocked();
672 
674  static GLuint getBoundTextureBuffer();
676  static GLenum getBoundTextureTarget();
677 
680 public:
681 
682  //===========================================================================
685  //===========================================================================
686 
688  void reset_projection();
689 
691  void set_projection(const GLMatrixd& _m) {
692  GLMatrixd inv_m(_m); inv_m.invert(); set_projection(_m, inv_m);
693  }
695  void set_projection(const GLMatrixd& _m, const GLMatrixd& _inv_m);
696 
698  void ortho( double _left, double _right,
699  double _bottom, double _top,
700  double _near_plane, double _far_plane );
701 
703  void frustum( double _left, double _right,
704  double _bottom, double _top,
705  double _near_plane, double _far_plane );
706 
708  void perspective( double _fovY, double _aspect,
709  double _near_plane, double _far_plane );
710 
712  void viewport( int _left, int _bottom, int _width, int _height,
713  int _glwidth = 0, int _glheight = 0);
714 
715 
718  //===========================================================================
721  //===========================================================================
722 
723 
725  void reset_modelview();
726 
728  void set_modelview(const GLMatrixd& _m) {
729  GLMatrixd inv_m(_m); inv_m.invert(); set_modelview(_m, inv_m);
730  }
732  void set_modelview(const GLMatrixd& _m, const GLMatrixd& _inv_m);
733 
735  void lookAt( const Vec3d& _eye, const Vec3d& _center, const Vec3d& _up );
736 
738  void translate( double _x, double _y, double _z,
739  MultiplyFrom _mult_from = MULT_FROM_RIGHT );
740 
742  void translate( Vec3d _vector,
743  MultiplyFrom _mult_from = MULT_FROM_RIGHT );
744 
746  void rotate( double _angle, double _x, double _y, double _z,
747  MultiplyFrom _mult_from = MULT_FROM_RIGHT );
748 
750  void scale( double _s )
751  { scale(_s, _s, _s); }
752 
754  void scale( double _s,
755  MultiplyFrom /* _mult_from = MULT_FROM_RIGHT */ )
756  { scale(_s, _s, _s); }
757 
759  void scale( double _sx, double _sy, double _sz,
760  MultiplyFrom _mult_from = MULT_FROM_RIGHT );
761 
763  void mult_matrix( const GLMatrixd& _m, const GLMatrixd& _inv_m,
764  MultiplyFrom _mult_from = MULT_FROM_RIGHT );
765 
766 
768  void push_projection_matrix();
770  void pop_projection_matrix();
771 
773  void push_modelview_matrix();
775  void pop_modelview_matrix();
776 
779  //===========================================================================
782  //===========================================================================
783 
784 
786  const GLMatrixd& projection() const {
787  return projection_;
788  }
789 
791  const GLMatrixd& modelview() const {
792  return modelview_;
793  }
794 
796  const GLMatrixd& viewport() const {
797  return window2viewport_;
798  }
799 
802  return window2viewport_ * projection_ * modelview_;
803  }
804 
806  const GLMatrixd& inverse_projection() const {
807  return inverse_projection_;
808  }
809 
811  const GLMatrixd& inverse_modelview() const {
812  return inverse_modelview_;
813  }
814 
816  void get_viewport( int& _left, int& _bottom,
817  int& _width, int& _height ) const {
818  _left = left_; _bottom = bottom_; _width = width_; _height = height_;
819  }
820 
822  int viewport_width() const { return width_; }
824  int viewport_height() const { return height_; }
825 
827  int context_width() const { return glwidth_; }
828 
830  int context_height() const { return glheight_; }
831 
833  double near_plane() const { return near_plane_; }
834 
836  double far_plane() const { return far_plane_; }
837 
839  double fovy() const;
840 
842  double aspect() const;
843 
845  Vec3d eye() const;
846 
849  return viewing_direction(width_>>1, height_>>1);
850  }
851 
853  Vec3d viewing_direction(int _x, int _y) const;
854 
856  Vec3d up() const;
857 
859  Vec3d right() const;
860 
864  void viewing_ray(int _x, int _y, Vec3d& _origin, Vec3d& _direction) const;
865 
869  const GLenum& depthFunc() const;
872  void set_depthFunc(const GLenum& _depth_func);
873 
874 
876  static void depthFunc(GLenum _depthFunc);
877 
878  inline static void lockDepthFunc() {depthFuncLock_ = true;}
879  inline static void unlockDepthFunc() {depthFuncLock_ = false;}
880  inline static bool isDepthFuncLocked() {return depthFuncLock_;}
881 
882 
883  //--- project and unproject points ------------------------------------------
884 
886  Vec3d project(const Vec3d& _point) const;
887 
889  Vec3d unproject(const Vec3d& _winPoint) const;
890 
891 
892 
893 
894  //--- color & material ------------------------------------------------------
895 
899  static const Vec4f default_base_color;
909  static const float default_shininess;
910 
911 
913  void set_color(const Vec4f& _col);
914 
916  const Vec4f& color() { return color_; };
917 
919  void set_clear_color(const Vec4f& _col);
921  const Vec4f& clear_color() const { return clear_color_; }
922 
924  void set_base_color(const Vec4f& _col);
926  const Vec4f& base_color() const { return base_color_; }
927 
929  void set_ambient_color(const Vec4f& _col);
931  const Vec4f& ambient_color() const { return ambient_color_; }
932 
934  void set_diffuse_color(const Vec4f& _col);
936  const Vec4f& diffuse_color() const { return diffuse_color_; }
937 
939  void set_specular_color(const Vec4f& _col);
941  const Vec4f& specular_color() const { return specular_color_; }
942 
948  void set_overlay_color(const Vec4f& _col);
949 
955  const Vec4f& overlay_color() const { return overlay_color_; }
956 
958  void set_shininess(float _shininess);
960  float shininess() const { return shininess_; }
961 
962 
963 
964 
965  //--- thickness -------------------------------------------------------------
966 
968  void set_point_size(float _f);
970  float point_size() const { return point_size_; }
971 
973  void set_line_width(float _f);
975  float line_width() const { return line_width_; }
976 
977  //===========================================================================
980  //===========================================================================
981 
982 public:
984  unsigned int render_pass() const { return render_pass_; }
985 
987  void reset_render_pass() { render_pass_ = 1; }
988 
990  void next_render_pass() { ++render_pass_; }
991 
993  unsigned int max_render_passes() const { return max_render_passes_; }
994 
996  void set_max_render_passes(const unsigned int _max) { max_render_passes_ = _max; }
997 
998 private:
1001  unsigned int render_pass_;
1002 
1005  unsigned int max_render_passes_;
1006 
1009  //===========================================================================
1012  //===========================================================================
1013 
1014  public:
1017  void set_bounding_box(ACG::Vec3d _min, ACG::Vec3d _max );
1018 
1021  void get_bounding_box(ACG::Vec3d& _min, ACG::Vec3d& _max );
1022 
1023 
1024  private:
1026 
1027 
1029  //--- misc ------------------------------------------------------------------
1030 
1031 public:
1033  void set_blending(bool _b) { blending_ = _b; }
1035  bool blending() { return blending_; }
1036 
1038  void set_twosided_lighting(bool _b);
1040  bool twosided_lighting() { return twosided_lighting_; }
1041 
1042  //--- Multi Sampling --------------------------------------------------------
1043 
1045  void set_multisampling( bool _b );
1046 
1048  bool multisampling() { return multisampling_; };
1049 
1051  void allow_multisampling( bool _b ) { allow_multisampling_ = _b; };
1052 
1054  bool multisampling_allowed(){ return allow_multisampling_; };
1055 
1057  int max_texture_units() const { return num_texture_units_; }
1058 
1059  //--- Mipmapping ------------------------------------------------------------
1060 
1068  void allow_mipmapping(bool _b) { mipmapping_ = _b; }
1069 
1071  bool mipmapping_allowed() const { return mipmapping_; }
1072 
1073  //--- picking ---------------------------------------------------------------
1074 
1083  void pick_init (bool _color);
1085 
1095  bool pick_set_maximum (size_t _idx);
1096 
1107  void pick_set_name (size_t _idx);
1108 
1112  Vec4uc pick_get_name_color (size_t _idx);
1113 
1115  Vec4f pick_get_name_color_norm (unsigned int _idx);
1116 
1118  void pick_push_name (size_t _idx);
1119 
1121  void pick_pop_name ();
1122 
1125  std::vector<size_t> pick_color_to_stack (Vec4uc _rgba) const;
1126 
1128  size_t pick_free_indicies () const;
1129 
1132  bool pick_error () const;
1133 
1143  size_t pick_current_index () const;
1144 
1146  bool color_picking () const;
1147 
1148 
1149 private: //--------------------------------------------------------------------
1150 
1151  // matrix stacks
1152  std::stack<GLMatrixd> stack_projection_,
1153  stack_modelview_,
1154  stack_inverse_projection_,
1155  stack_inverse_modelview_;
1156 
1157  // current matrices
1158  GLMatrixd projection_,
1159  inverse_projection_,
1160  modelview_,
1161  inverse_modelview_,
1162  window2viewport_,
1163  inverse_window2viewport_;
1164 
1165  // viewport
1166  int left_, bottom_, width_, height_;
1167 
1168  // gl context
1169  int glwidth_, glheight_;
1170 
1171  // projection
1172  double near_plane_, far_plane_;
1173 
1174  // colors & materials
1175  Vec4f clear_color_; //< The scenes clear color
1176  Vec4f color_;
1177  Vec4f base_color_; //< The emitted color of an Object
1178  Vec4f ambient_color_; //< The ambient color of an Object
1179  Vec4f diffuse_color_; //< The diffuse color of an Object
1180  Vec4f specular_color_; //< The specular color of an Object
1181  Vec4f overlay_color_; //< An additional color that can be used to color e.g. a wireframe overlay
1182 
1183 
1184  float shininess_;
1185 
1186  // thickness
1187  float point_size_, line_width_;
1188 
1189  // lighting
1190  bool twosided_lighting_;
1191 
1192  // Multisampling settings
1193  bool multisampling_;
1194  bool allow_multisampling_;
1195 
1196  static int num_texture_units_;
1197 
1198  // Mipmapping settings
1199  bool mipmapping_;
1200 
1201  // helper: should GL matrices be updated
1202  bool updateGL_;
1203 
1204  // true -> draw tranparent Objects
1205  bool blending_;
1206 
1207  // time since last redraw
1208  unsigned int msSinceLastRedraw_;
1209 
1210  // stack for color picking
1211  ColorStack colorStack_;
1212 
1213  // are we using color picking
1214  bool colorPicking_;
1215 
1216 
1217  // depth comparison function (GL_LESS by default)
1218  static bool depthFuncLock_;
1219 
1220 
1222  // state locking members
1223 
1224  // stack needed for glPush/PopAttrib
1225  static std::deque <GLStateContext> stateStack_;
1226 
1227  // all possible params for glEnable
1228  static GLenum glStateCaps[95];
1229 
1230  // glEnable / glDisable states locker
1231  // iff a bit is set for a state, it is locked
1232  static std::bitset<0xFFFF+1> glStateLock_;
1233 
1234  static bool blendFuncSeparateLock_[2];
1235  static bool blendEquationLock_;
1236  static bool blendColorLock_;
1237  static bool alphaFuncLock_;
1238 
1239  static bool depthRangeLock_;
1240 
1241 
1242  // 4 buffer targets:
1243  // GL_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER, GL_PIXEL_PACK_BUFFER, GL_PIXEL_UNPACK_BUFFER
1244  static int glBufferTargetLock_[4];
1245 
1246  // 16 texture stages
1247  static int glTextureStageLock_[16];
1248 
1249  // current shade model: GL_FLAT, GL_SMOOTH, set by glShadeModel
1250  static bool shadeModelLock_;
1251 
1252  // current cull face mode: GL_FRONT, GL_FRONT_AND_BACK
1253  static bool cullFaceLock_;
1254 
1255  static bool vertexPointerLock_;
1256  static bool normalPointerLock_;
1257  static bool texcoordPointerLock_;
1258  static bool colorPointerLock_;
1259 
1260 
1261  // draw buffers
1262  static bool drawBufferLock_;
1263 
1264  // framebuffer
1265  // framebuffer id for each target: 0 - GL_DRAW_FRAMEBUFFER, 1-> GL_READ_FRAMEBUFFER
1266  static bool framebufferLock_[2];
1267 
1268  // current gl shader program
1269  static bool programLock_;
1270 
1271 
1272  // graphics card caps, retrieved via glGet
1273  static int maxTextureCoords_;
1274  static int maxCombinedTextureImageUnits_;
1275  static int maxDrawBuffers_;
1276 };
1277 
1437 #ifdef _MSC_VER
1438  #pragma warning(push)
1439 #endif
1440 
1441 //=============================================================================
1442 } // namespace ACG
1443 //=============================================================================
1444 #endif // ACG_GLSTATE_HH defined
1445 //=============================================================================
static void unlockAlphaFunc()
unlock alpha func
Definition: GLState.hh:373
bool invert()
matrix inversion (returns true on success)
int max_texture_units() const
Get max number of available texture units.
Definition: GLState.hh:1057
static void colorPointer(const Vec3uc *_p)
Wrapper: glColorPointer for Vec3uc.
Definition: GLState.hh:468
const Vec4f & specular_color() const
get specular color
Definition: GLState.hh:941
static void lockProgram()
lock the program
Definition: GLState.hh:629
void set_blending(bool _b)
set whether transparent or solid objects should be drawn
Definition: GLState.hh:1033
static bool isBlendFuncSeparateColorLocked()
replaces glEnable, but supports locking
Definition: GLState.hh:333
Namespace providing different geometric functions concerning angles.
bool mipmapping_allowed() const
Get current global mipmapping state.
Definition: GLState.hh:1071
unsigned int max_render_passes_
Definition: GLState.hh:1005
static void unlockShadeModel()
unlock shade model
Definition: GLState.hh:385
void makeCurrent()
does nothing
Definition: GLState.hh:224
static const Vec4f default_specular_color
default value for specular color
Definition: GLState.hh:905
static void texcoordPointer(const Vec2f *_p)
Wrapper: glTexcoordPointer for Vec2f.
Definition: GLState.hh:494
const GLMatrixd & inverse_modelview() const
get inverse modelview matrix
Definition: GLState.hh:811
static void vertexPointer(const Vec3d *_p)
Wrapper: glVertexPointer for Vec3d.
Definition: GLState.hh:431
static void unlockCullFace()
unlock cull face
Definition: GLState.hh:397
static void unlockTexcoordPointer()
unlock vertex pointer
Definition: GLState.hh:514
const GLMatrixd & viewport() const
get viewport matrix
Definition: GLState.hh:796
static void lockNormalPointer()
lock normal pointer
Definition: GLState.hh:455
void allow_mipmapping(bool _b)
Allow mipmapping globally.
Definition: GLState.hh:1068
static bool isBlendColorLocked()
get blend color locking state
Definition: GLState.hh:361
GLMatrixd forward_projection() const
get forward projection matrix
Definition: GLState.hh:801
int context_width() const
get gl context width
Definition: GLState.hh:827
bool multisampling()
Get current multisampling state.
Definition: GLState.hh:1048
static void vertexPointer(const Vec3f *_p)
Wrapper: glVertexPointer for Vec3f.
Definition: GLState.hh:429
void set_updateGL(bool _b)
should GL matrices be updated after each matrix operation
Definition: GLState.hh:235
static void unlockNormalPointer()
unlock normal pointer
Definition: GLState.hh:457
static void colorPointer(const Vec4uc *_p)
Wrapper: glColorPointer for Vec4uc.
Definition: GLState.hh:472
static void texcoordPointer(const double *_p)
Wrapper: glTexcoordPointer for double.
Definition: GLState.hh:492
static void lockCullFace()
lock cull face
Definition: GLState.hh:395
int context_height() const
get gl context height
Definition: GLState.hh:830
static void unlockBlendFunc()
unlock blend func
Definition: GLState.hh:315
static void unlockBlendEquation()
unlock blend equation
Definition: GLState.hh:346
static bool isAlphaFuncLocked()
get alpha func locking state
Definition: GLState.hh:375
static bool isBlendFuncLocked()
get blend func locking state
Definition: GLState.hh:317
static void getBlendFunc(GLenum *_sfactor, GLenum *_dfactor)
get blend function, null-ptr safe
Definition: GLState.hh:310
const GLMatrixd & projection() const
get projection matrix
Definition: GLState.hh:786
static void vertexPointer(const Vec4f *_p)
Wrapper: glVertexPointer for Vec4f.
Definition: GLState.hh:433
MultiplyFrom
Definition: GLMatrixT.hh:73
static bool isNormalPointerLocked()
get normal pointer lock state
Definition: GLState.hh:459
int viewport_width() const
get viewport width
Definition: GLState.hh:822
static bool isDepthRangeLocked()
get depth range locking state
Definition: GLState.hh:410
static void vertexPointer(const Vec2f *_p)
Wrapper: glVertexPointer for Vec2f.
Definition: GLState.hh:425
static void lockBlendEquation()
lock blend equation
Definition: GLState.hh:344
float point_size() const
get point size
Definition: GLState.hh:970
float line_width() const
get line width
Definition: GLState.hh:975
static GLenum getCullFace()
get current cull face
Definition: GLState.hh:393
static GLenum getShadeModel()
get current shade model
Definition: GLState.hh:381
const Vec4f & clear_color() const
get background color
Definition: GLState.hh:921
static void vertexPointer(const Vec2d *_p)
Wrapper: glVertexPointer for Vec2d.
Definition: GLState.hh:427
static bool isBlendFuncSeparateAlphaLocked()
replaces glEnable, but supports locking
Definition: GLState.hh:334
static void texcoordPointer(const Vec3d *_p)
Wrapper: glTexcoordPointer for Vec3d.
Definition: GLState.hh:500
void reset_render_pass()
reset render pass counter
Definition: GLState.hh:987
void compatibilityProfile(bool _enableCoreProfile)
Store opengl core profile setting.
Definition: gl.cc:166
static void texcoordPointer(const Vec4f *_p)
Wrapper: glTexcoordPointer for Vec4f.
Definition: GLState.hh:502
ACG::Vec3d bb_min_
Definition: GLState.hh:1025
static void blendFunc(GLenum _sfactor, GLenum _dfactor)
replaces glBlendFunc, supports locking
Definition: GLState.hh:307
static void lockShadeModel()
lock shade model
Definition: GLState.hh:383
static void unlockBlendFuncSeparate()
unlock blend func
Definition: GLState.hh:330
static void lockBlendFunc()
lock blend func
Definition: GLState.hh:313
static void unlockColorPointer()
unlock vertex pointer
Definition: GLState.hh:479
static void texcoordPointer(const float *_p)
Wrapper: glTexcoordPointer for float.
Definition: GLState.hh:490
const Vec4f & overlay_color() const
Get overlay color.
Definition: GLState.hh:955
~GLState()
destructor
Definition: GLState.hh:221
void set_max_render_passes(const unsigned int _max)
set maximum number of render passes
Definition: GLState.hh:996
static bool isTexcoordPointerLocked()
get vertex pointer lock state
Definition: GLState.hh:516
static bool isCullFaceLocked()
get cull face locking state
Definition: GLState.hh:399
static const Vec4f default_clear_color
default value for clear color
Definition: GLState.hh:897
static void texcoordPointer(const Vec2d *_p)
Wrapper: glTexcoordPointer for Vec2d.
Definition: GLState.hh:496
bool blending()
get whether transparenet or solid objects should be drawn
Definition: GLState.hh:1035
static void lockDepthRange()
lock depth range
Definition: GLState.hh:406
static const Vec4f default_base_color
default value for base color
Definition: GLState.hh:899
static void colorPointer(const Vec4f *_p)
Wrapper: glColorPointer for Vec4f.
Definition: GLState.hh:474
static bool isBlendEquationLocked()
get blend equation locking state
Definition: GLState.hh:348
bool twosided_lighting()
get whether transparenet or solid objects should be drawn
Definition: GLState.hh:1040
static const Vec4f default_diffuse_color
default value for diffuse color
Definition: GLState.hh:903
const Vec4f & base_color() const
get base color (used when lighting is off)
Definition: GLState.hh:926
static int getActiveTextureIndex()
get active texture as zero based index
Definition: GLState.hh:659
int viewport_height() const
get viewport height
Definition: GLState.hh:824
void get_viewport(int &_left, int &_bottom, int &_width, int &_height) const
get viewport
Definition: GLState.hh:816
static void texcoordPointer(const Vec4d *_p)
Wrapper: glTexcoordPointer for Vec4d.
Definition: GLState.hh:504
float shininess() const
get specular shininess (must be in [0, 128])
Definition: GLState.hh:960
static void lockBlendColor()
lock blend color
Definition: GLState.hh:357
bool multisampling_allowed()
Check if Multisampling is globally disabled.
Definition: GLState.hh:1054
static bool isProgramLocked()
get program locking state
Definition: GLState.hh:633
void scale(double _s, MultiplyFrom)
scale by (_s, _s, _s)
Definition: GLState.hh:754
static void unlockVertexPointer()
unlock vertex pointer
Definition: GLState.hh:440
static const Vec4f default_overlay_color
default value for overlay color
Definition: GLState.hh:907
static void unlockProgram()
unlock the program
Definition: GLState.hh:631
static void lockAlphaFunc()
lock alpha func
Definition: GLState.hh:371
Vec3d viewing_direction() const
get viewing ray
Definition: GLState.hh:848
static void unlockDrawBuffer()
unlock draw buffer state
Definition: GLState.hh:596
static void unlockDepthRange()
unlock depth range
Definition: GLState.hh:408
bool updateGL() const
should GL matrices be updated after each matrix operation
Definition: GLState.hh:233
static void lockBlendFuncSeparate(bool _rgb=true, bool _alpha=true)
lock blend func
Definition: GLState.hh:328
static void activeTextureARB(GLenum _texunit)
same functiona as activeTexture
Definition: GLState.hh:653
static bool isVertexPointerLocked()
get vertex pointer lock state
Definition: GLState.hh:442
static void bindBufferARB(GLenum _target, GLuint _buffer)
same function as bindBuffer
Definition: GLState.hh:573
const GLMatrixd & modelview() const
get modelview matrix
Definition: GLState.hh:791
unsigned int render_pass() const
get current render pass counter
Definition: GLState.hh:984
static bool isColorPointerLocked()
get vertex pointer lock state
Definition: GLState.hh:481
const Vec4f & color()
set color
Definition: GLState.hh:916
double near_plane() const
get near clipping distance
Definition: GLState.hh:833
void scale(double _s)
scale by (_s, _s, _s)
Definition: GLState.hh:750
unsigned int render_pass_
Definition: GLState.hh:1001
static GLuint getProgram()
get bound program
Definition: GLState.hh:626
static const Vec4f default_ambient_color
default value for ambient color
Definition: GLState.hh:901
static void colorPointer(const Vec3f *_p)
Wrapper: glColorPointer for Vec3f.
Definition: GLState.hh:470
unsigned int max_render_passes() const
get maximum number of render passes
Definition: GLState.hh:993
void set_modelview(const GLMatrixd &_m)
set modelview
Definition: GLState.hh:728
static bool isBlendFuncSeparateLocked()
get blend func locking state
Definition: GLState.hh:332
void allow_multisampling(bool _b)
Disable multisampling globally.
Definition: GLState.hh:1051
static void lockVertexPointer()
lock vertex pointer
Definition: GLState.hh:438
static void unlockBlendColor()
unlock blend color
Definition: GLState.hh:359
static GLenum getBlendEquation()
get blend equation
Definition: GLState.hh:341
const Vec4f & diffuse_color() const
get diffuse color
Definition: GLState.hh:936
static void lockColorPointer()
lock color pointer
Definition: GLState.hh:477
static void normalPointer(const Vec3d *_p)
Wrapper: glNormalPointer for Vec3d.
Definition: GLState.hh:452
void set_msSinceLastRedraw(unsigned int _ms)
set time passed since last redraw in milliseconds
Definition: GLState.hh:241
const GLMatrixd & inverse_projection() const
get inverse projection matrix
Definition: GLState.hh:806
static void lockDrawBuffer()
lock draw buffer state, applies to drawBuffer and drawBuffers
Definition: GLState.hh:594
unsigned int msSinceLastRedraw() const
time passed since last redraw in milliseconds
Definition: GLState.hh:238
const Vec4f & ambient_color() const
get ambient color
Definition: GLState.hh:931
void next_render_pass()
increment render pass counter
Definition: GLState.hh:990
static GLenum getActiveTexture()
get active GL texture
Definition: GLState.hh:657
static void lockTexcoordPointer()
lock color pointer
Definition: GLState.hh:512
static void texcoordPointer(const Vec3f *_p)
Wrapper: glTexcoordPointer for Vec3f.
Definition: GLState.hh:498
void set_projection(const GLMatrixd &_m)
set projection
Definition: GLState.hh:691
static const float default_shininess
default value for shininess
Definition: GLState.hh:909
double far_plane() const
get far clipping distance
Definition: GLState.hh:836
static void vertexPointer(const Vec4d *_p)
Wrapper: glVertexPointer for Vec4d.
Definition: GLState.hh:435
static bool isShadeModelLocked()
get shade model locking state
Definition: GLState.hh:387
static bool isDrawBufferLocked()
get draw buffer lock state
Definition: GLState.hh:598
static void normalPointer(const Vec3f *_p)
Wrapper: glNormalPointer for Vec3f.
Definition: GLState.hh:450