VTK
Classes | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
vtkOpenGLState Class Reference

OpenGL state storage. More...

#include <vtkOpenGLState.h>

Collaboration diagram for vtkOpenGLState:
[legend]

Classes

class  GLState
 
class  ScopedglBlendFuncSeparate
 
class  ScopedglClearColor
 
class  ScopedglColorMask
 
class  ScopedglDepthMask
 
class  ScopedglEnableDisable
 
class  ScopedglScissor
 
class  ScopedglViewport
 
class  ScopedValue
 

Public Member Functions

 vtkOpenGLState ()
 
void GetBlendFuncState (int *)
 
bool GetEnumState (unsigned int name)
 
void SetEnumState (unsigned int name, bool value)
 
void ResetEnumState (unsigned int name)
 convenience method to reset an enum state from current openGL context More...
 
void Initialize (vtkOpenGLRenderWindow *)
 Initialize OpenGL context using current state. More...
 
void vtkglClearColor (float red, float green, float blue, float alpha)
 
void vtkglClearDepth (double depth)
 
void vtkglDepthFunc (unsigned int val)
 
void vtkglDepthMask (unsigned char flag)
 
void vtkglColorMask (unsigned char r, unsigned char g, unsigned char b, unsigned char a)
 
void vtkglViewport (int x, int y, int width, int height)
 
void vtkglScissor (int x, int y, int width, int height)
 
void vtkglEnable (unsigned int cap)
 
void vtkglDisable (unsigned int cap)
 
void vtkglBlendFunc (unsigned int sfactor, unsigned int dfactor)
 
void vtkglBlendFuncSeparate (unsigned int sfactorRGB, unsigned int dfactorRGB, unsigned int sfactorAlpha, unsigned int dfactorAlpha)
 
void vtkglBlendEquation (unsigned int val)
 
void vtkglBlendEquationSeparate (unsigned int col, unsigned int alpha)
 
void vtkglCullFace (unsigned int val)
 
void ResetGlClearColorState ()
 
void ResetGlClearDepthState ()
 
void ResetGlDepthFuncState ()
 
void ResetGlDepthMaskState ()
 
void ResetGlColorMaskState ()
 
void ResetGlViewportState ()
 
void ResetGlScissorState ()
 
void ResetGlBlendFuncState ()
 
void ResetGlBlendEquationState ()
 
void ResetGlCullFaceState ()
 
void vtkglClear (unsigned int mask)
 
void vtkglGetBooleanv (unsigned int pname, unsigned char *params)
 
void vtkglGetIntegerv (unsigned int pname, int *params)
 
void vtkglGetDoublev (unsigned int pname, double *params)
 
void vtkglGetFloatv (unsigned int pname, float *params)
 

Protected Member Functions

void BlendFuncSeparate (std::array< unsigned int, 4 > val)
 
void ClearColor (std::array< float, 4 > val)
 
void ColorMask (std::array< unsigned char, 4 > val)
 
void Scissor (std::array< int, 4 > val)
 
void Viewport (std::array< int, 4 > val)
 
void CheckState ()
 Check that this OpenGL state has consistent values with the current OpenGL context. More...
 

Protected Attributes

GLState CurrentState
 

Detailed Description

OpenGL state storage.

vtkOpenGLState is a class designed to keep track of the state of an OpenGL context. Applications using VTK have so much ontrol over the rendering process that is can be difficult in VTK code to know if the OpenGL state is correct for your code. The two traditional solutions have been to set everything yourself and to save and restore OpenGL state that you change. The former makes your code work, the latter hels prevent your code from breaking something else. The problem is that the former results in tons of redundent OpenGL calls and the later is done by querying the OpenGL state which can cause a pipeline sync/stall which is very slow.

To address these issues this class stores OpenGL state for commonly used functions. Requests made to change state to the current state become no-ops. Queries of state can be done by querying the state stored in this class without impacting the OpenGL driver.

To fascilitate saving state and restoring it this class contains a number of nested classes named Scoped<glFunction> that store the state of that glFunction and when they go out of scope they restore it. This is useful when you want to change the OpenGL state and then automatically restore it when done. They can be used as follows

