Skip to content

Vp::Scene ​

A scene representing a "game world" that contains entities and is viewed by a camera. More...

#include "Viewport/scene/Scene.h"

Inherited by Vp::MainScene, Vp::PreviewScene

Public Functions ​

Name
Scene(Viewport * viewport)
virtual~Scene() =default
template <typename T ,typename std::enable_if< std::is_base_of< Entity, T >::value, bool >::type =true&gt; <br>std::weak_ptr< T >addEntity(std::shared_ptr< T > entity)<br>Adds entity to the scene.
voidaddSelectionCallback(std::function< void(Entity *)> callback)
virtual Ptr< SceneRenderTarget >createRenderTarget(const RenderOptions & options)<br>Create and populates a SceneRenderTarget object with expected framebuffer objects for the scenes render pass.
virtual voiddraw(int width, int height, const glm::mat4 & model, const glm::mat4 & view, const glm::mat4 & projection, SceneRenderTarget & renderTarget, const DisplayOptions & displayOptions)<br>Draw the scene using the provided view and projection matrices.
virtual voiddraw(int width, int height, const glm::mat4 & model, SceneRenderTarget & renderTarget, const DisplayOptions & displayOptions)<br>Draw the scene using the scene's camera.
virtual voiddraw(int width, int height, const std::shared_ptr< AbstractCamera > & camera, const glm::mat4 & model, SceneRenderTarget & renderTarget, const DisplayOptions & displayOptions)<br>Draw the scene using a provided camera.
const std::vector< std::shared_ptr< Entity > > &getEntities() const
virtual voidinit()<br>Initialises the scene.
voidprocessInput(double dt, glm::vec2 mousePos, glm::ivec2 windowSize)<br>Update input logic.
voidprocessSelection(SceneRenderTarget & renderTarget, glm::vec2 mousePos, glm::ivec2 windowSize)<br>Update selection logic.
template <typename T ,typename std::enable_if< std::is_base_of< Entity, T >::value, bool >::type =true&gt; <br>voidremoveEntity(std::weak_ptr< T > entity)<br>Remove entity from the scene.
voidtriggerSelectionCallbacks(Entity * entity)
virtual voidupdate(double dt)<br>Update entity logic.

Protected Functions ​

Name
voiddrawHighlight(int width, int height, const glm::mat4 & model, const glm::mat4 & view, const glm::mat4 & projection, SceneRenderTarget & renderTarget, const DisplayOptions & displayOptions, ViewportSettings & stg, const Ptr< Framebuffer > & mainFBO, const Ptr< Framebuffer > & selectionFBO, const Ptr< Framebuffer > & selectionBlurFBO, const Ptr< Framebuffer > & selectionBlurSecondPassFBO)
voiddrawStandard(int width, int height, const glm::mat4 & model, const glm::mat4 & view, const glm::mat4 & projection, SceneRenderTarget & renderTarget, const DisplayOptions & displayOptions, RenderOptions renderOptions, bool alpha, glm::vec3 clearColor, const Ptr< Framebuffer > & mainFBO)
voiddrawWboit(int width, int height, const glm::mat4 & model, const glm::mat4 & view, const glm::mat4 & projection, SceneRenderTarget & renderTarget, const DisplayOptions & displayOptions, RenderOptions renderOptions, bool alpha, glm::vec3 clearColor, const Ptr< Framebuffer > & mainFBO, const Ptr< Framebuffer > & transparentFBO)
voidrenderSortedTransparentEntities(const std::vector< Entity * > & entities, const glm::mat4 & model, const glm::mat4 & view, const glm::mat4 & projection, const DisplayOptions & displayOptions) const
voidsortExplicitlyOrderedTransparentEntities(std::vector< Entity * > & entities)
voidsortUnorderedTransparentEntities(std::vector< Entity * > & entities, const glm::mat4 & model, const glm::mat4 & view)

Public Attributes ​

Name
std::shared_ptr< AbstractCamera >m_camera
std::shared_ptr< Lighting >m_lighting
std::shared_ptr< SelectStencil >m_selectStencil
Viewport *m_viewport

Protected Attributes ​

