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 texture 1D and 3D as we are using it
34  // for transfer functions and m_volume data
35  glEnable(GL_TEXTURE_1D);
36  glEnable(GL_TEXTURE_2D);
37  glEnable(GL_TEXTURE_3D);
38 
39  // Enable depth_sampler test
40  if (!this->DepthTestEnabled)
41  {
42  std::cerr << "enabling depth test" << std::endl;
43  glEnable(GL_DEPTH_TEST);
44  }
45 
46  // Set the over blending function
47  // NOTE: It is important to choose GL_ONE vs GL_SRC_ALPHA as our colors
48  // will be premultiplied by the alpha value (doing front to back blending)
49  glBlendFunc(GL_ONE,GL_ONE_MINUS_SRC_ALPHA);
50 
51  if (!this->BlendEnabled)
52  {
53  glEnable(GL_BLEND);
54  }
55 
56  // Enable cull face
57  if (!this->CullFaceEnabled)
58  {
59  glEnable(GL_CULL_FACE);
60  }
61  }
62 
64  {
65 #ifndef __APPLE__
66  glBindVertexArray(0);
67 #endif
68  glBindBuffer(GL_ARRAY_BUFFER, 0);
69  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
70 
71  if (!this->CullFaceEnabled)
72  {
73  glDisable(GL_CULL_FACE);
74  }
75 
76  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
77 
78  if (!this->BlendEnabled)
79  {
80  glDisable(GL_BLEND);
81  }
82 
83  if (!this->DepthTestEnabled)
84  {
85  glDisable(GL_DEPTH_TEST);
86  }
87 
88  glActiveTexture(GL_TEXTURE0);
89 
90  glDisable(GL_TEXTURE_3D);
91  glDisable(GL_TEXTURE_2D);
92  glDisable(GL_TEXTURE_1D);
93  }
94 
95 private:
96  bool DepthTestEnabled;
97  bool BlendEnabled;
98  bool CullFaceEnabled;
99 };
100 
101 #endif // vtkVolumeStateRAII_h
102 // VTK-HeaderTest-Exclude: vtkVolumeStateRAII.h