8#include "stb/stb_image.h"
33 unsigned char *data = stbi_load(path, &w, &h, &channels, 0);
36 printf(
"Failed to load image: %s\n", path);
41 glGenTextures(1, &textureID);
46 glBindTexture(GL_TEXTURE_2D, textureID);
53 printf(
"LOADING: %s %d\n", path, min_filter == GL_LINEAR_MIPMAP_LINEAR);
54 glTexImage2D(GL_TEXTURE_2D, 0, GL_SRGB8, w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
56 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter);
57 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter);
58 float max_aniso = 0.0f;
59 glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &max_aniso);
60 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT,
MIN(8.0f, max_aniso));
61 glGenerateMipmap(GL_TEXTURE_2D);
63 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_s);
64 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap_t);
68 printf(
"LOADING: %s %d\n", path, min_filter == GL_LINEAR_MIPMAP_LINEAR);
69 glTexImage2D(GL_TEXTURE_2D, 0, GL_SRGB8_ALPHA8, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
71 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter);
72 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter);
73 float max_aniso = 0.0f;
74 glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &max_aniso);
75 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT,
MIN(8.0f, max_aniso));
76 glGenerateMipmap(GL_TEXTURE_2D);
78 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_s);
79 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap_t);
88 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
90 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter);
91 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter);
92 float max_aniso = 0.0f;
93 glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &max_aniso);
94 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT,
MIN(8.0f, max_aniso));
95 glGenerateMipmap(GL_TEXTURE_2D);
97 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_s);
98 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap_t);
100 else if (channels == 4)
102 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
104 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter);
105 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter);
107 float max_aniso = 0.0f;
108 glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &max_aniso);
109 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT,
MIN(8.0f, max_aniso));
111 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_s);
112 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap_t);
114 glGenerateMipmap(GL_TEXTURE_2D);
119 else if (channels == 2)
121 glTexImage2D(GL_TEXTURE_2D, 0, GL_RG8, w, h, 0, GL_RG, GL_UNSIGNED_BYTE, data);
123 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter);
124 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter);
125 float max_aniso = 0.0f;
126 glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &max_aniso);
127 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT,
MIN(8.0f, max_aniso));
128 glGenerateMipmap(GL_TEXTURE_2D);
130 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_s);
131 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap_t);
134 else if (channels == 1)
136 glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, w, h, 0, GL_RED, GL_UNSIGNED_BYTE, data);
138 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter);
139 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter);
140 float max_aniso = 0.0f;
141 glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &max_aniso);
142 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT,
MIN(8.0f, max_aniso));
143 glGenerateMipmap(GL_TEXTURE_2D);
145 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_s);
146 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap_t);
153 stbi_image_free(data);
161 (
const char * path )
164 const char a[6][12] =
166 "/pos_x.hdr",
"/neg_x.hdr",
"/pos_y.hdr",
"/neg_y.hdr",
"/pos_z.hdr",
"/neg_z.hdr"
170 glGenTextures(1, &cubemap);
171 glBindTexture(GL_TEXTURE_CUBE_MAP, cubemap);
172 for (
int i = 0; i < 6; i++)
175 stbi_set_flip_vertically_on_load(0);
181 int w = 0, h = 0, channels = 0;
183 float * data = stbi_loadf(c, &w, &h, &channels, 0);
184 printf(
"W %d H %d C %d\n", w, h, channels);
188 printf(
"Failed to load image: %s\n", c);
195 glPixelStorei(GL_UNPACK_ALIGNMENT, 3);
196 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB16F, w, h, 0, GL_RGB, GL_FLOAT, NULL);
197 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, 0, 0, w, h, GL_RGB, GL_FLOAT, data);
201 glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
202 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGBA16F, w, h, 0, GL_RGBA, GL_FLOAT, NULL);
203 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, 0, 0, w, h, GL_RGBA, GL_FLOAT, data);
207 stbi_image_free(data);
211 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
212 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
213 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
214 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
215 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
222 FILE* file = fopen(filepath,
"r");
224 printf(
"Failed to open LUT file: %s\n", filepath);
231 while (fgets(line,
sizeof(line), file)) {
232 if (strncmp(line,
"LUT_3D_SIZE", 11) == 0) {
233 sscanf(line,
"LUT_3D_SIZE %d", &lut_size);
238 if (lut_size != 33) {
239 printf(
"Warning: Expected LUT size 33, got %d\n", lut_size);
242 int total_elements = lut_size * lut_size * lut_size * 3;
243 float* lut_data = (
float*)malloc(total_elements *
sizeof(
float));
246 while (fgets(line,
sizeof(line), file)) {
247 if (line[0] ==
'#' || line[0] ==
'\n' || line[0] ==
'\r')
continue;
250 if (sscanf(line,
"%f %f %f", &r, &g, &b) == 3) {
251 lut_data[index++] = r;
252 lut_data[index++] = g;
253 lut_data[index++] = b;
259 glGenTextures(1, &lut_texture);
260 glBindTexture(GL_TEXTURE_3D, lut_texture);
262 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
263 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
264 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
266 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
267 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
269 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB16F, lut_size, lut_size, lut_size, 0, GL_RGB, GL_FLOAT, lut_data);
280 unsigned char *data = stbi_load(image->
path, &w, &h, &channels, 0);
285 printf(
"Failed to load image: %s\\n", image->
path);
292int add_image_to_registry(
char * filename, GLint min_filter, GLint mag_filter, GLint wrap_s, GLint wrap_t,
bool sRGB)
295 GLuint i =
load_texture(filename, min_filter, mag_filter, wrap_s, wrap_t, sRGB);
296 if (i == 0)
return -1;
298 GLuint64 handle = glGetTextureHandleARB(i);
300 glMakeTextureHandleResidentARB(handle);
305 strncpy(image->
path, filename, 255);
306 image->
path[255] =
'\0';
320 strcat(ui_name, name);
321 strcat(ui_name,
".bin");
323 FILE * f = fopen(ui_name,
"wb");
330 fwrite(&m->
uID,
sizeof(uint32_t), 1, f);
331 fwrite(&m->
id,
sizeof(
char), 256, f);
339 fwrite(tb,
sizeof(
TextBox), 1, f);
353 strcat(ui_name, name);
354 strcat(ui_name,
".bin");
357 FILE * f = fopen(ui_name,
"rb");
370 fread(&m->
uID,
sizeof(uint32_t), 1, f);
371 fread(&m->
id,
sizeof(
char), 256, f);
379 fread(tb,
sizeof(
TextBox), 1, f);
399 glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
400 glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
401 glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
402 glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
403 glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
412 fwrite(&mn->
active,
sizeof(
bool), 1, f);
413 fwrite(&mn->
id,
sizeof(
int), 1, f);
414 fwrite(&mn->
parent,
sizeof(
int), 1, f);
420 fwrite(&mn->
mesh,
sizeof(
int), 1, f);
421 fwrite(&mn->
asset,
sizeof(
int), 1, f);
422 fwrite(&mn->
skin,
sizeof(
int), 1, f);
442 fwrite(&uv_map,
sizeof(
bool), 1, f);
448 fwrite(&uv_map,
sizeof(
bool), 1, f);
459 fwrite(&
id,
sizeof(
int), 1, f);
464 fwrite(&zero,
sizeof(
int), 1, f);
470 int id = mn->
ent->
id;
471 fwrite(&
id,
sizeof(
int), 1, f);
476 fwrite(&zero,
sizeof(
int), 1, f);
505 char scene_name[256];
507 strcat(scene_name, name);
508 strcat(scene_name,
".bin");
512 strcat(lm_name, name);
513 strcat(lm_name,
"_lm.bin");
515 char light_name[256];
517 strcat(light_name, name);
518 strcat(light_name,
"_lights.bin");
520 char aportal_name[256];
522 strcat(aportal_name, name);
523 strcat(aportal_name,
"_aportals.bin");
525 char rprobe_name[256];
527 strcat(rprobe_name, name);
528 strcat(rprobe_name,
"_rprobes.bin");
530 char lprobe_name[256];
532 strcat(lprobe_name, name);
533 strcat(lprobe_name,
"_lprobes.bin");
535 char aprobe_name[256];
537 strcat(aprobe_name, name);
538 strcat(aprobe_name,
"_aprobes.bin");
540 char scene_apv_name[256];
542 strcat(scene_apv_name, name);
543 strcat(scene_apv_name,
"_scene_apvs.bin");
546 FILE * f = fopen(scene_name,
"wb");
547 printf(
"%s\n", scene_name);
600 fwrite(&t,
sizeof(
bool), 1, f);
607 fwrite(&fl,
sizeof(
bool), 1, f);
617 fwrite(&uvi->
mesh_node,
sizeof(
int), 1, f);
618 fwrite(&uvi->
tris.
count,
sizeof(
size_t), 1, f);
648 Image * image = &images[i];
649 fwrite(image->
path,
sizeof(
char), 256, f);
650 fwrite(image->
mime_type,
sizeof(
char), 256, f);
651 fwrite(image->
name,
sizeof(
char), 256, f);
652 fwrite(&image->
min_filter,
sizeof(GLint), 1, f);
653 fwrite(&image->
mag_filter,
sizeof(GLint), 1, f);
654 fwrite(&image->
wrap_s,
sizeof(GLint), 1, f);
655 fwrite(&image->
wrap_t,
sizeof(GLint), 1, f);
656 fwrite(&image->
sRGB,
sizeof(
bool), 1, f);
659 printf(
"MATERIALS\n");
668 fwrite(mat->
name,
sizeof(
char), 256, f);
672 fwrite(&mat->
ka,
sizeof(
vec4), 1, f);
673 fwrite(&mat->
kd,
sizeof(
vec4), 1, f);
674 fwrite(&mat->
ks,
sizeof(
vec4), 1, f);
675 fwrite(&mat->
ke,
sizeof(
vec4), 1, f);
683 fwrite(&mat->
arm_tex,
sizeof(
int), 1, f);
684 fwrite(&mat->
ao_tex,
sizeof(
int), 1, f);
685 fwrite(&mat->
mr_tex,
sizeof(
int), 1, f);
689 fwrite(&mat->
metallic,
sizeof(
float), 1, f);
690 fwrite(&mat->
roughness,
sizeof(
float), 1, f);
706 Mesh * m = &meshes[i];
707 fwrite(m->
name,
sizeof(
char), 256, f);
708 fwrite(&m->
bvh_prim,
sizeof(
bool), 1, f);
709 fwrite(&m->
asset_id,
sizeof(
size_t), 1, f);
710 fwrite(&m->
id,
sizeof(
size_t), 1, f);
712 fwrite(&m->
aabb,
sizeof(
AABB), 1, f);
717 fwrite(&m->
hulls.
count,
sizeof(
size_t), 1, f);
725 fwrite(&h->
faces.
count,
sizeof(
size_t), 1, f);
730 fwrite(&h->
aabb,
sizeof(
AABB), 1, f);
738 fwrite(&m->
tris.
count,
sizeof(
size_t), 1, f);
755 fwrite(&m->
nodes.
count,
sizeof(
size_t), 1, f);
766 printf(
"MESH NODES\n");
798 Asset * asset = &assets[i];
800 fwrite(asset->
path,
sizeof(
char), 256, f);
806 fwrite(&asset->
node_count,
sizeof(
size_t), 1, f);
807 printf(
"NODE COUNT: %zu\n", asset->
node_count);
813 fwrite(&asset->
skin_count,
sizeof(
size_t), 1, f);
824 fwrite(anim->
name,
sizeof(
char), 256, f);
825 fwrite(&anim->
asset_id,
sizeof(
int), 1, f);
830 fwrite(&sampler->
count,
sizeof(
int), 1, f);
831 if (sampler->
times) fwrite(sampler->
times,
sizeof(
float), sampler->
count, f);
832 fwrite(&sampler->
elem_count,
sizeof(
int), 1, f);
846 fwrite(&asset->
asset_id,
sizeof(
int), 1, f);
847 fwrite(&asset->
aabb,
sizeof(
AABB), 1, f);
853 printf(
"ASSET INSTANCES\n");
859 fwrite(&ai->
free,
sizeof(
bool), 1, f);
861 if (ai->
free)
continue;
863 fwrite(&ai->
first_skin,
sizeof(
size_t), 1, f);
864 fwrite(&ai->
skin_count,
sizeof(
size_t), 1, f);
866 fwrite(&ai->
asset_id,
sizeof(
int), 1, f);
868 fwrite(&ai->
node_count,
sizeof(
size_t), 1, f);
870 fwrite(&ai->
aabb,
sizeof(
AABB), 1, f);
874 printf(
"ENTITIES\n");
880 fwrite(&ent->
free,
sizeof(
bool), 1, f);
882 if (ent->
free)
continue;
884 fwrite(&ent->
id,
sizeof(
size_t), 1, f);
885 fwrite(&ent->
mesh_node,
sizeof(
int), 1, f);
886 fwrite(&ent->
skin,
sizeof(
int), 1, f);
887 fwrite(&ent->
aabb,
sizeof(
AABB), 1, f);
893 fwrite(&
id,
sizeof(
int), 1, f);
898 fwrite(&n1,
sizeof(
int), 1, f);
904 int id = ent->
pc->
id;
905 fwrite(&
id,
sizeof(
int), 1, f);
911 fwrite(&n1,
sizeof(
int), 1, f);
927 fwrite(&pc->
free,
sizeof(
bool), 1, f);
928 if (pc->
free)
continue;
931 fwrite(&pc->
id,
sizeof(
size_t), 1, f);
932 fwrite(&pc->
at_rest,
sizeof(
bool), 1, f);
933 fwrite(&pc->
player_pc,
sizeof(
bool), 1, f);
934 fwrite(&pc->
mass,
sizeof(
float), 1, f);
936 fwrite(&pc->
mu,
sizeof(
float), 1, f);
938 fwrite(&pc->
vel,
sizeof(
vec3), 1, f);
945 fwrite(&pc->
aabb,
sizeof(
AABB), 1, f);
952 int id = pc->
ent->
id;
953 fwrite(&
id,
sizeof(
int), 1, f);
959 fwrite(&n1,
sizeof(
int), 1, f);
970 fwrite(&ac->
free,
sizeof(
bool), 1, f);
971 if (ac->
free)
continue;
979 fwrite(&t->
loop,
sizeof(
bool), 1, f);
980 fwrite(&t->
active,
sizeof(
bool), 1, f);
982 fwrite(&t->
duration,
sizeof(
float), 1, f);
983 fwrite(&t->
kf_count,
sizeof(
int), 1, f);
985 for (
int k = 0; k < t->
kf_count; k++)
989 fwrite(&kf->
time,
sizeof(
float), 1, f);
993 fwrite(&kf->
val.v,
sizeof(
float), 1, f);
996 fwrite(&kf->
val.v3,
sizeof(
vec3), 1, f);
999 fwrite(&kf->
val.i,
sizeof(
int), 1, f);
1017 int id = ac->
ent->
id;
1018 fwrite(&
id,
sizeof(
int), 1, f);
1023 fwrite(&n1,
sizeof(
int), 1, f);
1045 Font * font = &fonts[i];
1046 fwrite(font,
sizeof(
Font), 1, f);
1101 fread(&mn->
active,
sizeof(
bool), 1, f);
1102 fread(&mn->
id,
sizeof(
int), 1, f);
1103 fread(&mn->
parent,
sizeof(
int), 1, f);
1109 fread(&mn->
mesh,
sizeof(
int), 1, f);
1110 fread(&mn->
asset,
sizeof(
int), 1, f);
1111 fread(&mn->
skin,
sizeof(
int), 1, f);
1127 bool uv_map =
false;
1128 fread(&uv_map,
sizeof(
bool), 1, f);
1147 fread(&pc_id,
sizeof(
int), 1, f);
1159 fread(&ent_id,
sizeof(
int), 1, f);
1209 fread(&v->
count,
sizeof(
size_t), 1, f);
1234 fread(&v->
count,
sizeof(
size_t), 1, f);
1265 char scene_name[256];
1267 strcat(scene_name, name);
1268 strcat(scene_name,
".bin");
1272 strcat(lm_name, name);
1273 strcat(lm_name,
"_lm.bin");
1275 char light_name[256];
1277 strcat(light_name, name);
1278 strcat(light_name,
"_lights.bin");
1280 char aportal_name[256];
1282 strcat(aportal_name, name);
1283 strcat(aportal_name,
"_aportals.bin");
1285 char rprobe_name[256];
1287 strcat(rprobe_name, name);
1288 strcat(rprobe_name,
"_rprobes.bin");
1290 char lprobe_name[256];
1292 strcat(lprobe_name, name);
1293 strcat(lprobe_name,
"_lprobes.bin");
1295 char aprobe_name[256];
1297 strcat(aprobe_name, name);
1298 strcat(aprobe_name,
"_aprobes.bin");
1300 char scene_apv_name[256];
1302 strcat(scene_apv_name, name);
1303 strcat(scene_apv_name,
"_scene_apvs.bin");
1306 FILE * f = fopen(scene_name,
"rb");
1308 printf(
"%s\n", scene_name);
1321 printf(
"GLOBALS\n");
1410 fread(&t,
sizeof(
bool), 1, f);
1444 fread(&uvi->
mesh_node,
sizeof(
int), 1, f);
1445 fread(&uvi->
tris.
count,
sizeof(
size_t), 1, f);
1489 Image * image = &images[i];
1497 glDeleteTextures(1, &image->
i);
1523 Image * image = &images[i];
1524 fread(image->
path,
sizeof(
char), 256, f);
1525 fread(image->
mime_type,
sizeof(
char), 256, f);
1526 fread(image->
name,
sizeof(
char), 256, f);
1527 fread(&image->
min_filter,
sizeof(GLint), 1, f);
1528 fread(&image->
mag_filter,
sizeof(GLint), 1, f);
1529 fread(&image->
wrap_s,
sizeof(GLint), 1, f);
1530 fread(&image->
wrap_t,
sizeof(GLint), 1, f);
1531 fread(&image->
sRGB,
sizeof(
bool), 1, f);
1535 GLuint64 handle = glGetTextureHandleARB(i);
1537 glMakeTextureHandleResidentARB(handle);
1545 printf(
"MATERIALS\n");
1573 fread(mat->
name,
sizeof(
char), 256, f);
1577 fread(&mat->
ka,
sizeof(
vec4), 1, f);
1578 fread(&mat->
kd,
sizeof(
vec4), 1, f);
1579 fread(&mat->
ks,
sizeof(
vec4), 1, f);
1580 fread(&mat->
ke,
sizeof(
vec4), 1, f);
1589 fread(&mat->
arm_tex,
sizeof(
int), 1, f);
1590 fread(&mat->
ao_tex,
sizeof(
int), 1, f);
1591 fread(&mat->
mr_tex,
sizeof(
int), 1, f);
1595 fread(&mat->
metallic,
sizeof(
float), 1, f);
1596 fread(&mat->
roughness,
sizeof(
float), 1, f);
1613 Mesh * m = &meshes[i];
1661 Mesh * m = &meshes[i];
1662 fread(m->
name,
sizeof(
char), 256, f);
1663 fread(&m->
bvh_prim,
sizeof(
bool), 1, f);
1664 fread(&m->
asset_id,
sizeof(
size_t), 1, f);
1665 fread(&m->
id,
sizeof(
size_t), 1, f);
1667 fread(&m->
aabb,
sizeof(
AABB), 1, f);
1687 fread(&m->
hulls.
count,
sizeof(
size_t), 1, f);
1756 fread(&h->
aabb,
sizeof(
AABB), 1, f);
1843 printf(
"MESH NODES\n");
1936 Asset * asset = &assets[i];
1990 Asset * asset = &assets[i];
1992 fread(asset->
path,
sizeof(
char), 256, f);
2010 fread(&asset->
node_count,
sizeof(
size_t), 1, f);
2011 printf(
"NODE COUNT: %zu\n", asset->
node_count);
2023 asset->
nodes = NULL;
2026 fread(&asset->
skin_count,
sizeof(
size_t), 1, f);
2038 asset->
skins = NULL;
2050 fread(anim->
name,
sizeof(
char), 256, f);
2051 fread(&anim->
asset_id,
sizeof(
int), 1, f);
2056 fread(&sampler->
count,
sizeof(
int), 1, f);
2057 if (sampler->
count > 0)
2060 sampler->
times = malloc(
sizeof(
float) * sampler->
count);
2062 fread(sampler->
times,
sizeof(
float), sampler->
count, f);
2066 sampler->
times = NULL;
2068 fread(&sampler->
elem_count,
sizeof(
int), 1, f);
2109 fread(&asset->
asset_id,
sizeof(
int), 1, f);
2110 fread(&asset->
aabb,
sizeof(
AABB), 1, f);
2116 printf(
"ASSET INSTANCES\n");
2122 fread(&ai->
free,
sizeof(
bool), 1, f);
2124 if (ai->
free)
continue;
2126 fread(&ai->
first_skin,
sizeof(
size_t), 1, f);
2127 fread(&ai->
skin_count,
sizeof(
size_t), 1, f);
2129 fread(&ai->
asset_id,
sizeof(
int), 1, f);
2131 fread(&ai->
node_count,
sizeof(
size_t), 1, f);
2133 fread(&ai->
aabb,
sizeof(
AABB), 1, f);
2137 printf(
"ENTITIES\n");
2143 fread(&ent->
free,
sizeof(
bool), 1, f);
2145 if (ent->
free)
continue;
2147 fread(&ent->
id,
sizeof(
size_t), 1, f);
2148 fread(&ent->
mesh_node,
sizeof(
int), 1, f);
2149 fread(&ent->
skin,
sizeof(
int), 1, f);
2150 fread(&ent->
aabb,
sizeof(
AABB), 1, f);
2153 int instance_id = -1;
2154 fread(&instance_id,
sizeof(
int), 1, f);
2155 if (instance_id != -1)
2164 fread(&pc_id,
sizeof(
int), 1, f);
2182 fread(&pc->
free,
sizeof(
bool), 1, f);
2183 if (pc->
free)
continue;
2186 fread(&pc->
id,
sizeof(
size_t), 1, f);
2187 fread(&pc->
at_rest,
sizeof(
bool), 1, f);
2188 fread(&pc->
player_pc,
sizeof(
bool), 1, f);
2189 fread(&pc->
mass,
sizeof(
float), 1, f);
2191 fread(&pc->
mu,
sizeof(
float), 1, f);
2193 fread(&pc->
vel,
sizeof(
vec3), 1, f);
2200 fread(&pc->
aabb,
sizeof(
AABB), 1, f);
2205 fread(&ent_id,
sizeof(
int), 1, f);
2222 fread(&ac->
free,
sizeof(
bool), 1, f);
2223 if (ac->
free)
continue;
2231 fread(&t->
loop,
sizeof(
bool), 1, f);
2232 fread(&t->
active,
sizeof(
bool), 1, f);
2234 fread(&t->
duration,
sizeof(
float), 1, f);
2235 fread(&t->
kf_count,
sizeof(
int), 1, f);
2237 for (
int k = 0; k < t->
kf_count; k++)
2241 fread(&kf->
time,
sizeof(
float), 1, f);
2245 fread(&kf->
val.v,
sizeof(
float), 1, f);
2248 fread(&kf->
val.v3,
sizeof(
vec3), 1, f);
2251 fread(&kf->
val.i,
sizeof(
int), 1, f);
2271 fread(&ent_id,
sizeof(
int), 1, f);
2321 Font * font = &fonts[i];
2322 fread(font,
sizeof(
Font), 1, f);
2390 printf(
"FINISHED\n");
2402 char scene_name[256];
2404 strcat(scene_name, name);
2405 strcat(scene_name,
".bin");
2409 strcat(lm_name, name);
2410 strcat(lm_name,
"_lm.bin");
2412 char light_name[256];
2414 strcat(light_name, name);
2415 strcat(light_name,
"_lights.bin");
2417 char aportal_name[256];
2419 strcat(aportal_name, name);
2420 strcat(aportal_name,
"_aportals.bin");
2422 char rprobe_name[256];
2424 strcat(rprobe_name, name);
2425 strcat(rprobe_name,
"_rprobes.bin");
2427 char lprobe_name[256];
2429 strcat(lprobe_name, name);
2430 strcat(lprobe_name,
"_lprobes.bin");
2432 char aprobe_name[256];
2434 strcat(aprobe_name, name);
2435 strcat(aprobe_name,
"_aprobes.bin");
2437 char scene_apv_name[256];
2439 strcat(scene_apv_name, name);
2440 strcat(scene_apv_name,
"_scene_apvs.bin");
2455 char scene_name[256];
2457 strcat(scene_name, name);
2458 strcat(scene_name,
".bin");
2462 strcat(lm_name, name);
2463 strcat(lm_name,
"_lm.bin");
2465 char light_name[256];
2467 strcat(light_name, name);
2468 strcat(light_name,
"_lights.bin");
2470 char aportal_name[256];
2472 strcat(aportal_name, name);
2473 strcat(aportal_name,
"_aportals.bin");
2475 char rprobe_name[256];
2477 strcat(rprobe_name, name);
2478 strcat(rprobe_name,
"_rprobes.bin");
2480 char lprobe_name[256];
2482 strcat(lprobe_name, name);
2483 strcat(lprobe_name,
"_lprobes.bin");
2485 char aprobe_name[256];
2487 strcat(aprobe_name, name);
2488 strcat(aprobe_name,
"_aprobes.bin");
2490 char scene_apv_name[256];
2492 strcat(scene_apv_name, name);
2493 strcat(scene_apv_name,
"_scene_apvs.bin");
2519 FILE * f = fopen(filename,
"wb");
2522 fwrite(&vec->
count,
sizeof(
size_t), 1, f);
2531 FILE * f = fopen(filename,
"rb");
2545 FILE * f = fopen(filename,
"wb");
2548 fwrite(&vec->
count,
sizeof(
size_t), 1, f);
2557 FILE * f = fopen(filename,
"rb");
2571 FILE * f = fopen(filename,
"wb");
2575 fwrite(&vec->
count,
sizeof(
size_t), 1, f);
2585 FILE * f = fopen(filename,
"rb");
2609 FILE * f = fopen(filename,
"wb");
2612 fwrite(&vec->
count,
sizeof(
size_t), 1, f);
2616 for (
int i = 0; i < vec->
count; i++)
2621 fwrite(&p->
pos,
sizeof(
vec3), 1, f);
2636 FILE * f = fopen(filename,
"rb");
2640 fread(&count,
sizeof(
size_t), 1, f);
2650 for (
int i = 0; i < vec->
count; i++)
2654 fread(&p->
pos,
sizeof(
vec3), 1, f);
2682 FILE * f = fopen(filename,
"wb");
2702 FILE * f = fopen(filename,
"rb");
Audio probe baking, portal creation, probe volumes, and emitter functions.
The debug editor UI for the engine.
LightBVH light_bvh
The LightBVH, required for baking lighting.
int block_size
How much to allocate in one rect.
int joint_count
The amount of joints.
FILE * LPV_FILE
FILE pointer to the opened binary file.
vec2 LightmapUV[3]
The lightmap UVs stored on UVIslands per MeshFace.
bool noclip
If collision is enabled.
FILE * APV_FILE
FILE pointer to the opened binary file.
Vector mesh_nodes
MeshNodes.
bool free
Indicates an empty slot in ASSET_INSTANCES.
int skin
The GLTFSkin to be modified by this Entity (skeletal animations).
AnimationInterpolation interpolation
unsigned char * occupied
The map of what is currently occupied by LightmapRects.
Vector lights
The Lights that were created (emissive triangles become AREA_LIGHTS).
LightmapUV * uvs
The uvs for each MeshFace on this islands.
SceneData scene_data
SceneData that is more-so scene specific.
AnimationKeyframe kf[64]
The AnimationKeyframes for this track.
GLint min_filter
Refer to OpenGL texture loading.
bool loop
If the animation loops.
int height
Height of the atlas.
ivec3 probe_tex_size
The texture size for lighting probes.
char LPV_PATH[256]
Path to binary file with lighting ProbeVolumes.
size_t skin_count
The amount of GLTFSkins in this instance.
int asset_id
The ID into Globals.assets.
Vector vertex_layouts
VertexLayouts.
int mesh_node
The top-most MeshNode that belongs to this Entity.
int width
Width of the atlas.
#define DEFAULT_TEXTURES
How many dummy default textures are on init.
Vector audio_portals
AudioPortals.
int animation_indices_count
The amount of Animation indices.
int animation_indices[256]
Animation indices into Asset.
AnimationSampler * samplers
bool sRGB
To load in this Image as sRGB.
AnimationTargetType
Animation targets based on type to cast.
GLint wrap_t
Refer to OpenGL texture loading.
AnimationTrack tracks[64]
The AnimationTracks with individual values that occur simultaneously.
int mesh_node
The MeshNode this island belongs to.
int asset_id
The Asset ID in Globals.assets.
int kf_count
The amount of AnimationKeyframes.
vec3 normal
The normal of the island.
AABB aabb
The AABB over each MeshNode via Asset.
Vector tris
size_t indices of the MeshFaces in this island.
mat4 * inverse_bind
The inverse_bind that is computed on load_gltf().
int channels
The amount of channels for an Image (RGBA).
AnimationDataType
Indicates what type of structure the animation is targeting.
#define MAX_RPROBE_MIPS
The amount of mips to allocate for rprobes.
vec3 world_min
Unused but uploaded to main shader.
AABB aabb
AABB over each MeshNode for this Asset.
Globals GLOBALS
Engine Globals.
bool free
If the component is empty.
int * joints
The joints for skeletal animating.
Vector reflection_probes
ReflectionProbes in the scene.
GLint wrap_s
Refer to OpenGL texture loading.
Vector adjacent_indices
size_t indices.
float probe_spacing
The spacing between lighting probes.
float duration
The duration of all of the AnimationKeyframes.
void * data
Stored pointer to data to change during animation.
vec3 world_size
Unused but uploaded to main shader.
bool free
If the Entity is empty.
struct AssetInstance * instance
The AssetInstance that spawned this Entity.
Vector audio_probe_volumes
All of the AudioProbe% volumes, regardless of if they have been loaded yet.
Vector mesh_indices
int - Indices into Globals.meshes which indicate what Meshes are within this Asset.
GLint mag_filter
Refer to OpenGL texture loading.
size_t node_count
The amount of MeshNodes in this instance.
size_t data_byte_offset
The byte offset in the structure we are targeting.
size_t data_index_offset
The index of the structure we are targeting.
size_t id
The ID in ASSET_INSTANCES.
size_t first_skin
Refer to todo.
unsigned char * buf
If available, the raw bytes of the Image.
char name[256]
The name of the Image file.
char APV_PATH[256]
Path to binary file with Audio ProbeVolumes.
Entity * ent
The pointer to the Entity.
Vector materials
Materials.
mat4 * final_mat
The transformation after update_skin_matrices().
GLuint64 handle
The handle for the bindless texture.
int track_count
The amount of AnimationTracks.
GLTFAnimationChannel * channels
AABB aabb
AABB over the entire scene.
bool sample_cubemap
Unused - was used to toggle skybox sampling.
GLuint i
The handle for the texture.
PhysicsComponent * pc
The PhysicsComponent inside of PHYSICS_COMPONENTS.
size_t * indices
The indices sorted when initialized.
size_t id
ID inside of ENTITIES.
AABB aabb
The bounding box over all MeshNodes for this Entity.
Vector nodes
Each node of the BVH.
char directory[256]
Path to directory for the file.
int ibm_accessor
Which GLTFAccessor this refers to.
char path[256]
The path to the Asset.
AnimationDataType data_type
The type of data that is changed during animation.
union AnimationKeyframe::@243377164052067242366020157201307241363031166101 val
char path[256]
The path to the Image.
LightmapData lightmap_data
The loaded lightmap and lightmap configuration for the scene.
void * completion_data
Pointer to the data that is modified on completion.
char name[256]
Modifiable name of the scene.
AnimationTargetType type
The type of the data stored on AnimationKeyframe.
bool active
If this animation is currently running.
char mime_type[256]
Unused, refer to GLTF spec.
Vector islands
The UVIslands on the current lightmap.
float current_time
How long the animation has been running.
LightmapRect rect
The rect that this island allocates.
LightmapAtlas atlas
The atlas settings for the lightmap.
The structure of an Skeletatal Animation loaded in from GLTFAnimation.
The animation component for interpolation between AnimationKeyframes.
Tagged union for the value stored in a keyframe.
Engine-side sampler version of GLTFAnimationSampler with the field allocated.
Tagged union for the value stored in a keyframe.
An Asset after it is loaded in from file into Globals.assets.
A instance of an Asset that retains its node structure but can be duplicated into multiple instances ...
Entity structure that holds components and references to the data it owns.
The channels of an Animation.
The structure of an Skeletatal Animation loaded in from GLTFAnimation.
Where Material textures are saved upon loading from file.
The metadata for the lightmap settings.
The rects that are slotted into thet LightmapAtlas during UV generation for UV lightmaps.
Sections of Meshes that are divided based on Material for batching and DrawCommand ordering purposes.
Adjacent triangles for each MeshFace on a Mesh.
The UVIslands that are generated from contiguous MeshFaces with similar planes for UV lightmapping.
This bridges from MeshNode's MeshFaces to their respective UVIslands.
An unused abstraction for VertexLayouts.
Vector FONTS
All loaded Fonts.
Functions that modify TextBoxes and load Fonts.
void reset_audio_pvs()
Reset audio pvs, frees each slot in the global audio pv slots.
#define AUDIO_NUM_BANDS
The amount of bands to use for audio probe baking.
The ProbeVolumes for APVs and LPVs, controlled by OBBs.
Vector adjacent_portals
int - Vector of AudioPortals that can be seen from this one.
vec3 pos
The position of the AudioPortal.
AudioPortals used for determining paths to transmit sound when emitter and listener are occluded.
FileDirectoryRegistry rprobe_registry
FileDirectoryRegistry ui_registry
FileDirectoryRegistry aportal_registry
FileDirectoryRegistry scene_apv_registry
FileDirectoryRegistry lightmap_registry
FileDirectoryRegistry lprobe_registry
FileDirectoryRegistry light_registry
void create_performance_overlay()
Allocates and initializes position of the TextBoxes for the performance overlay.
FileDirectoryRegistry scene_registry
FileDirectoryRegistry aprobe_registry
Vector hull_faces
HullFaces that are generated after incremental_hull() that combine contiguous triangles into singular...
CollisionData cd
Tagged union for collision options.
Vector vertices
Points that initially copy the Mesh vertices but then are deduplicated and modified in incremental_hu...
mat3 inverse_world
PhysicsComponent.inverse_inertia transformed by rotation into world space for the current step.
size_t id
The ID in PHYSICS_COMPONENTS.
Vector faces
MeshFaces that initially copy the Mesh faces but then are modified in incremental_hull().
bool player_pc
If this is the Player PhysicsComponent.
vec3 centroid
The center of the hull.
mat3 inverse_inertia
IIA (currently just a calculated box).
AABB aabb
The bounding box of the hull.
float mass
Mass of the component.
AABB aabb
Bounding box of the PC, determined based on Mesh or MeshNode.
vec3 angular_velocity
Rotational velocity.
bool at_rest
If this component is at rest it does not update.
float mu
The friction constant for the component.
Entity * ent
Which Entity this component belongs to.
bool free
If this is an empty component.
vec3 center_of_mass
COM based on the AABB.
float restitution
The restitution (bounce).
The tagged union for collision type, stored in PhysicsComponent.
Convex Hulls that are generated via incremental hull for non-static meshes.
Entity Component used for physics resolution.
int fwd_shader
The corresponding forward rendering shader branch in DYNAMIC_SHADER.
size_t id
The ID inside of Globals.mesh_nodes.
int skin
The GLTFSkin it controls.
LightType light_type
The type of Light.
float normal_scale
Unused - Used to determine how much of the texture normal to use.
char name[256]
The Material path.
Entity * ent
The Entity this MeshNode refers to (all children point to the same Entity as parent).
PhysicsComponent * pc
The physics controller initialized based on data from this MeshNode.
bool skip_directional_uv_lighting
Skips directional Lights and rays go through them.
int children[128]
The children to this node, a global index into Globals.mesh_nodes.
int mesh
The Mesh it references.
int parent
The parent to this node, a global index into Globals.mesh_nodes.
bool active
If the MeshNode can be effected.
PhysicsType physics_mode
The type of physics to apply for the PhysicsComponent that may not have been created yet.
int child_count
The amount of children.
UVMapping * uv_map
The mapping between MeshNodes and UVIslands for uv lightmapping.
vec4 ks
Specular (unused).
bool static_mesh
If this mesh is static (DrawArrays) or dynamic (DrawElements), used to indicate Lightmap status.
int gbuffer_shader
The corresponding gbuffer rendering shader branch in DEPTH_PRE_PASS_SHADER or DEPTH_PRE_PASS_SHADER_M...
int asset
The Asset it comes from.
float alpha_cutoff
Used to discard transparent Materials.
float absorption_coefficients[6]
How much audio is absorbed when hitting this Material.
float scattering_coefficients[6]
How much audio specularly reflects when hitting this Material.
The CPU side structure for Lights.
The Materials parsed in from scene files that determine rendering pipeline setup, uploads,...
MeshNodes that describe the position of Meshes, GLTF nodes for GLTFAnimations, or hold references to ...
TextBox text_boxes[1024]
The TextBoxes.
UIElement elements[1024]
The UIElements.
Glyph * glyphs
Glyphs for each character.
int text_cap
The amount of characters allocated.
uint32_t uID
The index inside of MENUS.
UIContainer containers[1024]
The UIContainers.
char * text
The characters to render.
size_t glyph_count
The amount of Glyphs.
char id[256]
The unique name of this menu.
#define MAX_UI_CONTAINERS
A Font and its Glyphs used for rendering TextBoxes.
A single Glyph in a Font.
A structure holding a Font ID and text to be rendered and transformed with its properties.
UIContainer that contains both TextBoxes and UIElements and can mask and scroll them.
UIElements that are contained within a UIMenu that may receive events, be contained within UIContaine...
void GPU_upload_scene_data()
Uploads current Globals and SceneData structures to the GPU for baking SSBOs.
Important globals for the entire engine and initialization functions that are mainly called on engine...
#define MAX_ASSET_INSTANCES
#define MAX_PHYSICS_COMPONENTS
#define MAX_ANIMATION_COMPONENTS
void load_lightmap_from_binary(LightmapData *ld, const char *name)
Loads a UV lightmap and relevant UVIsland and MeshNode data fro, binary.
void save_lightmap_to_binary(LightmapData *ld, const char *name)
Saves a UV lightmap and relevant UVIsland and MeshNode data to binary.
void reset_lighting_pvs()
Resets current LPVs from their slots in SceneData.LOADED_LIGHTING_PV.
UV Lightmap setup and baking, ReflectionProbe baking, and lighting ProbeVolume baking.
Vector hulls
The ConvexHulls generated if this Mesh is dynamic.
TriangleAdjacency * tri_adjacency
Adjacent triangles allocated per MeshFace.
size_t id
The ID into Globals.meshes.
size_t asset_id
The Asset ID into Globals.assets.
bool static_mesh
This Mesh is static and must create a BVH or if not it must perform incremental_hull.
size_t * bvh_indices
Indices for the BVH, sorted as the BVH is generated.
AABB aabb
The AABB of the mesh.
Vector submeshes
The SubMeshes split via Materials.
Vector tri_aabbs
AABBs for each triangle inside of this Mesh.
char name[256]
The Mesh name assigned on load.
bool bvh_prim
This Mesh has a BVH computed.
Vector tris
The MeshFaces.
Vector vertices
The Points.
A Mesh with geometry data that is either initialized as static or dynamic and split into SubMeshes.
void read_skin(GLTFSkin *skin, FILE *f)
void free_mesh_node(MeshNode *mn)
void scene_save_volumes(const char *name)
Saves only AudioProbes, AudioPortals, and ReflectionProbes.
void save_ui(const char *name)
void read_alloc_vector(Vector *v, size_t byte_size, FILE *f)
void save_vector(const char *filename, Vector *vec)
void load_ui(const char *name)
void load_rprobes(const char *filename, Vector *vec)
void scene_save(const char *name)
Saves an entire scene into separate files.
void write_skin(GLTFSkin *skin, FILE *f)
void free_skin(GLTFSkin *skin)
void save_lprobes(const char *filename, Vector *vec)
unsigned char * open_image(Image *image)
Opens an image in bytes via stb.
void scene_load_volumes(const char *name)
Loads only AudioProbes, AudioPortals, and ReflectionProbes.
GLuint load_cubemap(const char *path)
Loads a cubemap in OpenGL naming convention (must be HDR).
void load_lprobes(const char *filename, Vector *vec)
void load_aportals(const char *filename, Vector *vec)
void load_aprobes(const char *filename)
int add_image_to_registry(char *filename, GLint min_filter, GLint mag_filter, GLint wrap_s, GLint wrap_t, bool sRGB)
Loads an adds an image to Globals.images.
void save_aportals(const char *filename, Vector *vec)
void load_vector(const char *filename, Vector *vec)
void write_mesh_node(MeshNode *mn, FILE *f)
void save_aprobes(const char *filename)
void read_mesh_node(MeshNode *mn, FILE *f)
void scene_load(const char *name)
Loads an entire scene from separate files in FileDirectoryRegistry directories.
GLuint load_texture(const char *path, GLint min_filter, GLint mag_filter, GLint wrap_s, GLint wrap_t, bool sRGB)
Loads a texture through OpenGL.
void reallocate_rprobe_array()
Reallocates RPROBE_CUBE_MAP_ARRAY to new dimensions or when loading.
void read_vector(Vector *v, size_t byte_size, FILE *f)
GLuint load_3d_lut(const char *filepath)
Loads a 3D LUT for postprocessing.
void save_rprobes(const char *filename, Vector *vec)
Saves and loads various files that store engine data.
PhysicsComponent PHYSICS_COMPONENTS[MAX_PHYSICS_COMPONENTS]
Entity ENTITIES[MAX_ENTITIES]
GLuint RPROBE_CUBE_MAP_ARRAY
AnimationComponent ANIMATION_COMPONENTS[MAX_ANIMATION_COMPONENTS]
bool draw_dirty
If we need to reupload and resort transforms in create_and_sort_draw_commands() and upload_instance_d...
AssetInstance ASSET_INSTANCES[MAX_ASSET_INSTANCES]
Nodes for the acceleration structures of BVHs.
void upload_lights()
Uploads all current Lights inside of Globals.lights to the GPU in a triple buffered LIGHT_SSBO.
void upload_material_data()
Uploads Material data to the GPU as MaterialGPU.
void add_all_text_boxes_to_draw_buffer()
Adds all TextBoxes to TEXT_VBO and iterates through each character to push indices to TEXT_EBO.
void add_all_meshes_to_buffer(VertexLayout *layout)
Adds all Meshes that have valid MeshNodes.
The main render pass, data GPU uploads, and SSBO management.
void init_vector(Vector *v, size_t i, size_t type_size)
void * vector_expand(Vector *v, size_t i)
#define CAST_VEC(vec, type)