blob: 9e93993aa947c8cf735e96d63b0cfcbcd77fb61c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
#pragma once
#include <stdint.h>
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;
|