Open CASCADE Technology  6.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Static Public Member Functions | Data Fields
OpenGl_Context Class Reference

This class generalize access to the GL context and available extensions. More...

#include <OpenGl_Context.hxx>

Inheritance diagram for OpenGl_Context:
Inheritance graph
[legend]

Public Member Functions

 OpenGl_Context (const Handle< OpenGl_Caps > &theCaps=NULL)
 Empty constructor. You should call Init() to perform initialization with bound GL context. More...
 
virtual ~OpenGl_Context ()
 Destructor. More...
 
void Share (const Handle< OpenGl_Context > &theShareCtx)
 Share GL context resources. theShareCtx - handle to context to retrieve handles to shared resources. More...
 
Standard_Boolean Init ()
 Initialize class from currently bound OpenGL context. Method should be called only once. More...
 
Standard_Boolean IsValid () const
 
Standard_Boolean Init (const Aspect_Drawable theWindow, const Aspect_Display theDisplay, const Aspect_RenderingContext theGContext)
 Initialize class from specified window and rendering context. Method should be called only once. More...
 
Aspect_Drawable Window () const
 
Standard_Boolean CheckExtension (const char *theExtName) const
 Check if theExtName extension is supported by active GL context. More...
 
template<typename FuncType_t >
Standard_Boolean FindProc (const char *theFuncName, FuncType_t &theFuncPtr)
 Auxiliary template to retrieve GL function pointer. Pointer to function retrieved from library is statically casted to requested type - there no way to check real signature of exported function. The context should be bound before call. More...
 
Standard_Boolean IsGlGreaterEqual (const Standard_Integer theVerMajor, const Standard_Integer theVerMinor) const
 
void ResetErrors ()
 Clean up errors stack for this GL context (glGetError() in loop). More...
 
Standard_Boolean IsCurrent () const
 This method uses system-dependent API to retrieve information about GL context bound to the current thread. More...
 
Standard_Boolean MakeCurrent ()
 Activates current context. Class should be initialized with appropriate info. More...
 
void SwapBuffers ()
 Swap front/back buffers for this GL context (should be activated before!). More...
 
Standard_Boolean IsFeedback () const
 Return true if active mode is GL_FEEDBACK (cached state) More...
 
void SetFeedback (const Standard_Boolean theFeedbackOn)
 Setup feedback mode cached state. More...
 
Standard_Size AvailableMemory () const
 This function retrieves information from GL about free GPU memory that is: More...
 
TCollection_AsciiString MemoryInfo () const
 This function retrieves information from GL about GPU memory and contains more vendor-specific values than AvailableMemory(). More...
 
const Handle< OpenGl_Resource > & GetResource (const TCollection_AsciiString &theKey) const
 Access shared resource by its name. More...
 
template<typename TheHandleType >
Standard_Boolean GetResource (const TCollection_AsciiString &theKey, TheHandleType &theValue) const
 Access shared resource by its name. More...
 
Standard_Boolean ShareResource (const TCollection_AsciiString &theKey, const Handle< OpenGl_Resource > &theResource)
 Register shared resource. Notice that after registration caller shouldn't release it by himself - it will be automatically released on context destruction. More...
 
void ReleaseResource (const TCollection_AsciiString &theKey, const Standard_Boolean theToDelay=Standard_False)
 Release shared resource. If there are more than one reference to this resource (also used by some other existing object) then call will be ignored. This means that current object itself should nullify handle before this call. Notice that this is unrecommended operation at all and should be used only in case of fat resources to release memory for other needs. More...
 
void DelayedRelease (Handle< OpenGl_Resource > &theResource)
 Append resource to queue for delayed clean up. Resources in this queue will be released at next redraw call. More...
 
void ReleaseDelayed ()
 Clean up the delayed release queue. More...
 
OpenGl_ClippingChangeClipping ()
 
const OpenGl_ClippingClipping () const
 
const Handle
< OpenGl_ShaderManager > & 
ShaderManager () const
 
Standard_Integer MaxDegreeOfAnisotropy () const
 
Standard_Integer MaxTextureSize () const
 
Standard_Integer MaxClipPlanes () const
 Get maximum number of clip planes supported by OpenGl. This value is implementation dependent. At least 6 planes should be supported by OpenGl (see specs). More...
 
const Handle_Message_Messenger & Messenger () const
 
