CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
CeresEngine::RendererMesh Class Reference

A mesh that is usable by the renderer and the GPU. More...

#include <CeresEngine/Renderer/Resources/RendererMesh.hpp>

Inheritance diagram for CeresEngine::RendererMesh:
CeresEngine::RefCounted< RendererMesh >

Public Member Functions

 RendererMesh (RendererMeshManager &manager, const MeshPtr &engineMesh)
 Creates a new renderer mesh instance.
 
 ~RendererMesh ()
 Destroys the renderer mesh instance.
 
void bind (GPUCommandBuffer &commandBuffer) const
 Binds the mesh vertex and index buffers.
 
void draw (GPUCommandBuffer &commandBuffer, const Optional< const ConvexVolume & > &viewFrustum={}, const RendererMeshDrawFlags &flags=RendererMeshDrawFlag::Default) const
 Draws the entire mesh.
 
void draw (GPUCommandBuffer &commandBuffer, UInt32 subMeshIdx, const Optional< const ConvexVolume & > &viewFrustum={}, const RendererMeshDrawFlags &flags=RendererMeshDrawFlag::Default) const
 Draws an specific sub-mesh index.
 
void draw (GPUCommandBuffer &commandBuffer, const Span< UInt32 > &subMeshIndices, const Optional< const ConvexVolume & > &viewFrustum={}, const RendererMeshDrawFlags &flags=RendererMeshDrawFlag::Default) const
 Draws an specific set of sub-meshes by index.
 
void draw (GPUCommandBuffer &commandBuffer, const SubMesh &subMesh, const Optional< const ConvexVolume & > &viewFrustum={}, const RendererMeshDrawFlags &flags=RendererMeshDrawFlag::Default) const
 Draws a specific sub-mesh.
 
RendererMeshFlags getFlags () const noexcept
 A set of flags for the renderer mesh.
 
RendererMeshState getState () const noexcept
 The state the renderer mesh is currently in.
 
bool isPending () const noexcept
 The mesh is not uploaded to the GPU and the upload process hasn't started yet.
 
bool isUploading () const noexcept
 The mesh is in the process of being uploaded to the GPU, but the asynchronous upload operation hasn't finished yet.
 
bool isRelocating () const noexcept
 The mesh is uploaded to the GPU but is in the process of being relocated to another vertex and index buffers.
 
bool isUploaded () const noexcept
 The mesh is uploaded to the GPU and is ready to be used by the renderer.
 
bool isReady () const noexcept
 Checks if the mesh is ready to be used by the renderer.
 
 operator bool () const noexcept
 Checks if the mesh is ready to be used by the renderer.
 
const SPtr< Mesh > & getResource () const noexcept
 A pointer to the mesh resource object that will be uploaded to the GPU.
 
const GPUVertexBuffergetVertexBuffer () const noexcept
 The current vertex buffer as allocated by the mesh manager.
 
const GPUIndexBuffergetIndexBuffer () const noexcept
 The current index buffer as allocated by the mesh manager.
 
const GPUVertexFormatgetVertexFormat () const noexcept
 A structure that describes the format of the vertex data as it was uploaded to the GPU.
 
const VertexDeclarationgetVertexDeclaration () const noexcept
 Determines how vertices are laid-out on a vertex buffer or a mesh data.
 
AABox getBoundingBox () const noexcept
 Gets the mesh bounding box.
 
Sphere getBoundingSphere () const noexcept
 Gets the mesh bounding sphere.
 
const Vector< SubMesh > & getSubMeshes () const noexcept
 An array of sub-meshes.
 
- Public Member Functions inherited from CeresEngine::RefCounted< RendererMesh >
 RefCounted (Args &&... args)
 Creates a new RefCounted object and constructs a new Deleter by forwarding Args to it.
 
void retain () noexcept
 Retains the object by increment it's reference count by one.
 
bool release () noexcept
 Relases the object by decrementing it's reference count by one.
 

Public Attributes

Event< void()> didChangeVertexBuffer
 An event triggered internally in the renderer whenever the vertex buffer for the mesh has changed.
 
Event< void()> didChangeIndexBuffer
 An event triggered internally in the renderer whenever the index buffer for the mesh has changed.
 

Private Member Functions

void setFlags (RendererMeshFlags flags)
 A set of flags for the renderer mesh.
 
void setState (RendererMeshState state)
 The state the renderer mesh is currently in.
 
void setBuffers (GPUVertexBuffer &&vertexBuffer, GPUIndexBuffer &&indexBuffer, const GPUVertexFormat &vertexFormat)
 Updates the vertex buffer, index buffer and the vertex formats.
 
Async uploadMesh ()
 Uploads the raw mesh data to the GPU.
 

Private Attributes

RendererMeshManagermManager
 The mesh manager that owns and manages this mesh instance.
 
RendererMeshFlags mFlags
 A set of flags for the renderer mesh.
 
RendererMeshState mState = RendererMeshState::Pending
 The state the renderer mesh is currently in.
 
SPtr< MeshmResource
 A pointer to the mesh resource object that will be uploaded to the GPU.
 
GPUVertexBuffer mVertexBuffer
 The current vertex buffer as allocated by the mesh manager.
 
GPUIndexBuffer mIndexBuffer
 The current index buffer as allocated by the mesh manager.
 
GPUVertexFormat mVertexFormat
 A structure that describes the format of the vertex data as it was uploaded to the GPU.
 
VertexDeclaration mVertexDeclaration
 Determines how vertices are laid-out on a vertex buffer or a mesh data.
 
Vector< SubMeshmSubMeshes
 An array of sub-meshes.
 

Friends

class RendererMeshManager
 

Detailed Description

A mesh that is usable by the renderer and the GPU.

A renderer mesh is allocated by a RendererMeshManager, which is responsible for taking an Mesh instance, uploading it to the GPU in an appropriate set of vertex and, if necessary, index buffers.

The manager is free to relocate the vertex and index buffers inside the same GPU buffer or to different buffers at any time. Whenever the manager relocates data, the user can be notified of changes by subscribing to the onVertexBufferChanged and onIndexBufferChanged events.

Constructor & Destructor Documentation

◆ RendererMesh()

CeresEngine::RendererMesh::RendererMesh ( RendererMeshManager manager,
const MeshPtr engineMesh 
)
explicit

Creates a new renderer mesh instance.

◆ ~RendererMesh()

CeresEngine::RendererMesh::~RendererMesh ( )

Destroys the renderer mesh instance.

Since this object is reference counted, the destructor is usually called automatically when the reference count reaches zero.

Member Function Documentation

◆ bind()

void CeresEngine::RendererMesh::bind ( GPUCommandBuffer commandBuffer) const

Binds the mesh vertex and index buffers.

◆ draw() [1/4]

void CeresEngine::RendererMesh::draw ( GPUCommandBuffer commandBuffer,
const Optional< const ConvexVolume & > &  viewFrustum = {},
const RendererMeshDrawFlags flags = RendererMeshDrawFlag::Default 
) const

Draws the entire mesh.

Parameters
commandBufferThe command buffer to submit draw calls to.
viewFrustumAn optional view frustum to be used to perform frustum culling. If not set, frustum culling is disabled and the entire mesh is drawn.
flagsA set of flags that can be used to customize the mesh drawing behavior.

◆ draw() [2/4]

void CeresEngine::RendererMesh::draw ( GPUCommandBuffer commandBuffer,
const Span< UInt32 > &  subMeshIndices,
const Optional< const ConvexVolume & > &  viewFrustum = {},
const RendererMeshDrawFlags flags = RendererMeshDrawFlag::Default 
) const

Draws an specific set of sub-meshes by index.

Parameters
commandBufferThe command buffer to submit draw calls to.
subMeshIndicesA set of sub-mesh indices to be drawn.
viewFrustumAn optional view frustum to be used to perform frustum culling. If not set, frustum culling is disabled and the entire mesh is drawn.
flagsA set of flags that can be used to customize the mesh drawing behavior.

◆ draw() [3/4]

void CeresEngine::RendererMesh::draw ( GPUCommandBuffer commandBuffer,
const SubMesh subMesh,
const Optional< const ConvexVolume & > &  viewFrustum = {},
const RendererMeshDrawFlags flags = RendererMeshDrawFlag::Default 
) const

Draws a specific sub-mesh.

Parameters
commandBufferThe command buffer to submit draw calls to.
subMeshThe sub-mesh to be drawn.
viewFrustumAn optional view frustum to be used to perform frustum culling. If not set, frustum culling is disabled and the entire mesh is drawn.
flagsA set of flags that can be used to customize the mesh drawing behavior.

◆ draw() [4/4]

void CeresEngine::RendererMesh::draw ( GPUCommandBuffer commandBuffer,
UInt32  subMeshIdx,
const Optional< const ConvexVolume & > &  viewFrustum = {},
const RendererMeshDrawFlags flags = RendererMeshDrawFlag::Default 
) const

Draws an specific sub-mesh index.

Parameters
commandBufferThe command buffer to submit draw calls to.
subMeshIdxThe index of the sub-mesh to be drawn.
viewFrustumAn optional view frustum to be used to perform frustum culling. If not set, frustum culling is disabled and the entire mesh is drawn.
flagsA set of flags that can be used to customize the mesh drawing behavior.

◆ getBoundingBox()

AABox CeresEngine::RendererMesh::getBoundingBox ( ) const
noexcept

Gets the mesh bounding box.

◆ getBoundingSphere()

Sphere CeresEngine::RendererMesh::getBoundingSphere ( ) const
noexcept

Gets the mesh bounding sphere.

◆ getFlags()

RendererMeshFlags CeresEngine::RendererMesh::getFlags ( ) const
inlinenoexcept

A set of flags for the renderer mesh.

◆ getIndexBuffer()

const GPUIndexBuffer & CeresEngine::RendererMesh::getIndexBuffer ( ) const
inlinenoexcept

The current index buffer as allocated by the mesh manager.

The manager is free to relocate this index buffer into another location if it can prove that relocating it will yield in faster rendering or better buffer re-utilization.

◆ getResource()

const SPtr< Mesh > & CeresEngine::RendererMesh::getResource ( ) const
inlinenoexcept

A pointer to the mesh resource object that will be uploaded to the GPU.

◆ getState()

RendererMeshState CeresEngine::RendererMesh::getState ( ) const
inlinenoexcept

The state the renderer mesh is currently in.

◆ getSubMeshes()

const Vector< SubMesh > & CeresEngine::RendererMesh::getSubMeshes ( ) const
inlinenoexcept

An array of sub-meshes.

◆ getVertexBuffer()

const GPUVertexBuffer & CeresEngine::RendererMesh::getVertexBuffer ( ) const
inlinenoexcept

The current vertex buffer as allocated by the mesh manager.

The manager is free to relocate this vertex buffer into another location if it can prove that relocating it will yield in faster rendering or better buffer re-utilization.

◆ getVertexDeclaration()

const VertexDeclaration & CeresEngine::RendererMesh::getVertexDeclaration ( ) const
inlinenoexcept

Determines how vertices are laid-out on a vertex buffer or a mesh data.

◆ getVertexFormat()

const GPUVertexFormat & CeresEngine::RendererMesh::getVertexFormat ( ) const
inlinenoexcept

A structure that describes the format of the vertex data as it was uploaded to the GPU.

◆ isPending()

bool CeresEngine::RendererMesh::isPending ( ) const
inlinenoexcept

The mesh is not uploaded to the GPU and the upload process hasn't started yet.

◆ isReady()

bool CeresEngine::RendererMesh::isReady ( ) const
inlinenoexcept

Checks if the mesh is ready to be used by the renderer.

◆ isRelocating()

bool CeresEngine::RendererMesh::isRelocating ( ) const
inlinenoexcept

The mesh is uploaded to the GPU but is in the process of being relocated to another vertex and index buffers.

The current buffers are still valid, but will be replaced soon as soon as the GPU finishes coping the data.

◆ isUploaded()

bool CeresEngine::RendererMesh::isUploaded ( ) const
inlinenoexcept

The mesh is uploaded to the GPU and is ready to be used by the renderer.

◆ isUploading()

bool CeresEngine::RendererMesh::isUploading ( ) const
inlinenoexcept

The mesh is in the process of being uploaded to the GPU, but the asynchronous upload operation hasn't finished yet.

◆ operator bool()

CeresEngine::RendererMesh::operator bool ( ) const
inlineexplicitnoexcept

Checks if the mesh is ready to be used by the renderer.

◆ setBuffers()

void CeresEngine::RendererMesh::setBuffers ( GPUVertexBuffer &&  vertexBuffer,
GPUIndexBuffer &&  indexBuffer,
const GPUVertexFormat vertexFormat 
)
private

Updates the vertex buffer, index buffer and the vertex formats.

◆ setFlags()

void CeresEngine::RendererMesh::setFlags ( RendererMeshFlags  flags)
private

A set of flags for the renderer mesh.

◆ setState()

void CeresEngine::RendererMesh::setState ( RendererMeshState  state)
private

The state the renderer mesh is currently in.

◆ uploadMesh()

Async CeresEngine::RendererMesh::uploadMesh ( )
private

Uploads the raw mesh data to the GPU.

Note that this operation will run in parallel on one or more background threads, but will always complete on the main thread.

Friends And Related Symbol Documentation

◆ RendererMeshManager

Member Data Documentation

◆ didChangeIndexBuffer

Event<void()> CeresEngine::RendererMesh::didChangeIndexBuffer

An event triggered internally in the renderer whenever the index buffer for the mesh has changed.

Users of the renderer mesh can subscribe to this event to be notified when the manager relocates the index buffer.

◆ didChangeVertexBuffer

Event<void()> CeresEngine::RendererMesh::didChangeVertexBuffer

An event triggered internally in the renderer whenever the vertex buffer for the mesh has changed.

Users of the renderer mesh can subscribe to this event to be notified when the manager relocates the vertex buffer.

◆ mFlags

RendererMeshFlags CeresEngine::RendererMesh::mFlags
private

A set of flags for the renderer mesh.

◆ mIndexBuffer

GPUIndexBuffer CeresEngine::RendererMesh::mIndexBuffer
private

The current index buffer as allocated by the mesh manager.

The manager is free to relocate this index buffer into another location if it can prove that relocating it will yield in faster rendering or better buffer re-utilization.

◆ mManager

RendererMeshManager& CeresEngine::RendererMesh::mManager
private

The mesh manager that owns and manages this mesh instance.

◆ mResource

SPtr<Mesh> CeresEngine::RendererMesh::mResource
private

A pointer to the mesh resource object that will be uploaded to the GPU.

◆ mState

RendererMeshState CeresEngine::RendererMesh::mState = RendererMeshState::Pending
private

The state the renderer mesh is currently in.

◆ mSubMeshes

Vector<SubMesh> CeresEngine::RendererMesh::mSubMeshes
private

An array of sub-meshes.

◆ mVertexBuffer

GPUVertexBuffer CeresEngine::RendererMesh::mVertexBuffer
private

The current vertex buffer as allocated by the mesh manager.

The manager is free to relocate this vertex buffer into another location if it can prove that relocating it will yield in faster rendering or better buffer re-utilization.

◆ mVertexDeclaration

VertexDeclaration CeresEngine::RendererMesh::mVertexDeclaration
private

Determines how vertices are laid-out on a vertex buffer or a mesh data.

◆ mVertexFormat

GPUVertexFormat CeresEngine::RendererMesh::mVertexFormat
private

A structure that describes the format of the vertex data as it was uploaded to the GPU.


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