12 mSizeOfVerticesBytes(0),
13 mSizeOfIndicesBytes(0),
21 mSizeOfVerticesBytes(0),
22 mSizeOfIndicesBytes(0),
32 mSizeOfVerticesBytes(0),
33 mSizeOfIndicesBytes(0),
52 if (mGpuHandle->IsOnGPU())
69 mGpuHandle->CreateIndexBuffer(mIndices);
75 mGpuHandle->CreateIndexBuffer(mIndices);
81 mGpuHandle->CreateIndexBuffer(mIndices);
98 mGpuHandle->Shutdown();
100 mGpuHandle =
nullptr;
109 result = mGpuHandle->IsOnGPU();
117 std::unique_ptr<Model> model = std::make_unique<Model>(path,
true);
121 if (model->HasMeshes())
123 mPositions = model->Meshes()[0]->Vertices();
125 if (model->Meshes()[0]->VertexColors().size() >= 1)
126 mColor = model->Meshes()[0]->VertexColors()[0];
128 mNormals = model->Meshes()[0]->Normals();
129 for (
const auto& texCoord : model->Meshes()[0]->TextureCoordinates()[0])
131 mTexCoords.push_back(glm::vec2(texCoord.x, texCoord.y));
133 mTangents = model->Meshes()[0]->Tangents();
134 mIndices = model->Meshes()[0]->Indices();
145 std::unique_ptr<Model> model = std::make_unique<Model>(fileBytes,
true);
149 if (model->HasMeshes())
151 mPositions = model->Meshes()[0]->Vertices();
153 if (model->Meshes()[0]->VertexColors().size() >= 1)
154 mColor = model->Meshes()[0]->VertexColors()[0];
156 mNormals = model->Meshes()[0]->Normals();
157 for (
const auto& texCoord : model->Meshes()[0]->TextureCoordinates()[0])
159 mTexCoords.push_back(glm::vec2(texCoord.x, texCoord.y));
161 mTangents = model->Meshes()[0]->Tangents();
162 mIndices = model->Meshes()[0]->Indices();
173 mPositions2D = { {-0.5f, -0.5f}, { 0.5f, -0.5f}, { 0.5f, 0.5f}, {-0.5f, 0.5f} };
183 mColor = { {1.0f, 0.0f, 0.0f, 1.0f}, {0.0f, 1.0f, 0.0f, 1.0f}, {0.0f, 0.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f} };
195void MeshDataGpu::LoadCustomMesh(std::vector<glm::vec2> positions2D, std::vector<glm::vec2> texCoords, std::vector<glm::vec4> colors, std::vector<std::uint32_t> indices)
197 mPositions2D = positions2D;
198 mTexCoords = texCoords;
213 result = mGpuHandle->GetVertexBufferSize();
225 result = mGpuHandle->GetIndexBufferSize();
233 return mSizeOfVerticesBytes;
238 return mSizeOfIndicesBytes;
247 return mGpuHandle.get();
252 size_t sizeOfVerticesBytes = 0;
253 size_t sizeOfIndicesBytes = 0;
255 sizeOfVerticesBytes += (mPositions2D.size() *
sizeof(glm::vec2));
256 sizeOfVerticesBytes += (mPositions.size() *
sizeof(glm::vec3));
257 sizeOfVerticesBytes += (mColor.size() *
sizeof(glm::vec4));
258 sizeOfVerticesBytes += (mNormals.size() *
sizeof(glm::vec3));
259 sizeOfVerticesBytes += (mTexCoords.size() *
sizeof(glm::vec2));
260 sizeOfVerticesBytes += (mTangents.size() *
sizeof(glm::vec3));
262 sizeOfIndicesBytes += (mIndices.size() *
sizeof(uint32_t));
264 mSizeOfVerticesBytes = sizeOfVerticesBytes;
265 mSizeOfIndicesBytes = sizeOfIndicesBytes;
270 std::vector<Vertex2D> result;
272 unsigned int index = 0;
273 for (
const auto& position : mPositions2D)
277 vert.
color = mColor.empty() ? glm::vec4(1.0f) : mColor[index];
280 result.push_back(vert);
289 std::vector<VertexPositionColorTexture> result;
291 unsigned int index = 0;
292 for (
const auto& position : mPositions)
296 vert.
color = mColor.empty() ? glm::vec4(1) : mColor[index];
299 result.push_back(vert);
308 std::vector<VertexPositionColorTextureNormalTangent> result;
310 unsigned int index = 0;
311 for (
const auto& position : mPositions)
315 vert.
color = mColor.empty() ? glm::vec4(1.0f) : mColor[index];
317 vert.
normal = mNormals.empty() ? glm::vec3(0.0f, 0.0f, 1.0f) : mNormals[index];
318 vert.
tangent = mTangents.empty() ? glm::vec3(1.0f, 0.0f, 0.0f) : mTangents[index];
320 result.push_back(vert);
Interface for GPU mesh resource management.
Defines an abstract interface for rendering backends.
virtual IMeshRenderResources * ProvideMeshRenderResources() const =0
Provides access to mesh-related GPU resources.
size_t GetCpuIndexBufferSize() const
Get the size (in bytes) of the index buffer in RAM.
void CreateQuad2D()
Creates a 1�1 unit quad centered at the origin.
std::vector< VertexPositionColorTextureNormalTangent > ComposeLitBuffer()
Compose a vertex buffer for lit 3D meshes (with normals, tangents).
void CalculateMeshParameters()
Calculate and cache sizes of RAM buffers for statistics or debugging.
void LoadModel(std::string path)
Load a model from file and extract mesh data to RAM.
size_t GetGpuIndexBufferSize() const
Get the size (in bytes) of the index buffer on GPU.
std::vector< Vertex2D > ComposeVertex2DBuffer()
Compose a vertex buffer for 2D meshes (e.g., sprites).
IMeshRenderResources * GetMeshRenderResources()
Get the interface for mesh GPU resources (Vulkan or other backend).
void UploadToGPU()
Upload mesh data to the GPU using the current mesh type.
void LoadCustomMesh(std::vector< glm::vec2 > positions2D, std::vector< glm::vec2 > texCoords, std::vector< glm::vec4 > colors, std::vector< std::uint32_t > indices)
bool IsOnGPU() const
Check if mesh data is currently uploaded to GPU.
std::vector< VertexPositionColorTexture > ComposeUnlitBuffer()
Compose a vertex buffer for unlit 3D meshes (e.g., billboards, particles).
MeshDataGpu(IRenderer *renderer)
Constructs an empty MeshDataGpu object.
size_t GetCpuVertexBufferSize() const
Get the size (in bytes) of the vertex buffer in RAM.
~MeshDataGpu()
Destructor. Releases GPU resources if allocated.
size_t GetGpuVertexBufferSize() const
Get the size (in bytes) of the vertex buffer on GPU.
void ReleaseFromGPU()
Release GPU resources associated with this mesh.
MeshType
Types of supported mesh layouts for GPU upload and rendering.
@ Sprite2D
2D sprite mesh (typically for UI or simple quads).
@ None
Undefined or not yet set.
@ Surface
Full 3D surface mesh (models with normals/tangents, etc.).
@ Billboard
3D billboard mesh (sprites that face the camera).
Vertex format for 2D UI/Overlay elements.
glm::vec4 color
Vertex color (RGBA)
glm::vec2 position
2D position in screen or world space
glm::vec2 textureCoordinates
UV coordinates for texturing.
Vertex format for lit 3D geometry (normal and tangent support).
glm::vec3 tangent
Tangent (for normal mapping)
glm::vec4 color
Vertex color (RGBA)
glm::vec2 textureCoordinates
UV coordinates for texturing.
glm::vec3 position
3D position
glm::vec3 normal
Surface normal (for lighting)
Vertex format for unlit 3D geometry.
glm::vec3 position
3D position
glm::vec4 color
Vertex color (RGBA)
glm::vec2 textureCoordinates
UV coordinates for texturing.