VTK
vtkVolumeStateRAII.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkVolumeStateRAII.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 =========================================================================*/
15 #ifndef vtkVolumeStateRAII_h
16 #define vtkVolumeStateRAII_h
17 #include "vtkOpenGLRenderWindow.h"
18 
19 // Only these states can be queries via glIsEnabled:
20 // http://www.khronos.org/opengles/sdk/docs/man/
21 
23 {
24  public:
25  vtkVolumeStateRAII(bool noOp = false)
26  : NoOp(noOp)
27  {
28  if (this->NoOp)
29  {
30  return;
31  }
32 
33  this->DepthTestEnabled = (glIsEnabled(GL_DEPTH_TEST) != GL_FALSE);
34 
35  this->BlendEnabled = (glIsEnabled(GL_BLEND) != GL_FALSE);
36 
37  this->CullFaceEnabled = (glIsEnabled(GL_CULL_FACE) != GL_FALSE);
38  glGetIntegerv(GL_CULL_FACE_MODE, &this->CullFaceMode);
39 
40  GLboolean depthMaskWrite = GL_TRUE;
41  glGetBooleanv(GL_DEPTH_WRITEMASK, &depthMaskWrite);
42  this->DepthMaskEnabled = (depthMaskWrite == GL_TRUE);
43 
44  // Enable depth_sampler test
45  if (!this->DepthTestEnabled)
46  {
47  glEnable(GL_DEPTH_TEST);
48  }
49 
50  // Set the over blending function
51  // NOTE: It is important to choose GL_ONE vs GL_SRC_ALPHA as our colors
52  // will be premultiplied by the alpha value (doing front to back blending)
53  glBlendFunc(GL_ONE,GL_ONE_MINUS_SRC_ALPHA);
54 
55  if (!this->BlendEnabled)
56  {
57  glEnable(GL_BLEND);
58  }
59 
60  // Enable cull face and set cull face mode
61  if (this->CullFaceMode != GL_BACK)
62  {
63  glCullFace(GL_BACK);
64  }
65 
66  if (!this->CullFaceEnabled)
67  {
68  glEnable(GL_CULL_FACE);
69  }
70 
71  // Disable depth mask writing
72  if (this->DepthMaskEnabled)
73  {
74  glDepthMask(GL_FALSE);
75  }
76  }
77 
79  {
80 #ifdef __APPLE__
82 #endif
83  {
84  glBindVertexArray(0);
85  }
86  glBindBuffer(GL_ARRAY_BUFFER, 0);
87  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
88 
89  if (this->NoOp)
90  {
91  return;
92  }
93 
94  glCullFace(this->CullFaceMode);
95  if (!this->CullFaceEnabled)
96  {
97  glDisable(GL_CULL_FACE);
98  }
99 
100  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
101 
102  if (!this->BlendEnabled)
103  {
104  glDisable(GL_BLEND);
105  }
106 
107  if (!this->DepthTestEnabled)
108  {
109  glDisable(GL_DEPTH_TEST);
110  }
111 
112  if (this->DepthMaskEnabled)
113  {
114  glDepthMask(GL_TRUE);
115  }
116  }
117 
118 private:
119  bool NoOp;
120  bool DepthTestEnabled;
121  bool BlendEnabled;
122  bool CullFaceEnabled;
123  GLint CullFaceMode;
124  bool DepthMaskEnabled;
125 };
126 
127 #endif // vtkVolumeStateRAII_h
128 // VTK-HeaderTest-Exclude: vtkVolumeStateRAII.h
vtkVolumeStateRAII(bool noOp=false)
static bool GetContextSupportsOpenGL32()
Get if the context includes opengl core profile 3.2 support.