NAP
Public Member Functions | List of all members
GPUMesh Class Reference

#include <gpumesh.h>

Public Member Functions

 GPUMesh (RenderService &renderService, EMemoryUsage usage)
 
virtual ~GPUMesh ()=default
 
 GPUMesh (const GPUMesh &other)=delete
 
GPUMeshoperator= (const GPUMesh &other)=delete
 
template<typename ELEMENTTYPE >
VertexBuffer< ELEMENTTYPE > & addVertexBuffer (const std::string &id)
 
const GPUBufferNumericfindVertexBuffer (const std::string &id) const
 
GPUBufferNumericgetVertexBuffer (const std::string &id)
 
IndexBuffergetOrCreateIndexBuffer (int index)
 
const IndexBuffergetIndexBuffer (int index) const
 

Description

Defines the GPU data of a polygonal mesh. Every GPU mesh contains at least one, but often multiple, nap::VertexBuffer(s). A vertex buffer contains vertex data, for example: color, position, normal etc.

At least one nap::IndexBuffer is required, but multiple are supported. The index buffer controls how triangles are formed (from the vertex data) when rendered. A GPU mesh has more than 1 index buffer when it contains multiple shapes, one for each.

Together they outline the functionality and capabilities of a mesh.

A static mesh is updated (uploaded to) only once, a dynamic mesh can be updated more frequently but requires more resources and is 'generally' slower to draw, depending of the memory layout of the underlying hardware. It is not allowed to update a static mesh after the initial upload!

Note that static meshes are often placed in a different cache on the GPU, not accessible by the CPU, which allows for faster drawing times. 'DynamicWrite' meshes are uploaded into shared CPU / GPU memory and are therefore slower to draw.

Constructor & Destructor Documentation

◆ GPUMesh() [1/2]

GPUMesh ( RenderService renderService,
EMemoryUsage  usage 
)
Parameters
renderServicerender backend.
usagehow the mesh data is used at runtime.

◆ ~GPUMesh()

virtual ~GPUMesh ( )
virtualdefault

◆ GPUMesh() [2/2]

GPUMesh ( const GPUMesh other)
delete

Member Function Documentation

◆ addVertexBuffer()

VertexBuffer< ELEMENTTYPE > & addVertexBuffer ( const std::string &  id)

Creates and adds a new vertex buffer to the mesh. The new buffer has yet to be initialized before it can be updated. This can be checked with isInitialized().

Parameters
idname of the vertex buffer to create and add.

◆ findVertexBuffer()

const GPUBufferNumeric* findVertexBuffer ( const std::string &  id) const

Finds a vertex buffer with the given name.

Parameters
idname of the vertex buffer
Returns
reference to the vertex buffer if found, nullptr otherwise.

◆ getIndexBuffer()

const IndexBuffer& getIndexBuffer ( int  index) const

Returns an index buffer at the specified index, asserts if not present.

Parameters
indexvalue of the index buffer to get.
Returns
an index buffer.

◆ getOrCreateIndexBuffer()

IndexBuffer& getOrCreateIndexBuffer ( int  index)

Creates an index buffer if one does not exist, returns the existing buffer otherwise. If the buffer was created, it has yet to be initialized before it can be updated. This can be checked with isInitialized().

Parameters
indexvalue of the index buffer to get or create.
Returns
an already existing or new index buffer.

◆ getVertexBuffer()

GPUBufferNumeric& getVertexBuffer ( const std::string &  id)

Returns a vertex buffer with the given name, asserts if not present.

Parameters
idname of the vertex buffer to get.

◆ operator=()

GPUMesh& operator= ( const GPUMesh other)
delete