Vp::Viewport
#include "Viewport/Viewport.h"
Public Functions
Name | |
---|---|
Viewport()<br>Creates an empty viewport. | |
~Viewport() | |
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. |
WPtr< SceneScreen > | createScreen(Core::ID guiNodeId) |
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, const glm::mat4 & referenceFrame, const glm::mat4 & view, const 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 glm::mat4 & referenceFrame, const RenderOptions & renderOptions =RenderOptions(), const DisplayOptions & displayOptions =DisplayOptions())<br>Render viewport's main scene into a framebuffer using its own camera. |
void | drawViewport(Ptr< SceneRenderTarget > & renderTarget, int width, int height, const std::shared_ptr< AbstractCamera > & camera, const glm::mat4 & referenceFrame, const RenderOptions & renderOptions =RenderOptions(), const DisplayOptions & displayOptions =DisplayOptions())<br>Render viewport's main scene into a framebuffer using a provided camera. |
MainScene * | getMainScene() |
Manipulators & | getManipulators() |
Scene * | getPreviewScene() |
ViewportSettings & | getSettings() |
void | init()<br>Initializes scenes and loads assets. |
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. |
void | update(double dt)<br>Update scene logic. |
Public Attributes
Name | |
---|---|
Ptr< Manipulators > | m_manipulators |
Friends
Name | |
---|---|
class | MainScene |
class | Scene |
class | SceneCamera |
class | SceneModel |
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 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 createScreen
WPtr< SceneScreen > createScreen(
Core::ID guiNodeId
)
WPtr< SceneScreen > createScreen(
Core::ID guiNodeId
)
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,
const glm::mat4 & referenceFrame,
const glm::mat4 & view,
const glm::mat4 & projection,
const RenderOptions & renderOptions =RenderOptions(),
const DisplayOptions & displayOptions =DisplayOptions()
)
void drawScreen(
Ptr< SceneRenderTarget > & renderTarget,
int width,
int height,
const glm::mat4 & referenceFrame,
const glm::mat4 & view,
const 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
- referenceFrame Implicit model matrix, multiplies all model transforms from the left.
- 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 glm::mat4 & referenceFrame,
const RenderOptions & renderOptions =RenderOptions(),
const DisplayOptions & displayOptions =DisplayOptions()
)
void drawViewport(
Ptr< SceneRenderTarget > & renderTarget,
int width,
int height,
const glm::mat4 & referenceFrame,
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
- referenceFrame Implicit model matrix, multiplies all model transforms from the left.
- 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 std::shared_ptr< AbstractCamera > & camera,
const glm::mat4 & referenceFrame,
const RenderOptions & renderOptions =RenderOptions(),
const DisplayOptions & displayOptions =DisplayOptions()
)
void drawViewport(
Ptr< SceneRenderTarget > & renderTarget,
int width,
int height,
const std::shared_ptr< AbstractCamera > & camera,
const glm::mat4 & referenceFrame,
const RenderOptions & renderOptions =RenderOptions(),
const DisplayOptions & displayOptions =DisplayOptions()
)
Render viewport's main scene into a framebuffer using a provided 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
- camera The camera to render the viewport with
- referenceFrame Implicit model matrix, multiplies all model transforms from the left.
- 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 MainScene * getMainScene()
inline MainScene * getMainScene()
function getManipulators
Manipulators & getManipulators()
Manipulators & getManipulators()
function getPreviewScene
inline Scene * getPreviewScene()
inline Scene * getPreviewScene()
function getSettings
ViewportSettings & getSettings()
ViewportSettings & getSettings()
function init
void init()
void init()
Initializes scenes and loads assets.
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 update
void update(
double dt
)
void update(
double dt
)
Update scene logic.
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-05-31 at 12:55:31 +0000