{ vtkOpenGLState *ostate = renWin->GetState(); vtkOpenGLState::ScopedglDepthMask dmsaved(ostate); // the prior state is now saved ... ostate->glDepthMask(GL_TRUE); // maybe change the state ... etc } // prior state will be restored here as it goes out of scope

You must use this class to make stat changing OpenGL class otherwise the results will be undefined.

For convenience some OpenGL calls that do not impact state are also provided.

Definition at line 67 of file vtkOpenGLState.h.

Constructor & Destructor Documentation

vtkOpenGLState::vtkOpenGLState ( )

Member Function Documentation

void vtkOpenGLState::vtkglClearColor ( float  red,
float  green,
float  blue,
float  alpha 
)
void vtkOpenGLState::vtkglClearDepth ( double  depth)
void vtkOpenGLState::vtkglDepthFunc ( unsigned int  val)
void vtkOpenGLState::vtkglDepthMask ( unsigned char  flag)
void vtkOpenGLState::vtkglColorMask ( unsigned char  r,
unsigned char  g,
unsigned char  b,
unsigned char  a 
)
void vtkOpenGLState::vtkglViewport ( int  x,
int  y,
int  width,
int  height 
)
void vtkOpenGLState::vtkglScissor ( int  x,
int  y,
int  width,
int  height 
)
void vtkOpenGLState::vtkglEnable ( unsigned int  cap)
void vtkOpenGLState::vtkglDisable ( unsigned int  cap)
void vtkOpenGLState::vtkglBlendFunc ( unsigned int  sfactor,
unsigned int  dfactor 
)
inline

Definition at line 86 of file vtkOpenGLState.h.

void vtkOpenGLState::vtkglBlendFuncSeparate ( unsigned int  sfactorRGB,
unsigned int  dfactorRGB,
unsigned int  sfactorAlpha,
unsigned int  dfactorAlpha 
)
void vtkOpenGLState::vtkglBlendEquation ( unsigned int  val)
void vtkOpenGLState::vtkglBlendEquationSeparate ( unsigned int  col,
unsigned int  alpha 
)
void vtkOpenGLState::vtkglCullFace ( unsigned int  val)
void vtkOpenGLState::ResetGlClearColorState ( )
void vtkOpenGLState::ResetGlClearDepthState ( )
void vtkOpenGLState::ResetGlDepthFuncState ( )
void vtkOpenGLState::ResetGlDepthMaskState ( )
void vtkOpenGLState::ResetGlColorMaskState ( )
void vtkOpenGLState::ResetGlViewportState ( )
void vtkOpenGLState::ResetGlScissorState ( )
void vtkOpenGLState::ResetGlBlendFuncState ( )
void vtkOpenGLState::ResetGlBlendEquationState ( )
void vtkOpenGLState::ResetGlCullFaceState ( )
void vtkOpenGLState::vtkglClear ( unsigned int  mask)
void vtkOpenGLState::vtkglGetBooleanv ( unsigned int  pname,
unsigned char *  params 
)
void vtkOpenGLState::vtkglGetIntegerv ( unsigned int  pname,
int params 
)
void vtkOpenGLState::vtkglGetDoublev ( unsigned int  pname,
double params 
)
void vtkOpenGLState::vtkglGetFloatv ( unsigned int  pname,
float params 
)
void vtkOpenGLState::GetBlendFuncState ( int )
bool vtkOpenGLState::GetEnumState ( unsigned int  name)
void vtkOpenGLState::SetEnumState ( unsigned int  name,
bool  value 
)
void vtkOpenGLState::ResetEnumState ( unsigned int  name)

convenience method to reset an enum state from current openGL context

void vtkOpenGLState::Initialize ( vtkOpenGLRenderWindow )

Initialize OpenGL context using current state.

void vtkOpenGLState::BlendFuncSeparate ( std::array< unsigned int, 4 >  val)
protected
void vtkOpenGLState::ClearColor ( std::array< float, 4 >  val)
protected
void vtkOpenGLState::ColorMask ( std::array< unsigned char, 4 >  val)
protected
void vtkOpenGLState::Scissor ( std::array< int, 4 >  val)
protected
void vtkOpenGLState::Viewport ( std::array< int, 4 >  val)
protected
void vtkOpenGLState::CheckState ( )
protected

Check that this OpenGL state has consistent values with the current OpenGL context.

Member Data Documentation

GLState vtkOpenGLState::CurrentState
protected

Definition at line 244 of file vtkOpenGLState.h.


The documentation for this class was generated from the following file: