candlewick 0.1.0
A renderer
Loading...
Searching...
No Matches
candlewick::Mesh Class Reference

Handle class for meshes (vertex buffers and an optional index buffer) on the GPU. More...

#include <candlewick/core/Mesh.h>

Public Member Functions

 Mesh (const Device &device, const MeshLayout &layout)
 
const MeshLayoutlayout () const
 
 Mesh (NoInitT)
 
 Mesh (const Mesh &)=delete
 
 Mesh (Mesh &&other) noexcept
 
Meshoperator= (const Mesh &)=delete
 
Meshoperator= (Mesh &&other) noexcept
 
const MeshViewview (size_t i) const
 
std::span< const MeshViewviews () const
 
size_t numViews () const
 
MeshViewaddView (Uint32 vertexOffset, Uint32 vertexSubCount, Uint32 indexOffset, Uint32 indexSubCount)
 Add a stored MeshView object. The added view will be drawn when calling Renderer::draw() with a Mesh argument.
 
MeshbindVertexBuffer (Uint32 slot, SDL_GPUBuffer *buffer)
 Bind an existing vertex buffer to a given slot of the Mesh.
 
MeshsetIndexBuffer (SDL_GPUBuffer *buffer)
 Bind an existing index buffer for the Mesh.
 
Uint32 numVertexBuffers () const
 Number of vertex buffers.
 
bool isIndexed () const
 
void release () noexcept
 Release all owned vertex and index buffers in the Mesh object.
 
 ~Mesh () noexcept
 
SDL_GPUBufferBinding getVertexBinding (Uint32 slot) const
 
SDL_GPUBufferBinding getIndexBinding () const
 

Public Attributes

Uint32 vertexCount
 
Uint32 indexCount {0u}
 
std::vector< SDL_GPUBuffer * > vertexBuffers
 
SDL_GPUBuffer * indexBuffer {nullptr}
 

Detailed Description

Handle class for meshes (vertex buffers and an optional index buffer) on the GPU.

This class contains the layout, vertex (and index) count(s), and handles to the GPU vertex and index buffers the Mesh references.

A Mesh owns its vertex and index buffers.

See also
MeshView

Constructor & Destructor Documentation

◆ Mesh() [1/4]

candlewick::Mesh::Mesh ( const Device & device,
const MeshLayout & layout )
explicit

◆ Mesh() [2/4]

candlewick::Mesh::Mesh ( NoInitT )

◆ Mesh() [3/4]

candlewick::Mesh::Mesh ( const Mesh & )
delete

◆ Mesh() [4/4]

candlewick::Mesh::Mesh ( Mesh && other)
noexcept

◆ ~Mesh()

candlewick::Mesh::~Mesh ( )
inlinenoexcept

Member Function Documentation

◆ addView()

MeshView & candlewick::Mesh::addView ( Uint32 vertexOffset,
Uint32 vertexSubCount,
Uint32 indexOffset,
Uint32 indexSubCount )

Add a stored MeshView object. The added view will be drawn when calling Renderer::draw() with a Mesh argument.

Returns
Reference to the created MeshView object.

◆ bindVertexBuffer()

Mesh & candlewick::Mesh::bindVertexBuffer ( Uint32 slot,
SDL_GPUBuffer * buffer )

Bind an existing vertex buffer to a given slot of the Mesh.

Warning
This function will take ownership of the buffer.
Parameters
slotBinding slot of the vertex buffer. Used by SDL_GPUVertexAttribute.
bufferExisting buffer.
Returns
Reference to this, for method chaining.

◆ getIndexBinding()

SDL_GPUBufferBinding candlewick::Mesh::getIndexBinding ( ) const
inline

◆ getVertexBinding()

SDL_GPUBufferBinding candlewick::Mesh::getVertexBinding ( Uint32 slot) const
inline

◆ isIndexed()

bool candlewick::Mesh::isIndexed ( ) const
inline

◆ layout()

const MeshLayout & candlewick::Mesh::layout ( ) const
inline

◆ numVertexBuffers()

Uint32 candlewick::Mesh::numVertexBuffers ( ) const
inline

Number of vertex buffers.

◆ numViews()

size_t candlewick::Mesh::numViews ( ) const
inline

◆ operator=() [1/2]

Mesh & candlewick::Mesh::operator= ( const Mesh & )
delete

◆ operator=() [2/2]

Mesh & candlewick::Mesh::operator= ( Mesh && other)
noexcept

◆ release()

void candlewick::Mesh::release ( )
noexcept

Release all owned vertex and index buffers in the Mesh object.

◆ setIndexBuffer()

Mesh & candlewick::Mesh::setIndexBuffer ( SDL_GPUBuffer * buffer)

Bind an existing index buffer for the Mesh.

This function does not check that the buffer is non-null. The lack of check is to allow method chaining with arguments which may or may not be null, depending on context.

Warning
This function will take ownership of the buffer.
Parameters
bufferExisting index buffer.
Returns
Reference to this, for method chaining.

◆ view()

const MeshView & candlewick::Mesh::view ( size_t i) const
inline

◆ views()

std::span< const MeshView > candlewick::Mesh::views ( ) const
inline

Member Data Documentation

◆ indexBuffer

SDL_GPUBuffer* candlewick::Mesh::indexBuffer {nullptr}

Index buffer for the mesh's index data. If this is null, then the Mesh is considered to be non-indexed when it is bound or when draw commands are issued.

◆ indexCount

Uint32 candlewick::Mesh::indexCount {0u}

◆ vertexBuffers

std::vector<SDL_GPUBuffer *> candlewick::Mesh::vertexBuffers

Vertex buffers the Mesh has its vertex data in.

There may be multiple vertex buffers, depending on how the mesh data is laid out. For instance, some vertex attributes may be non-interleaved, e.g. the vertex positions, normals, and colors may be in different vertex buffers in GPU memory, instead of being laid out as [pos0, norm0, col0, pos1, ...].

◆ vertexCount

Uint32 candlewick::Mesh::vertexCount

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