Vp::Viewport
#include "Viewport/Viewport.h"
Inherits from Module, IStateful
Public Functions
Name | |
---|---|
Viewport()<br>Creates an empty viewport. | |
~Viewport() | |
virtual void | clearGlobal() override<br>Set the global state to some default empty state. |
virtual void | clearScene() 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. |
void | drawPreview(Ptr< SceneRenderTarget > & renderTarget, int width, int height, WPtr< GameObject > gameObject, const RenderOptions & renderOptions)<br>Draw a preview of an object into a framebuffer. |
void | drawScreen(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. |
void | drawViewport(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 void | loadGlobal(const Memento & memento) override<br>Load global state from a memento. |
virtual void | loadScene(const Memento & memento, State::Scene * scene) override<br>Called on scene load, undo and redo. |
virtual void | onInit() override<br>Initializes scenes and loads assets. |
virtual void | onUpdate(double dt) override<br>Update scene logic. |
void | processInput(double dt, glm::vec2 mousePos, glm::ivec2 windowSize)<br>Process viewport user input. |
void | processSelection(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> <br>void | removeEntity(WPtr< T > & entity)<br>Remove an entity from the main scene. |
virtual Memento | saveGlobal() override<br>Save shared global state. |
virtual Memento | saveScene(State::Scene * scene) override<br>Save state for the current scene. |
Public Attributes
Name | |
---|---|
Ptr< Manipulators > | m_manipulators |
Friends
Name | |
---|---|
class | MainScene |
class | Scene |
class | SceneCamera |
class | SceneModel |
Additional inherited members
Public Functions inherited from Module
Name | |
---|---|
Module() =default | |
virtual | ~Module() =default |
virtual void | onBeginFrame() |
virtual void | onClose() |
virtual void | onEndFrame() |
Friends inherited from Module
Name | |
---|---|
class | Application |
Public Functions inherited from IStateful
Name | |
---|---|
virtual | ~IStateful() |
Memento | emptyMemento()<br>Create an empty memento (rapidjson::Document) |
Detailed Description
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
- Main scene
- Scene used for the main viewport and user interaction
- Used by drawViewport() and drawScreen().
- Preview scene
- Scene for small 3D model previews
- Used by drawPreview()
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
Viewport()
Viewport()
Creates an empty viewport.
Before any other calls it should be initialized using init()
function ~Viewport
~Viewport()
~Viewport()
function clearGlobal
virtual void clearGlobal() override
virtual void clearGlobal() override
Set the global state to some default empty state.
Reimplements: IStateful::clearGlobal
function clearScene
virtual void clearScene() override
virtual void clearScene() override
Set the scene state to some default empty state.
Reimplements: IStateful::clearScene
function createCamera
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
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
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
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
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
inline WPtr< Scene > getMainScene()
inline WPtr< Scene > getMainScene()
function getMainViewportCamera
WPtr< AggregateCamera > getMainViewportCamera()
WPtr< AggregateCamera > getMainViewportCamera()
Returns the viewport camera of the main scene.
function getManipulators
Manipulators & getManipulators()
Manipulators & getManipulators()
function getPreviewScene
inline WPtr< Scene > getPreviewScene()
inline WPtr< Scene > getPreviewScene()
function getSettings
ViewportSettings & getSettings()
ViewportSettings & getSettings()
function loadGlobal
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
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
virtual void onInit() override
virtual void onInit() override
Initializes scenes and loads assets.
Reimplements: Module::onInit
function onUpdate
virtual void onUpdate(
double dt
) override
virtual void onUpdate(
double dt
) override
Update scene logic.
Reimplements: Module::onUpdate
function processInput
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
void processSelection(
Ptr< SceneRenderTarget > renderTarget,
glm::vec2 mousePos,
glm::ivec2 windowSize
)
void processSelection(
Ptr< SceneRenderTarget > renderTarget,
glm::vec2 mousePos,
glm::ivec2 windowSize
)
function removeEntity
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
virtual Memento saveGlobal() override
virtual Memento saveGlobal() override
Save shared global state.
Reimplements: IStateful::saveGlobal
function saveScene
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
Ptr< Manipulators > m_manipulators;
Ptr< Manipulators > m_manipulators;
Friends
friend MainScene
friend class MainScene(
MainScene
);
friend class MainScene(
MainScene
);
friend Scene
friend class Scene(
Scene
);
friend class Scene(
Scene
);
friend SceneCamera
friend class SceneCamera(
SceneCamera
);
friend class SceneCamera(
SceneCamera
);
friend SceneModel
friend class SceneModel(
SceneModel
);
friend class SceneModel(
SceneModel
);
Updated on 2025-01-07 at 13:40:44 +0000