Ream v0.1.0-1
C++ graphics library for Linux
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | List of all members
RGLContextDataManager Class Reference

OpenGL context data manager. More...

#include <RGLContext.h>

+ Inheritance diagram for RGLContextDataManager:

Public Types

using AllocFunc = std::function< RGLContextData *(RGLDevice *device)>
 Allocator function.
 

Public Member Functions

RGLContextDatagetData (RGLDevice *device) noexcept
 Retrieves or creates context-specific data for the given device on the current thread.
 
void freeData (RGLDevice *device) noexcept
 Frees all RGLContextData instances associated with the specified device across all threads.
 
 ~RGLContextDataManager () noexcept
 Destroys the manager and all RGLContextData instances it owns.
 
- Public Member Functions inherited from RObject
 RObject ()=default
 Constructs a default RObject.
 

Static Public Member Functions

static std::shared_ptr< RGLContextDataManagerMake (AllocFunc func) noexcept
 Creates an RGLContextDataManager.
 

Detailed Description

OpenGL context data manager.

In Ream, each device has a dedicated OpenGL context for every thread that uses it. Although these contexts are created as shared, they do not always share all OpenGL resources— such as framebuffers, shader programs, and others, making it difficult for users to allocate and manage their own graphics resources.

This class enables users to provide a custom allocator function that creates an instance of a subclass of RGLContextData, which can be populated with any required data members. The instance is automatically created if one does not already exist for the current device/context combination when getData() is called.

At allocation time, the EGL context for the corresponding device and thread is made current. The same applies when the destructor of the associated RGLContextData is invoked.

Each allocated RGLContextData instance is automatically destroyed under the following conditions:

Member Typedef Documentation

◆ AllocFunc

using AllocFunc = std::function<RGLContextData *(RGLDevice *device)>

Allocator function.

This function is used to create instances of a subclass of RGLContextData associated with a specific device/thread.

Parameters
devicePointer to the RGLDevice for which context-specific data is requested.
Returns
A pointer to a new subclass of RGLContextData containing the necessary data members. Returning nullptr is valid, in such cases, getData() will return nullptr for the corresponding thread/device pair.

Constructor & Destructor Documentation

◆ ~RGLContextDataManager()

~RGLContextDataManager ( )
noexcept

Destroys the manager and all RGLContextData instances it owns.

Instances belonging to the current thread are destroyed immediately (with their context made current); those belonging to other threads are queued as garbage and released when those threads terminate or call RGLCore::clearGarbage().

Member Function Documentation

◆ Make()

static std::shared_ptr< RGLContextDataManager > Make ( AllocFunc  func)
staticnoexcept

Creates an RGLContextDataManager.

Parameters
funcAllocator function.
Returns
A shared pointer to the created manager instance, or nullptr if the allocator is invalid.

◆ getData()

RGLContextData * getData ( RGLDevice device)
noexcept

Retrieves or creates context-specific data for the given device on the current thread.

If no data exists for the current device/context pair, a new instance is allocated using the registered allocator function. The associated EGL context is bound during allocation.

Parameters
devicePointer to the target device.
Returns
Pointer to the user data, or nullptr if the allocator functuin returned nullptr.

◆ freeData()

void freeData ( RGLDevice device)
noexcept

Frees all RGLContextData instances associated with the specified device across all threads.

This method releases the context-specific data allocated for the given device in every thread where it was used.

Note
Resources allocated on the current thread are destroyed immediately. For other threads, cleanup is deferred until either the threads are terminated or RGLCore::clearGarbage() is explicitly invoked from those threads.
Parameters
devicePointer to the target RGLDevice whose associated context data will be released.