LibGame  v0.4.0
The LG Game Engine - Copyright (C) 2024-2025 ETMSoftware
lg_vertex.h
1 /*
2  * LibGame - Copyright (C) Emmanuel Thomas-Maurin 2011-2025
3  * All rights reserved
4  */
5 
6 #ifndef LG_VERTEX_H
7 #define LG_VERTEX_H
8 
9 #define LG_MESH_MAX_WEIGHTS 4
10 
11 /*
12  * === Vertex* struct's ===
13  */
14 
15 /* Coords (only) */
16 typedef struct __attribute__((packed, aligned(4))) {
17  float x;
18  float y;
19  float z;
20 } Vertex;
21 
22 /* Coords + (texture) uv coords */
23 typedef struct __attribute__((packed, aligned(4))) {
24  float x;
25  float y;
26  float z;
27  uint16_t u;
28  uint16_t v;
29 } Vertex_uv;
30 
31 /* Coords + normals */
32 typedef struct __attribute__((packed, aligned(4))) {
33  float x;
34  float y;
35  float z;
36  int16_t n_x;
37  int16_t n_y;
38  int16_t n_z;
39  uint16_t flag1; /* Explicit padding to align to 4 bytes boundaries */
40 } Vertex_n;
41 
42 /*
43  * === The most used/useful vertex struct, appropriate for LG_Mesh's VBOs ===
44  */
45 /* Coords + uv coords + normals */
46 typedef struct __attribute__((packed, aligned(4))) {
47  float x; /* sizeof(float) = 4 */
48  float y;
49  float z;
50  uint16_t u; /* sizeof(unsigned short) = 2 */
51  uint16_t v;
52  int16_t n_x; /* sizeof(short) = 2 */
53  int16_t n_y;
54  int16_t n_z;
55  uint16_t flag1; /* Explicit padding to align to 4 bytes boundaries */
56 } Vertex_uv_n;
57 
58 /*
59  * === Skinned vertex struct ===
60  */
61 /* Coords + uv coords + normals + bones indices/weights */
62 typedef struct __attribute__((packed, aligned(4))) {
63  float x; /* sizeof(float) = 4 */
64  float y;
65  float z;
66  uint16_t u; /* sizeof(unsigned short) = 2 */
67  uint16_t v;
68  int16_t n_x; /* sizeof(short) = 2 */
69  int16_t n_y;
70  int16_t n_z;
71  uint16_t flag1; /* Explicit padding to align to 4 bytes boundaries */
72  uint8_t i[LG_MESH_MAX_WEIGHTS];
73  uint16_t w[LG_MESH_MAX_WEIGHTS];
75 
76 /*
77  * === Very useful vertex struct, appropriate for Lines3D_VB's vb_array/vb_ptr ===
78  */
79 /* Coords + colors */
80 typedef struct __attribute__((packed, aligned(4))) {
81  float x;
82  float y;
83  float z;
84  uint8_t r;
85  uint8_t g;
86  uint8_t b;
87  uint8_t a;
88 } Vertex_rgba;
89 
90 /*
91  * No Vertex_rgba_uv because we don't want/need colors and tex coords at the same time
92  * (at least so far).
93  */
94 
95 /* Coords + colors + normals */
96 typedef struct __attribute__((packed, aligned(4))) {
97  float x;
98  float y;
99  float z;
100  uint8_t r;
101  uint8_t g;
102  uint8_t b;
103  uint8_t a;
104  int16_t n_x;
105  int16_t n_y;
106  int16_t n_z;
107  uint16_t flag1; /* Explicit padding to align to 4 bytes boundaries */
108 } Vertex_rgba_n;
109 
110 /* RGBA color as 4 unsigned bytes (ie in range [0, 255]) */
111 typedef struct __attribute__((packed, aligned(4))) {
112  uint8_t r;
113  uint8_t g;
114  uint8_t b;
115  uint8_t a;
116 } LG_Color_u;
117 
118 /* RGBA color as 4 normalized float's (ie in range [0.0, 1.0]) */
119 typedef struct __attribute__((packed, aligned(4))) {
120  float r;
121  float g;
122  float b;
123  float a;
124 } LG_Color_f;
125 
126 Vertex lg_vertex(float, float, float);
127 
129 
130 Vertex_uv lg_vertex_uv(float, float, float, uint16_t, uint16_t);
131 
132 Vertex_n lg_vertex_n(float, float, float, int16_t, int16_t, int16_t);
133 
134 Vertex_uv_n lg_vertex_uv_n(float, float, float, uint16_t, uint16_t, int16_t, int16_t, int16_t);
135 
136 Vertex_uvn_iw lg_vertex_uvn_iw(float, float, float, uint16_t, uint16_t, int16_t, int16_t, int16_t, uint8_t[4], uint16_t[4]);
137 
138 Vertex_rgba lg_vertex_rgba(float, float, float, LG_Color_u);
139 
141 
142 Vertex_rgba_n lg_vertex_rgba_n(float, float, float, LG_Color_u, int16_t, int16_t, int16_t);
143 
144 LG_Color_u lg_color_u(uint8_t, uint8_t, uint8_t, uint8_t);
145 
146 LG_Color_f lg_color_f(float, float, float, float);
147 
149 
151 
152 void lg_vertex_sizes_info();
153 
154 #endif /* LG_VERTEX_H */
lg_color_u_from_f
LG_Color_u lg_color_u_from_f(LG_Color_f c)
Definition: lg_vertex.c:242
Vertex_uv
Definition: lg_vertex.h:23
lg_vertex_uv
Vertex_uv lg_vertex_uv(float x, float y, float z, uint16_t u, uint16_t v)
Definition: lg_vertex.c:75
Vertex_rgba_n
Definition: lg_vertex.h:96
lg_vertex_from_vec3
Vertex lg_vertex_from_vec3(vec3_t v)
Definition: lg_vertex.c:54
Vertex_uv_n
Definition: lg_vertex.h:46
lg_vertex_n
Vertex_n lg_vertex_n(float x, float y, float z, int16_t n_x, int16_t n_y, int16_t n_z)
Definition: lg_vertex.c:93
Vertex_n
Definition: lg_vertex.h:32
lg_color_f
LG_Color_f lg_color_f(float r, float g, float b, float a)
Definition: lg_vertex.c:224
Vertex
Definition: lg_vertex.h:16
vec3_t
Definition: math_3d.h:128
LG_Color_f
Definition: lg_vertex.h:119
lg_vertex_sizes_info
void lg_vertex_sizes_info()
Definition: lg_vertex.c:268
LG_Color_u
Definition: lg_vertex.h:111
lg_vertex_rgba
Vertex_rgba lg_vertex_rgba(float x, float y, float z, LG_Color_u c)
Definition: lg_vertex.c:159
lg_vertex_rgba_n
Vertex_rgba_n lg_vertex_rgba_n(float x, float y, float z, LG_Color_u c, int16_t n_x, int16_t n_y, int16_t n_z)
Definition: lg_vertex.c:192
lg_vertex
Vertex lg_vertex(float x, float y, float z)
Definition: lg_vertex.c:37
lg_vertex_rgba_from_vec3
Vertex_rgba lg_vertex_rgba_from_vec3(vec3_t v, LG_Color_u c)
Definition: lg_vertex.c:173
Vertex_uvn_iw
Definition: lg_vertex.h:62
Vertex_rgba
Definition: lg_vertex.h:80
lg_vertex_uvn_iw
Vertex_uvn_iw lg_vertex_uvn_iw(float x, float y, float z, uint16_t u, uint16_t v, int16_t n_x, int16_t n_y, int16_t n_z, uint8_t i[4], uint16_t w[4])
Definition: lg_vertex.c:141
lg_color_u
LG_Color_u lg_color_u(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
Definition: lg_vertex.c:208
lg_vertex_uv_n
Vertex_uv_n lg_vertex_uv_n(float x, float y, float z, uint16_t u, uint16_t v, int16_t n_x, int16_t n_y, int16_t n_z)
Definition: lg_vertex.c:115
lg_color_f_from_u
LG_Color_f lg_color_f_from_u(LG_Color_u c)
Definition: lg_vertex.c:258