VTK
/Users/kitware/Dashboards/MyTests/VTK_BLD_Release_docs/Utilities/Doxygen/dox/Rendering/VolumeOpenGL2/vtkVolumeStateRAII.h
Go to the documentation of this file.
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 depth_sampler test
00034       if (!this->DepthTestEnabled)
00035         {
00036         std::cerr << "enabling depth test" << std::endl;
00037         glEnable(GL_DEPTH_TEST);
00038         }
00039 
00040       // Set the over blending function
00041       // NOTE: It is important to choose GL_ONE vs GL_SRC_ALPHA as our colors
00042       // will be premultiplied by the alpha value (doing front to back blending)
00043       glBlendFunc(GL_ONE,GL_ONE_MINUS_SRC_ALPHA);
00044 
00045       if (!this->BlendEnabled)
00046         {
00047         glEnable(GL_BLEND);
00048         }
00049 
00050       // Enable cull face
00051       if (!this->CullFaceEnabled)
00052         {
00053         glEnable(GL_CULL_FACE);
00054         }
00055       }
00056 
00057     ~vtkVolumeStateRAII()
00058       {
00059 #ifndef __APPLE__
00060       glBindVertexArray(0);
00061 #endif
00062       glBindBuffer(GL_ARRAY_BUFFER, 0);
00063       glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
00064 
00065       if (!this->CullFaceEnabled)
00066         {
00067         glDisable(GL_CULL_FACE);
00068         }
00069 
00070       glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00071 
00072       if (!this->BlendEnabled)
00073         {
00074         glDisable(GL_BLEND);
00075         }
00076 
00077       if (!this->DepthTestEnabled)
00078         {
00079         glDisable(GL_DEPTH_TEST);
00080         }
00081       }
00082 
00083 private:
00084   bool DepthTestEnabled;
00085   bool BlendEnabled;
00086   bool CullFaceEnabled;
00087 };
00088 
00089 #endif // vtkVolumeStateRAII_h
00090 // VTK-HeaderTest-Exclude: vtkVolumeStateRAII.h