easy-gl › ResourceRegistry
ResourceRegistry
Central registry that tracks RecoverableResource instances and drives the context-lost / context-restored cycle. Implements metagl::ContextListener so it receives automatic notifications from meta-gl when the context changes.
Setup
Create one registry per application, register it with meta-gl once, then add all recoverable resources to it:
easygl::ResourceRegistry registry;
registry.register_with_meta_gl(); // subscribe to context events
// Register each recoverable resource:
registry.add(&myTexture);
registry.add(&myVertexBuffer);
Context-loss flow
When meta-gl detects a context loss, it calls registry.OnContextLost() automatically. The registry then calls release_gl_handle_only() on every registered resource — no GL functions are issued, only the stored handles are cleared.
When the context is restored and a new loader is provided, meta-gl calls registry.OnContextRestored(). The registry calls recreate_gl_resource() on every resource, which recreates the GPU objects from their stored CPU data.
RAII registration with ResourceRegistration
ResourceRegistration is a helper that registers a resource in its constructor and unregisters it in its destructor. Use it for resources with a bounded lifetime:
easygl::ResourceRegistry registry;
registry.register_with_meta_gl();
{
MyTexture temporaryTex;
temporaryTex.load(256, 256, pixelData);
easygl::ResourceRegistration reg(registry, temporaryTex);
// temporaryTex is now registered for context-loss callbacks
// ... use temporaryTex ...
} // reg destructor calls registry.remove(&temporaryTex)
add(). Pointers must remain valid until remove() is called or the registry is destroyed.Method reference
| Method | Description |
|---|---|
add(resource*) | Register a resource for context-event notifications. |
remove(resource*) | Unregister a resource. No-op if not found. |
register_with_meta_gl() | Subscribe this registry to meta-gl context events. |
unregister_from_meta_gl() | Unsubscribe from meta-gl context events. |
OnContextLost() | Called by meta-gl on context loss. Calls release_gl_handle_only() on all resources. |
OnContextRestored() | Called by meta-gl after context restoration. Calls recreate_gl_resource() on all resources. |
ResourceRegistration method reference
| Method | Description |
|---|---|
ResourceRegistration(registry, resource) | Register resource with registry immediately. |
~ResourceRegistration() | Unregister the resource from the registry. |