Skip to content

Vp::Viewport

Scene viewport class. More...

#include "Viewport/Viewport.h"

Inherits from Module, IStateful

Public Functions

Name
Viewport()<br>Creates an empty viewport.
~Viewport()
virtual voidclearGlobal() override<br>Set the global state to some default empty state.
virtual voidclearScene() override<br>Set the scene state to some default empty state.
WPtr< SceneCamera >createCamera(Core::ID guiNodeId)<br>Creates a SceneCamera in the main scene to represent a Camera node.
WPtr< SceneModel >createModel(Core::ID guiNodeId)<br>Creates a SceneModel in the main scene to represent a Model node.
voiddrawPreview(Ptr< SceneRenderTarget > & renderTarget, int width, int height, WPtr< GameObject > gameObject, const RenderOptions & renderOptions)<br>Draw a preview of an object into a framebuffer.
voiddrawScreen(Ptr< SceneRenderTarget > & renderTarget, int width, int height, glm::mat4 view, glm::mat4 projection, const RenderOptions & renderOptions =RenderOptions(), const DisplayOptions & displayOptions =DisplayOptions())<br>Render viewport's main scene into a framebuffer with the specified camera matrices.
voiddrawViewport(Ptr< SceneRenderTarget > & renderTarget, int width, int height, const RenderOptions & renderOptions =RenderOptions(), const DisplayOptions & displayOptions =DisplayOptions())<br>Render viewport's main scene into a framebuffer using its own camera.
WPtr< Scene >getMainScene()
WPtr< AggregateCamera >getMainViewportCamera()<br>Returns the viewport camera of the main scene.
Manipulators &getManipulators()
WPtr< Scene >getPreviewScene()
ViewportSettings &getSettings()
virtual voidloadGlobal(const Memento & memento) override<br>Load global state from a memento.
virtual voidloadScene(const Memento & memento, State::Scene * scene) override<br>Called on scene load, undo and redo.
virtual voidonInit() override<br>Initializes scenes and loads assets.
virtual voidonUpdate(double dt) override<br>Update scene logic.
voidprocessInput(double dt, glm::vec2 mousePos, glm::ivec2 windowSize)<br>Process viewport user input.
voidprocessSelection(Ptr< SceneRenderTarget > renderTarget, glm::vec2 mousePos, glm::ivec2 windowSize)
template <typename T ,typename std::enable_if< std::is_base_of< Entity, T >::value, bool >::type =true&gt; <br>voidremoveEntity(WPtr< T > & entity)<br>Remove an entity from the main scene.
virtual MementosaveGlobal() override<br>Save shared global state.
virtual MementosaveScene(State::Scene * scene) override<br>Save state for the current scene.

Public Attributes

Name
Ptr< Manipulators >m_manipulators

Friends

Name
classMainScene
classScene
classSceneCamera
classSceneModel

Additional inherited members

Public Functions inherited from Module

Name
Module() =default
virtual~Module() =default
virtual voidonBeginFrame()
virtual voidonClose()
virtual voidonEndFrame()

Friends inherited from Module

Name
classApplication

Public Functions inherited from IStateful

Name
virtual~IStateful()
MementoemptyMemento()<br>Create an empty memento (rapidjson::Document)

Detailed Description

cpp
class Vp::Viewport;
class Vp::Viewport;

Scene viewport class.

Has simple public interface to be used by GUI

Manages "global" resources for drawing like shaders (via ResourceManager)

It also currently manages two viewport Scenes

Viewport provides three functions to draw:

  • The main scene from a viewport camera to be used as the main viewport
  • The main scene from an arbitrary camera specified by view and projection matrices
  • A preview of a model

These very specific functions are provided rather than a generic draw function to avoid managing framebuffer objects outside this class. The scenes are drawn into a SceneRenderTarget, which holds necessary framebuffers. Each function uses a different SceneRenderTarget with potentially different render settings. That means the main scene can be drawn with or without antialiasing for example. The settings are abstracted away using RenderOptions.

Further, DisplayOptions are used to toggle visibility of certain objects.

Public Functions Documentation

function Viewport

cpp
Viewport()
Viewport()

Creates an empty viewport.

Before any other calls it should be initialized using init()

function ~Viewport

cpp
~Viewport()
~Viewport()

function clearGlobal

cpp
virtual void clearGlobal() override
virtual void clearGlobal() override

Set the global state to some default empty state.

Reimplements: IStateful::clearGlobal

function clearScene

cpp
virtual void clearScene() override
virtual void clearScene() override

Set the scene state to some default empty state.

Reimplements: IStateful::clearScene

function createCamera

cpp
WPtr< SceneCamera > createCamera(
    Core::ID guiNodeId
)
WPtr< SceneCamera > createCamera(
    Core::ID guiNodeId
)

Creates a SceneCamera in the main scene to represent a Camera node.

Parameters:

  • Id of the gui node equivalent.

Return: Weak pointer to it.

Can be later removed with removeEntity()

function createModel

cpp
WPtr< SceneModel > createModel(
    Core::ID guiNodeId
)
WPtr< SceneModel > createModel(
    Core::ID guiNodeId
)

Creates a SceneModel in the main scene to represent a Model node.

Parameters:

  • id Id of the gui node equivalent.

Return: Weak pointer to it.

Can be later removed with removeEntity()

function drawPreview

cpp
void drawPreview(
    Ptr< SceneRenderTarget > & renderTarget,
    int width,
    int height,
    WPtr< GameObject > gameObject,
    const RenderOptions & renderOptions
)
void drawPreview(
    Ptr< SceneRenderTarget > & renderTarget,
    int width,
    int height,
    WPtr< GameObject > gameObject,
    const RenderOptions & renderOptions
)

Draw a preview of an object into a framebuffer.

Parameters:

  • renderTarget A reference to a shared pointer containing the desired render target. An empty pointer can be passed and it will be filled with an appropriate render target.
  • width Framebuffer width in pixels
  • height Framebuffer height in pixels
  • gameObject Game object to preview
  • renderOptions Optional rendering options. DON'T call this function multiple times with different renderOptions per frame.

Return: Void. The drawn framebuffer can be retrieved with renderTarget->getOutputFramebuffer(). Use outputFramebuffer.lock()->getColorTexture() to get the resulting texture.

function drawScreen

cpp
void drawScreen(
    Ptr< SceneRenderTarget > & renderTarget,
    int width,
    int height,
    glm::mat4 view,
    glm::mat4 projection,
    const RenderOptions & renderOptions =RenderOptions(),
    const DisplayOptions & displayOptions =DisplayOptions()
)
void drawScreen(
    Ptr< SceneRenderTarget > & renderTarget,
    int width,
    int height,
    glm::mat4 view,
    glm::mat4 projection,
    const RenderOptions & renderOptions =RenderOptions(),
    const DisplayOptions & displayOptions =DisplayOptions()
)

Render viewport's main scene into a framebuffer with the specified camera matrices.

Parameters:

  • renderTarget A reference to a shared pointer containing the desired render target. An empty pointer can be passed and it will be filled with an appropriate render target.
  • width Framebuffer width in pixels
  • height Framebuffer height in pixels
  • view View matrix of the camera
  • projection Projection matrix of the camera
  • renderOptions Optional rendering options. DON'T call this function multiple times with different renderOptions per frame.
  • displayOptions Optional display options. These can change without restriction.

Return: Void. The drawn framebuffer can be retrieved with renderTarget->getOutputFramebuffer(). Use outputFramebuffer.lock()->getColorTexture() to get the resulting texture.

function drawViewport

cpp
void drawViewport(
    Ptr< SceneRenderTarget > & renderTarget,
    int width,
    int height,
    const RenderOptions & renderOptions =RenderOptions(),
    const DisplayOptions & displayOptions =DisplayOptions()
)
void drawViewport(
    Ptr< SceneRenderTarget > & renderTarget,
    int width,
    int height,
    const RenderOptions & renderOptions =RenderOptions(),
    const DisplayOptions & displayOptions =DisplayOptions()
)

Render viewport's main scene into a framebuffer using its own camera.

Parameters:

  • renderTarget A reference to a shared pointer containing the desired render target. An empty pointer can be passed and it will be filled with an appropriate render target.
  • width Framebuffer width in pixels
  • height Framebuffer height in pixels
  • renderOptions Optional rendering options. DON'T call this function multiple times with different renderOptions per frame.
  • displayOptions Optional display options. These can change without restriction.

Return: Void. The drawn framebuffer can be retrieved with renderTarget->getOutputFramebuffer(). Use outputFramebuffer.lock()->getColorTexture() to get the resulting texture.

function getMainScene

cpp
inline WPtr< Scene > getMainScene()
inline WPtr< Scene > getMainScene()

function getMainViewportCamera

cpp
WPtr< AggregateCamera > getMainViewportCamera()
WPtr< AggregateCamera > getMainViewportCamera()

Returns the viewport camera of the main scene.

function getManipulators

cpp
Manipulators & getManipulators()
Manipulators & getManipulators()

function getPreviewScene

cpp
inline WPtr< Scene > getPreviewScene()
inline WPtr< Scene > getPreviewScene()

function getSettings

cpp
ViewportSettings & getSettings()
ViewportSettings & getSettings()

function loadGlobal

cpp
virtual void loadGlobal(
    const Memento & memento
) override
virtual void loadGlobal(
    const Memento & memento
) override

Load global state from a memento.

Parameters:

  • memento New global state

Reimplements: IStateful::loadGlobal

function loadScene

cpp
virtual void loadScene(
    const Memento & memento,
    State::Scene * scene
) override
virtual void loadScene(
    const Memento & memento,
    State::Scene * scene
) override

Called on scene load, undo and redo.

Parameters:

  • scene The current scene or nullptr (in case of undo/redo)
  • memento New scene state

Reimplements: IStateful::loadScene

function onInit

cpp
virtual void onInit() override
virtual void onInit() override

Initializes scenes and loads assets.

Reimplements: Module::onInit

function onUpdate

cpp
virtual void onUpdate(
    double dt
) override
virtual void onUpdate(
    double dt
) override

Update scene logic.

Reimplements: Module::onUpdate

function processInput

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

Process viewport user input.

Parameters:

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

Should be called before draw and only if the viewport is in focus. InputManager is used to handle input.

Ensure this methods is only called once per frame.

function processSelection

cpp
void processSelection(
    Ptr< SceneRenderTarget > renderTarget,
    glm::vec2 mousePos,
    glm::ivec2 windowSize
)
void processSelection(
    Ptr< SceneRenderTarget > renderTarget,
    glm::vec2 mousePos,
    glm::ivec2 windowSize
)

function removeEntity

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

Remove an entity from the main scene.

function saveGlobal

cpp
virtual Memento saveGlobal() override
virtual Memento saveGlobal() override

Save shared global state.

Reimplements: IStateful::saveGlobal

function saveScene

cpp
virtual Memento saveScene(
    State::Scene * scene
) override
virtual Memento saveScene(
    State::Scene * scene
) override

Save state for the current scene.

Parameters:

  • scene The current scene or nullptr (in case of undo/redo)

Reimplements: IStateful::saveScene

The scene parameter should contain a scene object for full filesystem saves and nullptr for quick undo/redo operations.

Public Attributes Documentation

variable m_manipulators

cpp
Ptr< Manipulators > m_manipulators;
Ptr< Manipulators > m_manipulators;

Friends

friend MainScene

cpp
friend class MainScene(
    MainScene 
);
friend class MainScene(
    MainScene 
);

friend Scene

cpp
friend class Scene(
    Scene 
);
friend class Scene(
    Scene 
);

friend SceneCamera

cpp
friend class SceneCamera(
    SceneCamera 
);
friend class SceneCamera(
    SceneCamera 
);

friend SceneModel

cpp
friend class SceneModel(
    SceneModel 
);
friend class SceneModel(
    SceneModel 
);

Updated on 2024-03-16 at 19:15:01 +0000