Name
std::vector< std::shared_ptr< Entity > >m_entities
std::vector< Entity * >m_explicitTransparencyOrderEntitiesFirst
std::vector< Entity * >m_explicitTransparencyOrderEntitiesLast
std::vector< Entity * >m_highlightedEntities
Entity *m_selectedEntity
std::vector< std::function< void(Entity *)> >m_selectionCallbacks <br>Callbacks that get triggered on entity selection.
std::vector< Entity * >m_unorderedTransparentEntities

Friends ​

Name
classViewport

Detailed Description ​

cpp
class Vp::Scene;

A scene representing a "game world" that contains entities and is viewed by a camera.

Handles drawing and logic updates.

Public Functions Documentation ​

function Scene ​

cpp
explicit Scene(
    Viewport * viewport
)

function ~Scene ​

cpp
virtual ~Scene() =default

function addEntity ​

cpp
template <typename T ,
typename std::enable_if< std::is_base_of< Entity, T >::value, bool >::type  =true>
inline std::weak_ptr< T > addEntity(
    std::shared_ptr< T > entity
)

Adds entity to the scene.

Parameters:

  • entity A shared pointer to the entity to add. This pointer should be destroyed afterwards.

Template Parameters:

Return: A weak pointer to the added entity of said type.

Entity is added via a shared pointer which is copied and stored. The original pointer should be discarded after this call and the weak reference can be further used.

function addSelectionCallback ​

cpp
inline void addSelectionCallback(
    std::function< void(Entity *)> callback
)

function createRenderTarget ​

cpp
virtual Ptr< SceneRenderTarget > createRenderTarget(
    const RenderOptions & options
)

Create and populates a SceneRenderTarget object with expected framebuffer objects for the scenes render pass.

Parameters:

  • options Relevant render options to take into account during render target creation

Return: Owning pointer to the created render target object

Individual framebuffers are only identified by their index in the render target framebuffer array. It is expected that these indexes are kept track of somewhere else, or just expected to be a certain way.

function draw ​

cpp
virtual void draw(
    int width,
    int height,
    const glm::mat4 & model,
    const glm::mat4 & view,
    const glm::mat4 & projection,
    SceneRenderTarget & renderTarget,
    const DisplayOptions & displayOptions
)

Draw the scene using the provided view and projection matrices.

Parameters:

  • width Desired framebuffer pixel width
  • height Desired framebuffer pixel height
  • model Implicit model matrix, multiplies all model transforms from the left.

Reimplemented by: Vp::MainScene::draw, Vp::MainScene::draw

function draw ​

cpp
virtual void draw(
    int width,
    int height,
    const glm::mat4 & model,
    SceneRenderTarget & renderTarget,
    const DisplayOptions & displayOptions
)

Draw the scene using the scene's camera.

Parameters:

  • width Desired framebuffer pixel width
  • height Desired framebuffer pixel height
  • model Implicit model matrix, multiplies all model transforms from the left.

Reimplemented by: Vp::MainScene::draw

function draw ​

cpp
virtual void draw(
    int width,
    int height,
    const std::shared_ptr< AbstractCamera > & camera,
    const glm::mat4 & model,
    SceneRenderTarget & renderTarget,
    const DisplayOptions & displayOptions
)

Draw the scene using a provided camera.

Parameters:

  • width Desired framebuffer pixel width
  • height Desired framebuffer pixel height
  • camera The camera to render the scene with
  • model Implicit model matrix, multiplies all model transforms from the left.

Reimplemented by: Vp::MainScene::draw

function getEntities ​

cpp
inline const std::vector< std::shared_ptr< Entity > > & getEntities() const

function init ​

cpp
inline virtual void init()

Initialises the scene.

Reimplemented by: Vp::MainScene::init, Vp::PreviewScene::init

Should be called before any draw operations.

function processInput ​

cpp
void processInput(
    double dt,
    glm::vec2 mousePos,
    glm::ivec2 windowSize
)

Update input logic.

Parameters:

  • dt Time since last frame
  • mousePos Current mouse position relative to the window
  • windowSize Current window size

function processSelection ​

cpp
void processSelection(
    SceneRenderTarget & renderTarget,
    glm::vec2 mousePos,
    glm::ivec2 windowSize
)

Update selection logic.

Parameters:

  • diwne
  • renderTarget Scene's render target
  • mousePos Current mouse position relative to the window
  • windowSize Current window size

