Skip to content

Vp::GridObject ​

#include "Viewport/entity/GridObject.h"

Inherits from Vp::GameObject, Vp::Entity

Public Functions ​

Name
GridObject()
virtual voidprepareRenderContext(RenderContext & context, const DisplayOptions & displayOptions) override
virtual voidrender(const glm::mat4 & model, const glm::mat4 & view, const glm::mat4 & projection, const RenderContext & context) override<br>IMPLEMENTATION NOTE: Derived entity classes should expect a certain kind of shader and be able to directly static cast to it.
voidsetReferenceSpace(const glm::mat4 & referenceSpace, const glm::mat4 & referenceSpaceInv)

Protected Functions ​

Name
voidupdateGridShader()

Public Attributes ​

Name
boolisStandard
const float *m_axisXColor
const float *m_axisYColor
const float *m_axisZColor
floatm_grid1FadeEnd
floatm_grid1FadeStart
floatm_grid2FadeEnd
floatm_grid2FadeStart
const float *m_gridColor
floatm_gridSize
floatm_gridStrength
floatm_lineWidth
glm::mat4m_modelMatrixInv
boolm_showGrid
boolm_showXAxis
boolm_showYAxis
boolm_showZAxis

Additional inherited members ​

Public Functions inherited from Vp::GameObject

Name
GameObject() =default<br>Creates an empty GameObject.
GameObject(Core::Mesh * mesh, ObjectShader * shader)
virtual voiddispose() override
virtual voidupdate(Scene & scene) override

Public Attributes inherited from Vp::GameObject

Name
Core::Mesh *m_mesh
floatm_opacity

Public Classes inherited from Vp::Entity

Name
structRenderContext

Public Types inherited from Vp::Entity

Name
enum classRenderType { NORMAL, CUSTOM, SILHOUETTE}

Public Functions inherited from Vp::Entity

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.
voidsetDisplayType(DisplayType type)
voidsetHighlightColor(glm::vec3 highlightColor)
voidsetHighlighted(bool highlight)
virtual voidupdate(Scene & scene) =0

Public Attributes inherited from Vp::Entity

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 inherited from Vp::Entity

Name
DisplayTypem_displayType

Public Functions Documentation ​

function GridObject ​

cpp
GridObject()

function prepareRenderContext ​

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

Reimplements: Vp::GameObject::prepareRenderContext

function render ​

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

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().

Reimplements: 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 setReferenceSpace ​

cpp
void setReferenceSpace(
    const glm::mat4 & referenceSpace,
    const glm::mat4 & referenceSpaceInv
)

Protected Functions Documentation ​

function updateGridShader ​

cpp
void updateGridShader()

Public Attributes Documentation ​

variable isStandard ​

cpp
bool isStandard {true};

variable m_axisXColor ​

cpp
const float * m_axisXColor;

variable m_axisYColor ​

cpp
const float * m_axisYColor;

variable m_axisZColor ​

cpp
const float * m_axisZColor;

variable m_grid1FadeEnd ​

cpp
float m_grid1FadeEnd {0.4f};

variable m_grid1FadeStart ​

cpp
float m_grid1FadeStart {0.0f};

variable m_grid2FadeEnd ​

cpp
float m_grid2FadeEnd {1.0f};

variable m_grid2FadeStart ​

cpp
float m_grid2FadeStart {0.1f};

variable m_gridColor ​

cpp
const float * m_gridColor;

variable m_gridSize ​

cpp
float m_gridSize {1.0f};

variable m_gridStrength ​

cpp
float m_gridStrength {0.5f};

variable m_lineWidth ​

cpp
float m_lineWidth {1.0f};

variable m_modelMatrixInv ​

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

variable m_showGrid ​

cpp
bool m_showGrid = true;

variable m_showXAxis ​

cpp
bool m_showXAxis = true;

variable m_showYAxis ​

cpp
bool m_showYAxis = false;

variable m_showZAxis ​

cpp
bool m_showZAxis = true;

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