Skip to content

Scene

Root node and entry point for a scene graph.

Scene is the top-level container for all nodes in a VGLX application. It acts as the root of the scene graph and is responsible for propagating update and input events throughout the hierarchy. Each application has one active scene at a time, which is managed by the Application.

A custom scene can be created by inheriting from this class and overriding behavior or adding initial nodes. The scene must be provided to the application during startup:

cpp
class MyApp : public vglx::Application {
public:
  auto Configure() -> void override {
    params.title = "My App";
  }

  auto CreateScene() -> std::shared_ptr<vglx::Scene> override {
    auto scene = vglx::Scene::Create();
    // Add nodes to the scene
    return scene;
  }

  auto Update(float delta) -> bool override {
    // Called every frame
    return true;
  }
};

INFO

Derives from Node and inherits all public properties and methods.

Construction

Constructors


Scene()

Constructs an Scene instance.

cpp
Scene::Scene();

Factories preferred


Scene::Create() auto

Creates a shared pointer to a Scene object.

cpp
static auto Scene::Create();

Properties

fog std::unique_ptr<Fog>

Fog settings applied to the entire scene. Set this to a LinearFog or ExponentialFog instance to enable distance-based atmospheric fading. This is typically done during scene setup.

cpp
scene->fog = vglx::LinearFog::Create(0x444444, 2.0f, 6.0f);
cpp
std::unique_ptr<Fog> fog {};

Functions

Advance() void

Advances the scene by one frame.

Propagates the per-frame update through the scene graph, calling NodeUpdate(float delta) on all attached nodes in depth-first order. This is invoked automatically by the runtime each frame.

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

GetNodeType() Node::Type virtual

Returns node type.

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

SetContext() void

Attaches a shared context to the scene.

Deprecated

The context provides runtime parameters (e.g., window size, active camera) and resource loaders. This is normally called by the runtime during initialization. All nodes added to the scene will receive the context via NodeOnAttached.

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

Released under the MIT License.