mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-11 22:11:51 +00:00
feat: multiple index buffers per mesh support
This commit is contained in:
parent
6debc92ae5
commit
4a6ccf4847
7 changed files with 81 additions and 43 deletions
|
|
@ -1,5 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "MeshData.hpp"
|
||||
|
||||
|
||||
|
|
@ -8,25 +10,32 @@ struct MeshStats {
|
|||
static int drawCalls;
|
||||
};
|
||||
|
||||
struct IndexBufferData {
|
||||
const uint32_t* indices;
|
||||
size_t indicesCount;
|
||||
};
|
||||
|
||||
template <typename VertexStructure>
|
||||
class Mesh {
|
||||
struct IndexBuffer {
|
||||
unsigned int ibo;
|
||||
size_t indexCount;
|
||||
};
|
||||
unsigned int vao;
|
||||
unsigned int vbo;
|
||||
unsigned int ibo;
|
||||
std::vector<IndexBuffer> ibos;
|
||||
size_t vertexCount;
|
||||
size_t indexCount;
|
||||
public:
|
||||
explicit Mesh(const MeshData<VertexStructure>& data);
|
||||
|
||||
Mesh(
|
||||
const VertexStructure* vertexBuffer,
|
||||
size_t vertices,
|
||||
const uint32_t* indexBuffer,
|
||||
size_t indices
|
||||
std::vector<IndexBufferData> indices
|
||||
);
|
||||
|
||||
Mesh(const VertexStructure* vertexBuffer, size_t vertices)
|
||||
: Mesh<VertexStructure>(vertexBuffer, vertices, nullptr, 0) {};
|
||||
: Mesh<VertexStructure>(vertexBuffer, vertices, {}) {};
|
||||
|
||||
~Mesh();
|
||||
|
||||
|
|
@ -34,18 +43,21 @@ public:
|
|||
/// attributes
|
||||
/// @param vertexBuffer vertex data buffer
|
||||
/// @param vertexCount number of vertices in new buffer
|
||||
/// @param indexBuffer indices buffer
|
||||
/// @param indexCount number of values in indices buffer
|
||||
/// @param indices indices buffer
|
||||
void reload(
|
||||
const VertexStructure* vertexBuffer,
|
||||
size_t vertexCount,
|
||||
const uint32_t* indexBuffer = nullptr,
|
||||
size_t indexCount = 0
|
||||
const std::vector<IndexBufferData>& indices
|
||||
);
|
||||
|
||||
void reload(const VertexStructure* vertexBuffer, size_t vertexCount) {
|
||||
static const std::vector<IndexBufferData> indices {};
|
||||
reload(vertexBuffer, vertexCount, indices);
|
||||
}
|
||||
|
||||
/// @brief Draw mesh with specified primitives type
|
||||
/// @param primitive primitives type
|
||||
void draw(unsigned int primitive) const;
|
||||
/// @param iboIndex index of used element buffer
|
||||
void draw(unsigned int primitive, int iboIndex = 0) const;
|
||||
|
||||
/// @brief Draw mesh as triangles
|
||||
void draw() const;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue