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

This class defines the layout of a mesh's vertices. More...

#include <candlewick/core/MeshLayout.h>

Public Member Functions

 MeshLayout ()
 
MeshLayoutaddBinding (Uint32 slot, Uint32 pitch)
 Add a binding (i.e. a vertex binding) for the mesh.
 
constexpr MeshLayoutaddAttribute (VertexAttrib loc, Uint32 binding, SDL_GPUVertexElementFormat format, Uint32 offset)
 Add a vertex attribute.
 
const SDL_GPUVertexAttribute * getAttribute (VertexAttrib loc) const noexcept
 
SDL_GPUVertexInputState toVertexInputState () const noexcept
 Cast to the SDL_GPU vertex input state struct, used to create pipelines.
 
 operator SDL_GPUVertexInputState () const noexcept
 
bool operator== (const MeshLayout &other) const noexcept
 
Uint32 numBuffers () const
 Number of vertex buffers.
 
Uint32 numAttributes () const
 Number of vertex attributes.
 
Uint32 vertexSize () const
 Total size of a vertex (in bytes).
 
Uint32 indexSize () const
 Size of mesh indices (in bytes).
 

Public Attributes

std::vector< SDL_GPUVertexBufferDescription > m_bufferDescs
 
std::vector< SDL_GPUVertexAttribute > m_attrs
 

Detailed Description

This class defines the layout of a mesh's vertices.

This is used to build both rasterization pipeline and create Mesh objects. Due to its large size, we store these objects in centralized storage and hand out handles to them.

See also
Mesh
MeshData

Constructor & Destructor Documentation

◆ MeshLayout()

candlewick::MeshLayout::MeshLayout ( )
inline

Member Function Documentation

◆ addAttribute()

MeshLayout & candlewick::MeshLayout::addAttribute ( VertexAttrib loc,
Uint32 binding,
SDL_GPUVertexElementFormat format,
Uint32 offset )
inlineconstexpr

Add a vertex attribute.

Parameters
nameThe vertex attribute name.
locLocation index in the vertex shader.
bindingBinding slot of the corresponding vertex buffer.
formatFormat of the vertex attribute.
offsetByte offset of the attribute relative to the start of the vertex buffer element.

◆ addBinding()

MeshLayout & candlewick::MeshLayout::addBinding ( Uint32 slot,
Uint32 pitch )
inline

Add a binding (i.e. a vertex binding) for the mesh.

Calling this multiple times allows to describe a mesh layout where e.g. positions and normals are non-interleaved and should be uploaded to different vertex buffers.

Parameters
slotIndex for vertex buffer
sizeEquivalent of pitch in SDL_gpu, size of consecutive elements of the vertex buffer, i.e. sizeof(Vertex) if your vertices are of some type Vertex.

◆ getAttribute()

const SDL_GPUVertexAttribute * candlewick::MeshLayout::getAttribute ( VertexAttrib loc) const
inlinenoexcept

◆ indexSize()

Uint32 candlewick::MeshLayout::indexSize ( ) const
inline

Size of mesh indices (in bytes).

◆ numAttributes()

Uint32 candlewick::MeshLayout::numAttributes ( ) const
inline

Number of vertex attributes.

◆ numBuffers()

Uint32 candlewick::MeshLayout::numBuffers ( ) const
inline

Number of vertex buffers.

◆ operator SDL_GPUVertexInputState()

candlewick::MeshLayout::operator SDL_GPUVertexInputState ( ) const
inlinenoexcept

◆ operator==()

bool candlewick::MeshLayout::operator== ( const MeshLayout & other) const
inlinenoexcept

◆ toVertexInputState()

SDL_GPUVertexInputState candlewick::MeshLayout::toVertexInputState ( ) const
inlinenoexcept

Cast to the SDL_GPU vertex input state struct, used to create pipelines.

Warning
The data here only references data internal to MeshLayout and not copied. It must stay in scope until the pipeline is created.

◆ vertexSize()

Uint32 candlewick::MeshLayout::vertexSize ( ) const
inline

Total size of a vertex (in bytes).

Todo
Make this compatible with multiple vertex bindings.

Member Data Documentation

◆ m_attrs

std::vector<SDL_GPUVertexAttribute> candlewick::MeshLayout::m_attrs

◆ m_bufferDescs

std::vector<SDL_GPUVertexBufferDescription> candlewick::MeshLayout::m_bufferDescs

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