VTK
vtkOpenGLState.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkOpenGLState.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
33 #ifndef __vtkOpenGLState_h
34 #define __vtkOpenGLState_h
35 
36 #include "vtkgl.h"
37 #include <vtkstd/vector>
38 
40 
42 {
43 public:
44  GLfloat Ambient[4];
45  GLfloat Diffuse[4];
46  GLfloat Specular[4];
47  GLfloat Shininess;
48 
49  GLfloat AmbientIndex;
50  GLfloat DiffuseIndex;
51  GLfloat SpecularIndex;
52 };
53 
55 {
56 public:
57  void Update();
58 
59  GLfloat Ambient[4];
60  GLfloat Diffuse[4];
61  GLfloat Specular[4];
62  GLfloat Position[4];
66  GLfloat SpotDirection[4];
67  GLfloat SpotExponent;
68  GLfloat SpotCutoff;
69 };
70 
72 {
73 public:
74  void Update();
75 
76  GLvoid *Image;
77  GLint Width;
78  GLint Height;
79  GLint Border;
81  GLint RedSize;
82  GLint GreenSize;
83  GLint BlueSize;
84  GLint AlphaSize;
87 
88  // 1.2.1
89  GLint Depth;
90 
91  // 1.3
92  GLboolean Compressed;
94 
95  // 1.4
96  GLint DepthSize;
97 
98 };
99 
100 #if 0
101 class vtkOpenGLTextureObjectState
102 {
103 public:
104  void Update();
105 
106  static const int n=10;
107  vtkOpenGLTextureImageState Texture1D[n];
108  vtkOpenGLTextureImageState Texture2D[n];
109 
110  GLfloat BorderColor[4];
111  GLint MinFilter;
112  GLint MagFilter;
113  GLint WrapS;
114  GLint WrapT;
115  GLfloat TexturePriority;
116  GLboolean TextureResident;
117 
118  // 1.2.1
119  vtkOpenGLTextureImageState Texture3D[n];
120 
121  GLint WrapR;
122  GLint MinLOD;
123  GLint MaxLOD;
124  GLint BaseLevel;
125  GLint MaxLevel;
126 
127  // 1.3
128  vtkOpenGLTextureImageState TextureCubeMapPositiveX[n];
129  vtkOpenGLTextureImageState TextureCubeMapNegativeX[n];
130  vtkOpenGLTextureImageState TextureCubeMapPositiveY[n];
131  vtkOpenGLTextureImageState TextureCubeMapNegativeY[n];
132  vtkOpenGLTextureImageState TextureCubeMapPositiveZ[n];
133  vtkOpenGLTextureImageState TextureCubeMapNegativeZ[n];
134 
135  // 1.4
136  GLfloat LODBias;
137  GLint DepthTextureMode;
138  GLint TextureCompareMode;
139  GLint TextureCompareFunc;
140  GLboolean GenerateMipmap;
141 };
142 #endif
143 
145 {
146 public:
147  void Update();
148 
149  GLboolean Enabled;
150  GLfloat EyePlane[4];
151  GLfloat ObjectPlane[4];
152  GLint Mode;
153 };
154 
156 {
157 public:
158  void Update();
159  void PrintSelf(ostream &os,
160  vtkIndent indent);
161  GLboolean SwapBytes;
162  GLboolean LsbFirst; // Warning: cannot be LSBFirst, as it is defined in X.h
163  GLint RowLength;
164  GLint SkipRows;
165  GLint SkipPixels;
166  GLint Alignment;
167 
168  // 1.2.1
169  GLint ImageHeight;
170  GLint SkipImages;
171 };
172 
174 {
175 public:
176  void Update();
177  void PrintSelf(ostream &os,
178  vtkIndent indent);
179  GLfloat Scale;
180  GLfloat Bias;
181 };
182 
184 {
185 public:
186  void Update();
187 
188  GLint Size;
189  GLfloat *Map; // values
190 };
191 
193 {
194 public:
195  void Update();
196 
197  GLint Size;
198  GLint *Map; // values
199 };
200 
202 {
203 public:
204  GLfloat CurrentMatrix[16];
210  // Texture environment generation, 2.0
211  GLboolean CoordReplace;
212 
215 };
216 
218 {
219 public:
220  // Texture object bound to 1D target/sampler
222  // Texture object bound to 2D target/sampler
224  // 1.2.1
225  // Texture object bound to 3D target/sampler
227  // 1.3
228  // Texture object bound to cubemap target/sampler
230 };
231 
233 {
234 public:
235  GLboolean Texture1DEnabled;
236  GLboolean Texture2DEnabled;
237  // 1.2.1
238  GLboolean Texture3DEnabled;
239  // 1.3
241 };
242 
244 {
245 public:
246  GLfloat Equation[4];
247  GLboolean Enabled;
248 };
249 
250 
251 // Replaced by shader program
253 {
254 public:
255  // Replaced by verter shader
256 
257  // Transformation state
258  GLboolean Normalize;
259 
260  // Transformation state: 1.2.1
261  GLboolean RescaleNormal;
262 
263  // Lighting
264  GLboolean LightingEnabled;
265 
266  vtkstd::vector<GLboolean> *LightEnabled; // MaxLights (ex:8)
267 
268 
269  // Replaced by fragment shader:
270 
271  // 1.3
272  GLint CombineRGB;
274  GLint Source0RGB;
275  GLint Source1RGB;
276  GLint Source2RGB;
280  GLint Operand0RGB;
281  GLint Operand1RGB;
282  GLint Operand2RGB;
286  GLint RGBScale;
287  GLint AlphaScale;
288 
289  vtkstd::vector<vtkOpenGLTextureImageUnitFixedPipelineState> *TextureImageUnitEnabled; // MaxTextureUnits (ex: 4)
290 
291  // Coloring
292  GLboolean FogEnabled;
293  // Coloring, 1.4
294  GLboolean ColorSumEnabled;
295 };
296 
298 {
299 public:
300  void PrintSelf(ostream &os,
301  vtkIndent indent);
302 
303  GLuint Id;
304  GLint Size;
305  GLenum Usage;
306  GLenum Access;
307  GLenum AccessFlags; // in GL 3.1 spec but missing in header files
308  GLboolean Mapped;
309  GLvoid *MapPointer;
310  GLint MapOffset; // in GL 3.1 spec but missing in header files
311  GLint MapLength; // in GL 3.1 spec but missing in header files
312 protected:
313  void BufferAccessFlagsToStream(ostream &os);
314  const char *BufferUsageToString();
315  const char *BufferAccessToString();
316 };
317 
319 {
320 public:
321  void PrintSelf(ostream &os,
322  vtkIndent indent);
323  GLuint Id;
324  GLenum Type;
325  GLboolean DeleteStatus;
326  GLboolean CompileStatus;
327  vtkgl::GLchar *InfoLog;
329  vtkgl::GLchar *Source;
331 protected:
332  const char *ShaderTypeToString();
333 };
334 
336 {
337 public:
338  void PrintSelf(ostream &os,
339  vtkIndent indent);
340  GLuint Id;
341  GLboolean DeleteStatus;
342  GLboolean LinkStatus;
343  GLboolean ValidateStatus;
350  vtkstd::vector<vtkOpenGLShaderState> *AttachedShaders;
351  vtkgl::GLchar *InfoLog;
352 
353 
356 };
357 
359 {
360 public:
362  ~vtkOpenGLState();
363 
364  // Save current OpenGL state in the object.
365  void Update();
366 
367  void PrintSelf(ostream &os,
368  vtkIndent indent);
369 
370  // There are too many variables to make them protected and implement
371  // a public Get method for each of them. We keep them public.
372  // I wish C++ would syntaxically forbid construction like c->value=x,
373  // like Eiffel does...
374 
375 
377 
378  // OpenGL 1.1 state
379 
380  // Current values and associated data
381 
382  GLfloat CurrentColor[4];
383  GLfloat CurrentIndex;
384  // CurrentTextureCoords: see vtkOpenGLTextureCoordinateProcessingUnit
385  GLfloat CurrentNormal[3];
386 
387  GLfloat CurrentRasterPosition[4];
389  GLfloat CurrentRasterColor[4];
391  // CurrentRasterTextureCoords: see vtkOpenGLTextureCoordinateProcessingUnit
393  GLboolean EdgeFlag;
394 
395  // Current values and associated data, 1.4
396  GLfloat CurrentSecondaryColor[4];
397  GLfloat CurrentFogCoordinate[3]; // or scalar?
398 
399  // Current values and associated data, 2.1
400  GLfloat CurrentRasterSecondaryColor[4];
401 
402 
403  // Vertex Array Data
404 
410 
415 
416  GLboolean ColorArrayEnabled;
421 
422  GLboolean IndexArrayEnabled;
426 
432 
433  GLboolean EdgeFlagArray;
436 
437  // Vertex Array Data, 1.3
439 
440  // Vertex Array Data, 1.4
445 
451 
452  // Vertex Array Data, 1.5, VBO
463 
464  // Vertex Array Data, 2.0
471 
472  // Vertex Array Data, 2.1
474 
475  // Buffer Object State, 1.5
476  GLint BufferSize;
477  GLint BufferUsage;
479  GLboolean BufferMapped;
481 
482  // Transformation state
483 
484  GLfloat ModelViewMatrix[16];
486 
487  GLfloat ProjectionMatrix[16];
489 
490  // 2.0
491  GLint MaxTextureCoords; // 8
492  vtkstd::vector<vtkOpenGLTextureCoordinateProcessingUnit> *TCPU;
493 
494  // 2.0
496  vtkstd::vector<vtkOpenGLTextureImageUnit> *TIU;
497 
498  GLint Viewport[4];
499  GLfloat DepthRange[2];
500 
501  GLint MatrixMode;
502  GLboolean Normalize;
503 
504  vtkstd::vector<vtkOpenGLClipPlaneState> *ClipPlanes; // MaxClipPlanes (ex: 6)
505 
506  // Transformation state: 1.2.1, optional
507  GLfloat ColorMatrix[16];
509 
510  // Coloring
511 
512  GLfloat FogColor[4];
513  GLfloat FogIndex;
514  GLfloat FogDensity;
515  GLfloat FogStart;
516  GLfloat FogEnd;
517  GLint FogMode;
518 
519  GLint ShadeModel; // fixed-pipeline and GLSL
520 
521  // Coloring, 1.4
522  GLint FogCoordinateSource; // renamed FogCoordSrc in 1.5
523 
524  // Lighting
530 
531  GLfloat LightModelAmbient[4];
533  GLboolean LightModelTwoSide;
534 
535  vtkstd::vector<vtkOpenGLLightState> *Lights; // MaxLights (ex: 8)
536 
537  // Lighting: 1.2.1
539 
540  // Rasterization
541  GLfloat PointSize;
543 
544  GLfloat LineWidth;
545  GLboolean LineSmoothEnabled;
549 
550  GLboolean CullFaceEnabled;
552  GLint FrontFace;
554  GLint PolygonMode[2]; //0=front, 1=back
562 
563  // Rasterization, 1.4
564  GLfloat PointSizeMin;
565  GLfloat PointSizeMax;
568 
569  // Rasterization, 2.0
572 
573  // Multisampling (1.2.1)
580 
581 
582 
583 // vtkOpenGLTextureObjectState TextureObjects;
584 
585  // Texture environment generation
588 
589  // Texture environment generation, 1.3
591 
592  // Texture environment generation, 1.4
593  GLfloat TextureLODBias;
594 
595  // Pixel operations
596  // - Scissor
598  GLint ScissorBox[4];
599 
600  GLboolean AlphaTestEnabled;
602  GLfloat AlphaTestRef;
603 
605  GLint StencilFunc;
607  GLint StencilRef;
608  GLint StencilFail;
611 
612  // - Stencil, 2.0
619 
620  GLboolean DepthTestEnabled;
621  GLint DepthFunc;
622 
623  GLboolean BlendEnabled;
624  GLint BlendSrc; // <=1.3
625  GLint BlendDst; // <=1.3
626 
627  // Optional in 1.2.1, mandatory in 1.4
628  GLint BlendEquation; // renamed BlendEquationRGB in 2.0
629  GLfloat BlendColor[4];
630 
631  // 1.4
632  GLint BlendSrcRGB;
634  GLint BlendDstRGB;
636 
637  // 2.0
640 
641  GLboolean DitherEnabled;
642 
645  GLint LogicOpMode;
646 
647  // Framebuffer control (drawing)
648 
649  // 2.0
651  vtkstd::vector<GLint> *DrawBuffers;
652 
654  GLboolean ColorWriteMask[4];
655  GLboolean DepthWriteMask;
657  GLfloat ColorClearValue[4];
661  GLfloat AccumClearValue[4];
662 
663  // Framebuffer control (drawing) 2.0
665 
666  // Framebuffer control (drawing) 2.1
667  GLint DrawBuffer0;
668  GLint DrawBuffer1;
669  GLint DrawBuffer3; // <max
670 
671  // Pixels
672 
675 
676  GLboolean MapColor; // see PixelMap
677  GLboolean MapStencil; // see PixelMap
678  GLint IndexShift;
679  GLint IndexOffset;
680 
686 
687  GLfloat ZoomX;
688  GLfloat ZoomY;
689 
690  // Size==1 <=> not used.
701 
702  // Pixels, 2.1
705 
706  // Relevant only if PixelPackBufferBinding>0
708  // Relevant only if PixelUnPackBufferBinding>0
710 
711  // 1.2.1, optional
712  GLboolean ColorTableEnabled;
715  // TODO ...
716 
717  // Framebuffer control (reading)
718 
719  GLint ReadBuffer;
720 
721  // Evaluators
722  // TODO
723 
724  // Shader Object State 2.0
726 
727 #if 0
728  GLint ShaderType;
729  GLboolean DeleteStatus;
730  GLboolean CompileStatus;
731  vtkgl::GLchar *ShaderLogInfo;
732  GLint InfoLogLength;
733  vtkgl::GLchar *ShaderSource;
734  GLint ShaderSourceLength;
735 #endif
736  // Program Object State 2.0
738 
739 #if 0
740  GLboolean DeleteStatus;
741  GLboolean LinkStatus;
742  GLboolean ValidateStatus;
743  GLint *AttachedShaders;
744  GLint InfoLogLength;
745  GLint ActiveUniforms;
746  GLint ActiveUniformMaxLength;
747  GLint ActiveAttributes;
748  GLint ActiveAttributesMaxLength;
749 #endif
750 
751  // Vertex Shader State 2.0
753  GLfloat CurrentVertexAttrib[16][4];
755 
756  // Hints
761  GLint FogHint;
762  // Hints: 1.3
764  // Hints: 1.4
766  // Hints: 2.0
768 
769  // Implementation dependent values
770 
771  // per OpenGL implementation
772 
773  GLint MaxLights;
787 
788  // per framebuffer
789  GLint AuxBuffers;
790  GLboolean RGBAMode;
791  GLboolean IndexMode;
792  GLboolean DoubleBuffer;
793  GLboolean Stereo;
794 
795  // per framebuffer object
797 
798  // per OpenGL implementation
799 
800  GLfloat PointSizeRange[2]; // 1.2.1: renamed SmoothPointSizeRange
801  GLfloat PointSizeGranularity; // 1.2.1: renamed SmoothPointSizeGranularity
802  GLfloat LineWidthRange[2]; // 1.2.1: renamed SmoothLineWidthRange
803  GLfloat LineWidthGranularity; // 1.2.1: renamed SmoothLineWidthGranularity
804 
805  // per framebuffer (for each color buffer)
806  GLint RedBits;
807  GLint GreenBits;
808  GLint BlueBits;
809  GLint AlphaBits;
810  GLint IndexBits;
811 
812  GLint DepthBits; // depth buffer
813  GLint StencilBits; // stencil buffer
814 
819 
820  // per OpenGL implementation, 1.2.1
822  GLfloat AliasedPointSizeRange[2];
823  GLfloat AliasedLineWidthRange[2];
826 
827 
828  // per OpenGL implementation, 1.2.1, optional
830  GLint MaxConvolutionWidth[3];
831  GLint MaxConvolutionHeight[2];
832 
833  // per OpenGL implementation, 1.3
838 
839  // per framebuffer, 1.3
841  GLint Samples;
842 
843  // per OpenGL implementation, 1.4
845 
846  // per OpenGL implementation, 1.5
848 
849  // per OpenGL implementations, 2.0
850  GLubyte *Extensions;
851  GLubyte *Renderer;
853  GLubyte *Vendor;
854  GLubyte *Version;
861 
862  // Misc.
863 
864  // - Display lists
865  GLint ListBase;
866  GLint ListIndex;
867  GLint ListMode;
868 
869 
870  // - Current depth of stacks
874 
875  GLint RenderMode;
876 
877  // - Selection buffer
880 
881  // - Feedback buffer
885 
886  // - error code
887  GLenum ErrorCode;
888 
889  // Misc, 1.5
891 
892  // Framebuffer, GL_EXT_framebuffer_object
894  GLint Read;
895 
896 protected:
897  void UpdateCurrentProgram();
898  void UpdateShader(size_t i);
899 
900  void ColorBufferToStream(ostream &os,GLint colorBuffer);
901  const char *ErrorCodeToString();
902  const char *BlendFuncToString(GLint blendFunc);
903  const char *BlendEquationToString(GLint blendEquation);
904  const char *LogicOpModeToString();
905  const char *ListModeToString();
906  const char *BooleanToString(GLint booleanValue);
907  const char *ShadeModelToString();
908  const char *CullFaceModeToString();
909  const char *FrontFaceToString();
910  const char *PolygonModeToString(GLint polygonMode);
911  const char *AlphaTestFuncToString();
912  const char *DepthFuncToString();
913  const char *RenderModeToString();
914  const char *MatrixModeToString();
915 
916  const char *ValueToString(GLint value,
917  int valueTable[],
918  const char *stringTable[],
919  int tableSize);
920 
921  void PrintMatrix(ostream &os,
922  vtkIndent indent,
923  GLfloat matrix[16]);
924 
926 };
927 
928 
929 
930 #endif