Loading...
Searching...
No Matches
GlfAnyGLContextScopeHolder Class Referencefinal

Helper class to make the shared GL context current if there is no valid current context, or when the current context isn't sharing with the shared context. More...

#include <glContext.h>

+ Inheritance diagram for GlfAnyGLContextScopeHolder:

Detailed Description

Helper class to make the shared GL context current if there is no valid current context, or when the current context isn't sharing with the shared context.

This mechanism lets us skip context switches to the shared context (see GlfSharedGLContextScopeHolder) when possible, while ensuring that we have a valid GL context prior to any resource allocation or destruction.

Example:

class MyTexture {
public:
MyTexture() : _textureId(0) {
// Ensure we have valid GL context to allocate
GlfAnyGLContextScopeHolder anyContextScopeHolder;
glGenTextures(1, &_textureId);
}
~MyTexture() {
// Ensure we have valid GL context to delete
GlfAnyGLContextScopeHolder anyContextScopeHolder;
glDeleteTextures(1, &_texureId);
_textureId = 0;
}
// The caller is responsible for making sure that a suitable
// GL context is current before calling other methods.
void Bind() {
glBindTexture(GL_TEXTURE_2D, _textureId);
}
void Unbind() {
glBindTexture(GL_TEXTURE_2D, 0);
}
...
private:
GLuint _textureId;
};
Helper class to make the shared GL context current if there is no valid current context,...
Definition: glContext.h:304

Definition at line 303 of file glContext.h.

Constructor & Destructor Documentation

◆ GlfAnyGLContextScopeHolder()

Definition at line 306 of file glContext.h.


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