Skip to content

Vp::Entity ​

A scene entity base class.

#include "Viewport/entity/Entity.h"

Inherited by Vp::GameObject

Public Classes ​

Name
structRenderContext

Public Types ​

Name
enum classRenderType { NORMAL, CUSTOM, SILHOUETTE}

Public Functions ​

Name
Entity()
virtual~Entity() =default
RenderContextcreateRenderContext(const DisplayOptions & displayOptions)
virtual voiddispose() =0
DisplayTypegetDisplayType() const
glm::vec3getHighlightColor() const
boolisHighlighted() const
virtual voidonSceneAdd(Scene & scene)<br>Called when the entity is added to a scene.
virtual voidonSceneRemove(Scene & scene)<br>Called when the entity is removed from a scene.
virtual voidprepareRenderContext(RenderContext & context, const DisplayOptions & displayOptions) =0
voidrender(const glm::mat4 & model, const glm::mat4 & view, const glm::mat4 & projection, const DisplayOptions & displayOptions)<br>Renders the entity with default rendering parameters.
virtual voidrender(const glm::mat4 & model, const glm::mat4 & view, const glm::mat4 & projection, const RenderContext & context) =0<br>IMPLEMENTATION NOTE: Derived entity classes should expect a certain kind of shader and be able to directly static cast to it.
voidsetDisplayType(DisplayType type)
voidsetHighlightColor(glm::vec3 highlightColor)
voidsetHighlighted(bool highlight)
virtual voidupdate(Scene & scene) =0

Public Attributes ​

Name
boolm_backFaceCull
unsigned intm_explicitTransparencyOrder <br>Explicit order for ordered transparency.
boolm_highlight <br>Whether to paint this entity with an outline, can be used for selection or just highlighting.
glm::vec3m_highlightColor
boolm_highlightUseDepth <br>Whether the highlight outline should respect the scene's depth buffer.
boolm_ignoreReferenceSpace <br>When true, the "global"/"reference space" model matrix passed to viewport drawing methods is ignored.
boolm_ignoreUserClipping <br>Whether to ignore user clip planes defined in DisplayOptions.
glm::mat4m_lastModelMatrix <br>Potentially modifed model matrix last passed to the shader.
glm::mat4m_modelMatrix <br>Model "world" transformation of the entity.
glm::mat4m_modMatrix <br>Modification transformation, precedes any other transformations, modifies entity vertex data as if the modified data came directly from a source (model file).
boolm_opaque
boolm_selectable <br>Whether this entity should be written into the selection stencil buffer.
intm_selectionId <br>Id of the object, -1 if not assigned, for selection purposes.
Shader *m_shader
boolm_visible
boolm_wboit <br>Whether this entity should be rendered using order independent transparency, relevant if using a shader that supports wboit.
intm_wboitFunc <br>Index of the weight function to be used in wboit.

Protected Attributes ​

Name
DisplayTypem_displayType

Public Types Documentation ​

enum RenderType ​

EnumeratorValueDescription
NORMAL
CUSTOM
SILHOUETTE

Public Functions Documentation ​

function Entity ​

cpp
Entity()

function ~Entity ​

cpp
virtual ~Entity() =default

function createRenderContext ​

cpp
RenderContext createRenderContext(
    const DisplayOptions & displayOptions
)

function dispose ​

cpp
virtual void dispose() =0

Reimplemented by: Vp::GameObject::dispose

function getDisplayType ​

cpp
inline DisplayType getDisplayType() const

function getHighlightColor ​

cpp
inline glm::vec3 getHighlightColor() const

function isHighlighted ​

cpp
inline bool isHighlighted() const

function onSceneAdd ​

cpp
inline virtual void onSceneAdd(
    Scene & scene
)

Called when the entity is added to a scene.

Parameters:

  • scene Scene to which it has been added

Reimplemented by: Vp::SceneCamera::onSceneAdd, Vp::SceneModel::onSceneAdd, Vp::SceneScreen::onSceneAdd

function onSceneRemove ​

cpp
inline virtual void onSceneRemove(
    Scene & scene
)

Called when the entity is removed from a scene.

Parameters:

  • scene Scene from which it has been removed

Reimplemented by: Vp::SceneCamera::onSceneRemove, Vp::SceneModel::onSceneRemove, Vp::SceneScreen::onSceneRemove

function prepareRenderContext ​

cpp
virtual void prepareRenderContext(
    RenderContext & context,
    const DisplayOptions & displayOptions
) =0

Reimplemented by: Vp::ColoredObject::prepareRenderContext, Vp::FrustumObject::prepareRenderContext, Vp::GameObject::prepareRenderContext, Vp::GridObject::prepareRenderContext, Vp::TexturedObject::prepareRenderContext

function render ​

