Refactor mesh handling to use templated vertex structures for improved type safety and flexibility
This commit is contained in:
@@ -1,25 +1,43 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <array>
|
||||
#include <memory>
|
||||
#include <GL/glew.h>
|
||||
#include <glm/vec3.hpp>
|
||||
|
||||
#include "graphics/core/MeshData.hpp"
|
||||
#include "util/Buffer.hpp"
|
||||
|
||||
/// @brief Chunk mesh vertex attributes
|
||||
inline const VertexAttribute CHUNK_VATTRS[]{ {3}, {2}, {1}, {0} };
|
||||
/// @brief Chunk mesh vertex size divided by sizeof(float)
|
||||
inline constexpr int CHUNK_VERTEX_SIZE = 6;
|
||||
|
||||
|
||||
/// @brief Chunk mesh vertex format
|
||||
#pragma pack(push, 2)
|
||||
struct ChunkVertex {
|
||||
glm::vec3 position;
|
||||
glm::vec2 uv;
|
||||
std::array<uint8_t, 4> color;
|
||||
|
||||
static constexpr VertexAttribute ATTRIBUTES[] = {
|
||||
{GL_FLOAT, false, 3},
|
||||
{GL_FLOAT, false, 2},
|
||||
{GL_UNSIGNED_BYTE, true, 4},
|
||||
{0}
|
||||
};
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
/// @brief Chunk mesh vertex attributes
|
||||
|
||||
template<typename VertexStructure>
|
||||
class Mesh;
|
||||
|
||||
struct SortingMeshEntry {
|
||||
glm::vec3 position;
|
||||
util::Buffer<float> vertexData;
|
||||
util::Buffer<ChunkVertex> vertexData;
|
||||
long long distance;
|
||||
|
||||
inline bool operator<(const SortingMeshEntry& o) const noexcept {
|
||||
inline bool operator<(const SortingMeshEntry &o) const noexcept {
|
||||
return distance > o.distance;
|
||||
}
|
||||
};
|
||||
@@ -29,12 +47,12 @@ struct SortingMeshData {
|
||||
};
|
||||
|
||||
struct ChunkMeshData {
|
||||
MeshData mesh;
|
||||
MeshData<ChunkVertex> mesh;
|
||||
SortingMeshData sortingMesh;
|
||||
};
|
||||
|
||||
struct ChunkMesh {
|
||||
std::unique_ptr<Mesh> mesh;
|
||||
std::unique_ptr<Mesh<ChunkVertex> > mesh;
|
||||
SortingMeshData sortingMeshData;
|
||||
std::unique_ptr<Mesh> sortedMesh = nullptr;
|
||||
std::unique_ptr<Mesh<ChunkVertex> > sortedMesh = nullptr;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user