98 lines
2.6 KiB
C++
98 lines
2.6 KiB
C++
#pragma once
|
|
#include "DeerRender/Render/VertexArray.h"
|
|
#include "DeerRender/Resource.h"
|
|
#include "DeerRender/Tools/Memory.h"
|
|
#include "DeerRender/Tools/Path.h"
|
|
|
|
#include <cstdint>
|
|
|
|
namespace Deer {
|
|
struct VertexPosition {
|
|
float x;
|
|
float y;
|
|
float z;
|
|
|
|
VertexPosition() = default;
|
|
VertexPosition(float _x, float _y, float _z) : x(_x), y(_y), z(_z) {}
|
|
};
|
|
|
|
struct VertexUV {
|
|
float u;
|
|
float v;
|
|
|
|
VertexUV() = default;
|
|
VertexUV(float _u, float _v) : u(_u), v(_v) {}
|
|
};
|
|
|
|
struct VertexNormal {
|
|
int8_t x = 0;
|
|
int8_t y = 0;
|
|
int8_t z = 0;
|
|
|
|
VertexNormal() = default;
|
|
VertexNormal(int8_t _x, int8_t _y, int8_t _z) : x(_x), y(_y), z(_z) {}
|
|
};
|
|
|
|
struct VertexColor {
|
|
uint8_t r = 0;
|
|
uint8_t g = 0;
|
|
uint8_t b = 0;
|
|
|
|
VertexColor() = default;
|
|
VertexColor(uint8_t _r, uint8_t _g, uint8_t _b) : r(_r), g(_g), b(_b) {}
|
|
};
|
|
|
|
struct MeshData {
|
|
public:
|
|
void createVertices(uint32_t count) {
|
|
vertexPositionsData = MakeScope<VertexPosition[]>(count);
|
|
vertexNormalData = MakeScope<VertexNormal[]>(count);
|
|
vertexCount = count;
|
|
}
|
|
void createIndices(uint32_t count) {
|
|
indexData = MakeScope<uint32_t[]>(count);
|
|
indexCount = count;
|
|
}
|
|
|
|
void createUVData() { vertexUVData = MakeScope<VertexUV[]>(vertexCount); }
|
|
void createColorData() { vertexColorData = MakeScope<VertexColor[]>(vertexCount); }
|
|
void createAuxData() { vertexAuxData = MakeScope<uint8_t[]>(vertexCount); }
|
|
|
|
inline VertexPosition* getVertexPosition() const { return vertexPositionsData.get(); }
|
|
inline VertexNormal* getVertexNormal() const { return vertexNormalData.get(); }
|
|
inline VertexUV* getVertexUV() const { return vertexUVData.get(); }
|
|
inline VertexColor* getVertexColor() const { return vertexColorData.get(); }
|
|
inline uint8_t* getVertexAuxData() const { return vertexAuxData.get(); }
|
|
inline uint32_t* getIndexData() const { return indexData.get(); }
|
|
|
|
inline uint32_t getVertexCount() const { return vertexCount; }
|
|
inline uint32_t getIndexCount() const { return indexCount; }
|
|
|
|
private:
|
|
uint32_t vertexCount = 0;
|
|
Scope<VertexPosition[]> vertexPositionsData;
|
|
Scope<VertexNormal[]> vertexNormalData;
|
|
Scope<VertexUV[]> vertexUVData;
|
|
Scope<VertexColor[]> vertexColorData;
|
|
Scope<uint8_t[]> vertexAuxData;
|
|
|
|
uint32_t indexCount = 0;
|
|
Scope<uint32_t[]> indexData;
|
|
};
|
|
|
|
struct GPUMesh {
|
|
Scope<VertexArray> vertexArray;
|
|
};
|
|
|
|
template <>
|
|
class ResourceBuilder<GPUMesh> {
|
|
public:
|
|
using BaseDataType = MeshData;
|
|
static Scope<GPUMesh> buildResource(const BaseDataType& baseData);
|
|
};
|
|
|
|
namespace Builtin {
|
|
Resource<GPUMesh> cube();
|
|
Resource<GPUMesh> sphere();
|
|
} // namespace Builtin
|
|
} // namespace Deer
|