cpp
void render(
    const glm::mat4 & model,
    const glm::mat4 & view,
    const glm::mat4 & projection,
    const DisplayOptions & displayOptions
)

Renders the entity with default rendering parameters.

Parameters:

  • model Implicit model matrix, multiplies the entity's model transform from the left.
  • view View matrix
  • projection Projection matrix

function render ​

cpp
virtual void render(
    const glm::mat4 & model,
    const glm::mat4 & view,
    const glm::mat4 & projection,
    const RenderContext & context
) =0

IMPLEMENTATION NOTE: Derived entity classes should expect a certain kind of shader and be able to directly static cast to it.

Parameters:

  • model Implicit model matrix, multiplies the entity's model transform from the left.
  • view View matrix
  • projection Projection matrix
  • context Additional per-instance rendering parameters generated by createRenderContext() or prepareRenderContext().

Reimplemented by: Vp::FrustumObject::render, Vp::GameObject::render, Vp::GridObject::render, Vp::SceneCamera::render, Vp::SceneModel::render, Vp::GameObject::render

Currently there is no error checking and wrongly passed shader type will CAUSE UNDEFINED BEHAVIOUR!

Using dynamic casts instead might be undesirable (slow) here (this might just be a premature optimalization) Generally the shader passed to this method is the m_shader of this entity. However we need functionality that allows us to change the shader temporarily (like for drawing silhouettes) Because of this the shader can also sometimes be something else, usually some derived type of the one the entity expects. I couldn't find a way to inform what kinds of shaders an entity is able to use in its render methods. The type of the shader must be the base Shader class and so some kind of casting must occur.

Another option could be to use some kind of a typeid/enum system that tells us what type a shader is (rather than use dynamic cast). But that approach ignores inheritance which we need and having multiple types of shaders and entity member variable seems very inflexible.

The true elegant solution probably doesn't involve inheritance at all and rather uses composition, together with an ECS or something. But it was decided to not dive into that realm and so we are stuck with this seemingly simple but not very flexible inheritance structure.

function setDisplayType ​

cpp
inline void setDisplayType(
    DisplayType type
)

function setHighlightColor ​

cpp
inline void setHighlightColor(
    glm::vec3 highlightColor
)

function setHighlighted ​

cpp
inline void setHighlighted(
    bool highlight
)

function update ​

cpp
virtual void update(
    Scene & scene
) =0

Reimplemented by: Vp::GameObject::update, Vp::SceneCamera::update, Vp::SceneModel::update, Vp::SceneScreen::update

Public Attributes Documentation ​

variable m_backFaceCull ​

cpp
bool m_backFaceCull;

variable m_explicitTransparencyOrder ​

cpp
unsigned int m_explicitTransparencyOrder;

Explicit order for ordered transparency.

variable m_highlight ​

cpp
bool m_highlight;

Whether to paint this entity with an outline, can be used for selection or just highlighting.

variable m_highlightColor ​

cpp
glm::vec3 m_highlightColor;

variable m_highlightUseDepth ​

cpp
bool m_highlightUseDepth;

Whether the highlight outline should respect the scene's depth buffer.

variable m_ignoreReferenceSpace ​

cpp
bool m_ignoreReferenceSpace {false};

When true, the "global"/"reference space" model matrix passed to viewport drawing methods is ignored.

variable m_ignoreUserClipping ​

cpp
bool m_ignoreUserClipping {false};

Whether to ignore user clip planes defined in DisplayOptions.

variable m_lastModelMatrix ​

cpp
glm::mat4 m_lastModelMatrix {1.f};

Potentially modifed model matrix last passed to the shader.

variable m_modelMatrix ​

cpp
glm::mat4 m_modelMatrix {1.f};

Model "world" transformation of the entity.

variable m_modMatrix ​

cpp
glm::mat4 m_modMatrix {1.f};

Modification transformation, precedes any other transformations, modifies entity vertex data as if the modified data came directly from a source (model file).

variable m_opaque ​

cpp
bool m_opaque;

variable m_selectable ​

cpp
bool m_selectable;

Whether this entity should be written into the selection stencil buffer.

variable m_selectionId ​

cpp
int m_selectionId {-1};

Id of the object, -1 if not assigned, for selection purposes.

variable m_shader ​

cpp
Shader * m_shader {nullptr};

variable m_visible ​

cpp
bool m_visible;

variable m_wboit ​

cpp
bool m_wboit;

Whether this entity should be rendered using order independent transparency, relevant if using a shader that supports wboit.

variable m_wboitFunc ​

cpp
int m_wboitFunc;

Index of the weight function to be used in wboit.

Protected Attributes Documentation ​

variable m_displayType ​

cpp
DisplayType m_displayType {DisplayType::Default};

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