diff options
| author | 3gg <3gg@shellblade.net> | 2025-12-30 17:25:44 -0800 |
|---|---|---|
| committer | 3gg <3gg@shellblade.net> | 2025-12-30 17:25:44 -0800 |
| commit | fdaa55621fc7f815c236520ff65033eb8c8c6ca0 (patch) | |
| tree | 29deb2eeff919c2bc17c7f6a8dfb7461ea6ad158 /include/model.h | |
| parent | eba20320bf8d542a46dc3fd84ec401057a25b9da (diff) | |
Parse diffuse texture from material
Diffstat (limited to 'include/model.h')
| -rw-r--r-- | include/model.h | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/include/model.h b/include/model.h index 9e93993..0730809 100644 --- a/include/model.h +++ b/include/model.h | |||
| @@ -1,13 +1,20 @@ | |||
| 1 | #pragma once | 1 | #pragma once |
| 2 | 2 | ||
| 3 | #include <stddef.h> | ||
| 3 | #include <stdint.h> | 4 | #include <stdint.h> |
| 4 | 5 | ||
| 6 | constexpr size_t ModelPathLen = 256; | ||
| 7 | |||
| 5 | typedef uint16_t mdIdx; | 8 | typedef uint16_t mdIdx; |
| 6 | typedef struct mdVert { mdIdx position, normal, texcoord; } mdVert; | 9 | typedef struct mdVert { mdIdx position, texcoord, normal; } mdVert; |
| 7 | typedef struct mdTri { mdVert v0, v1, v2; } mdTri; | 10 | typedef struct mdTri { mdVert v0, v1, v2; } mdTri; |
| 8 | typedef struct mdVec2 { float x, y; } mdVec2; | 11 | typedef struct mdVec2 { float x, y; } mdVec2; |
| 9 | typedef struct mdVec3 { float x, y, z; } mdVec3; | 12 | typedef struct mdVec3 { float x, y, z; } mdVec3; |
| 10 | 13 | ||
| 14 | typedef struct Material { | ||
| 15 | char diffuseTexture[ModelPathLen]; | ||
| 16 | } Material; | ||
| 17 | |||
| 11 | // Every three indices form a triangle, and each index indexes all attribute | 18 | // Every three indices form a triangle, and each index indexes all attribute |
| 12 | // arrays simultaneously. This is best for a fast, linear-scan rendering. | 19 | // arrays simultaneously. This is best for a fast, linear-scan rendering. |
| 13 | // This is what you would render with glDrawElements(). | 20 | // This is what you would render with glDrawElements(). |
| @@ -18,13 +25,13 @@ typedef struct FlatModel { | |||
| 18 | // Offsets. | 25 | // Offsets. |
| 19 | uint32_t offsetIdxs; | 26 | uint32_t offsetIdxs; |
| 20 | uint32_t offsetPositions; | 27 | uint32_t offsetPositions; |
| 21 | uint32_t offsetNormals; | ||
| 22 | uint32_t offsetTexcoords; | 28 | uint32_t offsetTexcoords; |
| 29 | uint32_t offsetNormals; | ||
| 23 | /* | 30 | /* |
| 24 | [indices] -- numIdxs mdIdx | 31 | [indices] -- numIdxs mdIdx |
| 25 | [positions] -- numVerts mdVec3 | 32 | [positions] -- numVerts mdVec3 |
| 26 | [normals] -- numVerts mdVec3 | ||
| 27 | [texcoords] -- numVerts mdVec2 | 33 | [texcoords] -- numVerts mdVec2 |
| 34 | [normals] -- numVerts mdVec3 | ||
| 28 | */ | 35 | */ |
| 29 | uint8_t data[]; | 36 | uint8_t data[]; |
| 30 | } FlatModel; | 37 | } FlatModel; |
| @@ -38,18 +45,18 @@ typedef struct IndexedModel { | |||
| 38 | // Counts. | 45 | // Counts. |
| 39 | uint32_t numTris; | 46 | uint32_t numTris; |
| 40 | uint32_t numPositions; | 47 | uint32_t numPositions; |
| 41 | uint32_t numNormals; | ||
| 42 | uint32_t numTexcoords; | 48 | uint32_t numTexcoords; |
| 49 | uint32_t numNormals; | ||
| 43 | // Offsets. | 50 | // Offsets. |
| 44 | uint32_t offsetTris; | 51 | uint32_t offsetTris; |
| 45 | uint32_t offsetPositions; | 52 | uint32_t offsetPositions; |
| 46 | uint32_t offsetNormals; | ||
| 47 | uint32_t offsetTexcoords; | 53 | uint32_t offsetTexcoords; |
| 54 | uint32_t offsetNormals; | ||
| 48 | /* | 55 | /* |
| 49 | [triangles] -- numTris mdTri | 56 | [triangles] -- numTris mdTri |
| 50 | [positions] -- numPositions mdVec3 | 57 | [positions] -- numPositions mdVec3 |
| 51 | [normals] -- numNormals mdVec3 | ||
| 52 | [texcoords] -- numTexcoords mdVec2 | 58 | [texcoords] -- numTexcoords mdVec2 |
| 59 | [normals] -- numNormals mdVec3 | ||
| 53 | */ | 60 | */ |
| 54 | uint8_t data[]; | 61 | uint8_t data[]; |
| 55 | } IndexedModel; | 62 | } IndexedModel; |
| @@ -61,6 +68,7 @@ typedef enum ModelType { | |||
| 61 | 68 | ||
| 62 | typedef struct Model { | 69 | typedef struct Model { |
| 63 | uint32_t type; | 70 | uint32_t type; |
| 71 | Material material; | ||
| 64 | union { | 72 | union { |
| 65 | FlatModel flat; | 73 | FlatModel flat; |
| 66 | IndexedModel indexed; | 74 | IndexedModel indexed; |
