SharedContext
The shared context encapsulates common runtime state and services accessible throughout the scene graph. It is constructed and propagated automatically by the runtime, which also keeps its values synchronized as rendering parameters change — such as window size, framebuffer dimensions, or the active camera.
Nodes can access the shared context via the Node::OnAttached callback, which is invoked when the node joins an active scene hierarchy. Override this method in your node subclass to perform initialization that depends on the context — such as loading resources, querying the active camera, or accessing other global services.
auto MyNode::OnAttached(SharedContextPointer context) -> void {
context->texture_loader->LoadAsync(
"assets/my_texture.tex",
[this](auto result) {
if (result) {
texture_ = result.value();
} else {
std::println(stderr, "{}", result.error());
}
}
);
}Types
SharedContextPointer typedef
Alias for a unique pointer to a SharedContext instance.
This typedef simplifies ownership semantics for the shared context, ensuring a single owner at any given time. Use this when returning or storing the main rendering context instance.
using SharedContextPointer = const vglx::SharedContext*Properties
aspect_ratio float
Aspect ratio of the render surface. Computed as framebuffer width divided by height. Used for projection and viewport setup.
float aspect_ratio {};Pointer to the active camera. Commonly used by scene nodes to query camera parameters or implement camera controls.
Camera* camera {};framebuffer_height int
Framebuffer height in physical pixels. Reflects the true pixel height of the render target.
int framebuffer_height {};framebuffer_width int
Framebuffer width in physical pixels. Reflects the true pixel width of the render target. May differ from window width on high-DPI displays.
int framebuffer_width {};mesh_loader std::shared_ptr<MeshLoader>
Shared texture loader. Handles loading and caching of mesh assets, targeting the engine's custom .msh format.
std::shared_ptr<MeshLoader> mesh_loader {MeshLoader::Create()};texture_loader std::shared_ptr<TextureLoader>
Shared texture loader. Handles loading and caching of image assets, targeting the engine's custom .tex format.
std::shared_ptr<TextureLoader> texture_loader {TextureLoader::Create()};window_height int
Window height in logical units. Represents window dimensions in OS coordinate space.
int window_height {};window_width int
Window width in logical units. Represents window dimensions in OS coordinate space. Differs from framebuffer size on high-DPI displays.
int window_width {};