VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: vtkVolumeStateRAII.h 00005 00006 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 00007 All rights reserved. 00008 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 00009 00010 This software is distributed WITHOUT ANY WARRANTY; without even 00011 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00012 PURPOSE. See the above copyright notice for more information. 00013 00014 =========================================================================*/ 00015 00016 #ifndef vtkVolumeStateRAII_h 00017 #define vtkVolumeStateRAII_h 00018 00019 // Only these states can be queries via glIsEnabled: 00020 // http://www.khronos.org/opengles/sdk/docs/man/ 00021 00022 class vtkVolumeStateRAII 00023 { 00024 public: 00025 vtkVolumeStateRAII() 00026 { 00027 this->DepthTestEnabled = (glIsEnabled(GL_DEPTH_TEST) != 0); 00028 00029 this->BlendEnabled = (glIsEnabled(GL_BLEND) != 0); 00030 00031 this->CullFaceEnabled = (glIsEnabled(GL_CULL_FACE) != 0); 00032 00033 // Enable texture 1D and 3D as we are using it 00034 // for transfer functions and m_volume data 00035 glEnable(GL_TEXTURE_1D); 00036 glEnable(GL_TEXTURE_2D); 00037 glEnable(GL_TEXTURE_3D); 00038 00039 // Enable depth_sampler test 00040 if (!this->DepthTestEnabled) 00041 { 00042 std::cerr << "enabling depth test" << std::endl; 00043 glEnable(GL_DEPTH_TEST); 00044 } 00045 00046 // Set the over blending function 00047 // NOTE: It is important to choose GL_ONE vs GL_SRC_ALPHA as our colors 00048 // will be premultiplied by the alpha value (doing front to back blending) 00049 glBlendFunc(GL_ONE,GL_ONE_MINUS_SRC_ALPHA); 00050 00051 if (!this->BlendEnabled) 00052 { 00053 glEnable(GL_BLEND); 00054 } 00055 00056 // Enable cull face 00057 if (!this->CullFaceEnabled) 00058 { 00059 glEnable(GL_CULL_FACE); 00060 } 00061 } 00062 00063 ~vtkVolumeStateRAII() 00064 { 00065 #ifndef __APPLE__ 00066 glBindVertexArray(0); 00067 #endif 00068 glBindBuffer(GL_ARRAY_BUFFER, 0); 00069 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); 00070 00071 if (!this->CullFaceEnabled) 00072 { 00073 glDisable(GL_CULL_FACE); 00074 } 00075 00076 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 00077 00078 if (!this->BlendEnabled) 00079 { 00080 glDisable(GL_BLEND); 00081 } 00082 00083 if (!this->DepthTestEnabled) 00084 { 00085 glDisable(GL_DEPTH_TEST); 00086 } 00087 00088 glActiveTexture(GL_TEXTURE0); 00089 00090 glDisable(GL_TEXTURE_3D); 00091 glDisable(GL_TEXTURE_2D); 00092 glDisable(GL_TEXTURE_1D); 00093 } 00094 00095 private: 00096 bool DepthTestEnabled; 00097 bool BlendEnabled; 00098 bool CullFaceEnabled; 00099 }; 00100 00101 #endif // vtkVolumeStateRAII_h 00102 // VTK-HeaderTest-Exclude: vtkVolumeStateRAII.h