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