#pragma once #include typedef uint16_t mdIdx; typedef struct mdVert { mdIdx position, normal, texcoord; } mdVert; typedef struct mdTri { mdVert v0, v1, v2; } mdTri; typedef struct mdVec2 { float x, y; } mdVec2; typedef struct mdVec3 { float x, y, z; } mdVec3; // Every three indices form a triangle, and each index indexes all attribute // arrays simultaneously. This is best for a fast, linear-scan rendering. // This is what you would render with glDrawElements(). typedef struct FlatModel { // Counts. uint32_t numIdxs; uint32_t numVerts; // Offsets. uint32_t offsetIdxs; uint32_t offsetPositions; uint32_t offsetNormals; uint32_t offsetTexcoords; /* [indices] -- numIdxs mdIdx [positions] -- numVerts mdVec3 [normals] -- numVerts mdVec3 [texcoords] -- numVerts mdVec2 */ uint8_t data[]; } FlatModel; // Every triangle is made up of three vertices, and each vertex holds one index // for each of the attribute arrays. This allows for a smaller representation of // some models by virtue of being able to re-use attributes across vertices. // This is the sort of format that OBJ follows, where the indices to each array // given by a face may be non-uniform. typedef struct IndexedModel { // Counts. uint32_t numTris; uint32_t numPositions; uint32_t numNormals; uint32_t numTexcoords; // Offsets. uint32_t offsetTris; uint32_t offsetPositions; uint32_t offsetNormals; uint32_t offsetTexcoords; /* [triangles] -- numTris mdTri [positions] -- numPositions mdVec3 [normals] -- numNormals mdVec3 [texcoords] -- numTexcoords mdVec2 */ uint8_t data[]; } IndexedModel; typedef enum ModelType { ModelTypeFlat, ModelTypeIndexed } ModelType; typedef struct Model { uint32_t type; union { FlatModel flat; IndexedModel indexed; }; } Model;