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

OpenGL state storage. More...

#include <vtkOpenGLState.h>

Inheritance diagram for vtkOpenGLState:
Collaboration diagram for vtkOpenGLState:


class  BufferBindingState
class  GLState
class  ScopedglActiveTexture
class  ScopedglBlendFuncSeparate
class  ScopedglClearColor
class  ScopedglColorMask
class  ScopedglDepthFunc
class  ScopedglDepthMask
class  ScopedglEnableDisable
class  ScopedglScissor
class  ScopedglViewport
class  ScopedValue

Public Types

typedef vtkObject Superclass

Public Member Functions

virtual vtkTypeBool IsA (const char *type)
 Return 1 if this class is the same type of (or a subclass of) the named class. More...
vtkOpenGLStateNewInstance () const
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 vtkglActiveTexture (unsigned int)
void vtkglBindFramebuffer (unsigned int target, unsigned int fb)
void vtkglDrawBuffer (unsigned int)
void vtkglDrawBuffers (unsigned int n, unsigned int *)
void vtkglReadBuffer (unsigned int)
void vtkBindFramebuffer (unsigned int target, vtkOpenGLFramebufferObject *fo)
void vtkDrawBuffers (unsigned int n, unsigned int *, vtkOpenGLFramebufferObject *)
void vtkReadBuffer (unsigned int, vtkOpenGLFramebufferObject *)
void ResetGLClearColorState ()
void ResetGLClearDepthState ()
void ResetGLDepthFuncState ()
void ResetGLDepthMaskState ()
void ResetGLColorMaskState ()
void ResetGLViewportState ()
void ResetGLScissorState ()
void ResetGLBlendFuncState ()
void ResetGLBlendEquationState ()
void ResetGLCullFaceState ()
void ResetGLActiveTexture ()
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)
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 ActivateTexture (vtkTextureObject *)
 Activate a texture unit for this texture. More...
void DeactivateTexture (vtkTextureObject *)
 Deactivate a previously activated texture. More...
int GetTextureUnitForTexture (vtkTextureObject *)
 Get the texture unit for a given texture object. More...
void VerifyNoActiveTextures ()
 Check to make sure no textures have been left active. More...
void PushFramebufferBindings ()
 Store/Restore the current framebuffer bindings and buffers. More...
void PushDrawFramebufferBinding ()
void PushReadFramebufferBinding ()
void PopFramebufferBindings ()
void PopDrawFramebufferBinding ()
void PopReadFramebufferBinding ()
void ResetFramebufferBindings ()
void Initialize (vtkOpenGLRenderWindow *)
 Initialize OpenGL context using current state. More...
void SetTextureUnitManager (vtkTextureUnitManager *textureUnitManager)
 Set the texture unit manager. More...
vtkTextureUnitManagerGetTextureUnitManager ()
 Returns its texture unit manager object. More...
virtual vtkOpenGLShaderCacheGetShaderCache ()
virtual vtkOpenGLVertexBufferObjectCacheGetVBOCache ()
void SetVBOCache (vtkOpenGLVertexBufferObjectCache *val)
int GetDefaultTextureInternalFormat (int vtktype, int numComponents, bool needInteger, bool needFloat, bool needSRGB)
 Get a mapping of vtk data types to native texture formats for this window we put this on the RenderWindow so that every texture does not have to build these structures themselves. More...
- Public Member Functions inherited from vtkObject
 vtkBaseTypeMacro (vtkObject, vtkObjectBase)
virtual void DebugOn ()
 Turn debugging output on. More...
virtual void DebugOff ()
 Turn debugging output off. More...
bool GetDebug ()
 Get the value of the debug flag. More...
void SetDebug (bool debugFlag)
 Set the value of the debug flag. More...
virtual void Modified ()
 Update the modification time for this object. More...
virtual vtkMTimeType GetMTime ()
 Return this object's modified time. More...
void PrintSelf (ostream &os, vtkIndent indent) override
 Methods invoked by print to print information about the object including superclasses. More...
unsigned long AddObserver (unsigned long event, vtkCommand *, float priority=0.0f)
 Allow people to add/remove/invoke observers (callbacks) to any VTK object. More...