function removeEntity ​

cpp
template <typename T ,
typename std::enable_if< std::is_base_of< Entity, T >::value, bool >::type  =true>
inline void removeEntity(
    std::weak_ptr< T > entity
)

Remove entity from the scene.

Parameters:

  • entity

Template Parameters:

The entity is passed as a weak pointer previously acquired by addEntity()

function triggerSelectionCallbacks ​

cpp
void triggerSelectionCallbacks(
    Entity * entity
)

function update ​

cpp
virtual void update(
    double dt
)

Update entity logic.

Reimplemented by: Vp::MainScene::update

Protected Functions Documentation ​

function drawHighlight ​

cpp
void drawHighlight(
    int width,
    int height,
    const glm::mat4 & model,
    const glm::mat4 & view,
    const glm::mat4 & projection,
    SceneRenderTarget & renderTarget,
    const DisplayOptions & displayOptions,
    ViewportSettings & stg,
    const Ptr< Framebuffer > & mainFBO,
    const Ptr< Framebuffer > & selectionFBO,
    const Ptr< Framebuffer > & selectionBlurFBO,
    const Ptr< Framebuffer > & selectionBlurSecondPassFBO
)

function drawStandard ​

cpp
void drawStandard(
    int width,
    int height,
    const glm::mat4 & model,
    const glm::mat4 & view,
    const glm::mat4 & projection,
    SceneRenderTarget & renderTarget,
    const DisplayOptions & displayOptions,
    RenderOptions renderOptions,
    bool alpha,
    glm::vec3 clearColor,
    const Ptr< Framebuffer > & mainFBO
)

function drawWboit ​

cpp
void drawWboit(
    int width,
    int height,
    const glm::mat4 & model,
    const glm::mat4 & view,
    const glm::mat4 & projection,
    SceneRenderTarget & renderTarget,
    const DisplayOptions & displayOptions,
    RenderOptions renderOptions,
    bool alpha,
    glm::vec3 clearColor,
    const Ptr< Framebuffer > & mainFBO,
    const Ptr< Framebuffer > & transparentFBO
)

function renderSortedTransparentEntities ​

cpp
void renderSortedTransparentEntities(
    const std::vector< Entity * > & entities,
    const glm::mat4 & model,
    const glm::mat4 & view,
    const glm::mat4 & projection,
    const DisplayOptions & displayOptions
) const

function sortExplicitlyOrderedTransparentEntities ​

cpp
void sortExplicitlyOrderedTransparentEntities(
    std::vector< Entity * > & entities
)

function sortUnorderedTransparentEntities ​

cpp
void sortUnorderedTransparentEntities(
    std::vector< Entity * > & entities,
    const glm::mat4 & model,
    const glm::mat4 & view
)

Public Attributes Documentation ​

variable m_camera ​

cpp
std::shared_ptr< AbstractCamera > m_camera;

variable m_lighting ​

cpp
std::shared_ptr< Lighting > m_lighting;

variable m_selectStencil ​

cpp
std::shared_ptr< SelectStencil > m_selectStencil;

variable m_viewport ​

cpp
Viewport * m_viewport;

Protected Attributes Documentation ​

variable m_entities ​

cpp
std::vector< std::shared_ptr< Entity > > m_entities;

variable m_explicitTransparencyOrderEntitiesFirst ​

cpp
std::vector< Entity * > m_explicitTransparencyOrderEntitiesFirst;

variable m_explicitTransparencyOrderEntitiesLast ​

cpp
std::vector< Entity * > m_explicitTransparencyOrderEntitiesLast;

variable m_highlightedEntities ​

cpp
std::vector< Entity * > m_highlightedEntities;

variable m_selectedEntity ​

cpp
Entity * m_selectedEntity = nullptr;

variable m_selectionCallbacks ​

cpp
std::vector< std::function< void(Entity *)> > m_selectionCallbacks;

Callbacks that get triggered on entity selection.

variable m_unorderedTransparentEntities ​

cpp
std::vector< Entity * > m_unorderedTransparentEntities;

Friends ​

friend Viewport ​

cpp
friend class Viewport(
    Viewport 
);

Updated on 2026-09-11 at 21:24:25 +0000