![]() |
ImFusion SDK 4.3
|
#include <ImFusion/Core/GL/ContextManager.h>
Singleton class to manage access to OpenGL contexts. More...
Singleton class to manage access to OpenGL contexts.
The ContextManager maintains two OpenGL contexts for the ImFusion SDK:
Public Member Functions | |
std::unique_ptr< Context > | createContext () |
Convenience method to create a OpenGL context for the calling thread. | |
void | ensureLocalContext () |
Convenience method that creates a GL context for the local thread if necessary. | |
void | releaseLocalContext () |
Delete a local context previously created by ensureLocalContext() and free its resources. | |
void | runWithOpenGL (const std::function< void()> &func, bool forceBackgroundThread=false) |
Ensures that the given function is run in a valid OpenGL context. | |
Context * | mainContext () const |
Access the main OpenGL context instance. | |
Static Public Member Functions | |
static ContextManager & | get () |
Return the singleton instance of the manager. | |
static bool | hasCurrent () |
Returns whether the calling thread has a current OpenGL context. | |
static bool | makeCurrent () |
Convenience method to make the main context current. | |
static bool | doneCurrent () |
Convenience method to release the currently active context of the calling thread. Can be called from any thread. | |
static void * | currentContextId () |
Returns a platform-specific handle to the currently active OpenGL context. | |
static bool | useCoreContext () |
static bool | openGlDisabled () |
std::unique_ptr< Context > createContext | ( | ) |
Convenience method to create a OpenGL context for the calling thread.
The context will be shared with the main and background context. This function returns nullptr if called from the main or background processing thread because creating another local context would violate the one-context-per-thread rule.
Example:
void ensureLocalContext | ( | ) |
Convenience method that creates a GL context for the local thread if necessary.
If a GL context already exists for the calling thread (i.e. because it is the main or background thread, or because this function has already been called in the same thread), it will do nothing. It is safe to just call this function once before making use of OpenGL in code where the executing thread is undetermined (e.g. thread pool) to avoid problems related to the absence of a GL context.
void releaseLocalContext | ( | ) |
Delete a local context previously created by ensureLocalContext() and free its resources.
This function will do nothing if the current thread does not have a local context.
void runWithOpenGL | ( | const std::function< void()> & | func, |
bool | forceBackgroundThread = false ) |
Ensures that the given function is run in a valid OpenGL context.
If the calling thread has a current OpenGL context and forceBackgroundThread is false it will call func directly. Otherwise it will run func in a separate thread using the background OpenGL thread managed by ContextManager.
func | Function object to call from a valid OpenGL context. |
forceBackgroundThread | Set to true to force execution on background thread. |
|
static |
Convenience method to make the main context current.
Will only work if called from the main thread.
|
static |
Returns a platform-specific handle to the currently active OpenGL context.