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 #ifndef __APPLE__
60  glBindVertexArray(0);
61 #endif
62  glBindBuffer(GL_ARRAY_BUFFER, 0);
63  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
64 
65  if (!this->CullFaceEnabled)
66  {
67  glDisable(GL_CULL_FACE);
68  }
69 
70  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
71 
72  if (!this->BlendEnabled)
73  {
74  glDisable(GL_BLEND);
75  }
76 
77  if (!this->DepthTestEnabled)
78  {
79  glDisable(GL_DEPTH_TEST);
80  }
81  }
82 
83 private:
84  bool DepthTestEnabled;
85  bool BlendEnabled;
86  bool CullFaceEnabled;
87 };
88 
89 #endif // vtkVolumeStateRAII_h
90 // VTK-HeaderTest-Exclude: vtkVolumeStateRAII.h