VEX Engine
Retro looking game engine made in vulkan mostly because i wanted to understand it better.
Loading...
Searching...
No Matches
vex::VulkanMesh Class Reference

Class defining mesh object with vulkan specific data and methods. More...

#include <VulkanMesh.hpp>

Classes

struct  SubmeshBuffers
 struct used to hold buffers and allocations for each submesh in single object. More...

Public Member Functions

 VulkanMesh (VulkanContext &context)
 Constructor for VulkanMesh class.
void upload (const MeshData &meshData)
 Uploads mesh data to the GPU.
void extractTransparentTriangles (const glm::mat4 &modelMatrix, const glm::vec3 &cameraPos, uint32_t modelIndex, uint32_t frameIndex, vex::Entity entity, std::vector< TransparentTriangle > &outTriangles)
void draw (VkCommandBuffer cmd, VkPipelineLayout pipelineLayout, VulkanResources &resources, uint32_t frameIndex, uint32_t modelIndex, glm::mat4 modelMatrix, const MeshComponent &mc) const
 Draws the mesh to the screen.
void bindAndDrawBatched (VkCommandBuffer cmd, VkPipelineLayout pipelineLayout, VulkanResources &resources, uint32_t frameIndex, uint32_t modelIndex, uint32_t submeshIndex, glm::mat4 modelMatrix, bool modelChanged, bool submeshChanged, const MeshComponent &mc) const
 Batch-optimized draw call for sorted transparent triangles.
int getNumOfInstances () const
 Helper function to get number of mesh components using this VulkanMesh instance, needed for mesh manager to know when to unload VulkanMesh.
void addInstance ()
 increments number of mesh components using this VulkanMesh instance.
void removeInstance ()
 decrements number of mesh components using this VulkanMesh instance.

Private Member Functions

void StreamToGPU (void *dst, const void *src, size_t sizeBytes)
 Helper function to stream data to GPU memory.

Private Attributes

VulkanContextm_r_context
std::vector< SubmeshBuffersm_submeshBuffers
std::vector< std::string > m_submeshTextures
int numOfInstances = 0
std::vector< Submeshm_cpuSubmeshData

Detailed Description

Class defining mesh object with vulkan specific data and methods.

Definition at line 24 of file VulkanMesh.hpp.

Constructor & Destructor Documentation

◆ VulkanMesh()

vex::VulkanMesh::VulkanMesh ( VulkanContext & context)

Constructor for VulkanMesh class.

Parameters
VulkanContext&context - Reference to the VulkanContext object.

Definition at line 21 of file VulkanMesh.cpp.

◆ ~VulkanMesh()

vex::VulkanMesh::~VulkanMesh ( )

Definition at line 25 of file VulkanMesh.cpp.

Member Function Documentation

◆ addInstance()

void vex::VulkanMesh::addInstance ( )
inline

increments number of mesh components using this VulkanMesh instance.

Definition at line 96 of file VulkanMesh.hpp.

◆ bindAndDrawBatched()

void vex::VulkanMesh::bindAndDrawBatched ( VkCommandBuffer cmd,
VkPipelineLayout pipelineLayout,
VulkanResources & resources,
uint32_t frameIndex,
uint32_t modelIndex,
uint32_t submeshIndex,
glm::mat4 modelMatrix,
bool modelChanged,
bool submeshChanged,
const MeshComponent & mc ) const

Batch-optimized draw call for sorted transparent triangles.

Only re-binds descriptors/buffers if modelChanged or submeshChanged is true. Used in conjunction with issueMultiDrawIndexed.

Parameters
VkCommandBuffercmd - Command buffer.
VkPipelineLayoutpipelineLayout - Pipeline layout.
VulkanResources&resources - Resource manager.
uint32_tframeIndex - Frame index.
uint32_tmodelIndex - Model index.
uint32_tsubmeshIndex - Submesh index.
glm::mat4modelMatrix - Transform matrix.
boolmodelChanged - Flag indicating if model-level data (matrix/lights) needs rebinding.
boolsubmeshChanged - Flag indicating if submesh-level data (buffers/textures) needs rebinding.
constMeshComponent& mc - Component data.

Definition at line 166 of file VulkanMesh.cpp.

◆ draw()

void vex::VulkanMesh::draw ( VkCommandBuffer cmd,
VkPipelineLayout pipelineLayout,
VulkanResources & resources,
uint32_t frameIndex,
uint32_t modelIndex,
glm::mat4 modelMatrix,
const MeshComponent & mc ) const

Draws the mesh to the screen.

Binds buffers, descriptors, and issues draw calls for each submesh. Resolves texture overrides from MeshComponent.

Parameters
VkCommandBuffercmd - Command buffer to draw the mesh.
VkPipelineLayoutpipelineLayout - Pipeline layout for the mesh.
VulkanResources&resources - Vulkan resources for the mesh.
uint32_tframeIndex - Index of the current frame.
uint32_tmodelIndex - Index of the current model.
floatcurrentTime - Current time.
glm::uvec2currentRenderResolution - Current render resolution.

It is called automatically in Renderer for every mesh component having a VulkanMesh.

Definition at line 246 of file VulkanMesh.cpp.

◆ extractTransparentTriangles()

void vex::VulkanMesh::extractTransparentTriangles ( const glm::mat4 & modelMatrix,
const glm::vec3 & cameraPos,
uint32_t modelIndex,
uint32_t frameIndex,
vex::Entity entity,
std::vector< TransparentTriangle > & outTriangles )

Definition at line 131 of file VulkanMesh.cpp.

◆ getNumOfInstances()

int vex::VulkanMesh::getNumOfInstances ( ) const
inline

Helper function to get number of mesh components using this VulkanMesh instance, needed for mesh manager to know when to unload VulkanMesh.

Returns
int

Definition at line 93 of file VulkanMesh.hpp.

◆ removeInstance()

void vex::VulkanMesh::removeInstance ( )
inline

decrements number of mesh components using this VulkanMesh instance.

Definition at line 99 of file VulkanMesh.hpp.

◆ StreamToGPU()

void vex::VulkanMesh::StreamToGPU ( void * dst,
const void * src,
size_t sizeBytes )
private

Helper function to stream data to GPU memory.

Copies data to GPU memory using non-temporal stores (bypasses CPU cache)

Parameters
void*dst Destination buffer on GPU memory
constvoid* src Source buffer on CPU memory
size_tsizeBytes Size of data to copy in bytes

Definition at line 41 of file VulkanMesh.cpp.

◆ upload()

void vex::VulkanMesh::upload ( const MeshData & meshData)

Uploads mesh data to the GPU.

Creates VMA buffers (VK_BUFFER_USAGE_VERTEX_BUFFER_BIT / INDEX) and uploads data from MeshData. Stores CPU copies of triangle centers for transparency sorting.

Parameters
constMeshData& meshData - The source mesh data.

Definition at line 79 of file VulkanMesh.cpp.

Member Data Documentation

◆ m_cpuSubmeshData

std::vector<Submesh> vex::VulkanMesh::m_cpuSubmeshData
private

Definition at line 123 of file VulkanMesh.hpp.

◆ m_r_context

VulkanContext& vex::VulkanMesh::m_r_context
private

Definition at line 118 of file VulkanMesh.hpp.

◆ m_submeshBuffers

std::vector<SubmeshBuffers> vex::VulkanMesh::m_submeshBuffers
private

Definition at line 119 of file VulkanMesh.hpp.

◆ m_submeshTextures

std::vector<std::string> vex::VulkanMesh::m_submeshTextures
private

Definition at line 120 of file VulkanMesh.hpp.

◆ numOfInstances

int vex::VulkanMesh::numOfInstances = 0
private

Definition at line 121 of file VulkanMesh.hpp.


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