mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-08 12:31:51 +00:00
Refactor mesh handling to use templated vertex structures for improved type safety and flexibility
This commit is contained in:
parent
bba647db5c
commit
1ffbeb8148
28 changed files with 591 additions and 521 deletions
|
|
@ -1,31 +1,43 @@
|
|||
#pragma once
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "typedefs.hpp"
|
||||
#include "MeshData.hpp"
|
||||
|
||||
|
||||
struct MeshStats {
|
||||
static int meshesCount;
|
||||
static int drawCalls;
|
||||
};
|
||||
|
||||
|
||||
template<typename VertexStructure>
|
||||
class Mesh {
|
||||
unsigned int vao;
|
||||
unsigned int vbo;
|
||||
unsigned int ibo;
|
||||
size_t vertices;
|
||||
size_t indices;
|
||||
size_t vertexCount;
|
||||
size_t indexCount;
|
||||
size_t vertexSize;
|
||||
|
||||
public:
|
||||
Mesh(const MeshData& data);
|
||||
Mesh(const float* vertexBuffer, size_t vertices, const int* indexBuffer, size_t indices, const VertexAttribute* attrs);
|
||||
Mesh(const float* vertexBuffer, size_t vertices, const VertexAttribute* attrs) :
|
||||
Mesh(vertexBuffer, vertices, nullptr, 0, attrs) {};
|
||||
explicit Mesh(const MeshData<VertexStructure> &data);
|
||||
|
||||
Mesh(const VertexStructure *vertexBuffer, size_t vertices, const uint32_t *indexBuffer, size_t indices,
|
||||
const VertexAttribute *attrs);
|
||||
|
||||
Mesh(const VertexStructure *vertexBuffer, size_t vertices, const VertexAttribute *attrs) : Mesh<VertexStructure>(
|
||||
vertexBuffer, vertices, nullptr, 0, attrs) {
|
||||
};
|
||||
|
||||
~Mesh();
|
||||
|
||||
/// @brief Update GL vertex and index buffers data without changing VAO attributes
|
||||
/// @param vertexBuffer vertex data buffer
|
||||
/// @param vertices number of vertices in new buffer
|
||||
/// @param vertexCount number of vertices in new buffer
|
||||
/// @param indexBuffer indices buffer
|
||||
/// @param indices number of values in indices buffer
|
||||
void reload(const float* vertexBuffer, size_t vertices, const int* indexBuffer = nullptr, size_t indices = 0);
|
||||
|
||||
/// @param indexCount number of values in indices buffer
|
||||
void reload(const VertexStructure *vertexBuffer, size_t vertexCount, const uint32_t *indexBuffer = nullptr,
|
||||
size_t indexCount = 0);
|
||||
|
||||
/// @brief Draw mesh with specified primitives type
|
||||
/// @param primitive primitives type
|
||||
void draw(unsigned int primitive) const;
|
||||
|
|
@ -34,6 +46,6 @@ public:
|
|||
void draw() const;
|
||||
|
||||
/// @brief Total numbers of alive mesh objects
|
||||
static int meshesCount;
|
||||
static int drawCalls;
|
||||
};
|
||||
|
||||
#include "graphics/core/Mesh.inl"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue