Physics Simulation & Visualization Tool 0.1
A C++ physics simulation engine with real-time 3D visualization
Loading...
Searching...
No Matches
IInstancedDrawable Interface Referenceabstract

Interface for objects that support GPU instanced rendering. More...

#include <IDrawable.h>

Inheritance diagram for IInstancedDrawable:
[legend]
Collaboration diagram for IInstancedDrawable:
[legend]

Public Member Functions

virtual glm::mat4 getModelMatrix () const =0
 Gets the model transformation matrix for this instance.
 
virtual Rendering::InstanceData getInstanceData () const
 Gets the complete per-instance data for GPU upload.
 
- Public Member Functions inherited from IDrawable
virtual ~IDrawable ()=default
 Virtual destructor for proper cleanup of derived classes.
 
virtual ShadergetShader () const =0
 Gets the shader used to render this object.
 
virtual MeshgetMesh () const =0
 Gets the mesh geometry for this object.
 
virtual uint32_t getObjectID () const =0
 Gets the unique identifier for this object.
 

Detailed Description

Interface for objects that support GPU instanced rendering.

Objects implementing this interface can be efficiently batched and rendered together when they share the same mesh and shader. The Scene groups compatible objects and renders them in a single instanced draw call, significantly reducing CPU overhead and draw call count.

This is the preferred rendering path for most scene objects (SceneObject, etc.) as it provides optimal performance for large numbers of similar objects.

Note
The default getInstanceData() implementation provides basic transform and ID data. Override for custom per-instance attributes (e.g., color).

Example usage:

glm::mat4 getModelMatrix() const override {
return computeTransformMatrix();
}
};
Interface for objects that support GPU instanced rendering.
Definition IDrawable.h:111
See also
Scene::draw()
Mesh::drawInstanced()
Rendering::InstanceData

Definition at line 111 of file IDrawable.h.

Member Function Documentation

◆ getInstanceData()

virtual Rendering::InstanceData IInstancedDrawable::getInstanceData ( ) const
inlinevirtual

Gets the complete per-instance data for GPU upload.

Constructs an InstanceData structure containing the model matrix, object ID, and any additional per-instance attributes. This data is uploaded to the GPU's instance buffer for instanced rendering.

The default implementation provides model matrix and object ID. Override to add custom attributes (e.g., per-instance color).

Returns
InstanceData structure for this object.
Note
The InstanceData layout must match the vertex attribute setup in Mesh::setupInstanceAttributes().
See also
Rendering::InstanceData
Mesh::drawInstanced()

Implemented in SceneObject.

Definition at line 145 of file IDrawable.h.

Here is the call graph for this function:

◆ getModelMatrix()

virtual glm::mat4 IInstancedDrawable::getModelMatrix ( ) const
pure virtual

Gets the model transformation matrix for this instance.

The model matrix transforms vertices from model space to render space. World-space drawables should subtract SceneObject::getRenderOrigin() before uploading instance data. Simulation, picking, and serialization must keep using world-space transforms.

Returns
The 4x4 model transformation matrix.
Note
This is called once per frame during batch preparation.

Implemented in SceneObject.

Here is the caller graph for this function:

The documentation for this interface was generated from the following file: