Skip to content

Scene

Root node of a renderable scene graph.

Scene is the top-level container for all nodes that participate in rendering and updates. It owns the scene graph hierarchy, optional global fog settings, and a shared runtime context. Create a scene by overriding the application runtime Application::CreateScene. The runtime will attach it to the active context and advance it once per frame.

cpp
class MyApp : public vglx::Application {
public:
  auto Configure() -> Application::Parameters override {
    return {
      .title = "Hello VGLX",
      .clear_color = {0x000000},
      .width = 1280,
      .height = 720,
      .antialiasing = 4,
    };
  }

  auto CreateScene() -> std::unique_ptr<vglx::Scene> override {
    auto scene = vglx::Scene::Create();
    scene->fog = vglx::Fog::CreateExponential(0x444444, 0.3f);

    // Add nodes to the scene...

    return scene;
  }

  auto Update(float delta) -> bool override {
    return true;
  }
};

INFO

Derives from Node and inherits all public properties and methods.

Construction

Constructors


Scene()

Constructs a scene object.

cpp
Scene::Scene();

Factories preferred


Scene::Create() std::unique_ptr<Scene>

Creates an instance of Scene.

cpp
static std::unique_ptr<Scene> Scene::Create();

Properties

background std::shared_ptr<Texture>

Optional for defining a flat texture background.

cpp
std::shared_ptr<Texture> background {nullptr};

fog std::optional<Fog>

Optional global fog settings applied during rendering.

cpp
std::optional<Fog> fog {};

Functions

Advance() void

Advances the scene by one frame.

Propagates per-frame updates through the scene graph, calling OnUpdate on the scene and all attached nodes in depth-first order. This is invoked automatically by the runtime once per frame.

cpp
void Scene::Advance(float delta);
ParameterDescription
deltaElapsed time in seconds since the last frame.

GetContext() SharedContextPointer

Returns the active shared context.

Returns the context previously set via SetContext, or nullptr if the scene has not been attached to a context yet.

cpp
SharedContextPointer Scene::GetContext() const;

GetNodeType() Node::Type virtual

Identifies this node as Node::Type::Scene.

cpp
Type vglx::Scene::GetNodeType() const override;

SetContext() void

Attaches a shared context to the scene.

Stores the active shared context and propagates it to all nodes in the scene graph via Node::OnAttached. The context provides access to runtime state such as the active camera, window parameters, and renderer resources. This is normally called by the application runtime during initialization.

cpp
void Scene::SetContext(SharedContextPointer context);
ParameterDescription
contextPointer to the active SharedContext instance.

Released under the MIT License.