unsigned long AddObserver (const char *event, vtkCommand *, float priority=0.0f)
vtkCommandGetCommand (unsigned long tag)
void RemoveObserver (vtkCommand *)
void RemoveObservers (unsigned long event, vtkCommand *)
void RemoveObservers (const char *event, vtkCommand *)
vtkTypeBool HasObserver (unsigned long event, vtkCommand *)
vtkTypeBool HasObserver (const char *event, vtkCommand *)
void RemoveObserver (unsigned long tag)
void RemoveObservers (unsigned long event)
void RemoveObservers (const char *event)
void RemoveAllObservers ()
vtkTypeBool HasObserver (unsigned long event)
vtkTypeBool HasObserver (const char *event)
template<class U , class T >
unsigned long AddObserver (unsigned long event, U observer, void(T::*callback)(), float priority=0.0f)
 Overloads to AddObserver that allow developers to add class member functions as callbacks for events. More...
template<class U , class T >
unsigned long AddObserver (unsigned long event, U observer, void(T::*callback)(vtkObject *, unsigned long, void *), float priority=0.0f)
template<class U , class T >
unsigned long AddObserver (unsigned long event, U observer, bool(T::*callback)(vtkObject *, unsigned long, void *), float priority=0.0f)
 Allow user to set the AbortFlagOn() with the return value of the callback method. More...
int InvokeEvent (unsigned long event, void *callData)
 This method invokes an event and return whether the event was aborted or not. More...
int InvokeEvent (const char *event, void *callData)
int InvokeEvent (unsigned long event)
int InvokeEvent (const char *event)
- Public Member Functions inherited from vtkObjectBase
const char * GetClassName () const
 Return the class name as a string. More...
virtual void Delete ()
 Delete a VTK object. More...
virtual void FastDelete ()
 Delete a reference to this object. More...
void InitializeObjectBase ()
void Print (ostream &os)
 Print an object to an ostream. More...
virtual void PrintHeader (ostream &os, vtkIndent indent)
virtual void PrintTrailer (ostream &os, vtkIndent indent)
virtual void Register (vtkObjectBase *o)
 Increase the reference count (mark as used by another object). More...
virtual void UnRegister (vtkObjectBase *o)
 Decrease the reference count (release by another object). More...
int GetReferenceCount ()
 Return the current reference count of this object. More...
void SetReferenceCount (int)
 Sets the reference count. More...
void PrintRevisions (ostream &)
 Legacy. More...

Static Public Member Functions

static vtkOpenGLStateNew ()
static vtkTypeBool IsTypeOf (const char *type)
static vtkOpenGLStateSafeDownCast (vtkObjectBase *o)
- Static Public Member Functions inherited from vtkObject
static vtkObjectNew ()
 Create an object with Debug turned off, modified time initialized to zero, and reference counting on. More...
static void BreakOnError ()
 This method is called when vtkErrorMacro executes. More...
static void SetGlobalWarningDisplay (int val)
 This is a global flag that controls whether any debug, warning or error messages are displayed. More...
static void GlobalWarningDisplayOn ()
static void GlobalWarningDisplayOff ()
static int GetGlobalWarningDisplay ()
- Static Public Member Functions inherited from vtkObjectBase
static vtkTypeBool IsTypeOf (const char *name)
 Return 1 if this class type is the same type of (or a subclass of) the named class. More...
static vtkObjectBaseNew ()
 Create an object with Debug turned off, modified time initialized to zero, and reference counting on. More...

Protected Member Functions

virtual vtkObjectBaseNewInstanceInternal () const
 vtkOpenGLState ()
 ~vtkOpenGLState () override
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 InitializeTextureInternalFormats ()
void CheckState ()
 Check that this OpenGL state has consistent values with the current OpenGL context. More...
- Protected Member Functions inherited from vtkObject
 vtkObject ()
 ~vtkObject () override
void RegisterInternal (vtkObjectBase *, vtkTypeBool check) override
void UnRegisterInternal (vtkObjectBase *, vtkTypeBool check) override
void InternalGrabFocus (vtkCommand *mouseEvents, vtkCommand *keypressEvents=nullptr)
 These methods allow a command to exclusively grab all events. More...
void InternalReleaseFocus ()
- Protected Member Functions inherited from vtkObjectBase
 vtkObjectBase ()
