VTK
9.0.2
|
OpenGL state storage. More...
#include <vtkOpenGLState.h>
Classes | |
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... | |
vtkOpenGLState * | NewInstance () 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... | |
vtkTextureUnitManager * | GetTextureUnitManager () |
Returns its texture unit manager object. More... | |
virtual vtkOpenGLShaderCache * | GetShaderCache () |
virtual vtkOpenGLVertexBufferObjectCache * | GetVBOCache () |
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... | |
![]() | |
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) |
vtkCommand * | GetCommand (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) |
![]() | |
const char * | GetClassName () const |
Return the class name as a string. More... | |
virtual vtkIdType | GetNumberOfGenerationsFromBase (const char *name) |
Given a the name of a base class of this class type, return the distance of inheritance between this class type and the named class (how many generations of inheritance are there between this class and the named class). 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 vtkOpenGLState * | New () |
static vtkTypeBool | IsTypeOf (const char *type) |
static vtkOpenGLState * | SafeDownCast (vtkObjectBase *o) |
![]() | |
static vtkObject * | New () |
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 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 vtkIdType | GetNumberOfGenerationsFromBaseType (const char *name) |
Given a the name of a base class of this class type, return the distance of inheritance between this class type and the named class (how many generations of inheritance are there between this class and the named class). More... | |
static vtkObjectBase * | New () |
Create an object with Debug turned off, modified time initialized to zero, and reference counting on. More... | |
Protected Member Functions | |
virtual vtkObjectBase * | NewInstanceInternal () 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... | |
![]() | |
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 () |
![]() | |
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] |
vtkTextureUnitManager * | TextureUnitManager |
std::map< const vtkTextureObject *, int > | TextureResourceIds |
std::list< BufferBindingState > | DrawBindings |
std::list< BufferBindingState > | ReadBindings |
GLState | CurrentState |
vtkOpenGLVertexBufferObjectCache * | VBOCache |
vtkOpenGLShaderCache * | ShaderCache |
![]() | |
bool | Debug |
vtkTimeStamp | MTime |
vtkSubjectHelper * | SubjectHelper |
![]() | |
std::atomic< int32_t > | ReferenceCount |
vtkWeakPointerBase ** | WeakPointers |
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.
typedef vtkObject vtkOpenGLState::Superclass |
Definition at line 83 of file vtkOpenGLState.h.
|
protected |
|
overrideprotected |
|
static |
|
static |
|
virtual |
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.
|
static |
|
protectedvirtual |
vtkOpenGLState* vtkOpenGLState::NewInstance | ( | ) | const |
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 | ) |
|
inline |
Definition at line 99 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::vtkglActiveTexture | ( | unsigned int | ) |
void vtkOpenGLState::vtkglBindFramebuffer | ( | unsigned int | target, |
unsigned int | fb | ||
) |
void vtkOpenGLState::vtkglDrawBuffer | ( | unsigned int | ) |
void vtkOpenGLState::vtkglDrawBuffers | ( | unsigned int | n, |
unsigned int * | |||
) |
void vtkOpenGLState::vtkglReadBuffer | ( | unsigned int | ) |
void vtkOpenGLState::vtkBindFramebuffer | ( | unsigned int | target, |
vtkOpenGLFramebufferObject * | fo | ||
) |
void vtkOpenGLState::vtkDrawBuffers | ( | unsigned int | n, |
unsigned int * | , | ||
vtkOpenGLFramebufferObject * | |||
) |
void vtkOpenGLState::vtkReadBuffer | ( | unsigned int | , |
vtkOpenGLFramebufferObject * | |||
) |
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::ResetGLActiveTexture | ( | ) |
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::ActivateTexture | ( | vtkTextureObject * | ) |
Activate a texture unit for this texture.
void vtkOpenGLState::DeactivateTexture | ( | vtkTextureObject * | ) |
Deactivate a previously activated texture.
int vtkOpenGLState::GetTextureUnitForTexture | ( | vtkTextureObject * | ) |
Get the texture unit for a given texture object.
void vtkOpenGLState::VerifyNoActiveTextures | ( | ) |
Check to make sure no textures have been left active.
|
inline |
Store/Restore the current framebuffer bindings and buffers.
Definition at line 208 of file vtkOpenGLState.h.
void vtkOpenGLState::PushDrawFramebufferBinding | ( | ) |
void vtkOpenGLState::PushReadFramebufferBinding | ( | ) |
|
inline |
Definition at line 216 of file vtkOpenGLState.h.
void vtkOpenGLState::PopDrawFramebufferBinding | ( | ) |
void vtkOpenGLState::PopReadFramebufferBinding | ( | ) |
void vtkOpenGLState::ResetFramebufferBindings | ( | ) |
void vtkOpenGLState::Initialize | ( | vtkOpenGLRenderWindow * | ) |
Initialize OpenGL context using current state.
void vtkOpenGLState::SetTextureUnitManager | ( | vtkTextureUnitManager * | textureUnitManager | ) |
Set the texture unit manager.
vtkTextureUnitManager* vtkOpenGLState::GetTextureUnitManager | ( | ) |
Returns its texture unit manager object.
A new one will be created if one hasn't already been set up.
|
virtual |
|
virtual |
void vtkOpenGLState::SetVBOCache | ( | vtkOpenGLVertexBufferObjectCache * | val | ) |
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.
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
Check that this OpenGL state has consistent values with the current OpenGL context.
|
protected |
Definition at line 339 of file vtkOpenGLState.h.
|
protected |
Definition at line 342 of file vtkOpenGLState.h.
|
protected |
Definition at line 343 of file vtkOpenGLState.h.
|
protected |
Definition at line 369 of file vtkOpenGLState.h.
|
protected |
Definition at line 370 of file vtkOpenGLState.h.
|
protected |
Definition at line 401 of file vtkOpenGLState.h.
|
protected |
Definition at line 403 of file vtkOpenGLState.h.
|
protected |
Definition at line 404 of file vtkOpenGLState.h.