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 "vtkRenderingOpenGLModule.h" // For export macro
37 #include "vtkgl.h"
38 #include <vector>
39 
41 
43 {
44 public:
45  GLfloat Ambient[4];
46  GLfloat Diffuse[4];
47  GLfloat Specular[4];
48  GLfloat Shininess;
49 
50  GLfloat AmbientIndex;
51  GLfloat DiffuseIndex;
52  GLfloat SpecularIndex;
53 };
54 
56 {
57 public:
58  void Update();
59 
60  GLfloat Ambient[4];
61  GLfloat Diffuse[4];
62  GLfloat Specular[4];
63  GLfloat Position[4];
67  GLfloat SpotDirection[4];
68  GLfloat SpotExponent;
69  GLfloat SpotCutoff;
70 };
71 
73 {
74 public:
75  void Update();
76 
77  GLvoid *Image;
78  GLint Width;
79  GLint Height;
80  GLint Border;
82  GLint RedSize;
83  GLint GreenSize;
84  GLint BlueSize;
85  GLint AlphaSize;
88 
89  // 1.2.1
90  GLint Depth;
91 
92  // 1.3
93  GLboolean Compressed;
95 
96  // 1.4
97  GLint DepthSize;
98 
99 };
100 
101 #if 0
102 class vtkOpenGLTextureObjectState
103 {
104 public:
105  void Update();
106 
107  static const int n=10;
108  vtkOpenGLTextureImageState Texture1D[n];
109  vtkOpenGLTextureImageState Texture2D[n];
110 
111  GLfloat BorderColor[4];
112  GLint MinFilter;
113  GLint MagFilter;
114  GLint WrapS;
115  GLint WrapT;
116  GLfloat TexturePriority;
117  GLboolean TextureResident;
118 
119  // 1.2.1
120  vtkOpenGLTextureImageState Texture3D[n];
121 
122  GLint WrapR;
123  GLint MinLOD;
124  GLint MaxLOD;
125  GLint BaseLevel;
126  GLint MaxLevel;
127 
128  // 1.3
129  vtkOpenGLTextureImageState TextureCubeMapPositiveX[n];
130  vtkOpenGLTextureImageState TextureCubeMapNegativeX[n];
131  vtkOpenGLTextureImageState TextureCubeMapPositiveY[n];
132  vtkOpenGLTextureImageState TextureCubeMapNegativeY[n];
133  vtkOpenGLTextureImageState TextureCubeMapPositiveZ[n];
134  vtkOpenGLTextureImageState TextureCubeMapNegativeZ[n];
135 
136  // 1.4
137  GLfloat LODBias;
138  GLint DepthTextureMode;
139  GLint TextureCompareMode;
140  GLint TextureCompareFunc;
141  GLboolean GenerateMipmap;
142 };
143 #endif
144 
146 {
147 public:
148  void Update();
149 
150  GLboolean Enabled;
151  GLfloat EyePlane[4];
152  GLfloat ObjectPlane[4];
153  GLint Mode;
154 };
155 
157 {
158 public:
159  void Update();
160  void PrintSelf(ostream &os,
161  vtkIndent indent);
162  GLboolean SwapBytes;
163  GLboolean LsbFirst; // Warning: cannot be LSBFirst, as it is defined in X.h
164  GLint RowLength;
165  GLint SkipRows;
166  GLint SkipPixels;
167  GLint Alignment;
168 
169  // 1.2.1
170  GLint ImageHeight;
171  GLint SkipImages;
172 };
173 
175 {
176 public:
177  void Update();
178  void PrintSelf(ostream &os,
179  vtkIndent indent);
180  GLfloat Scale;
181  GLfloat Bias;
182 };
183 
185 {
186 public:
187  void Update();
188 
189  GLint Size;
190  GLfloat *Map; // values
191 };
192 
194 {
195 public:
196  void Update();
197 
198  GLint Size;
199  GLint *Map; // values
200 };
201 
203 {
204 public:
205  GLfloat CurrentMatrix[16];
211  // Texture environment generation, 2.0
212  GLboolean CoordReplace;
213 
216 };
217 
219 {
220 public:
221  // Texture object bound to 1D target/sampler
223  // Texture object bound to 2D target/sampler
225  // 1.2.1
226  // Texture object bound to 3D target/sampler
228  // 1.3
229  // Texture object bound to cubemap target/sampler
231 };
232 
234 {
235 public:
236  GLboolean Texture1DEnabled;
237  GLboolean Texture2DEnabled;
238  // 1.2.1
239  GLboolean Texture3DEnabled;
240  // 1.3
242 };
243 
245 {
246 public:
247  GLfloat Equation[4];
248  GLboolean Enabled;
249 };
250 
251 
252 // Replaced by shader program
254 {
255 public:
256  // Replaced by verter shader
257 
258  // Transformation state
259  GLboolean Normalize;
260 
261  // Transformation state: 1.2.1
262  GLboolean RescaleNormal;
263 
264  // Lighting
265  GLboolean LightingEnabled;
266 
267  std::vector<GLboolean> *LightEnabled; // MaxLights (ex:8)
268 
269 
270  // Replaced by fragment shader:
271 
272  // 1.3
273  GLint CombineRGB;
275  GLint Source0RGB;
276  GLint Source1RGB;
277  GLint Source2RGB;
281  GLint Operand0RGB;
282  GLint Operand1RGB;
283  GLint Operand2RGB;
287  GLint RGBScale;
288  GLint AlphaScale;
289 
290  std::vector<vtkOpenGLTextureImageUnitFixedPipelineState> *TextureImageUnitEnabled; // MaxTextureUnits (ex: 4)
291 
292  // Coloring
293  GLboolean FogEnabled;
294  // Coloring, 1.4
295  GLboolean ColorSumEnabled;
296 };
297 
299 {
300 public:
301  void PrintSelf(ostream &os,
302  vtkIndent indent);
303 
304  GLuint Id;
305  GLint Size;
306  GLenum Usage;
307  GLenum Access;
308  GLenum AccessFlags; // in GL 3.1 spec but missing in header files
309  GLboolean Mapped;
310  GLvoid *MapPointer;
311  GLint MapOffset; // in GL 3.1 spec but missing in header files
312  GLint MapLength; // in GL 3.1 spec but missing in header files
313 protected:
314  void BufferAccessFlagsToStream(ostream &os);
315  const char *BufferUsageToString();
316  const char *BufferAccessToString();
317 };
318 
320 {
321 public:
322  void PrintSelf(ostream &os,
323  vtkIndent indent);
324  GLuint Id;
325  GLenum Type;
326  GLboolean DeleteStatus;
327  GLboolean CompileStatus;
328  vtkgl::GLchar *InfoLog;
330  vtkgl::GLchar *Source;
332 protected:
333  const char *ShaderTypeToString();
334 };
335 
337 {
338 public:
339  void PrintSelf(ostream &os,
340  vtkIndent indent);
341  GLuint Id;
342  GLboolean DeleteStatus;
343  GLboolean LinkStatus;
344  GLboolean ValidateStatus;
351  std::vector<vtkOpenGLShaderState> *AttachedShaders;
352  vtkgl::GLchar *InfoLog;
353 
354 
357 };
358 
359 class VTKRENDERINGOPENGL_EXPORT vtkOpenGLState
360 {
361 public:
363  ~vtkOpenGLState();
364 
365  // Save current OpenGL state in the object.
366  void Update();
367 
368  void PrintSelf(ostream &os,
369  vtkIndent indent);
370 
371  // There are too many variables to make them protected and implement
372  // a public Get method for each of them. We keep them public.
373  // I wish C++ would syntaxically forbid construction like c->value=x,
374  // like Eiffel does...
375 
376 
378 
379  // OpenGL 1.1 state
380 
381  // Current values and associated data
382 
383  GLfloat CurrentColor[4];
384  GLfloat CurrentIndex;
385  // CurrentTextureCoords: see vtkOpenGLTextureCoordinateProcessingUnit
386  GLfloat CurrentNormal[3];
387 
388  GLfloat CurrentRasterPosition[4];
390  GLfloat CurrentRasterColor[4];
392  // CurrentRasterTextureCoords: see vtkOpenGLTextureCoordinateProcessingUnit
394  GLboolean EdgeFlag;
395 
396  // Current values and associated data, 1.4
397  GLfloat CurrentSecondaryColor[4];
398  GLfloat CurrentFogCoordinate[3]; // or scalar?
399 
400  // Current values and associated data, 2.1
401  GLfloat CurrentRasterSecondaryColor[4];
402 
403 
404  // Vertex Array Data
405 
411 
416 
417  GLboolean ColorArrayEnabled;
422 
423  GLboolean IndexArrayEnabled;
427 
433 
434  GLboolean EdgeFlagArray;
437 
438  // Vertex Array Data, 1.3
440 
441  // Vertex Array Data, 1.4
446 
452 
453  // Vertex Array Data, 1.5, VBO
464 
465  // Vertex Array Data, 2.0
472 
473  // Vertex Array Data, 2.1
475 
476  // Buffer Object State, 1.5
477  GLint BufferSize;
478  GLint BufferUsage;
480  GLboolean BufferMapped;
482 
483  // Transformation state
484 
485  GLfloat ModelViewMatrix[16];
487 
488  GLfloat ProjectionMatrix[16];
490 
491  // 2.0
492  GLint MaxTextureCoords; // 8
493  std::vector<vtkOpenGLTextureCoordinateProcessingUnit> *TCPU;
494 
495  // 2.0
497  std::vector<vtkOpenGLTextureImageUnit> *TIU;
498 
499  GLint Viewport[4];
500  GLfloat DepthRange[2];
501 
502  GLint MatrixMode;
503  GLboolean Normalize;
504 
505  std::vector<vtkOpenGLClipPlaneState> *ClipPlanes; // MaxClipPlanes (ex: 6)
506 
507  // Transformation state: 1.2.1, optional
508  GLfloat ColorMatrix[16];
510 
511  // Coloring
512 
513  GLfloat FogColor[4];
514  GLfloat FogIndex;
515  GLfloat FogDensity;
516  GLfloat FogStart;
517  GLfloat FogEnd;
518  GLint FogMode;
519 
520  GLint ShadeModel; // fixed-pipeline and GLSL
521 
522  // Coloring, 1.4
523  GLint FogCoordinateSource; // renamed FogCoordSrc in 1.5
524 
525  // Lighting
531 
532  GLfloat LightModelAmbient[4];
534  GLboolean LightModelTwoSide;
535 
536  std::vector<vtkOpenGLLightState> *Lights; // MaxLights (ex: 8)
537 
538  // Lighting: 1.2.1
540 
541  // Rasterization
542  GLfloat PointSize;
544 
545  GLfloat LineWidth;
546  GLboolean LineSmoothEnabled;
550 
551  GLboolean CullFaceEnabled;
553  GLint FrontFace;
555  GLint PolygonMode[2]; //0=front, 1=back
563 
564  // Rasterization, 1.4
565  GLfloat PointSizeMin;
566  GLfloat PointSizeMax;
569 
570  // Rasterization, 2.0
573 
574  // Multisampling (1.2.1)
581 
582 
583 
584 // vtkOpenGLTextureObjectState TextureObjects;
585 
586  // Texture environment generation
589 
590  // Texture environment generation, 1.3
592 
593  // Texture environment generation, 1.4
594  GLfloat TextureLODBias;
595 
596  // Pixel operations
597  // - Scissor
599  GLint ScissorBox[4];
600 
601  GLboolean AlphaTestEnabled;
603  GLfloat AlphaTestRef;
604 
606  GLint StencilFunc;
608  GLint StencilRef;
609  GLint StencilFail;
612 
613  // - Stencil, 2.0
620 
621  GLboolean DepthTestEnabled;
622  GLint DepthFunc;
623 
624  GLboolean BlendEnabled;
625  GLint BlendSrc; // <=1.3
626  GLint BlendDst; // <=1.3
627 
628  // Optional in 1.2.1, mandatory in 1.4
629  GLint BlendEquation; // renamed BlendEquationRGB in 2.0
630  GLfloat BlendColor[4];
631 
632  // 1.4
633  GLint BlendSrcRGB;
635  GLint BlendDstRGB;
637 
638  // 2.0
641 
642  GLboolean DitherEnabled;
643 
646  GLint LogicOpMode;
647 
648  // Framebuffer control (drawing)
649 
650  // 2.0
652  std::vector<GLint> *DrawBuffers;
653 
655  GLboolean ColorWriteMask[4];
656  GLboolean DepthWriteMask;
658  GLfloat ColorClearValue[4];
662  GLfloat AccumClearValue[4];
663 
664  // Framebuffer control (drawing) 2.0
666 
667  // Framebuffer control (drawing) 2.1
668  GLint DrawBuffer0;
669  GLint DrawBuffer1;
670  GLint DrawBuffer3; // <max
671 
672  // Pixels
673 
676 
677  GLboolean MapColor; // see PixelMap
678  GLboolean MapStencil; // see PixelMap
679  GLint IndexShift;
680  GLint IndexOffset;
681 
687 
688  GLfloat ZoomX;
689  GLfloat ZoomY;
690 
691  // Size==1 <=> not used.
702 
703  // Pixels, 2.1
706 
707  // Relevant only if PixelPackBufferBinding>0
709  // Relevant only if PixelUnPackBufferBinding>0
711 
712  // 1.2.1, optional
713  GLboolean ColorTableEnabled;
716  // TODO ...
717 
718  // Framebuffer control (reading)
719 
720  GLint ReadBuffer;
721 
722  // Evaluators
723  // TODO
724 
725  // Shader Object State 2.0
727 
728 #if 0
729  GLint ShaderType;
730  GLboolean DeleteStatus;
731  GLboolean CompileStatus;
732  vtkgl::GLchar *ShaderLogInfo;
733  GLint InfoLogLength;
734  vtkgl::GLchar *ShaderSource;
735  GLint ShaderSourceLength;
736 #endif
737  // Program Object State 2.0
739 
740 #if 0
741  GLboolean DeleteStatus;
742  GLboolean LinkStatus;
743  GLboolean ValidateStatus;
744  GLint *AttachedShaders;
745  GLint InfoLogLength;
746  GLint ActiveUniforms;
747  GLint ActiveUniformMaxLength;
748  GLint ActiveAttributes;
749  GLint ActiveAttributesMaxLength;
750 #endif
751 
752  // Vertex Shader State 2.0
754  GLfloat CurrentVertexAttrib[16][4];
756 
757  // Hints
762  GLint FogHint;
763  // Hints: 1.3
765  // Hints: 1.4
767  // Hints: 2.0
769 
770  // Implementation dependent values
771 
772  // per OpenGL implementation
773 
774  GLint MaxLights;
788 
789  // per framebuffer
790  GLint AuxBuffers;
791  GLboolean RGBAMode;
792  GLboolean IndexMode;
793  GLboolean DoubleBuffer;
794  GLboolean Stereo;
795 
796  // per framebuffer object
798 
799  // per OpenGL implementation
800 
801  GLfloat PointSizeRange[2]; // 1.2.1: renamed SmoothPointSizeRange
802  GLfloat PointSizeGranularity; // 1.2.1: renamed SmoothPointSizeGranularity
803  GLfloat LineWidthRange[2]; // 1.2.1: renamed SmoothLineWidthRange
804  GLfloat LineWidthGranularity; // 1.2.1: renamed SmoothLineWidthGranularity
805 
806  // per framebuffer (for each color buffer)
807  GLint RedBits;
808  GLint GreenBits;
809  GLint BlueBits;
810  GLint AlphaBits;
811  GLint IndexBits;
812 
813  GLint DepthBits; // depth buffer
814  GLint StencilBits; // stencil buffer
815 
820 
821  // per OpenGL implementation, 1.2.1
823  GLfloat AliasedPointSizeRange[2];
824  GLfloat AliasedLineWidthRange[2];
827 
828 
829  // per OpenGL implementation, 1.2.1, optional
831  GLint MaxConvolutionWidth[3];
832  GLint MaxConvolutionHeight[2];
833 
834  // per OpenGL implementation, 1.3
839 
840  // per framebuffer, 1.3
842  GLint Samples;
843 
844  // per OpenGL implementation, 1.4
846 
847  // per OpenGL implementation, 1.5
849 
850  // per OpenGL implementations, 2.0
851  GLubyte *Extensions;
852  GLubyte *Renderer;
854  GLubyte *Vendor;
855  GLubyte *Version;
862 
863  // Misc.
864 
865  // - Display lists
866  GLint ListBase;
867  GLint ListIndex;
868  GLint ListMode;
869 
870 
871  // - Current depth of stacks
875 
876  GLint RenderMode;
877 
878  // - Selection buffer
881 
882  // - Feedback buffer
886 
887  // - error code
888  GLenum ErrorCode;
889 
890  // Misc, 1.5
892 
893  // Framebuffer, GL_EXT_framebuffer_object
895  GLint Read;
896 
897 protected:
898  void UpdateCurrentProgram();
899  void UpdateShader(size_t i);
900 
901  void ColorBufferToStream(ostream &os,GLint colorBuffer);
902  const char *ErrorCodeToString();
903  const char *BlendFuncToString(GLint blendFunc);
904  const char *BlendEquationToString(GLint blendEquation);
905  const char *LogicOpModeToString();
906  const char *ListModeToString();
907  const char *BooleanToString(GLint booleanValue);
908  const char *ShadeModelToString();
909  const char *CullFaceModeToString();
910  const char *FrontFaceToString();
911  const char *PolygonModeToString(GLint polygonMode);
912  const char *AlphaTestFuncToString();
913  const char *DepthFuncToString();
914  const char *RenderModeToString();
915  const char *MatrixModeToString();
916 
917  const char *ValueToString(GLint value,
918  int valueTable[],
919  const char *stringTable[],
920  int tableSize);
921 
922  void PrintMatrix(ostream &os,
923  vtkIndent indent,
924  GLfloat matrix[16]);
925 
927 };
928 
929 
930 
931 #endif
932 // VTK-HeaderTest-Exclude: vtkOpenGLState.h