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
74namespace 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
118public:
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
213class ACGDLLEXPORT GLState
214{
215public:
216
218 GLState(bool _updateGL = true, bool _compatibilityProfile = true );
219
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
258private:
259
260 bool compatibilityProfile_;
261
264 //===========================================================================
267 //===========================================================================
268
269public:
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 size_t getBufferSize(GLenum _target);
569
574 static void deleteBuffers(GLsizei n, const GLuint* buffers);
575
577 static void bindBuffer(GLenum _target, GLuint _buffer);
579 static void bindBufferARB(GLenum _target, GLuint _buffer) {bindBuffer(_target, _buffer);}
580
582 static void lockBufferTarget(GLenum _target);
583
585 static void unlockBufferTarget(GLenum _target);
586
588 static bool isBufferTargetLocked(GLenum _target);
589
591 static GLuint getBoundBuf(GLenum _target);
592
595 static GLenum getShaderType(GLuint _shader);
596
599 static size_t getShaderSourceLength(GLuint _shader);
600
604 static size_t getShaderSource(GLuint _shader, char* _buffer, size_t _bufferSize);
605
606
611 static GLuint getAttachedShader(GLuint _program, GLenum _type);
612
614 static void drawBuffer(GLenum _mode);
616 static void drawBuffers(GLsizei _n, const GLenum* _bufs);
617
619 static void lockDrawBuffer() {drawBufferLock_ = true;}
621 static void unlockDrawBuffer() {drawBufferLock_ = false;}
623 static bool isDrawBufferLocked() {return drawBufferLock_;}
624
625
627 static void bindFramebuffer(GLenum _target, GLuint _framebuffer);
629 static GLuint getFramebufferDraw();
631 static GLuint getFramebufferRead();
632
634 static void lockFramebuffer(GLenum _target);
636 static void unlockFramebuffer(GLenum _target);
638 static bool isFramebufferLocked(GLenum _target);
639
640
643 //===========================================================================
646 //===========================================================================
647
649 static void useProgram(GLuint _program);
651 static GLuint getProgram() {return stateStack_.back().program_;}
652
654 static void lockProgram() {programLock_ = true;}
656 static void unlockProgram() {programLock_ = false;}
658 static bool isProgramLocked() {return programLock_;}
659
660
663private:
664
666 static int getBufferTargetIndex(GLenum _target);
667
668public:
669
670 //===========================================================================
673 //===========================================================================
674
676 static void activeTexture(GLenum _texunit);
678 static void activeTextureARB(GLenum _texunit) {activeTexture(_texunit);}
679
680
682 inline static GLenum getActiveTexture() {return stateStack_.back().activeTexture_;}
684 inline static int getActiveTextureIndex() {return getActiveTexture() - GL_TEXTURE0;}
685
687 static void bindTexture(GLenum _target, GLuint _buffer);
688
690 static void lockTextureStage();
691
693 static void unlockTextureStage();
694
696 static bool isTextureTargetLocked();
697
699 static GLuint getBoundTextureBuffer();
701 static GLenum getBoundTextureTarget();
702
705public:
706
707 //===========================================================================
710 //===========================================================================
711
713 void reset_projection();
714
716 void set_projection(const GLMatrixd& _m) {
717 GLMatrixd inv_m(_m); inv_m.invert(); set_projection(_m, inv_m);
718 }
720 void set_projection(const GLMatrixd& _m, const GLMatrixd& _inv_m);
721
723 void ortho( double _left, double _right,
724 double _bottom, double _top,
725 double _near_plane, double _far_plane );
726
728 void frustum( double _left, double _right,
729 double _bottom, double _top,
730 double _near_plane, double _far_plane );
731
733 void perspective( double _fovY, double _aspect,
734 double _near_plane, double _far_plane );
735
737 void viewport( int _left, int _bottom, int _width, int _height,
738 int _glwidth = 0, int _glheight = 0);
739
740
743 //===========================================================================
746 //===========================================================================
747
748
750 void reset_modelview();
751
753 void set_modelview(const GLMatrixd& _m) {
754 GLMatrixd inv_m(_m); inv_m.invert(); set_modelview(_m, inv_m);
755 }
757 void set_modelview(const GLMatrixd& _m, const GLMatrixd& _inv_m);
758
760 void lookAt( const Vec3d& _eye, const Vec3d& _center, const Vec3d& _up );
761
763 void translate( double _x, double _y, double _z,
764 MultiplyFrom _mult_from = MULT_FROM_RIGHT );
765
767 void translate( Vec3d _vector,
768 MultiplyFrom _mult_from = MULT_FROM_RIGHT );
769
771 void rotate( double _angle, double _x, double _y, double _z,
772 MultiplyFrom _mult_from = MULT_FROM_RIGHT );
773
775 void scale( double _s )
776 { scale(_s, _s, _s); }
777
779 void scale( double _s,
780 MultiplyFrom /* _mult_from = MULT_FROM_RIGHT */ )
781 { scale(_s, _s, _s); }
782
784 void scale( double _sx, double _sy, double _sz,
785 MultiplyFrom _mult_from = MULT_FROM_RIGHT );
786
788 void mult_matrix( const GLMatrixd& _m, const GLMatrixd& _inv_m,
789 MultiplyFrom _mult_from = MULT_FROM_RIGHT );
790
791
793 void push_projection_matrix();
795 void pop_projection_matrix();
796
798 void push_modelview_matrix();
800 void pop_modelview_matrix();
801
804 //===========================================================================
807 //===========================================================================
808
809
811 const GLMatrixd& projection() const {
812 return projection_;
813 }
814
816 const GLMatrixd& modelview() const {
817 return modelview_;
818 }
819
821 const GLMatrixd& viewport() const {
822 return window2viewport_;
823 }
824
827 return window2viewport_ * projection_ * modelview_;
828 }
829
832 return inverse_projection_;
833 }
834
837 return inverse_modelview_;
838 }
839
841 void get_viewport( int& _left, int& _bottom,
842 int& _width, int& _height ) const {
843 _left = left_; _bottom = bottom_; _width = width_; _height = height_;
844 }
845
847 int viewport_width() const { return width_; }
849 int viewport_height() const { return height_; }
850
852 int context_width() const { return glwidth_; }
853
855 int context_height() const { return glheight_; }
856
858 double near_plane() const { return near_plane_; }
859
861 double far_plane() const { return far_plane_; }
862
864 double fovy() const;
865
867 double aspect() const;
868
870 Vec3d eye() const;
871
874 return viewing_direction(width_>>1, height_>>1);
875 }
876
878 Vec3d viewing_direction(int _x, int _y) const;
879
881 Vec3d up() const;
882
884 Vec3d right() const;
885
889 void viewing_ray(int _x, int _y, Vec3d& _origin, Vec3d& _direction) const;
890
895 const GLenum& depthFunc() const;
897 void set_depthFunc(const GLenum& _depth_func);
898
899
901 static void depthFunc(GLenum _depthFunc);
902
903 inline static void lockDepthFunc() {depthFuncLock_ = true;}
904 inline static void unlockDepthFunc() {depthFuncLock_ = false;}
905 inline static bool isDepthFuncLocked() {return depthFuncLock_;}
906
907
908 //--- project and unproject points ------------------------------------------
909
911 Vec3d project(const Vec3d& _point) const;
912
914 Vec3d unproject(const Vec3d& _winPoint) const;
915
916
917
918
919 //--- color & material ------------------------------------------------------
920
934 static const float default_shininess;
935
936
938 void set_color(const Vec4f& _col);
939
941 const Vec4f& color() { return color_; };
942
944 void set_clear_color(const Vec4f& _col);
946 const Vec4f& clear_color() const { return clear_color_; }
947
949 void set_base_color(const Vec4f& _col);
951 const Vec4f& base_color() const { return base_color_; }
952
954 void set_ambient_color(const Vec4f& _col);
956 const Vec4f& ambient_color() const { return ambient_color_; }
957
959 void set_diffuse_color(const Vec4f& _col);
961 const Vec4f& diffuse_color() const { return diffuse_color_; }
962
964 void set_specular_color(const Vec4f& _col);
966 const Vec4f& specular_color() const { return specular_color_; }
967
973 void set_overlay_color(const Vec4f& _col);
974
980 const Vec4f& overlay_color() const { return overlay_color_; }
981
983 void set_shininess(float _shininess);
985 float shininess() const { return shininess_; }
986
987
988
989
990 //--- thickness -------------------------------------------------------------
991
993 void set_point_size(float _f);
995 float point_size() const { return point_size_; }
996
998 void set_line_width(float _f);
1000 float line_width() const { return line_width_; }
1001
1002 //===========================================================================
1005 //===========================================================================
1006
1007public:
1009 unsigned int render_pass() const { return render_pass_; }
1010
1012 void reset_render_pass() { render_pass_ = 1; }
1013
1015 void next_render_pass() { ++render_pass_; }
1016
1018 unsigned int max_render_passes() const { return max_render_passes_; }
1019
1021 void set_max_render_passes(const unsigned int _max) { max_render_passes_ = _max; }
1022
1023private:
1026 unsigned int render_pass_;
1027
1031
1034 //===========================================================================
1037 //===========================================================================
1038
1039 public:
1042 void set_bounding_box(ACG::Vec3d _min, ACG::Vec3d _max );
1043
1046 void get_bounding_box(ACG::Vec3d& _min, ACG::Vec3d& _max );
1047
1048
1049 private:
1051
1052
1054 //--- misc ------------------------------------------------------------------
1055
1056public:
1058 void set_blending(bool _b) { blending_ = _b; }
1060 bool blending() { return blending_; }
1061
1063 void set_twosided_lighting(bool _b);
1065 bool twosided_lighting() { return twosided_lighting_; }
1066
1067 //--- Multi Sampling --------------------------------------------------------
1068
1070 void set_multisampling( bool _b );
1071
1073 bool multisampling() { return multisampling_; };
1074
1076 void allow_multisampling( bool _b ) { allow_multisampling_ = _b; };
1077
1079 bool multisampling_allowed(){ return allow_multisampling_; };
1080
1082 int max_texture_units() const { return num_texture_units_; }
1083
1084 //--- Mipmapping ------------------------------------------------------------
1085
1093 void allow_mipmapping(bool _b) { mipmapping_ = _b; }
1094
1096 bool mipmapping_allowed() const { return mipmapping_; }
1097
1098 //--- picking ---------------------------------------------------------------
1099
1109 void pick_init (bool _color);
1110
1120 bool pick_set_maximum (size_t _idx);
1121
1132 void pick_set_name (size_t _idx);
1133
1137 Vec4uc pick_get_name_color (size_t _idx);
1138
1140 Vec4f pick_get_name_color_norm (unsigned int _idx);
1141
1143 void pick_push_name (size_t _idx);
1144
1146 void pick_pop_name ();
1147
1150 std::vector<size_t> pick_color_to_stack (Vec4uc _rgba) const;
1151
1153 size_t pick_free_indicies () const;
1154
1157 bool pick_error () const;
1158
1168 size_t pick_current_index () const;
1169
1171 bool color_picking () const;
1172
1173
1174private: //--------------------------------------------------------------------
1175
1176 // matrix stacks
1177 std::stack<GLMatrixd> stack_projection_,
1178 stack_modelview_,
1179 stack_inverse_projection_,
1180 stack_inverse_modelview_;
1181
1182 // current matrices
1183 GLMatrixd projection_,
1184 inverse_projection_,
1185 modelview_,
1186 inverse_modelview_,
1187 window2viewport_,
1188 inverse_window2viewport_;
1189
1190 // viewport
1191 int left_, bottom_, width_, height_;
1192
1193 // gl context
1194 int glwidth_, glheight_;
1195
1196 // projection
1197 double near_plane_, far_plane_;
1198
1199 // colors & materials
1200 Vec4f clear_color_; //< The scenes clear color
1201 Vec4f color_;
1202 Vec4f base_color_; //< The emitted color of an Object
1203 Vec4f ambient_color_; //< The ambient color of an Object
1204 Vec4f diffuse_color_; //< The diffuse color of an Object
1205 Vec4f specular_color_; //< The specular color of an Object
1206 Vec4f overlay_color_; //< An additional color that can be used to color e.g. a wireframe overlay
1207
1208
1209 float shininess_;
1210
1211 // thickness
1212 float point_size_, line_width_;
1213
1214 // lighting
1215 bool twosided_lighting_;
1216
1217 // Multisampling settings
1218 bool multisampling_;
1219 bool allow_multisampling_;
1220
1221 static int num_texture_units_;
1222
1223 // Mipmapping settings
1224 bool mipmapping_;
1225
1226 // helper: should GL matrices be updated
1227 bool updateGL_;
1228
1229 // true -> draw tranparent Objects
1230 bool blending_;
1231
1232 // time since last redraw
1233 unsigned int msSinceLastRedraw_;
1234
1235 // stack for color picking
1236 ColorStack colorStack_;
1237
1238 // are we using color picking
1239 bool colorPicking_;
1240
1241
1242 // depth comparison function (GL_LESS by default)
1243 static bool depthFuncLock_;
1244
1245
1247 // state locking members
1248
1249 // stack needed for glPush/PopAttrib
1250 static std::deque <GLStateContext> stateStack_;
1251
1252 // all possible params for glEnable
1253 static GLenum glStateCaps[95];
1254
1255 // glEnable / glDisable states locker
1256 // iff a bit is set for a state, it is locked
1257 static std::bitset<0xFFFF+1> glStateLock_;
1258
1259 static bool blendFuncSeparateLock_[2];
1260 static bool blendEquationLock_;
1261 static bool blendColorLock_;
1262 static bool alphaFuncLock_;
1263
1264 static bool depthRangeLock_;
1265
1266
1267 // 4 buffer targets:
1268 // GL_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER, GL_PIXEL_PACK_BUFFER, GL_PIXEL_UNPACK_BUFFER
1269 static int glBufferTargetLock_[4];
1270
1271 // 16 texture stages
1272 static int glTextureStageLock_[16];
1273
1274 // current shade model: GL_FLAT, GL_SMOOTH, set by glShadeModel
1275 static bool shadeModelLock_;
1276
1277 // current cull face mode: GL_FRONT, GL_FRONT_AND_BACK
1278 static bool cullFaceLock_;
1279
1280 static bool vertexPointerLock_;
1281 static bool normalPointerLock_;
1282 static bool texcoordPointerLock_;
1283 static bool colorPointerLock_;
1284
1285
1286 // draw buffers
1287 static bool drawBufferLock_;
1288
1289 // framebuffer
1290 // framebuffer id for each target: 0 - GL_DRAW_FRAMEBUFFER, 1-> GL_READ_FRAMEBUFFER
1291 static bool framebufferLock_[2];
1292
1293 // current gl shader program
1294 static bool programLock_;
1295
1296
1297 // graphics card caps, retrieved via glGet
1298 static int maxTextureCoords_;
1299 static int maxCombinedTextureImageUnits_;
1300 static int maxDrawBuffers_;
1301};
1302
1462#ifdef _MSC_VER
1463 #pragma warning(push)
1464#endif
1465
1466//=============================================================================
1467} // namespace ACG
1468//=============================================================================
1469#endif // ACG_GLSTATE_HH defined
1470//=============================================================================
void set_msSinceLastRedraw(unsigned int _ms)
set time passed since last redraw in milliseconds
Definition: GLState.hh:241
static void vertexPointer(const Vec4f *_p)
Wrapper: glVertexPointer for Vec4f.
Definition: GLState.hh:433
static void lockDrawBuffer()
lock draw buffer state, applies to drawBuffer and drawBuffers
Definition: GLState.hh:619
static void vertexPointer(const Vec3f *_p)
Wrapper: glVertexPointer for Vec3f.
Definition: GLState.hh:429
void makeCurrent()
does nothing
Definition: GLState.hh:224
~GLState()
destructor
Definition: GLState.hh:221
int max_texture_units() const
Get max number of available texture units.
Definition: GLState.hh:1082
static void lockProgram()
lock the program
Definition: GLState.hh:654
static bool isTexcoordPointerLocked()
get vertex pointer lock state
Definition: GLState.hh:516
int context_width() const
get gl context width
Definition: GLState.hh:852
static void normalPointer(const Vec3f *_p)
Wrapper: glNormalPointer for Vec3f.
Definition: GLState.hh:450
static void unlockNormalPointer()
unlock normal pointer
Definition: GLState.hh:457
static GLenum getShadeModel()
get current shade model
Definition: GLState.hh:381
static const Vec4f default_clear_color
default value for clear color
Definition: GLState.hh:922
static void lockDepthRange()
lock depth range
Definition: GLState.hh:406
static void activeTextureARB(GLenum _texunit)
same functiona as activeTexture
Definition: GLState.hh:678
static const Vec4f default_ambient_color
default value for ambient color
Definition: GLState.hh:926
double far_plane() const
get far clipping distance
Definition: GLState.hh:861
static void lockVertexPointer()
lock vertex pointer
Definition: GLState.hh:438
static void bindBufferARB(GLenum _target, GLuint _buffer)
same function as bindBuffer
Definition: GLState.hh:579
static const float default_shininess
default value for shininess
Definition: GLState.hh:934
static void texcoordPointer(const Vec4d *_p)
Wrapper: glTexcoordPointer for Vec4d.
Definition: GLState.hh:504
const Vec4f & specular_color() const
get specular color
Definition: GLState.hh:966
static GLenum getActiveTexture()
get active GL texture
Definition: GLState.hh:682
static void colorPointer(const Vec4uc *_p)
Wrapper: glColorPointer for Vec4uc.
Definition: GLState.hh:472
static void unlockShadeModel()
unlock shade model
Definition: GLState.hh:385
static void lockTexcoordPointer()
lock color pointer
Definition: GLState.hh:512
static void unlockBlendColor()
unlock blend color
Definition: GLState.hh:359
static void lockCullFace()
lock cull face
Definition: GLState.hh:395
static void unlockTexcoordPointer()
unlock vertex pointer
Definition: GLState.hh:514
int context_height() const
get gl context height
Definition: GLState.hh:855
const GLMatrixd & modelview() const
get modelview matrix
Definition: GLState.hh:816
static void vertexPointer(const Vec4d *_p)
Wrapper: glVertexPointer for Vec4d.
Definition: GLState.hh:435
static void texcoordPointer(const Vec3d *_p)
Wrapper: glTexcoordPointer for Vec3d.
Definition: GLState.hh:500
void allow_mipmapping(bool _b)
Allow mipmapping globally.
Definition: GLState.hh:1093
int viewport_width() const
get viewport width
Definition: GLState.hh:847
void set_projection(const GLMatrixd &_m)
set projection
Definition: GLState.hh:716
unsigned int max_render_passes() const
get maximum number of render passes
Definition: GLState.hh:1018
static void unlockBlendFuncSeparate()
unlock blend func
Definition: GLState.hh:330
static void colorPointer(const Vec3f *_p)
Wrapper: glColorPointer for Vec3f.
Definition: GLState.hh:470
static void lockBlendEquation()
lock blend equation
Definition: GLState.hh:344
static bool isProgramLocked()
get program locking state
Definition: GLState.hh:658
static void texcoordPointer(const Vec4f *_p)
Wrapper: glTexcoordPointer for Vec4f.
Definition: GLState.hh:502
Vec3d viewing_direction() const
get viewing ray
Definition: GLState.hh:873
static void lockColorPointer()
lock color pointer
Definition: GLState.hh:477
void set_blending(bool _b)
set whether transparent or solid objects should be drawn
Definition: GLState.hh:1058
unsigned int render_pass() const
get current render pass counter
Definition: GLState.hh:1009
const Vec4f & base_color() const
get base color (used when lighting is off)
Definition: GLState.hh:951
static void lockBlendFuncSeparate(bool _rgb=true, bool _alpha=true)
lock blend func
Definition: GLState.hh:328
static void getBlendFunc(GLenum *_sfactor, GLenum *_dfactor)
get blend function, null-ptr safe
Definition: GLState.hh:310
void set_updateGL(bool _b)
should GL matrices be updated after each matrix operation
Definition: GLState.hh:235
const GLMatrixd & viewport() const
get viewport matrix
Definition: GLState.hh:821
static void texcoordPointer(const Vec2f *_p)
Wrapper: glTexcoordPointer for Vec2f.
Definition: GLState.hh:494
void scale(double _s, MultiplyFrom)
scale by (_s, _s, _s)
Definition: GLState.hh:779
void scale(double _s)
scale by (_s, _s, _s)
Definition: GLState.hh:775
static void texcoordPointer(const double *_p)
Wrapper: glTexcoordPointer for double.
Definition: GLState.hh:492
static bool isBlendEquationLocked()
get blend equation locking state
Definition: GLState.hh:348
const Vec4f & overlay_color() const
Get overlay color.
Definition: GLState.hh:980
static bool isCullFaceLocked()
get cull face locking state
Definition: GLState.hh:399
static void vertexPointer(const Vec2f *_p)
Wrapper: glVertexPointer for Vec2f.
Definition: GLState.hh:425
void set_max_render_passes(const unsigned int _max)
set maximum number of render passes
Definition: GLState.hh:1021
static void texcoordPointer(const Vec2d *_p)
Wrapper: glTexcoordPointer for Vec2d.
Definition: GLState.hh:496
const GLMatrixd & projection() const
get projection matrix
Definition: GLState.hh:811
static const Vec4f default_specular_color
default value for specular color
Definition: GLState.hh:930
static int getActiveTextureIndex()
get active texture as zero based index
Definition: GLState.hh:684
static void lockAlphaFunc()
lock alpha func
Definition: GLState.hh:371
static void normalPointer(const Vec3d *_p)
Wrapper: glNormalPointer for Vec3d.
Definition: GLState.hh:452
bool blending()
get whether transparenet or solid objects should be drawn
Definition: GLState.hh:1060
static void texcoordPointer(const Vec3f *_p)
Wrapper: glTexcoordPointer for Vec3f.
Definition: GLState.hh:498
void set_modelview(const GLMatrixd &_m)
set modelview
Definition: GLState.hh:753
static void colorPointer(const Vec3uc *_p)
Wrapper: glColorPointer for Vec3uc.
Definition: GLState.hh:468
static void blendFunc(GLenum _sfactor, GLenum _dfactor)
replaces glBlendFunc, supports locking
Definition: GLState.hh:307
bool multisampling_allowed()
Check if Multisampling is globally disabled.
Definition: GLState.hh:1079
static void lockBlendColor()
lock blend color
Definition: GLState.hh:357
static bool isNormalPointerLocked()
get normal pointer lock state
Definition: GLState.hh:459
static void unlockCullFace()
unlock cull face
Definition: GLState.hh:397
static bool isAlphaFuncLocked()
get alpha func locking state
Definition: GLState.hh:375
static void unlockBlendFunc()
unlock blend func
Definition: GLState.hh:315
ACG::Vec3d bb_max_
Definition: GLState.hh:1050
static const Vec4f default_diffuse_color
default value for diffuse color
Definition: GLState.hh:928
static void unlockColorPointer()
unlock vertex pointer
Definition: GLState.hh:479
static void unlockDrawBuffer()
unlock draw buffer state
Definition: GLState.hh:621
static const Vec4f default_overlay_color
default value for overlay color
Definition: GLState.hh:932
static void unlockVertexPointer()
unlock vertex pointer
Definition: GLState.hh:440
static const Vec4f default_base_color
default value for base color
Definition: GLState.hh:924
static void vertexPointer(const Vec3d *_p)
Wrapper: glVertexPointer for Vec3d.
Definition: GLState.hh:431
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:956
static void unlockDepthRange()
unlock depth range
Definition: GLState.hh:408
static void lockBlendFunc()
lock blend func
Definition: GLState.hh:313
const Vec4f & color()
set color
Definition: GLState.hh:941
GLMatrixd forward_projection() const
get forward projection matrix
Definition: GLState.hh:826
const Vec4f & clear_color() const
get background color
Definition: GLState.hh:946
static bool isBlendFuncLocked()
get blend func locking state
Definition: GLState.hh:317
const GLMatrixd & inverse_modelview() const
get inverse modelview matrix
Definition: GLState.hh:836
int viewport_height() const
get viewport height
Definition: GLState.hh:849
static void lockShadeModel()
lock shade model
Definition: GLState.hh:383
static GLenum getBlendEquation()
get blend equation
Definition: GLState.hh:341
void get_viewport(int &_left, int &_bottom, int &_width, int &_height) const
get viewport
Definition: GLState.hh:841
static bool isBlendFuncSeparateColorLocked()
replaces glEnable, but supports locking
Definition: GLState.hh:333
static GLenum getCullFace()
get current cull face
Definition: GLState.hh:393
double near_plane() const
get near clipping distance
Definition: GLState.hh:858
static void lockNormalPointer()
lock normal pointer
Definition: GLState.hh:455
static bool isDepthRangeLocked()
get depth range locking state
Definition: GLState.hh:410
bool twosided_lighting()
get whether transparenet or solid objects should be drawn
Definition: GLState.hh:1065
bool updateGL() const
should GL matrices be updated after each matrix operation
Definition: GLState.hh:233
static bool isColorPointerLocked()
get vertex pointer lock state
Definition: GLState.hh:481
static bool isShadeModelLocked()
get shade model locking state
Definition: GLState.hh:387
bool multisampling()
Get current multisampling state.
Definition: GLState.hh:1073
static void colorPointer(const Vec4f *_p)
Wrapper: glColorPointer for Vec4f.
Definition: GLState.hh:474
float line_width() const
get line width
Definition: GLState.hh:1000
static GLuint getProgram()
get bound program
Definition: GLState.hh:651
static void unlockAlphaFunc()
unlock alpha func
Definition: GLState.hh:373
static bool isBlendColorLocked()
get blend color locking state
Definition: GLState.hh:361
static void unlockProgram()
unlock the program
Definition: GLState.hh:656
const Vec4f & diffuse_color() const
get diffuse color
Definition: GLState.hh:961
void allow_multisampling(bool _b)
Disable multisampling globally.
Definition: GLState.hh:1076
void reset_render_pass()
reset render pass counter
Definition: GLState.hh:1012
static bool isBlendFuncSeparateAlphaLocked()
replaces glEnable, but supports locking
Definition: GLState.hh:334
static void vertexPointer(const Vec2d *_p)
Wrapper: glVertexPointer for Vec2d.
Definition: GLState.hh:427
static bool isBlendFuncSeparateLocked()
get blend func locking state
Definition: GLState.hh:332
static void unlockBlendEquation()
unlock blend equation
Definition: GLState.hh:346
unsigned int max_render_passes_
Definition: GLState.hh:1030
void next_render_pass()
increment render pass counter
Definition: GLState.hh:1015
unsigned int render_pass_
Definition: GLState.hh:1026
const GLMatrixd & inverse_projection() const
get inverse projection matrix
Definition: GLState.hh:831
static bool isDrawBufferLocked()
get draw buffer lock state
Definition: GLState.hh:623
static void texcoordPointer(const float *_p)
Wrapper: glTexcoordPointer for float.
Definition: GLState.hh:490
bool mipmapping_allowed() const
Get current global mipmapping state.
Definition: GLState.hh:1096
static bool isVertexPointerLocked()
get vertex pointer lock state
Definition: GLState.hh:442
float shininess() const
get specular shininess (must be in [0, 128])
Definition: GLState.hh:985
float point_size() const
get point size
Definition: GLState.hh:995
bool invert()
matrix inversion (returns true on success)
Namespace providing different geometric functions concerning angles.
MultiplyFrom
Definition: GLMatrixT.hh:73
void compatibilityProfile(bool _enableCoreProfile)
Store opengl core profile setting.
Definition: gl.cc:166