Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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  * $Revision$ *
45  * $Author$ *
46  * $Date$ *
47  * *
48 \*===========================================================================*/
49 
50 
51 //=============================================================================
52 //
53 // CLASS GLState
54 //
55 //=============================================================================
56 
57 
58 #ifndef ACG_GLSTATE_HH
59 #define ACG_GLSTATE_HH
60 
61 
62 //== INCLUDES =================================================================
63 
64 
65 #include "gl.hh"
66 #include "../Math/GLMatrixT.hh"
67 #include "../Math/VectorT.hh"
68 #include "../Config/ACGDefines.hh"
69 #include "ColorStack.hh"
70 #include <stack>
71 #include <vector>
72 #include <bitset>
73 #include <deque>
74 
75 #ifdef _MSC_VER
76  #pragma warning(push)
77  #pragma warning(disable:4251)
78 #endif
79 
80 //== NAMESPACES ===============================================================
81 
82 
83 namespace ACG {
84 
85 
86 //== CLASS DEFINITION =========================================================
87 
88 
123 {
124  // this struct is needed for push/popAttrib operations
125  // it contains a copy of the OpenGL state machine
126 
127 public:
128  GLStateContext();
129 
130 
131  // glEnable / glDisable states
132  // iff a bit is set for a state, it is enabled in OpenGL
133  std::bitset<0xFFFF+1> glStateEnabled_;
134 
135  // element 0: sfactor, 1: dfactor, 2 : alpha_sfactor, 3 : alpha_dfactor
136  GLenum blendFuncState_[4];
137 
138  GLenum blendEquationState_;
139 
140  GLclampf blendColorState_[4];
141 
142  GLenum alphaFuncState_;
143  GLclampf alphaRefState_;
144 
145  // depth function
146  GLenum depthFunc_;
147 
148  // 4 buffer targets:
149  // GL_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER, GL_PIXEL_PACK_BUFFER, GL_PIXEL_UNPACK_BUFFER
150  // current state of a buffer target
151  GLuint glBufferTargetState_[4];
152 
153 
154  // active texture unit: GL_TEXTUREi
155  GLenum activeTexture_;
156 
157 
159  {
160  TextureStage() : target_(0), buf_(0) {}
161  // current stage target
162  GLenum target_;
163  // current stage buffer
164  GLuint buf_;
165  };
166  // 16 texture stages
167  TextureStage glTextureStage_[16];
168 
169  // current shade model: GL_FLAT, GL_SMOOTH, set by glShadeModel
170  GLenum shadeModel_;
171 
172  // current cull face mode: GL_FRONT, GL_FRONT_AND_BACK
173  GLenum cullFace_;
174 
175 
176  // current depth range: zNear and zFar
177  GLclampd depthRange_[2];
178 
179  // vertex pointers, used in glVertexPointer, glTexcoordPointer..
181  {
182  GLVertexPointer() : size(0), type(0), stride(0), pointer(0) {}
183 
184  GLint size;
185  GLenum type;
186  GLsizei stride;
187  const GLvoid* pointer;
188 
189  bool equals(GLint _size, GLenum _type, GLsizei _stride, const GLvoid* _ptr)
190  {
191  return (size == _size && _type == type && _stride == stride && pointer == _ptr);
192  }
193 
194  void set(GLint _size, GLenum _type, GLsizei _stride, const GLvoid* _ptr)
195  {
196  size = _size; type = _type; stride = _stride, pointer = _ptr;
197  }
198  };
199 
200  GLVertexPointer vertexPointer_;
201  GLVertexPointer normalPointer_;
202  GLVertexPointer texcoordPointer_;
203  GLVertexPointer colorPointer_;
204 
205 
206  // draw buffers
207  GLenum drawBufferSingle_;
208  GLenum drawBufferState_[16];
209  int activeDrawBuffer_; // = 0 -> drawBufferSignle_; != 0 -> drawBufferState
210 
211  // framebuffer
212  // framebuffer id for each target: 0 - GL_DRAW_FRAMEBUFFER, 1-> GL_READ_FRAMEBUFFER
213  GLuint framebuffers_[2];
214 
215  // current gl shader program
216  GLuint program_;
217 };
218 
219 
220 class ACGDLLEXPORT GLState
221 {
222 public:
223 
225  GLState(bool _updateGL = true, bool _compatibilityProfile = true );
226 
228  ~GLState() {}
229 
231  void makeCurrent() { }
232 
234  static void syncFromGL();
235 
237  void initialize();
238 
240  bool updateGL() const { return updateGL_; }
242  void set_updateGL(bool _b) { updateGL_ = _b; }
243 
245  unsigned int msSinceLastRedraw () const { return msSinceLastRedraw_; }
246 
248  void set_msSinceLastRedraw (unsigned int _ms) { msSinceLastRedraw_ = _ms; }
249 
251  void setState ();
252 
254  void clearBuffers ();
255 
256  //===========================================================================
259  //===========================================================================
260 
261  void setCompatibilityProfile( bool _compatibility );
262 
263  bool compatibilityProfile() const;
264 
265 private:
266 
267  bool compatibilityProfile_;
268 
271  //===========================================================================
274  //===========================================================================
275 
276 public:
277 
279  static void enable(GLenum _cap);
280 
282  static void disable(GLenum _cap);
283 
285  static void lockState(GLenum _cap);
286 
288  static void unlockState(GLenum _cap);
289 
291  static bool isStateLocked(GLenum _cap);
292 
294  static bool isStateEnabled(GLenum _cap);
295 
296 
298  static void enableClientState(GLenum _cap);
300  static void disableClientState(GLenum _cap);
301 
303  static void lockClientState(GLenum _cap);
305  static void unlockClientState(GLenum _cap);
306 
308  static bool isClientStateEnabled(GLenum _cap);
310  static bool isClientStateLocked(GLenum _cap);
311 
312 
314  static void blendFunc(GLenum _sfactor, GLenum _dfactor) { blendFuncSeparate(_sfactor, _dfactor, _sfactor, _dfactor); }
315 
317  static void getBlendFunc(GLenum* _sfactor, GLenum* _dfactor) { getBlendFuncSeparate(_sfactor, _dfactor, 0, 0); }
318 
320  static void lockBlendFunc() { lockBlendFuncSeparate(); }
322  static void unlockBlendFunc() { unlockBlendFuncSeparate(); }
324  static bool isBlendFuncLocked() {return isBlendFuncSeparateLocked();}
325 
326 
327 
329  static void blendFuncSeparate(GLenum _srcRGB, GLenum _dstRGB, GLenum _srcAlpha, GLenum _dstAlpha);
330 
332  static void getBlendFuncSeparate(GLenum* _srcRGB, GLenum* _dstRGB, GLenum* _srcAlpha, GLenum* _dstAlpha);
333 
335  static void lockBlendFuncSeparate(bool _rgb = true, bool _alpha = true) { blendFuncSeparateLock_[0] = _rgb; blendFuncSeparateLock_[1] = _alpha; }
337  static void unlockBlendFuncSeparate() { lockBlendFuncSeparate(false, false); }
339  static bool isBlendFuncSeparateLocked() { return blendFuncSeparateLock_[0] || blendFuncSeparateLock_[1]; }
340  static bool isBlendFuncSeparateColorLocked() { return blendFuncSeparateLock_[0]; }
341  static bool isBlendFuncSeparateAlphaLocked() { return blendFuncSeparateLock_[1]; }
342 
343 
345  static void blendEquation(GLenum _mode);
346 
348  static GLenum getBlendEquation() {return stateStack_.back().blendEquationState_;}
349 
351  static void lockBlendEquation() {blendEquationLock_ = true;}
353  static void unlockBlendEquation() {blendEquationLock_ = false;}
355  static bool isBlendEquationLocked() {return blendEquationLock_;}
356 
358  static void blendColor(GLclampf _red, GLclampf _green, GLclampf _blue, GLclampf _alpha);
359 
361  static void getBlendColor(GLclampf* _col);
362 
364  static void lockBlendColor() {blendColorLock_ = true;}
366  static void unlockBlendColor() {blendColorLock_ = false;}
368  static bool isBlendColorLocked() {return blendColorLock_;}
369 
370 
372  static void alphaFunc(GLenum _func, GLclampf _ref);
373 
375  static void getAlphaFunc(GLenum* _func, GLclampf* _ref);
376 
378  static void lockAlphaFunc() {alphaFuncLock_ = true;}
380  static void unlockAlphaFunc() {alphaFuncLock_ = false;}
382  static bool isAlphaFuncLocked() {return alphaFuncLock_;}
383 
384 
386  static void shadeModel(GLenum _mode);
388  static GLenum getShadeModel() {return stateStack_.back().shadeModel_;}
390  static void lockShadeModel() {shadeModelLock_ = true;}
392  static void unlockShadeModel() {shadeModelLock_ = false;}
394  static bool isShadeModelLocked() {return shadeModelLock_;}
395 
396 
398  static void cullFace(GLenum _mode);
400  static GLenum getCullFace() {return stateStack_.back().cullFace_;}
402  static void lockCullFace() {cullFaceLock_ = true;}
404  static void unlockCullFace() {cullFaceLock_ = false;}
406  static bool isCullFaceLocked() {return cullFaceLock_;}
407 
409  static void depthRange(GLclampd _zNear, GLclampd _zFar);
411  static void getDepthRange(GLclampd* _zNearOut, GLclampd* _zFarOut);
413  static void lockDepthRange() {depthRangeLock_ = true;}
415  static void unlockDepthRange() {depthRangeLock_ = false;}
417  static bool isDepthRangeLocked() {return depthRangeLock_;}
418 
421  //===========================================================================
424  //===========================================================================
425 
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);
430 
432  static void vertexPointer(const Vec2f* _p) {vertexPointer(2, GL_FLOAT, 0, _p);}
434  static void vertexPointer(const Vec2d* _p) {vertexPointer(2, GL_DOUBLE, 0, _p);}
436  static void vertexPointer(const Vec3f* _p) {vertexPointer(3, GL_FLOAT, 0, _p);}
438  static void vertexPointer(const Vec3d* _p) {vertexPointer(3, GL_DOUBLE, 0, _p);}
440  static void vertexPointer(const Vec4f* _p) {vertexPointer(4, GL_FLOAT, 0, _p);}
442  static void vertexPointer(const Vec4d* _p) {vertexPointer(4, GL_DOUBLE, 0, _p);}
443 
445  static void lockVertexPointer() {vertexPointerLock_ = true;}
447  static void unlockVertexPointer() {vertexPointerLock_ = false;}
449  static bool isVertexPointerLocked() {return vertexPointerLock_;}
450 
452  static void normalPointer(GLenum _type, GLsizei _stride, const GLvoid* _pointer);
454  static void getNormalPointer(GLenum* _type, GLsizei* _stride, const GLvoid** _pointer);
455 
457  static void normalPointer(const Vec3f* _p) { glNormalPointer(GL_FLOAT, 0, _p); }
459  static void normalPointer(const Vec3d* _p) { glNormalPointer(GL_DOUBLE, 0, _p); }
460 
462  static void lockNormalPointer() {normalPointerLock_ = true;}
464  static void unlockNormalPointer() {normalPointerLock_ = false;}
466  static bool isNormalPointerLocked() {return normalPointerLock_;}
467 
468 
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);
473 
475  static void colorPointer(const Vec3uc* _p) {colorPointer(3, GL_UNSIGNED_BYTE, 0, _p);}
477  static void colorPointer(const Vec3f* _p) {colorPointer(3, GL_FLOAT, 0, _p);}
479  static void colorPointer(const Vec4uc* _p) {colorPointer(4, GL_UNSIGNED_BYTE, 0, _p);}
481  static void colorPointer(const Vec4f* _p) {colorPointer(4, GL_FLOAT, 0, _p);}
482 
484  static void lockColorPointer() {colorPointerLock_ = true;}
486  static void unlockColorPointer() {colorPointerLock_ = false;}
488  static bool isColorPointerLocked() {return colorPointerLock_;}
489 
490 
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);
495 
497  static void texcoordPointer(const float* _p) {texcoordPointer(1, GL_FLOAT, 0, _p); }
499  static void texcoordPointer(const double* _p) {texcoordPointer(1, GL_DOUBLE, 0, _p); }
501  static void texcoordPointer(const Vec2f* _p) {texcoordPointer(2, GL_FLOAT, 0, _p); }
503  static void texcoordPointer(const Vec2d* _p) {texcoordPointer(2, GL_DOUBLE, 0, _p); }
505  static void texcoordPointer(const Vec3f* _p) {texcoordPointer(3, GL_FLOAT, 0, _p); }
507  static void texcoordPointer(const Vec3d* _p) {texcoordPointer(3, GL_DOUBLE, 0, _p); }
509  static void texcoordPointer(const Vec4f* _p) {texcoordPointer(4, GL_FLOAT, 0, _p); }
511  static void texcoordPointer(const Vec4d* _p) {texcoordPointer(4, GL_DOUBLE, 0, _p); }
512 
513 
515  static void lockTexcoordPointer() {colorPointerLock_ = true;}
517  static void unlockTexcoordPointer() {colorPointerLock_ = false;}
519  static bool isTexcoordPointerLocked() {return colorPointerLock_;}
520 
521 
524  //===========================================================================
527  //===========================================================================
528 
533  static void genBuffersARB(GLsizei n, GLuint* buffers);
534 
539  static void genBuffers(GLsizei n, GLuint* buffers);
540 
545  static void bufferDataARB(
546  GLenum target, GLsizeiptrARB size, const GLvoid *data, GLenum usage);
547 
552  static void bufferData(
553  GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage);
554 
559  static GLvoid* mapBuffer (GLenum target, GLenum access);
560 
565  static GLboolean unmapBuffer (GLenum target);
566 
571  static void deleteBuffers(GLsizei n, const GLuint* buffers);
572 
574  static void bindBuffer(GLenum _target, GLuint _buffer);
576  static void bindBufferARB(GLenum _target, GLuint _buffer) {bindBuffer(_target, _buffer);}
577 
579  static void lockBufferTarget(GLenum _target);
580 
582  static void unlockBufferTarget(GLenum _target);
583 
585  static bool isBufferTargetLocked(GLenum _target);
586 
588  static GLuint getBoundBuf(GLenum _target);
589 
590 
592  static void drawBuffer(GLenum _mode);
594  static void drawBuffers(GLsizei _n, const GLenum* _bufs);
595 
597  static void lockDrawBuffer() {drawBufferLock_ = true;}
599  static void unlockDrawBuffer() {drawBufferLock_ = false;}
601  static bool isDrawBufferLocked() {return drawBufferLock_;}
602 
603 
605  static void bindFramebuffer(GLenum _target, GLuint _framebuffer);
607  static GLuint getFramebufferDraw();
609  static GLuint getFramebufferRead();
610 
612  static void lockFramebuffer(GLenum _target);
614  static void unlockFramebuffer(GLenum _target);
616  static bool isFramebufferLocked(GLenum _target);
617 
618 
621  //===========================================================================
624  //===========================================================================
625 
627  static void useProgram(GLuint _program);
629  static GLuint getProgram() {return stateStack_.back().program_;}
630 
632  static void lockProgram() {programLock_ = true;}
634  static void unlockProgram() {programLock_ = false;}
636  static bool isProgramLocked() {return programLock_;}
637 
638 
641 private:
642 
644  static int getBufferTargetIndex(GLenum _target);
645 
646 public:
647 
648  //===========================================================================
651  //===========================================================================
652 
654  static void activeTexture(GLenum _texunit);
656  static void activeTextureARB(GLenum _texunit) {activeTexture(_texunit);}
657 
658 
660  inline static GLenum getActiveTexture() {return stateStack_.back().activeTexture_;}
662  inline static int getActiveTextureIndex() {return getActiveTexture() - GL_TEXTURE0;}
663 
665  static void bindTexture(GLenum _target, GLuint _buffer);
666 
668  static void lockTextureStage();
669 
671  static void unlockTextureStage();
672 
674  static bool isTextureTargetLocked();
675 
677  static GLuint getBoundTextureBuffer();
679  static GLenum getBoundTextureTarget();
680 
683 public:
684 
685  //===========================================================================
688  //===========================================================================
689 
691  void reset_projection();
692 
694  void set_projection(const GLMatrixd& _m) {
695  GLMatrixd inv_m(_m); inv_m.invert(); set_projection(_m, inv_m);
696  }
698  void set_projection(const GLMatrixd& _m, const GLMatrixd& _inv_m);
699 
701  void ortho( double _left, double _right,
702  double _bottom, double _top,
703  double _near_plane, double _far_plane );
704 
706  void frustum( double _left, double _right,
707  double _bottom, double _top,
708  double _near_plane, double _far_plane );
709 
711  void perspective( double _fovY, double _aspect,
712  double _near_plane, double _far_plane );
713 
715  void viewport( int _left, int _bottom, int _width, int _height,
716  int _glwidth = 0, int _glheight = 0);
717 
718 
721  //===========================================================================
724  //===========================================================================
725 
726 
728  void reset_modelview();
729 
731  void set_modelview(const GLMatrixd& _m) {
732  GLMatrixd inv_m(_m); inv_m.invert(); set_modelview(_m, inv_m);
733  }
735  void set_modelview(const GLMatrixd& _m, const GLMatrixd& _inv_m);
736 
738  void lookAt( const Vec3d& _eye, const Vec3d& _center, const Vec3d& _up );
739 
741  void translate( double _x, double _y, double _z,
742  MultiplyFrom _mult_from = MULT_FROM_RIGHT );
743 
745  void translate( Vec3d _vector,
746  MultiplyFrom _mult_from = MULT_FROM_RIGHT );
747 
749  void rotate( double _angle, double _x, double _y, double _z,
750  MultiplyFrom _mult_from = MULT_FROM_RIGHT );
751 
753  void scale( double _s )
754  { scale(_s, _s, _s); }
755 
757  void scale( double _s,
758  MultiplyFrom /* _mult_from = MULT_FROM_RIGHT */ )
759  { scale(_s, _s, _s); }
760 
762  void scale( double _sx, double _sy, double _sz,
763  MultiplyFrom _mult_from = MULT_FROM_RIGHT );
764 
766  void mult_matrix( const GLMatrixd& _m, const GLMatrixd& _inv_m,
767  MultiplyFrom _mult_from = MULT_FROM_RIGHT );
768 
769 
771  void push_projection_matrix();
773  void pop_projection_matrix();
774 
776  void push_modelview_matrix();
778  void pop_modelview_matrix();
779 
782  //===========================================================================
785  //===========================================================================
786 
787 
789  const GLMatrixd& projection() const {
790  return projection_;
791  }
792 
794  const GLMatrixd& modelview() const {
795  return modelview_;
796  }
797 
799  const GLMatrixd& viewport() const {
800  return window2viewport_;
801  }
802 
805  return window2viewport_ * projection_ * modelview_;
806  }
807 
809  const GLMatrixd& inverse_projection() const {
810  return inverse_projection_;
811  }
812 
814  const GLMatrixd& inverse_modelview() const {
815  return inverse_modelview_;
816  }
817 
819  void get_viewport( int& _left, int& _bottom,
820  int& _width, int& _height ) const {
821  _left = left_; _bottom = bottom_; _width = width_; _height = height_;
822  }
823 
825  int viewport_width() const { return width_; }
827  int viewport_height() const { return height_; }
828 
830  int context_width() const { return glwidth_; }
831 
833  int context_height() const { return glheight_; }
834 
836  double near_plane() const { return near_plane_; }
837 
839  double far_plane() const { return far_plane_; }
840 
842  double fovy() const;
843 
845  double aspect() const;
846 
848  Vec3d eye() const;
849 
852  return viewing_direction(width_>>1, height_>>1);
853  }
854 
856  Vec3d viewing_direction(int _x, int _y) const;
857 
859  Vec3d up() const;
860 
862  Vec3d right() const;
863 
867  void viewing_ray(int _x, int _y, Vec3d& _origin, Vec3d& _direction) const;
868 
872  const GLenum& depthFunc() const;
875  void set_depthFunc(const GLenum& _depth_func);
876 
877 
879  static void depthFunc(GLenum _depthFunc);
880 
881  inline static void lockDepthFunc() {depthFuncLock_ = true;}
882  inline static void unlockDepthFunc() {depthFuncLock_ = false;}
883  inline static bool isDepthFuncLocked() {return depthFuncLock_;}
884 
885 
886  //--- project and unproject points ------------------------------------------
887 
889  Vec3d project(const Vec3d& _point) const;
890 
892  Vec3d unproject(const Vec3d& _winPoint) const;
893 
894 
895 
896 
897  //--- color & material ------------------------------------------------------
898 
902  static const Vec4f default_base_color;
912  static const float default_shininess;
913 
914 
916  void set_color(const Vec4f& _col);
917 
919  const Vec4f& color() { return color_; };
920 
922  void set_clear_color(const Vec4f& _col);
924  const Vec4f& clear_color() const { return clear_color_; }
925 
927  void set_base_color(const Vec4f& _col);
929  const Vec4f& base_color() const { return base_color_; }
930 
932  void set_ambient_color(const Vec4f& _col);
934  const Vec4f& ambient_color() const { return ambient_color_; }
935 
937  void set_diffuse_color(const Vec4f& _col);
939  const Vec4f& diffuse_color() const { return diffuse_color_; }
940 
942  void set_specular_color(const Vec4f& _col);
944  const Vec4f& specular_color() const { return specular_color_; }
945 
951  void set_overlay_color(const Vec4f& _col);
952 
958  const Vec4f& overlay_color() const { return overlay_color_; }
959 
961  void set_shininess(float _shininess);
963  float shininess() const { return shininess_; }
964 
965 
966 
967 
968  //--- thickness -------------------------------------------------------------
969 
971  void set_point_size(float _f);
973  float point_size() const { return point_size_; }
974 
976  void set_line_width(float _f);
978  float line_width() const { return line_width_; }
979 
980  //===========================================================================
983  //===========================================================================
984 
985 public:
987  unsigned int render_pass() const { return render_pass_; }
988 
990  void reset_render_pass() { render_pass_ = 1; }
991 
993  void next_render_pass() { ++render_pass_; }
994 
996  unsigned int max_render_passes() const { return max_render_passes_; }
997 
999  void set_max_render_passes(const unsigned int _max) { max_render_passes_ = _max; }
1000 
1001 private:
1004  unsigned int render_pass_;
1005 
1008  unsigned int max_render_passes_;
1009 
1012  //===========================================================================
1015  //===========================================================================
1016 
1017  public:
1020  void set_bounding_box(ACG::Vec3d _min, ACG::Vec3d _max );
1021 
1024  void get_bounding_box(ACG::Vec3d& _min, ACG::Vec3d& _max );
1025 
1026 
1027  private:
1029 
1030 
1032  //--- misc ------------------------------------------------------------------
1033 
1034 public:
1036  void set_blending(bool _b) { blending_ = _b; }
1038  bool blending() { return blending_; }
1039 
1041  void set_twosided_lighting(bool _b);
1043  bool twosided_lighting() { return twosided_lighting_; }
1044 
1045  //--- Multi Sampling --------------------------------------------------------
1046 
1048  void set_multisampling( bool _b );
1049 
1051  bool multisampling() { return multisampling_; };
1052 
1054  void allow_multisampling( bool _b ) { allow_multisampling_ = _b; };
1055 
1057  bool multisampling_allowed(){ return allow_multisampling_; };
1058 
1060  int max_texture_units() const { return num_texture_units_; }
1061 
1062  //--- Mipmapping ------------------------------------------------------------
1063 
1071  void allow_mipmapping(bool _b) { mipmapping_ = _b; }
1072 
1074  bool mipmapping_allowed() const { return mipmapping_; }
1075 
1076  //--- picking ---------------------------------------------------------------
1077 
1086  void pick_init (bool _color);
1088 
1098  bool pick_set_maximum (unsigned int _idx);
1099 
1110  void pick_set_name (unsigned int _idx);
1111 
1115  Vec4uc pick_get_name_color (unsigned int _idx);
1116 
1118  void pick_push_name (unsigned int _idx);
1119 
1121  void pick_pop_name ();
1122 
1125  std::vector<unsigned int> pick_color_to_stack (Vec4uc _rgba) const;
1126 
1128  unsigned int pick_free_indicies () const;
1129 
1132  bool pick_error () const;
1133 
1143  unsigned int 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 //=============================================================================
void scale(double _s)
scale by (_s, _s, _s)
Definition: GLState.hh:753
static void unlockBlendColor()
unlock blend color
Definition: GLState.hh:366
float shininess() const
get specular shininess (must be in [0, 128])
Definition: GLState.hh:963
static void vertexPointer(const Vec4d *_p)
Wrapper: glVertexPointer for Vec4d.
Definition: GLState.hh:442
static int getActiveTextureIndex()
get active texture as zero based index
Definition: GLState.hh:662
static void vertexPointer(const Vec4f *_p)
Wrapper: glVertexPointer for Vec4f.
Definition: GLState.hh:440
bool multisampling_allowed()
Check if Multisampling is globally disabled.
Definition: GLState.hh:1057
static const Vec4f default_clear_color
default value for clear color
Definition: GLState.hh:900
static const Vec4f default_ambient_color
default value for ambient color
Definition: GLState.hh:904
Namespace providing different geometric functions concerning angles.
Definition: DBSCANT.cc:51
void allow_mipmapping(bool _b)
Allow mipmapping globally.
Definition: GLState.hh:1071
static void lockBlendFunc()
lock blend func
Definition: GLState.hh:320
static bool isVertexPointerLocked()
get vertex pointer lock state
Definition: GLState.hh:449
int context_height() const
get gl context height
Definition: GLState.hh:833
double far_plane() const
get far clipping distance
Definition: GLState.hh:839
unsigned int msSinceLastRedraw() const
time passed since last redraw in milliseconds
Definition: GLState.hh:245
MultiplyFrom
Definition: GLMatrixT.hh:79
static void lockBlendEquation()
lock blend equation
Definition: GLState.hh:351
static void unlockAlphaFunc()
unlock alpha func
Definition: GLState.hh:380
bool blending()
get whether transparenet or solid objects should be drawn
Definition: GLState.hh:1038
static void vertexPointer(const Vec3d *_p)
Wrapper: glVertexPointer for Vec3d.
Definition: GLState.hh:438
const Vec4f & clear_color() const
get background color
Definition: GLState.hh:924
unsigned int render_pass() const
get current render pass counter
Definition: GLState.hh:987
void next_render_pass()
increment render pass counter
Definition: GLState.hh:993
static GLenum getActiveTexture()
get active GL texture
Definition: GLState.hh:660
static void texcoordPointer(const Vec2d *_p)
Wrapper: glTexcoordPointer for Vec2d.
Definition: GLState.hh:503
static GLenum getBlendEquation()
get blend equation
Definition: GLState.hh:348
static void lockAlphaFunc()
lock alpha func
Definition: GLState.hh:378
bool multisampling()
Get current multisampling state.
Definition: GLState.hh:1051
static void unlockVertexPointer()
unlock vertex pointer
Definition: GLState.hh:447
static bool isColorPointerLocked()
get vertex pointer lock state
Definition: GLState.hh:488
static void lockColorPointer()
lock color pointer
Definition: GLState.hh:484
static void colorPointer(const Vec4uc *_p)
Wrapper: glColorPointer for Vec4uc.
Definition: GLState.hh:479
static void texcoordPointer(const float *_p)
Wrapper: glTexcoordPointer for float.
Definition: GLState.hh:497
static GLuint getProgram()
get bound program
Definition: GLState.hh:629
VectorT< double, 3 > Vec3d
Definition: VectorT.hh:127
const GLMatrixd & modelview() const
get modelview matrix
Definition: GLState.hh:794
static GLenum getCullFace()
get current cull face
Definition: GLState.hh:400
const GLMatrixd & projection() const
get projection matrix
Definition: GLState.hh:789
static void lockShadeModel()
lock shade model
Definition: GLState.hh:390
static bool isBlendFuncSeparateAlphaLocked()
replaces glEnable, but supports locking
Definition: GLState.hh:341
static bool isBlendColorLocked()
get blend color locking state
Definition: GLState.hh:368
void reset_render_pass()
reset render pass counter
Definition: GLState.hh:990
static void unlockBlendFuncSeparate()
unlock blend func
Definition: GLState.hh:337
const GLMatrixd & inverse_projection() const
get inverse projection matrix
Definition: GLState.hh:809
static void colorPointer(const Vec3f *_p)
Wrapper: glColorPointer for Vec3f.
Definition: GLState.hh:477
const Vec4f & overlay_color() const
Get overlay color.
Definition: GLState.hh:958
static bool isTexcoordPointerLocked()
get vertex pointer lock state
Definition: GLState.hh:519
void set_blending(bool _b)
set whether transparent or solid objects should be drawn
Definition: GLState.hh:1036
static bool isDepthRangeLocked()
get depth range locking state
Definition: GLState.hh:417
static void texcoordPointer(const Vec4d *_p)
Wrapper: glTexcoordPointer for Vec4d.
Definition: GLState.hh:511
void makeCurrent()
does nothing
Definition: GLState.hh:231
static bool isBlendFuncLocked()
get blend func locking state
Definition: GLState.hh:324
static const Vec4f default_diffuse_color
default value for diffuse color
Definition: GLState.hh:906
static bool isProgramLocked()
get program locking state
Definition: GLState.hh:636
static void unlockTexcoordPointer()
unlock vertex pointer
Definition: GLState.hh:517
void scale(double _s, MultiplyFrom)
scale by (_s, _s, _s)
Definition: GLState.hh:757
static GLenum getShadeModel()
get current shade model
Definition: GLState.hh:388
void set_max_render_passes(const unsigned int _max)
set maximum number of render passes
Definition: GLState.hh:999
const Vec4f & color()
set color
Definition: GLState.hh:919
static void lockVertexPointer()
lock vertex pointer
Definition: GLState.hh:445
static void lockTexcoordPointer()
lock color pointer
Definition: GLState.hh:515
int viewport_width() const
get viewport width
Definition: GLState.hh:825
static void lockCullFace()
lock cull face
Definition: GLState.hh:402
static void unlockDepthRange()
unlock depth range
Definition: GLState.hh:415
static void lockBlendFuncSeparate(bool _rgb=true, bool _alpha=true)
lock blend func
Definition: GLState.hh:335
static void blendFunc(GLenum _sfactor, GLenum _dfactor)
replaces glBlendFunc, supports locking
Definition: GLState.hh:314
const Vec4f & specular_color() const
get specular color
Definition: GLState.hh:944
const GLMatrixd & inverse_modelview() const
get inverse modelview matrix
Definition: GLState.hh:814
static void activeTextureARB(GLenum _texunit)
same functiona as activeTexture
Definition: GLState.hh:656
static void vertexPointer(const Vec3f *_p)
Wrapper: glVertexPointer for Vec3f.
Definition: GLState.hh:436
float line_width() const
get line width
Definition: GLState.hh:978
static void unlockProgram()
unlock the program
Definition: GLState.hh:634
static const Vec4f default_base_color
default value for base color
Definition: GLState.hh:902
static void colorPointer(const Vec3uc *_p)
Wrapper: glColorPointer for Vec3uc.
Definition: GLState.hh:475
double near_plane() const
get near clipping distance
Definition: GLState.hh:836
float point_size() const
get point size
Definition: GLState.hh:973
bool mipmapping_allowed() const
Get current global mipmapping state.
Definition: GLState.hh:1074
static void texcoordPointer(const Vec3d *_p)
Wrapper: glTexcoordPointer for Vec3d.
Definition: GLState.hh:507
static void unlockShadeModel()
unlock shade model
Definition: GLState.hh:392
static bool isNormalPointerLocked()
get normal pointer lock state
Definition: GLState.hh:466
static const Vec4f default_overlay_color
default value for overlay color
Definition: GLState.hh:910
unsigned int max_render_passes_
Definition: GLState.hh:1008
static void vertexPointer(const Vec2f *_p)
Wrapper: glVertexPointer for Vec2f.
Definition: GLState.hh:432
void set_updateGL(bool _b)
should GL matrices be updated after each matrix operation
Definition: GLState.hh:242
static void colorPointer(const Vec4f *_p)
Wrapper: glColorPointer for Vec4f.
Definition: GLState.hh:481
Vec3d viewing_direction() const
get viewing ray
Definition: GLState.hh:851
unsigned int max_render_passes() const
get maximum number of render passes
Definition: GLState.hh:996
static bool isBlendEquationLocked()
get blend equation locking state
Definition: GLState.hh:355
void get_viewport(int &_left, int &_bottom, int &_width, int &_height) const
get viewport
Definition: GLState.hh:819
const GLMatrixd & viewport() const
get viewport matrix
Definition: GLState.hh:799
static bool isBlendFuncSeparateLocked()
get blend func locking state
Definition: GLState.hh:339
static void unlockBlendFunc()
unlock blend func
Definition: GLState.hh:322
static void normalPointer(const Vec3f *_p)
Wrapper: glNormalPointer for Vec3f.
Definition: GLState.hh:457
static void texcoordPointer(const double *_p)
Wrapper: glTexcoordPointer for double.
Definition: GLState.hh:499
static void lockNormalPointer()
lock normal pointer
Definition: GLState.hh:462
static const float default_shininess
default value for shininess
Definition: GLState.hh:912
static void lockDepthRange()
lock depth range
Definition: GLState.hh:413
static void lockProgram()
lock the program
Definition: GLState.hh:632
bool twosided_lighting()
get whether transparenet or solid objects should be drawn
Definition: GLState.hh:1043
static bool isShadeModelLocked()
get shade model locking state
Definition: GLState.hh:394
static void vertexPointer(const Vec2d *_p)
Wrapper: glVertexPointer for Vec2d.
Definition: GLState.hh:434
static bool isBlendFuncSeparateColorLocked()
replaces glEnable, but supports locking
Definition: GLState.hh:340
void set_modelview(const GLMatrixd &_m)
set modelview
Definition: GLState.hh:731
static void texcoordPointer(const Vec2f *_p)
Wrapper: glTexcoordPointer for Vec2f.
Definition: GLState.hh:501
static void lockBlendColor()
lock blend color
Definition: GLState.hh:364
~GLState()
destructor
Definition: GLState.hh:228
static void lockDrawBuffer()
lock draw buffer state, applies to drawBuffer and drawBuffers
Definition: GLState.hh:597
void set_msSinceLastRedraw(unsigned int _ms)
set time passed since last redraw in milliseconds
Definition: GLState.hh:248
static void normalPointer(const Vec3d *_p)
Wrapper: glNormalPointer for Vec3d.
Definition: GLState.hh:459
unsigned int render_pass_
Definition: GLState.hh:1004
const Vec4f & ambient_color() const
get ambient color
Definition: GLState.hh:934
ACG::Vec3d bb_min_
Definition: GLState.hh:1028
static bool isDrawBufferLocked()
get draw buffer lock state
Definition: GLState.hh:601
static void bindBufferARB(GLenum _target, GLuint _buffer)
same function as bindBuffer
Definition: GLState.hh:576
static void unlockDrawBuffer()
unlock draw buffer state
Definition: GLState.hh:599
static bool isAlphaFuncLocked()
get alpha func locking state
Definition: GLState.hh:382
void set_projection(const GLMatrixd &_m)
set projection
Definition: GLState.hh:694
GLMatrixd forward_projection() const
get forward projection matrix
Definition: GLState.hh:804
bool invert()
matrix inversion (returns true on success)
Definition: Matrix4x4T.cc:297
static bool isCullFaceLocked()
get cull face locking state
Definition: GLState.hh:406
const Vec4f & base_color() const
get base color (used when lighting is off)
Definition: GLState.hh:929
static void unlockBlendEquation()
unlock blend equation
Definition: GLState.hh:353
static void unlockNormalPointer()
unlock normal pointer
Definition: GLState.hh:464
int context_width() const
get gl context width
Definition: GLState.hh:830
static void texcoordPointer(const Vec3f *_p)
Wrapper: glTexcoordPointer for Vec3f.
Definition: GLState.hh:505
int viewport_height() const
get viewport height
Definition: GLState.hh:827
static const Vec4f default_specular_color
default value for specular color
Definition: GLState.hh:908
static void getBlendFunc(GLenum *_sfactor, GLenum *_dfactor)
get blend function, null-ptr safe
Definition: GLState.hh:317
static void unlockCullFace()
unlock cull face
Definition: GLState.hh:404
static void unlockColorPointer()
unlock vertex pointer
Definition: GLState.hh:486
void allow_multisampling(bool _b)
Disable multisampling globally.
Definition: GLState.hh:1054
const Vec4f & diffuse_color() const
get diffuse color
Definition: GLState.hh:939
bool updateGL() const
should GL matrices be updated after each matrix operation
Definition: GLState.hh:240
static void texcoordPointer(const Vec4f *_p)
Wrapper: glTexcoordPointer for Vec4f.
Definition: GLState.hh:509
int max_texture_units() const
Get max number of available texture units.
Definition: GLState.hh:1060