virtual ~vtkObjectBase ()
virtual void CollectRevisions (ostream &)
virtual void ReportReferences (vtkGarbageCollector *)
 vtkObjectBase (const vtkObjectBase &)
void operator= (const vtkObjectBase &)

Protected Attributes

int TextureInternalFormats [VTK_UNICODE_STRING][3][5]
std::map< const vtkTextureObject *, intTextureResourceIds
std::list< BufferBindingStateDrawBindings
std::list< BufferBindingStateReadBindings
GLState CurrentState
- Protected Attributes inherited from vtkObject
bool Debug
vtkTimeStamp MTime
vtkSubjectHelper * SubjectHelper
- Protected Attributes inherited from vtkObjectBase
std::atomic< int32_t > ReferenceCount
vtkWeakPointerBase ** WeakPointers

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 control 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 helps prevent your code from breaking something else. The problem is that the former results in tons of redundant 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.

This class is designed to hold all context related values and could just as well be considered a representation of the OpenGL context.

To facilitate 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 state 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 79 of file vtkOpenGLState.h.

Member Typedef Documentation

◆ Superclass

Definition at line 83 of file vtkOpenGLState.h.

Constructor & Destructor Documentation

◆ vtkOpenGLState()

vtkOpenGLState::vtkOpenGLState ( )

◆ ~vtkOpenGLState()

vtkOpenGLState::~vtkOpenGLState ( )

Member Function Documentation

◆ New()

static vtkOpenGLState* vtkOpenGLState::New ( )

◆ IsTypeOf()

static vtkTypeBool vtkOpenGLState::IsTypeOf ( const char *  type)

◆ IsA()

virtual vtkTypeBool vtkOpenGLState::IsA ( const char *  name)

Return 1 if this class is the same type of (or a subclass of) the named class.

Returns 0 otherwise. This method works in combination with vtkTypeMacro found in vtkSetGet.h.

Reimplemented from vtkObjectBase.

◆ SafeDownCast()

static vtkOpenGLState* vtkOpenGLState::SafeDownCast ( vtkObjectBase o)

◆ NewInstanceInternal()

virtual vtkObjectBase* vtkOpenGLState::NewInstanceInternal ( ) const

◆ NewInstance()

vtkOpenGLState* vtkOpenGLState::NewInstance ( ) const

◆ vtkglClearColor()

