HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GlfGLContextScopeHolder Class Reference

#include <glContext.h>

+ Inheritance diagram for GlfGLContextScopeHolder:

Public Member Functions

GLF_API GlfGLContextScopeHolder (const GlfGLContextSharedPtr &newContext)
 
GLF_API ~GlfGLContextScopeHolder ()
 
 GlfGLContextScopeHolder (const GlfGLContextScopeHolder &)=delete
 
GlfGLContextScopeHolderoperator= (const GlfGLContextScopeHolder)=delete
 

Protected Member Functions

GLF_API void _MakeNewContextCurrent ()
 
GLF_API void _RestoreOldContext ()
 

Detailed Description

Helper class to make a GL context current.

It is often useful to wrap a dynamic GL resource with a class interface.

In addition to providing API to make it more convenient to use the underlying GL resource, the lifetime of the underlying resource can be tied to the lifetime of a wrapper object instance, e.g. allocate the GL resource during construction, delete the GL resource during destruction.

While the construction and use of these kinds of wrapper objects is usually pretty safe and straightforward, it can be more difficult to manage destruction. Specifically, it can be hard to guarantee that a suitable GL context is current at the time that a wrapper object instance is destroyed. If a suitable context is not current, then it will not be possible to delete the underlying resource, which may cause the resource to remain allocated, which will then result in a resource leak.

Typically, these GL resources are allocated from contexts which are sharing the GL resources. In which case it is sufficient for any one one of the sharing contexts to be current in order to be able to safely delete the GL resource from the destructor of a wrapper object.

GlfGLContext and GlfGLContextScopeHolder can help.

When GlfGLContext has been initialized, i.e. when suitable context callbacks have been registered, we can use GlfGLContext to make a GL context current.

GlfGLContextScopeHolder does this automatically for the duration of a code block.

The underlying calls to make GL contexts current can be moderately expensive. So, this mechanism should be used carefully.

Definition at line 170 of file glContext.h.

Constructor & Destructor Documentation

GLF_API GlfGLContextScopeHolder::GlfGLContextScopeHolder ( const GlfGLContextSharedPtr newContext)
explicit

Make the given context current and restore the current context when this object is destroyed.

GLF_API GlfGLContextScopeHolder::~GlfGLContextScopeHolder ( )
GlfGLContextScopeHolder::GlfGLContextScopeHolder ( const GlfGLContextScopeHolder )
delete

Member Function Documentation

GLF_API void GlfGLContextScopeHolder::_MakeNewContextCurrent ( )
protected
GLF_API void GlfGLContextScopeHolder::_RestoreOldContext ( )
protected
GlfGLContextScopeHolder& GlfGLContextScopeHolder::operator= ( const GlfGLContextScopeHolder  )
delete

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