void PushMessage (const unsigned int theSource, const unsigned int theType, const unsigned int theId, const unsigned int theSeverity, const TCollection_ExtendedString &theMessage)
 Callback for GL_ARB_debug_output extension. More...
 
 DEFINE_STANDARD_RTTI (OpenGl_Context) friend class OpenGl_Window
 
- Public Member Functions inherited from Standard_Transient
 Standard_Transient ()
 Empty constructor. More...
 
 Standard_Transient (const Standard_Transient &)
 Copy constructor – does nothing. More...
 
Standard_Transientoperator= (const Standard_Transient &)
 Assignment operator, needed to avoid copying reference counter. More...
 
virtual ~Standard_Transient ()
 Destructor must be virtual. More...
 
virtual void Delete () const
 Memory deallocator for transient classes. More...
 
virtual void ShallowDump (Standard_OStream &) const
 
virtual const
Handle_Standard_Type & 
DynamicType () const
 Returns a type information object about this object. More...
 
Standard_Boolean IsInstance (const Handle_Standard_Type &theType) const
 Returns a true value if this is an instance of Type. More...
 
Standard_Boolean IsInstance (const Standard_CString theTypeName) const
 Returns a true value if this is an instance of TypeName. More...
 
Standard_Boolean IsKind (const Handle_Standard_Type &theType) const
 Returns true if this is an instance of Type or an instance of any class that inherits from Type. Note that multiple inheritance is not supported by OCCT RTTI mechanism. More...
 
Standard_Boolean IsKind (const Standard_CString theTypeName) const
 Returns true if this is an instance of TypeName or an instance of any class that inherits from TypeName. Note that multiple inheritance is not supported by OCCT RTTI mechanism. More...
 
virtual Handle_Standard_Transient This () const
 Returns a Handle which references this object. Must never be called to objects created in stack. More...
 
Standard_Integer GetRefCount () const
 Get the reference counter of this object. More...
 

Static Public Member Functions

static Standard_Integer GetPowerOfTwo (const Standard_Integer theNumber, const Standard_Integer theThreshold)
 Function for getting power of to number larger or equal to input number. More...
 
static Standard_Boolean CheckExtension (const char *theExtString, const char *theExtName)
 Check if theExtName extension is in extensions string. More...
 

Data Fields

OpenGl_GlCore12core12
 
OpenGl_GlCore13core13
 
OpenGl_GlCore14core14
 
OpenGl_GlCore15core15
 
OpenGl_GlCore20core20
 
Handle< OpenGl_Capscaps
 context options More...
 
Standard_Boolean arbNPTW
 GL_ARB_texture_non_power_of_two. More...
 
OpenGl_ArbVBOarbVBO
 GL_ARB_vertex_buffer_object. More...
 
OpenGl_ArbTBOarbTBO
 GL_ARB_texture_buffer_object. More...
 
OpenGl_ArbInsarbIns
 GL_ARB_draw_instanced. More...
 
OpenGl_ArbDbgarbDbg
 GL_ARB_debug_output. More...
 
OpenGl_ExtFBOextFBO
 GL_EXT_framebuffer_object. More...
 
OpenGl_ExtGSextGS
 GL_EXT_geometry_shader4. More...
 
Standard_Boolean extBgra
 GL_EXT_bgra. More...
 
Standard_Boolean extAnis
 GL_EXT_texture_filter_anisotropic. More...
 
Standard_Boolean extPDS
 GL_EXT_packed_depth_stencil. More...
 
Standard_Boolean atiMem
 GL_ATI_meminfo. More...
 
Standard_Boolean nvxMem
 GL_NVX_gpu_memory_info. More...
 

Detailed Description

This class generalize access to the GL context and available extensions.

Functions are grouped into structures and accessed as fields. You should check the group for NULL before usage (if group is not NULL then all functions are available):

if (myContext->core20 != NULL)
{
myGlProgram = myContext->core20->glCreateProgram();
.. do more stuff ..
}
else
{
.. compatibility with outdated configurations ..
}

Current implementation provide access to OpenGL core functionality up to 2.0 version (core12, core13, core14, core15, fields core20). within several extensions (arbVBO, extFBO, etc.).

Simplified extensions classification:

Notice that some systems provide mechanisms to simultaneously incorporate with GL contexts with different capabilities. Thats why OpenGl_Context should be initialized and used for each GL context individually.

Constructor & Destructor Documentation

OpenGl_Context::OpenGl_Context ( const Handle< OpenGl_Caps > &  theCaps = NULL)

Empty constructor. You should call Init() to perform initialization with bound GL context.

virtual OpenGl_Context::~OpenGl_Context ( )
virtual

Destructor.

Member Function Documentation

Standard_Size OpenGl_Context::AvailableMemory ( ) const

This function retrieves information from GL about free GPU memory that is:

  • OS-dependent. On some OS it is per-process and on others - for entire system.
  • Vendor-dependent. Currently available only on NVIDIA and AMD/ATi drivers only.
  • Numbers meaning may vary. You should use this info only for diagnostics purposes.
    Returns
    free GPU dedicated memory in bytes.
OpenGl_Clipping& OpenGl_Context::ChangeClipping ( )
inline
Returns
tool for management of clippings within this context.
Standard_Boolean OpenGl_Context::CheckExtension ( const char *  theExtName) const

Check if theExtName extension is supported by active GL context.

static Standard_Boolean OpenGl_Context::CheckExtension ( const char *  theExtString,
const char *  theExtName 
)
static

Check if theExtName extension is in extensions string.

const OpenGl_Clipping& OpenGl_Context::Clipping ( ) const
inline
Returns
tool for management of clippings within this context.
OpenGl_Context::DEFINE_STANDARD_RTTI ( OpenGl_Context  )
void OpenGl_Context::DelayedRelease ( Handle< OpenGl_Resource > &  theResource)

Append resource to queue for delayed clean up. Resources in this queue will be released at next redraw call.

template<typename FuncType_t >
Standard_Boolean OpenGl_Context::FindProc ( const char *  theFuncName,
FuncType_t &  theFuncPtr 
)
inline

Auxiliary template to retrieve GL function pointer. Pointer to function retrieved from library is statically casted to requested type - there no way to check real signature of exported function. The context should be bound before call.

static Standard_Integer OpenGl_Context::GetPowerOfTwo ( const Standard_Integer  theNumber,
const Standard_Integer  theThreshold 
)
inlinestatic

Function for getting power of to number larger or equal to input number.

Parameters
theNumbernumber to 'power of two'
theThresholdupper threshold
Returns
power of two number
const Handle< OpenGl_Resource >& OpenGl_Context::GetResource ( const TCollection_AsciiString theKey) const

Access shared resource by its name.

Parameters
theKey- unique identifier;
Returns
handle to shared resource or NULL.
template<typename TheHandleType >
Standard_Boolean OpenGl_Context::GetResource ( const TCollection_AsciiString theKey,
TheHandleType &  theValue 
) const
inline

Access shared resource by its name.

Parameters
theKey- unique identifier;
theValue- handle to fill;
Returns
true if resource was shared.
Standard_Boolean OpenGl_Context::Init ( )

Initialize class from currently bound OpenGL context. Method should be called only once.

Returns
false if no GL context is bound to the current thread
Standard_Boolean OpenGl_Context::Init ( const Aspect_Drawable  theWindow,
const Aspect_Display  theDisplay,
const Aspect_RenderingContext  theGContext 
)

Initialize class from specified window and rendering context. Method should be called only once.

Returns
false if OpenGL context can not be bound to specified window
Standard_Boolean OpenGl_Context::IsCurrent ( ) const

This method uses system-dependent API to retrieve information about GL context bound to the current thread.

Returns
true if current thread is bound to this GL context
Standard_Boolean OpenGl_Context::IsFeedback ( ) const

Return true if active mode is GL_FEEDBACK (cached state)

Standard_Boolean OpenGl_Context::IsGlGreaterEqual ( const Standard_Integer  theVerMajor,
const Standard_Integer  theVerMinor 
) const
inline
Returns
true if detected GL version is greater or equal to requested one.
Standard_Boolean OpenGl_Context::IsValid ( ) const
inline
Returns
true if this context is valid (has been initialized)
Standard_Boolean OpenGl_Context::MakeCurrent ( )

Activates current context. Class should be initialized with appropriate info.

Standard_Integer OpenGl_Context::MaxClipPlanes ( ) const

Get maximum number of clip planes supported by OpenGl. This value is implementation dependent. At least 6 planes should be supported by OpenGl (see specs).

Returns
value for GL_MAX_CLIP_PLANES
Standard_Integer OpenGl_Context::MaxDegreeOfAnisotropy ( ) const
Returns
maximum degree of anisotropy texture filter
Standard_Integer OpenGl_Context::MaxTextureSize ( ) const
Returns
value for GL_MAX_TEXTURE_SIZE
TCollection_AsciiString OpenGl_Context::MemoryInfo ( ) const

This function retrieves information from GL about GPU memory and contains more vendor-specific values than AvailableMemory().

const Handle_Message_Messenger& OpenGl_Context::Messenger ( ) const
inline
Returns
messenger instance
void OpenGl_Context::PushMessage ( const unsigned int  theSource,
const unsigned int  theType,
const unsigned int  theId,
const unsigned int  theSeverity,
const TCollection_ExtendedString theMessage 
)

Callback for GL_ARB_debug_output extension.

Parameters
theSourcemessage source within GL_DEBUG_SOURCE_ enumeration
theTypemessage type within GL_DEBUG_TYPE_ enumeration
theIdmessage ID within source
theSeveritymessage severity within GL_DEBUG_SEVERITY_ enumeration
theMessagethe message itself
void OpenGl_Context::ReleaseDelayed ( )

Clean up the delayed release queue.

void OpenGl_Context::ReleaseResource ( const TCollection_AsciiString theKey,
const Standard_Boolean  theToDelay = Standard_False 
)

Release shared resource. If there are more than one reference to this resource (also used by some other existing object) then call will be ignored. This means that current object itself should nullify handle before this call. Notice that this is unrecommended operation at all and should be used only in case of fat resources to release memory for other needs.

Parameters
theKeyunique identifier
theToDelaypostpone release until next redraw call
void OpenGl_Context::ResetErrors ( )

Clean up errors stack for this GL context (glGetError() in loop).

void OpenGl_Context::SetFeedback ( const Standard_Boolean  theFeedbackOn)

Setup feedback mode cached state.

const Handle< OpenGl_ShaderManager >& OpenGl_Context::ShaderManager ( ) const
inline
Returns
tool for management of shader programs within this context.
void OpenGl_Context::Share ( const Handle< OpenGl_Context > &  theShareCtx)

Share GL context resources. theShareCtx - handle to context to retrieve handles to shared resources.

Standard_Boolean OpenGl_Context::ShareResource ( const TCollection_AsciiString theKey,
const Handle< OpenGl_Resource > &  theResource 
)

Register shared resource. Notice that after registration caller shouldn't release it by himself - it will be automatically released on context destruction.

Parameters
theKey- unique identifier, shouldn't be empty;
theResource- new resource to register, shouldn't be NULL.
void OpenGl_Context::SwapBuffers ( )

Swap front/back buffers for this GL context (should be activated before!).

Aspect_Drawable OpenGl_Context::Window ( ) const
inline
Returns
the window handle (GLXDrawable) currently bound to this OpenGL context

Field Documentation

OpenGl_ArbDbg* OpenGl_Context::arbDbg

GL_ARB_debug_output.

OpenGl_ArbIns* OpenGl_Context::arbIns

GL_ARB_draw_instanced.

Standard_Boolean OpenGl_Context::arbNPTW

GL_ARB_texture_non_power_of_two.

OpenGl_ArbTBO* OpenGl_Context::arbTBO

GL_ARB_texture_buffer_object.

OpenGl_ArbVBO* OpenGl_Context::arbVBO

GL_ARB_vertex_buffer_object.

Standard_Boolean OpenGl_Context::atiMem

GL_ATI_meminfo.

Handle< OpenGl_Caps > OpenGl_Context::caps

context options

OpenGl_GlCore12* OpenGl_Context::core12
OpenGl_GlCore13* OpenGl_Context::core13
OpenGl_GlCore14* OpenGl_Context::core14
OpenGl_GlCore15* OpenGl_Context::core15
OpenGl_GlCore20* OpenGl_Context::core20
Standard_Boolean OpenGl_Context::extAnis

GL_EXT_texture_filter_anisotropic.

Standard_Boolean OpenGl_Context::extBgra

GL_EXT_bgra.

OpenGl_ExtFBO* OpenGl_Context::extFBO

GL_EXT_framebuffer_object.

OpenGl_ExtGS* OpenGl_Context::extGS

GL_EXT_geometry_shader4.

Standard_Boolean OpenGl_Context::extPDS

GL_EXT_packed_depth_stencil.

Standard_Boolean OpenGl_Context::nvxMem

GL_NVX_gpu_memory_info.


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