summaryrefslogtreecommitdiff
path: root/include/model.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/model.h')
-rw-r--r--include/model.h68
1 files changed, 68 insertions, 0 deletions
diff --git a/include/model.h b/include/model.h
new file mode 100644
index 0000000..9e93993
--- /dev/null
+++ b/include/model.h
@@ -0,0 +1,68 @@
1#pragma once
2
3#include <stdint.h>
4
5typedef uint16_t mdIdx;
6typedef struct mdVert { mdIdx position, normal, texcoord; } mdVert;
7typedef struct mdTri { mdVert v0, v1, v2; } mdTri;
8typedef struct mdVec2 { float x, y; } mdVec2;
9typedef struct mdVec3 { float x, y, z; } mdVec3;
10
11// Every three indices form a triangle, and each index indexes all attribute
12// arrays simultaneously. This is best for a fast, linear-scan rendering.
13// This is what you would render with glDrawElements().
14typedef struct FlatModel {
15 // Counts.
16 uint32_t numIdxs;
17 uint32_t numVerts;
18 // Offsets.
19 uint32_t offsetIdxs;
20 uint32_t offsetPositions;
21 uint32_t offsetNormals;
22 uint32_t offsetTexcoords;
23 /*
24 [indices] -- numIdxs mdIdx
25 [positions] -- numVerts mdVec3
26 [normals] -- numVerts mdVec3
27 [texcoords] -- numVerts mdVec2
28 */
29 uint8_t data[];
30} FlatModel;
31
32// Every triangle is made up of three vertices, and each vertex holds one index
33// for each of the attribute arrays. This allows for a smaller representation of
34// some models by virtue of being able to re-use attributes across vertices.
35// This is the sort of format that OBJ follows, where the indices to each array
36// given by a face may be non-uniform.
37typedef struct IndexedModel {
38 // Counts.
39 uint32_t numTris;
40 uint32_t numPositions;
41 uint32_t numNormals;
42 uint32_t numTexcoords;
43 // Offsets.
44 uint32_t offsetTris;
45 uint32_t offsetPositions;
46 uint32_t offsetNormals;
47 uint32_t offsetTexcoords;
48 /*
49 [triangles] -- numTris mdTri
50 [positions] -- numPositions mdVec3
51 [normals] -- numNormals mdVec3
52 [texcoords] -- numTexcoords mdVec2
53 */
54 uint8_t data[];
55} IndexedModel;
56
57typedef enum ModelType {
58 ModelTypeFlat,
59 ModelTypeIndexed
60} ModelType;
61
62typedef struct Model {
63 uint32_t type;
64 union {
65 FlatModel flat;
66 IndexedModel indexed;
67 };
68} Model;