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) != 0);
28 
29  this->BlendEnabled = (glIsEnabled(GL_BLEND) != 0);
30 
31  this->CullFaceEnabled = (glIsEnabled(GL_CULL_FACE) != 0);
32 
33  // Enable depth_sampler test
34  if (!this->DepthTestEnabled)
35  {
36  std::cerr << "enabling depth test" << std::endl;
37  glEnable(GL_DEPTH_TEST);
38  }
39 
40  // Set the over blending function
41  // NOTE: It is important to choose GL_ONE vs GL_SRC_ALPHA as our colors
42  // will be premultiplied by the alpha value (doing front to back blending)
43  glBlendFunc(GL_ONE,GL_ONE_MINUS_SRC_ALPHA);
44 
45  if (!this->BlendEnabled)
46  {
47  glEnable(GL_BLEND);
48  }
49 
50  // Enable cull face
51  if (!this->CullFaceEnabled)
52  {
53  glEnable(GL_CULL_FACE);
54  }
55  }
56 
58  {
59 #ifdef __APPLE__
61 #endif
62  {
63  glBindVertexArray(0);
64  }
65  glBindBuffer(GL_ARRAY_BUFFER, 0);
66  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
67 
68  if (!this->CullFaceEnabled)
69  {
70  glDisable(GL_CULL_FACE);
71  }
72 
73  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
74 
75  if (!this->BlendEnabled)
76  {
77  glDisable(GL_BLEND);
78  }
79 
80  if (!this->DepthTestEnabled)
81  {
82  glDisable(GL_DEPTH_TEST);
83  }
84  }
85 
86 private:
87  bool DepthTestEnabled;
88  bool BlendEnabled;
89  bool CullFaceEnabled;
90 };
91 
92 #endif // vtkVolumeStateRAII_h
93 // VTK-HeaderTest-Exclude: vtkVolumeStateRAII.h
static bool GetContextSupportsOpenGL32()