void vtkOpenGLState::vtkglClearColor ( float  red,
float  green,
float  blue,
float  alpha 

◆ vtkglClearDepth()

void vtkOpenGLState::vtkglClearDepth ( double  depth)

◆ vtkglDepthFunc()

void vtkOpenGLState::vtkglDepthFunc ( unsigned int  val)

◆ vtkglDepthMask()

void vtkOpenGLState::vtkglDepthMask ( unsigned char  flag)

◆ vtkglColorMask()

void vtkOpenGLState::vtkglColorMask ( unsigned char  r,
unsigned char  g,
unsigned char  b,
unsigned char  a 

◆ vtkglViewport()

void vtkOpenGLState::vtkglViewport ( int  x,
int  y,
int  width,
int  height 

◆ vtkglScissor()

void vtkOpenGLState::vtkglScissor ( int  x,
int  y,
int  width,
int  height 

◆ vtkglEnable()

void vtkOpenGLState::vtkglEnable ( unsigned int  cap)

◆ vtkglDisable()

void vtkOpenGLState::vtkglDisable ( unsigned int  cap)

◆ vtkglBlendFunc()

void vtkOpenGLState::vtkglBlendFunc ( unsigned int  sfactor,
unsigned int  dfactor 

Definition at line 99 of file vtkOpenGLState.h.

◆ vtkglBlendFuncSeparate()

void vtkOpenGLState::vtkglBlendFuncSeparate ( unsigned int  sfactorRGB,
unsigned int  dfactorRGB,
unsigned int  sfactorAlpha,
unsigned int  dfactorAlpha 

◆ vtkglBlendEquation()

void vtkOpenGLState::vtkglBlendEquation ( unsigned int  val)

◆ vtkglBlendEquationSeparate()

void vtkOpenGLState::vtkglBlendEquationSeparate ( unsigned int  col,
unsigned int  alpha 

◆ vtkglCullFace()

void vtkOpenGLState::vtkglCullFace ( unsigned int  val)

◆ vtkglActiveTexture()

void vtkOpenGLState::vtkglActiveTexture ( unsigned int  )

◆ vtkglBindFramebuffer()

void vtkOpenGLState::vtkglBindFramebuffer ( unsigned int  target,
unsigned int  fb 

◆ vtkglDrawBuffer()

void vtkOpenGLState::vtkglDrawBuffer ( unsigned int  )

◆ vtkglDrawBuffers()

void vtkOpenGLState::vtkglDrawBuffers ( unsigned int  n,
unsigned int  

◆ vtkglReadBuffer()

void vtkOpenGLState::vtkglReadBuffer ( unsigned int  )

◆ vtkBindFramebuffer()

void vtkOpenGLState::vtkBindFramebuffer ( unsigned int  target,
vtkOpenGLFramebufferObject fo 

◆ vtkDrawBuffers()

void vtkOpenGLState::vtkDrawBuffers ( unsigned int  n,
unsigned int ,

◆ vtkReadBuffer()

void vtkOpenGLState::vtkReadBuffer ( unsigned int  ,

◆ ResetGLClearColorState()

void vtkOpenGLState::ResetGLClearColorState ( )

◆ ResetGLClearDepthState()

void vtkOpenGLState::ResetGLClearDepthState ( )

◆ ResetGLDepthFuncState()

void vtkOpenGLState::ResetGLDepthFuncState ( )

◆ ResetGLDepthMaskState()

void vtkOpenGLState::ResetGLDepthMaskState ( )

◆ ResetGLColorMaskState()

void vtkOpenGLState::ResetGLColorMaskState ( )

◆ ResetGLViewportState()

void vtkOpenGLState::ResetGLViewportState ( )

◆ ResetGLScissorState()

void vtkOpenGLState::ResetGLScissorState ( )

◆ ResetGLBlendFuncState()

void vtkOpenGLState::ResetGLBlendFuncState ( )

◆ ResetGLBlendEquationState()

void vtkOpenGLState::ResetGLBlendEquationState ( )

◆ ResetGLCullFaceState()

void vtkOpenGLState::ResetGLCullFaceState ( )

◆ ResetGLActiveTexture()

void vtkOpenGLState::ResetGLActiveTexture ( )

◆ vtkglClear()

void vtkOpenGLState::vtkglClear ( unsigned int  mask)

◆ vtkglGetBooleanv()

void vtkOpenGLState::vtkglGetBooleanv ( unsigned int  pname,
unsigned char *  params 

◆ vtkglGetIntegerv()

void vtkOpenGLState::vtkglGetIntegerv ( unsigned int  pname,
int params 

◆ vtkglGetDoublev()

void vtkOpenGLState::vtkglGetDoublev ( unsigned int  pname,
double params 

◆ vtkglGetFloatv()

void vtkOpenGLState::vtkglGetFloatv ( unsigned int  pname,
float params 

◆ GetBlendFuncState()

void vtkOpenGLState::GetBlendFuncState ( int )

◆ GetEnumState()

bool vtkOpenGLState::GetEnumState ( unsigned int  name)

◆ SetEnumState()

void vtkOpenGLState::SetEnumState ( unsigned int  name,
bool  value 

◆ ResetEnumState()

void vtkOpenGLState::ResetEnumState ( unsigned int  name)

convenience method to reset an enum state from current openGL context

◆ ActivateTexture()

void vtkOpenGLState::ActivateTexture ( vtkTextureObject )

Activate a texture unit for this texture.

◆ DeactivateTexture()

void vtkOpenGLState::DeactivateTexture ( vtkTextureObject )

Deactivate a previously activated texture.

◆ GetTextureUnitForTexture()

int vtkOpenGLState::GetTextureUnitForTexture ( vtkTextureObject )

Get the texture unit for a given texture object.

◆ VerifyNoActiveTextures()

void vtkOpenGLState::VerifyNoActiveTextures ( )

Check to make sure no textures have been left active.

◆ PushFramebufferBindings()

void vtkOpenGLState::PushFramebufferBindings ( )

Store/Restore the current framebuffer bindings and buffers.

Definition at line 207 of file vtkOpenGLState.h.

◆ PushDrawFramebufferBinding()

void vtkOpenGLState::PushDrawFramebufferBinding ( )

◆ PushReadFramebufferBinding()

void vtkOpenGLState::PushReadFramebufferBinding ( )

◆ PopFramebufferBindings()

void vtkOpenGLState::PopFramebufferBindings ( )

Definition at line 214 of file vtkOpenGLState.h.

◆ PopDrawFramebufferBinding()

void vtkOpenGLState::PopDrawFramebufferBinding ( )

◆ PopReadFramebufferBinding()

void vtkOpenGLState::PopReadFramebufferBinding ( )

◆ ResetFramebufferBindings()

void vtkOpenGLState::ResetFramebufferBindings ( )

◆ Initialize()

void vtkOpenGLState::Initialize ( vtkOpenGLRenderWindow )

Initialize OpenGL context using current state.

◆ SetTextureUnitManager()

void vtkOpenGLState::SetTextureUnitManager ( vtkTextureUnitManager textureUnitManager)

Set the texture unit manager.

◆ GetTextureUnitManager()

vtkTextureUnitManager* vtkOpenGLState::GetTextureUnitManager ( )

Returns its texture unit manager object.

A new one will be created if one hasn't already been set up.

◆ GetShaderCache()

virtual vtkOpenGLShaderCache* vtkOpenGLState::GetShaderCache ( )

◆ GetVBOCache()

virtual vtkOpenGLVertexBufferObjectCache* vtkOpenGLState::GetVBOCache ( )

◆ SetVBOCache()

void vtkOpenGLState::SetVBOCache ( vtkOpenGLVertexBufferObjectCache val)

◆ GetDefaultTextureInternalFormat()

int vtkOpenGLState::GetDefaultTextureInternalFormat ( int  vtktype,
int  numComponents,
bool  needInteger,
bool  needFloat,
bool  needSRGB 

Get a mapping of vtk data types to native texture formats for this window we put this on the RenderWindow so that every texture does not have to build these structures themselves.

◆ BlendFuncSeparate()

void vtkOpenGLState::BlendFuncSeparate ( std::array< unsigned int, 4 >  val)

◆ ClearColor()

void vtkOpenGLState::ClearColor ( std::array< float, 4 >  val)

◆ ColorMask()

void vtkOpenGLState::ColorMask ( std::array< unsigned char, 4 >  val)

◆ Scissor()

void vtkOpenGLState::Scissor ( std::array< int, 4 >  val)

◆ Viewport()

void vtkOpenGLState::Viewport ( std::array< int, 4 >  val)

◆ InitializeTextureInternalFormats()

void vtkOpenGLState::InitializeTextureInternalFormats ( )

◆ CheckState()

void vtkOpenGLState::CheckState ( )

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

Member Data Documentation

◆ TextureInternalFormats

int vtkOpenGLState::TextureInternalFormats[VTK_UNICODE_STRING][3][5]

Definition at line 318 of file vtkOpenGLState.h.

◆ TextureUnitManager

vtkTextureUnitManager* vtkOpenGLState::TextureUnitManager

Definition at line 321 of file vtkOpenGLState.h.

◆ TextureResourceIds

std::map<const vtkTextureObject *, int> vtkOpenGLState::TextureResourceIds

Definition at line 322 of file vtkOpenGLState.h.

◆ DrawBindings

std::list<BufferBindingState> vtkOpenGLState::DrawBindings

Definition at line 348 of file vtkOpenGLState.h.

◆ ReadBindings

std::list<BufferBindingState> vtkOpenGLState::ReadBindings

Definition at line 349 of file vtkOpenGLState.h.

◆ CurrentState

GLState vtkOpenGLState::CurrentState

Definition at line 381 of file vtkOpenGLState.h.

◆ VBOCache

vtkOpenGLVertexBufferObjectCache* vtkOpenGLState::VBOCache

Definition at line 383 of file vtkOpenGLState.h.

◆ ShaderCache

vtkOpenGLShaderCache* vtkOpenGLState::ShaderCache

Definition at line 384 of file vtkOpenGLState.h.

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