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