3#include "SDL2/SDL_timer.h"
34 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 4,
VERTEX_SSBO);
35 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 5,
TRI_SSBO);
36 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 6,
MESH_SSBO);
39 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 9,
PROBE_SSBO);
40 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 10,
RPROBE_SSBO);
50 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 10,
RPROBE_SSBO);
51 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 11,
JOINT_SSBO);
68 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 9,
UI_SSBO);
69 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 10,
RPROBE_SSBO);
70 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 11,
JOINT_SSBO);
73 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 14,
CLUSTER_SSBO);
91 int current_offset = offset;
95 if (mns[i].mesh != mesh->
id || mns[i].
free)
continue;
97 int current_count = 0;
98 mn->
offset = current_offset;
100 for (
int j = 0; j < mesh->
tris.
count; j++)
108 for (
int p = 0; p < 3; p++)
111 verts[current_offset + j * 3 + p].
pos = pts[tri->
indices[p]].
pos;
116 verts[current_offset + j * 3 + p].
uv = pts[tri->
indices[p]].
uv;
128 mn->
count = current_count;
129 current_offset += current_count;
134 for (
int i = 0; i < mesh->
tris.
count; i++)
138 for (
int p = 0; p < 3; p++)
146 verts[offset + i * 3 + p].
uv = pts[tri->
indices[p]].
uv;
161 size_t current_lm_offset = *lm_offset;
169 int current_offset = offset;
170 current_lm_offset = current_offset;
178 int current_count = 0;
187 for (
int p = 0; p < 3; p++)
192 verts[current_offset].
pos = pts[index].
pos;
197 verts[current_offset].
uv = pts[index].
uv;
203 if (!islands)
continue;
208 if (mns[i].mesh != mesh->
id || mns[i].
free || !mns[i].
uv_map)
continue;
227 for (
int p = 0; p < 3; p++)
245 verts[offset + j].
pos = pts[j].
pos;
250 verts[offset + j].
uv = pts[j].
uv;
260 size_t current_lm_offset = *lm_uv_offset;
280 for (
int p = 0; p < 3; p++)
283 indices[offset + count] = tri->
indices[p] + vertex_offset;
292 *lm_uv_offset = current_lm_offset;
312 if (mns[i].mesh != m->
id || mn->
free)
continue;
335 return m->
tris.
count *
sizeof(uint32_t) * 3;
351 glBindBuffer(GL_ARRAY_BUFFER,
layout->vbo);
353 layout->current_offset = 0;
354 layout->current_index_offset = 0;
359 for (
int i = 0; i <
layout->meshes.count; i++)
361 Mesh * m = &meshes[ms[i]];
368 glBufferData(GL_ARRAY_BUFFER,
layout->current_capacity, NULL, GL_DYNAMIC_DRAW);
370 uint32_t * indices = NULL;
378 size_t lm_offset = 0;
380 for (
int i = 0; i <
layout->meshes.count; i++)
382 Mesh * m = &meshes[ms[i]];
387 offset += current_offset;
391 glBufferSubData(GL_ARRAY_BUFFER, 0,
vsize, verts);
394 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,
layout->ebo);
395 glBufferData(GL_ELEMENT_ARRAY_BUFFER,
visize, indices, GL_DYNAMIC_DRAW);
401 if (indices) free(indices);
412 size_t index_count = 0;
416 Mesh * m = &meshes[i];
423 if (mn->
mesh != i || mn->
free)
continue;
450 size_t lm_offset = 0;
453 Mesh * m = &meshes[i];
460 if (mn->
mesh != i || mn->
free)
continue;
469 glBufferData(GL_SHADER_STORAGE_BUFFER,
sizeof(
vec4) * index_count,
LIGHTMAP_DATA.
uvs, GL_STATIC_DRAW);
470 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3,
LIGHTMAP_SSBO);
481 for (
int z = -1; z <= 1; z += 2){
482 for (
int y = -1; y <= 1; y += 2){
483 for (
int x = -1; x <= 1; x += 2){
484 corners[count++] =
vec3_add(aabb->
center, (
vec3){x * aabb->extents.x, y * aabb->extents.y, z * aabb->extents.z});
488 out[0].
pos = corners[1];
489 out[1].
pos = corners[0];
490 out[2].
pos = corners[3];
491 out[3].
pos = corners[2];
492 out[4].
pos = corners[5];
493 out[5].
pos = corners[4];
494 out[6].
pos = corners[7];
495 out[7].
pos = corners[6];
496 out[8].
pos = corners[0];
497 out[9].
pos = corners[2];
498 out[10].
pos = corners[1];
499 out[11].
pos = corners[3];
500 out[12].
pos = corners[4];
501 out[13].
pos = corners[6];
502 out[14].
pos = corners[5];
503 out[15].
pos = corners[7];
504 out[16].
pos = corners[1];
505 out[17].
pos = corners[5];
506 out[18].
pos = corners[0];
507 out[19].
pos = corners[4];
508 out[20].
pos = corners[3];
509 out[21].
pos = corners[7];
510 out[22].
pos = corners[2];
511 out[23].
pos = corners[6];
527 for (
int j = 0; j < 24; j++)
556 for (
int z = -1; z <= 1; z += 2){
557 for (
int y = -1; y <= 1; y += 2){
558 for (
int x = -1; x <= 1; x += 2){
567 out[0].
pos = corners[1];
568 out[1].
pos = corners[0];
569 out[2].
pos = corners[3];
570 out[3].
pos = corners[2];
571 out[4].
pos = corners[5];
572 out[5].
pos = corners[4];
573 out[6].
pos = corners[7];
574 out[7].
pos = corners[6];
575 out[8].
pos = corners[0];
576 out[9].
pos = corners[2];
577 out[10].
pos = corners[1];
578 out[11].
pos = corners[3];
579 out[12].
pos = corners[4];
580 out[13].
pos = corners[6];
581 out[14].
pos = corners[5];
582 out[15].
pos = corners[7];
583 out[16].
pos = corners[1];
584 out[17].
pos = corners[5];
585 out[18].
pos = corners[0];
586 out[19].
pos = corners[4];
587 out[20].
pos = corners[3];
588 out[21].
pos = corners[7];
589 out[22].
pos = corners[2];
590 out[23].
pos = corners[6];
641 Light * l = &lights[i];
651 uint32_t * light_data = (uint32_t*)(
light_ssbo_ptr + light_offset);
673 if (mn->
mesh == -1 || mn->
free)
continue;
678 int closest_counts[3] = {0};
685 Light * l = &lights[j];
702 float highest_val = -INFINITY;
703 int highest_index = -1;
704 for (
int k = 0; k < closest_counts[type]; k++)
706 if (closest[type][k] > highest_val)
708 highest_val = closest[type][k];
712 if (highest_val < d2)
714 closest_indices[type][highest_index] = j;
715 closest[type][highest_index] = d2;
721 closest_indices[type][closest_counts[type]] = j;
722 closest[type][closest_counts[type]++] = d2;
735 int current_offset = 0;
736 for (
int i = 0; i < 3; i++)
739 for (
int j = 0; j < closest_counts[i]; j++)
746 offset += total_count;
773 if (AI->
free)
continue;
801 n->global_matrix =
m4_mul(parent,
n->local_matrix);
803 for (
int c = 0; c <
n->child_count; c++) {
817 if (AI->
free)
continue;
838 if (AI->
free)
continue;
919 GL_SHADER_STORAGE_BUFFER,
922 GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT
928 glUnmapBuffer(GL_SHADER_STORAGE_BUFFER);
964 for (
int i = 0; i < 6; i++) {
968 if (length > 0.00001f) {
969 float inv_len = 1.0f / length;
991 for (
int i = 0; i < 6; i++)
1013 *meshes_frame_cnt = 0;
1021 if (mn->
mesh == -1 || mn->
free)
continue;
1027 meshes_frame[(*meshes_frame_cnt)++] = i;
1038 *draw_command_cnt = 0;
1047 if (mn->
mesh == -1 || mn->
free)
continue;
1112 (*draw_command_cnt)++;
1149 float x = (float)target_w / (
float)base_w;
1150 float y = (float)target_h / (
float)base_h;
1157 if (tb->
text == NULL)
return;
1158 int len = strlen(tb->
text);
1169 for (
int i = 0; i < len; i++){
1170 char ch = tb->
text[i];
1174 if (glyphs[j].
id == ch) {
1181 float x0 = x + g->
xoffset * scale;
1182 float y0 = (y - 7 * scale) + g->
yoffset * scale;
1183 float x1 = x0 + g->
width * scale;
1184 float y1 = y0 + g->
height * scale;
1189 vec2 center = (
vec2){(x1-x0) / 2 + x0, (y1-y0)/2 + y0};
1195 v[0] = (
TextVertex){.pos = (
vec2){x0, y0}, .uv = (
vec2){u0, v0}, .center = center, .color = tb->
color, .fill = tb->
fill, .state = 0, .uID = current_box};
1197 v[1] = (
TextVertex){.pos = (
vec2){x1, y0}, .uv = (
vec2){u1, v0}, .center = center, .color = tb->
color, .fill = tb->
fill, .state = 0, .uID = current_box};
1199 v[2] = (
TextVertex){.pos = (
vec2){x0, y1}, .uv = (
vec2){u0, v1}, .center = center, .color = tb->
color, .fill = tb->
fill, .state = 0, .uID = current_box};
1201 v[3] = (
TextVertex){.pos = (
vec2){x1, y1}, .uv = (
vec2){u1, v1}, .center = center, .color = tb->
color, .fill = tb->
fill, .state = 0, .uID = current_box};
1203 uint32_t i0 = tvs->
count-4;
1204 uint32_t i1 = tvs->
count-3;
1205 uint32_t i2 = tvs->
count-2;
1206 uint32_t i3 = tvs->
count-1;
1230 int current_box = 0;
1239 if (tbs[j].free)
continue;
1246 glBindBuffer(GL_ARRAY_BUFFER,
TEXT_VBO);
1249 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,
TEXT_EBO);
1250 glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0,
sizeof(uint32_t) * tis.
count, tis.
buffer);
1269 text_tr.
x *= scale_x;
1270 text_tr.
y *= scale_y;
1273 uint32_t visible = tb->
visible;
1277 tr.
x *= screen_scale_x;
1278 tr.
y *= screen_scale_y;
1280 tr_scale.
x *= screen_scale_x;
1281 tr_scale.
y *= screen_scale_y;
1283 uint32_t hovered = 0;
1295 float min_x =
MIN(
MIN(
MIN(pos0.
x, pos1.x), pos2.x), pos3.x);
1296 float max_x =
MAX(
MAX(
MAX(pos0.
x, pos1.x), pos2.x), pos3.x);
1297 float min_y =
MIN(
MIN(
MIN(pos0.
y, pos1.y), pos2.y), pos3.y);
1298 float max_y =
MAX(
MAX(
MAX(pos0.
y, pos1.y), pos2.y), pos3.y);
1370 text_tr.
x *= scale_x;
1371 text_tr.
y *= scale_y;
1374 uint32_t visible = el->
visible;
1378 tr.
x *= screen_scale_x;
1379 tr.
y *= screen_scale_y;
1381 tr_scale.
x *= screen_scale_x;
1382 tr_scale.
y *= screen_scale_y;
1384 uint32_t hovered = 0;
1470 size_t container_count = 0;
1476 if (ms[i].containers[j].free)
continue;
1491 printf(
"Malloc Failed UI Ele\n");
1517 if (el->
free)
continue;
1535 if (tb->
free)
continue;
1555 if (ms[i].containers[j].free)
continue;
1568 uint32_t * text_box_ssbo_data = (uint32_t*)(
text_box_ssbo_ptr + text_box_ssbo_offset);
1573 uint8_t * ui_ssbo_data = (uint8_t*)(
ui_ssbo_ptr + ui_ssbo_offset);
1578 uint32_t * ui_instance_vbo_data = (uint32_t*)(
ui_instance_vbo_ptr + ui_instance_vbo_offset);
1597 glActiveTexture(GL_TEXTURE1);
1600 glActiveTexture(GL_TEXTURE2);
1603 glActiveTexture(GL_TEXTURE3);
1604 glBindTexture(GL_TEXTURE_CUBE_MAP,
SKYBOX);
1606 glActiveTexture(GL_TEXTURE4);
1607 glBindTexture(GL_TEXTURE_2D,
BRDF_LUT);
1616 glActiveTexture(GL_TEXTURE5);
1622 glActiveTexture(GL_TEXTURE6);
1626 glActiveTexture(GL_TEXTURE7);
1632 glActiveTexture(GL_TEXTURE8);
1638 glActiveTexture(GL_TEXTURE8);
1642 glActiveTexture(GL_TEXTURE9);
1644 glUniform1i(glGetUniformLocation(
DYNAMIC_SHADER[shader].program,
"uPLSCMA"), 9);
1646 glActiveTexture(GL_TEXTURE10);
1648 glUniform1i(glGetUniformLocation(
DYNAMIC_SHADER[shader].program,
"uSSR"), 10);
1667 glActiveTexture(GL_TEXTURE11);
1676 glBindTexture(GL_TEXTURE_2D, images[mat->
diffuse_tex].
i);
1680 glActiveTexture(GL_TEXTURE12);
1689 glBindTexture(GL_TEXTURE_2D, images[mat->
normal_tex].
i);
1693 glActiveTexture(GL_TEXTURE13);
1697 glBindTexture(GL_TEXTURE_2D, images[
DEFAULT_ARM].i);
1702 glBindTexture(GL_TEXTURE_2D, images[mat->
arm_tex].
i);
1736 int current_mat = -1;
1745 int total_instance_count = 0;
1746 while (i < *draw_command_cnt)
1751 int instance_count = 0;
1788 while (i < *draw_command_cnt &&
1792 first_command->
sm_id == current_command->
sm_id &&
1798 int current_instance = i;
1807 total_instance_count++;
1809 current_command = &dcs[i];
1826 uint32_t * mesh_node_ssbo_data = (uint32_t*)(
mesh_node_ssbo_ptr + mesh_node_ssbo_offset);
1827 memcpy(mesh_node_ssbo_data, mn_data,
sizeof(
float) * 1 +
sizeof(uint32_t) * 3 +
sizeof(
MeshNodeDataGPU) * *draw_command_cnt);
1833#define MAX_MESHES_PER_PT_LIGHT_SHADOW 32
1838 if (array_count > 0)
1845 glUniform1ui(glGetUniformLocation(s->
program,
"uDynamicPass"), 0);
1846 glUniform1ui(glGetUniformLocation(s->
program,
"uStartArr"), start_arr);
1850 if (element_count > 0)
1856 glUniform1ui(glGetUniformLocation(s->
program,
"uStartEle"), start_ele);
1857 glUniform1ui(glGetUniformLocation(s->
program,
"uDynamicPass"), 1);
1858 glMultiDrawElementsIndirect(GL_TRIANGLES, GL_UNSIGNED_INT, (
void*)start_element_offset, element_count,
sizeof(
DrawElementsIndirectCommand));
1870 float pitches[6] = {0, 0,
M_PI / 2.0f, -
M_PI / 2.0f, 0, 0};
1872 flips[0] = (
vec3){0, 0, -1};
1873 flips[1] = (
vec3){0, 0, -1};
1874 flips[2] = (
vec3){0, -1, 0};
1875 flips[3] = (
vec3){0, 1, 0};
1876 flips[4] = (
vec3){0, 0, -1};
1877 flips[5] = (
vec3){0, 0, -1};
1879 glEnable(GL_DEPTH_TEST);
1880 glDepthMask(GL_TRUE);
1881 glDepthFunc(GL_LEQUAL);
1884 glFramebufferTexture3D(
1886 GL_DEPTH_ATTACHMENT,
1887 GL_TEXTURE_CUBE_MAP_ARRAY,
1896 Light * l = &lights[i];
1912 glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT | GL_COMMAND_BARRIER_BIT);
1924 glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT | GL_COMMAND_BARRIER_BIT);
1937 glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT | GL_COMMAND_BARRIER_BIT);
1941 float clear_color = 1.0f;
1942 glClearTexSubImage(
POINT_LIGHT_SHADOWS_FBO.
depth_texture.
i, 0, 0, 0, 6 * i,
POINT_LIGHT_SHADOWS_FBO.
w,
POINT_LIGHT_SHADOWS_FBO.
h, 6, GL_DEPTH_COMPONENT, GL_FLOAT, &clear_color);
1946 for (
int j = 0; j < 6; j++)
1953 sky_cam.
yaw = yaws[j];
1954 sky_cam.
pitch = pitches[j];
1975 glBindBuffer(GL_ARRAY_BUFFER,
MAIN_VBO);
1976 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,
MAIN_EBO);
1990 glDisable(GL_CULL_FACE);
2015 if (mn->
mesh == -1 || mn->
free)
continue;
2050 if (mn->
mesh == -1 || mn->
free)
continue;
2079 uint32_t * instance_ssbo_data = (uint32_t*)(
instance_ssbo_ptr + instance_ssbo_offset);
2095 glEnable(GL_DEPTH_TEST);
2096 glDepthMask(GL_TRUE);
2097 glDepthFunc(GL_LEQUAL);
2101 glDepthFunc(GL_EQUAL);
2102 glDepthMask(GL_FALSE);
2105 glBindBuffer(GL_ARRAY_BUFFER,
MAIN_VBO);
2107 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,
MAIN_EBO);
2111 int current_mat = 0;
2112 bool currently_static =
false;
2115 glBlendEquation(GL_FUNC_ADD);
2116 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
2117 glEnable(GL_CULL_FACE);
2118 glCullFace(GL_BACK);
2135 glActiveTexture(GL_TEXTURE0);
2146 int starting_array_offset = first_command->
array_offset;
2192 glActiveTexture(GL_TEXTURE0);
2199 uint32_t array_count = arr;
2200 uint32_t element_count = el;
2202 if (first_command->
opaque < 255)
2204 glDepthFunc(GL_LEQUAL);
2205 glDepthMask(GL_FALSE);
2206 glEnable(GL_CULL_FACE);
2207 glCullFace(GL_FRONT);
2209 glEnable(GL_CULL_FACE);
2210 glCullFace(GL_BACK);
2212 glEnable(GL_CULL_FACE);
2213 glCullFace(GL_BACK);
2242 const float MAX_DIST = 20.0f;
2243 for (
int i = 0; i < num_probes; i++)
2247 float longest = -INFINITY;
2248 int longest_index = 0;
2257 if (distances[j] > longest)
2260 longest = distances[j];
2265 if (current_dist < longest)
2293 glEnable(GL_MULTISAMPLE);
2298 glDisable(GL_MULTISAMPLE);
2302 glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS);
2305 *frame_cam_data = rprobe_cam->
cam_data;
2306 glBindBufferRange(GL_UNIFORM_BUFFER, 0,
CAM_UBO, cam_ubo_offset,
sizeof(
CamData));
2327 glBindBufferRange(GL_UNIFORM_BUFFER, 3,
RPROBE_UBO, rprobe_ubo_offset,
sizeof(
RProbeUBO));
2330 glBindBufferRange(GL_UNIFORM_BUFFER, 4,
CAM_UBO, prev_cam_ubo_offset,
sizeof(
CamData));
2350 *frame_probe_volume_data = frame_pv_data;
2363 glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT);
2377 glEndQuery(GL_TIME_ELAPSED);
2385 glEndQuery(GL_TIME_ELAPSED);
2400 glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT | GL_COMMAND_BARRIER_BIT);
2412 glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT | GL_COMMAND_BARRIER_BIT);
2426 glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT | GL_COMMAND_BARRIER_BIT);
2430 glBindFramebuffer(GL_FRAMEBUFFER, render_fbo);
2431 glViewport(0, 0, render_width, render_height);
2432 glClearColor(0, 0, 0, 1.0f);
2434 glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
2436 glEnable(GL_DEPTH_TEST);
2437 glDepthMask(GL_TRUE);
2438 glDepthFunc(GL_LEQUAL);
2441 glBindBuffer(GL_ARRAY_BUFFER,
SKY_VBO);
2446 glActiveTexture(GL_TEXTURE0);
2447 glBindTexture(GL_TEXTURE_CUBE_MAP,
SKYBOX);
2450 glDrawArrays(GL_TRIANGLES, 0, 36);
2455 glClearColor(0, 0, 0, 1.0f);
2457 glClear(GL_DEPTH_BUFFER_BIT);
2459 glBindBuffer(GL_ARRAY_BUFFER,
MAIN_VBO);
2460 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,
MAIN_EBO);
2468 glClear(GL_DEPTH_BUFFER_BIT);
2482 glEndQuery(GL_TIME_ELAPSED);
2483 glDisable(GL_CULL_FACE);
2502 glClearColor(0,0,0,1.0);
2504 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
2512 int starting_array_offset = first_command->
array_offset;
2554 uint32_t array_count = arr;
2555 uint32_t element_count = el;
2576 GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT,
2583 glClearColor(0,0,0,1.0);
2585 glClear(GL_DEPTH_BUFFER_BIT);
2587 glActiveTexture(GL_TEXTURE9);
2590 glBindTexture(GL_TEXTURE_2D, current_depth_texture);
2593 glDrawArrays(GL_TRIANGLES, 0, 3);
2594 glEndQuery(GL_TIME_ELAPSED);
2601 glBindFramebuffer(GL_FRAMEBUFFER, 0);
2605 glActiveTexture(GL_TEXTURE10);
2606 glBindTexture(GL_TEXTURE_2D, current_depth_texture);
2613 glDispatchCompute(1, 1, 1);
2614 glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT);
2617 glEndQuery(GL_TIME_ELAPSED);
2626 glClearColor(0,0,0,1.0);
2627 glClear(GL_COLOR_BUFFER_BIT);
2629 glActiveTexture(GL_TEXTURE9);
2637 glBindTexture(GL_TEXTURE_2D, current_depth_texture);
2640 glActiveTexture(GL_TEXTURE10);
2645 glDrawArrays(GL_TRIANGLES, 0, 3);
2650 glClearColor(0,0,0,1.0);
2651 glClear(GL_COLOR_BUFFER_BIT);
2653 glActiveTexture(GL_TEXTURE9);
2656 glActiveTexture(GL_TEXTURE10);
2664 glBindTexture(GL_TEXTURE_2D, current_depth_texture);
2668 glDrawArrays(GL_TRIANGLES, 0, 3);
2671 glEndQuery(GL_TIME_ELAPSED);
2675 glBindFramebuffer(GL_FRAMEBUFFER, render_fbo);
2676 glViewport(0, 0, render_width, render_height);
2680 glEndQuery(GL_TIME_ELAPSED);
2683 glBindFramebuffer(GL_FRAMEBUFFER, 0);
2688 glBindFramebuffer(GL_READ_FRAMEBUFFER,
MAIN_FBO.
fbo);
2693 GL_COLOR_BUFFER_BIT,
2702 glBindFramebuffer(GL_FRAMEBUFFER,
SSR_FBO.
fbo);
2705 glClearColor(0,0,0,1.0);
2706 glClear(GL_COLOR_BUFFER_BIT);
2709 glActiveTexture(GL_TEXTURE9);
2712 glActiveTexture(GL_TEXTURE10);
2720 glBindTexture(GL_TEXTURE_2D, current_depth_texture);
2723 glActiveTexture(GL_TEXTURE11);
2726 glActiveTexture(GL_TEXTURE12);
2729 glActiveTexture(GL_TEXTURE13);
2734 glDrawArrays(GL_TRIANGLES, 0, 3);
2737 glEndQuery(GL_TIME_ELAPSED);
2748 glClearColor(0,0,0,1.0);
2749 glClear(GL_COLOR_BUFFER_BIT);
2753 glActiveTexture(GL_TEXTURE0);
2758 glActiveTexture(GL_TEXTURE0);
2759 glBindTexture(GL_TEXTURE_2D, 0);
2763 glActiveTexture(GL_TEXTURE3);
2766 glActiveTexture(GL_TEXTURE1);
2769 glActiveTexture(GL_TEXTURE2);
2772 glActiveTexture(GL_TEXTURE10);
2773 glBindTexture(GL_TEXTURE_2D, current_depth_texture);
2777 glDrawArrays(GL_TRIANGLES, 0, 3);
2780 glEndQuery(GL_TIME_ELAPSED);
2781 glDisable(GL_BLEND);
2789 glBindFramebuffer(GL_FRAMEBUFFER,
COC_FBO.
fbo);
2791 glClearColor(0,0,0,1.0);
2792 glClear(GL_COLOR_BUFFER_BIT);
2794 glActiveTexture(GL_TEXTURE0);
2802 glBindTexture(GL_TEXTURE_2D, current_depth_texture);
2805 glActiveTexture(GL_TEXTURE1);
2822 glDrawArrays(GL_TRIANGLES, 0, 3);
2827 glClearColor(0,0,0,1.0);
2828 glClear(GL_COLOR_BUFFER_BIT);
2830 glActiveTexture(GL_TEXTURE0);
2835 glDrawArrays(GL_TRIANGLES, 0, 3);
2839 glEndQuery(GL_TIME_ELAPSED);
2846 glClearColor(0,0,0,1.0);
2847 glClear(GL_COLOR_BUFFER_BIT);
2849 glActiveTexture(GL_TEXTURE0);
2862 glDrawArrays(GL_TRIANGLES, 0, 3);
2865 glDisable(GL_BLEND);
2867 for (
int i = 0; i < 5; i++)
2873 glViewport(0, 0, dst->
w, dst->
h);
2874 glBindFramebuffer(GL_FRAMEBUFFER, dst->
fbo);
2876 glActiveTexture(GL_TEXTURE0);
2877 glBindTexture(GL_TEXTURE_2D, src->
texture[0].
i);
2880 glDrawArrays(GL_TRIANGLES, 0, 3);
2886 glBlendFunc(GL_ONE, GL_ONE);
2887 glBlendEquation(GL_FUNC_ADD);
2890 for (
int i = 4; i >= 0; i--)
2896 glViewport(0, 0, dst->
w, dst->
h);
2897 glBindFramebuffer(GL_FRAMEBUFFER, dst->
fbo);
2899 glActiveTexture(GL_TEXTURE0);
2900 glBindTexture(GL_TEXTURE_2D, src->
texture[0].
i);
2905 glDrawArrays(GL_TRIANGLES, 0, 3);
2908 glDisable(GL_BLEND);
2911 glEndQuery(GL_TIME_ELAPSED);
2918 if (node->
left != -1)
2923 if (node->
right != -1)
2936 if (node->
left == -1 && node->
right == -1)
2942 for (
int j = 0; j < 24; j++)
2944 v[j].
color =
vec3_lerp(start_color, end_color, (
float)depth / max_depth);
2949 if (node->
left != -1)
2951 render_tree(nodes, &nodes[node->
left], tr, points, count, depth + 1, max_depth, start_color, end_color);
2953 if (node->
right != -1)
2955 render_tree(nodes, &nodes[node->
right], tr, points, count, depth + 1, max_depth, start_color, end_color);
2968 render_tree(nodes, nodes, tr, points, &count, 0, depth, (
vec3){0,0,1}, (
vec3){1,0,0});
2971 glBufferData(GL_ARRAY_BUFFER,
sizeof(
DebugVertex) * count, points, GL_STREAM_DRAW);
2972 glDrawArrays(GL_LINES, 0, count);
2984 for (
int j = 0; j < 24; j++)
2999 vec3 step_x, step_y, step_z;
3000 step_x.
x = fwd.
x * dx;
3001 step_x.
y = fwd.
y * dx;
3002 step_x.
z = fwd.
z * dx;
3004 step_y.
x = right.
x * dy;
3005 step_y.
y = right.
y * dy;
3006 step_y.
z = right.
z * dy;
3008 step_z.
x = up.
x * dz;
3009 step_z.
y = up.
y * dz;
3010 step_z.
z = up.
z * dz;
3017 vec3 current_pos = pos;
3036 current_pos.
x = pos.
x + x * step_x.
x + y * step_y.
x + z * step_z.
x;
3037 current_pos.
y = pos.
y + x * step_x.
y + y * step_y.
y + z * step_z.
y;
3038 current_pos.
z = pos.
z + x * step_x.
z + y * step_y.
z + z * step_z.
z;
3040 aabb.
center = current_pos;
3044 for (
int j = 0; j < 24; j++)
3078 if (!still_has_time)
time = 0;
3099 glDisable(GL_DEPTH_TEST);
3101 glDisable(GL_CULL_FACE);
3108 glClearColor(0.0,0.0,0.0,0.0);
3109 glClear(GL_COLOR_BUFFER_BIT);
3110 glBindVertexArray(
UI_VAO);
3124 glBindBuffer(GL_ARRAY_BUFFER,
TEXT_VBO);
3125 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,
TEXT_EBO);
3131 Font * font = &fonts[0];
3134 glActiveTexture(GL_TEXTURE0);
3135 glBindTexture(GL_TEXTURE_2D, image->
i);
3193 for (
int j = 0; j < 24; j++)
3214 for (
int j = 0; j < 24; j++)
3251 Light * l = &lights[i];
3257 for (
int j = 0; j < 24; j++)
3271 for (
int j = 0; j < 24; j++)
3282 for (
int j = 0; j < 24; j++)
3311 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3313 glClearColor(0, 0, 0, 1.0f);
3315 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
3318 int pp_shader_idx = -1;
3323 uint32_t pp_perm = 0;
3332 pp_perm |= (1 <<
PP_DOF);
3349 pp_perm |= (1 <<
PP_LUT);
3359 if (pp_shader_idx == -1)
3361 printf(
"ERROR: PP SHADER NOT FOUND\n");
3373 glUseProgram(pp_shader->
program);
3375 glActiveTexture(GL_TEXTURE0);
3379 glActiveTexture(GL_TEXTURE1);
3386 glActiveTexture(GL_TEXTURE7);
3389 glActiveTexture(GL_TEXTURE8);
3392 glActiveTexture(GL_TEXTURE2);
3398 glActiveTexture(GL_TEXTURE10);
3400 glGenerateMipmap(GL_TEXTURE_2D);
3406 glActiveTexture(GL_TEXTURE10);
3410 glActiveTexture(GL_TEXTURE11);
3414 glActiveTexture(GL_TEXTURE3);
3417 glActiveTexture(GL_TEXTURE4);
3420 glActiveTexture(GL_TEXTURE5);
3423 glActiveTexture(GL_TEXTURE6);
3424 glBindTexture(GL_TEXTURE_2D,
BLOOM_PYRAMID[0].texture[0].i);
3426 glActiveTexture(GL_TEXTURE9);
3429 glActiveTexture(GL_TEXTURE12);
3432 glUniform1f(glGetUniformLocation(pp_shader->
program,
"uPhysicsFramerate"), 60);
3440 glDrawArrays(GL_TRIANGLES, 0, 3);
3442 glEndQuery(GL_TIME_ELAPSED);
3452 printf(
"FINISHING\n");
void play_animation(Animation *anim, float time, int asset_instance)
Plays an animation at a certain time value.
Animation * find_animation(const char *name, int asset_instance)
Finds an animation via name.
float animation_length(Animation *anim)
Finds the length of an animation.
Skeletal animation and animation component playback and management.
layout(local_size_x=16, local_size_y=16) in
mat4 make_ortho(float left, float right, float bottom, float top, float near, float far)
Makes an 4x4 orthographic matrix.
void compute_camera_basis(Camera *cam, float yaw, float pitch, float roll, vec3 world_up)
Computes camera vectors based on yaw, pitch, and roll.
mat4 make_look_at(Camera *cam, vec3 eye)
Makes a 4x4 view matrix using camera vectors.
mat4 make_projection(float fov_deg, float aspect, float near, float far)
Makes an 4x4 projection matrix.
Camera cam
This is currently the player cam.
bool aabb_in_frustum(vec3 min, vec3 max)
AABBBounds transform_aabb_by_model_matrix(MeshNode mn, mat4 mat)
DrawArraysIndirect commands are used for non-static meshes.
Engine specific types and defines.
uint8_t static_mesh
If it is a static mesh.
AABB aabb
Bounding box of area.
int joint_count
The amount of joints.
bool lights_dirty
If lights need to be reuploaded.
uint32_t array_offset
The offset into INDIRECT_ARRAYS_COMMAND_BUFFER.
vec3 p_right
The current right foot position.
uint16_t spot_light_offset
ivec4 joint_indices
The indices for each joint matrix (skeletal animations).
vec2 LightmapUV[3]
The lightmap UVs stored on UVIslands per MeshFace.
Vector mesh_nodes
MeshNodes.
bool free
Indicates an empty slot in ASSET_INSTANCES.
size_t lm_offset
The starting index in LIGHTMAP_DATA that this SubMesh points to.
#define MAX_LIGHTS_PER_CLUSTER
LightType
Enum for types of Lights.
vec3 right_hip_pos
The right hip pos, offset by right_leg_offset.
GLuint texture_id
The texture ID for the current lightmap.
uint32_t start_index
Where the indices / vertices start for this SubMesh in MAIN_VBO.
LightmapUV * uvs
The uvs for each MeshFace on this islands.
float absorption_coefficients[6]
SceneData scene_data
SceneData that is more-so scene specific.
mat4 tr
The Transform's matrix.
uint8_t material
The Material ID into Globals.materials.
uint16_t directional_light_count
mat4 matrix
The transformation matrix of the MeshNode.
GLuint i
The image handle for this texture.
ivec3 probe_tex_size
The texture size for lighting probes.
#define MAX_RPROBES_PER_FRAME
Max ReflectionProbes to push to UBOs per frame (for sizing).
#define MAX_DRAW_COMMANDS
Maxmimum amount of draw commands to push to the gpu.
uint32_t mn_id
The MeshNode this belongs to.
size_t skin_count
The amount of GLTFSkins in this instance.
uvec2 spot_lights
Spot Lights count and offset.
#define MINIMUM_LIGHT_VISIBILITY_DIST
Light visibility dist used for culling (only used for spot Lights(?) now).
Skeleton skeleton
Player Skeleton.
vec3 capture_pos
The position to capture the cubemap from.
vec3 p_left
The current left foot position.
uint32_t lm_offset
Lightmap offset into LIGHTMAP_DATA / LIGHTMAP_SSBO.
float outer_cos
Precomputed when uploading to the GPU for SPOT_LIGHTs.
size_t index_count
The amount of indices that this SubMesh refers to: Mesh.tris -> MeshFace.indices.
Mesh mesh
The Mesh for the ConvexHull used for collisions (an AABB).
MeshNodeDataGPU mns[1024]
Vector audio_portals
AudioPortals.
vec4 weights
The weights each joint is multiplied by.
uint32_t command_id
The DrawCommand this refers to.
GLuint program
Program handle.
uint32_t mn_id
The MeshNode.
float cos_diff
Precomputed when uploading to the GPU for SPOT_LIGHTs.
vec2 uv
The texture coordinates.
uint8_t fwd_shader
The shader in DYNAMIC_SHADER.
#define MAX_DIRECTIONAL_LIGHTS
Maxmimum directional Lights at one time (used for shadowmap sizing).
uint32_t material
The Material ID for this submesh.
#define VIEW_NEAR
Near plane for player.
mat4 * inverse_bind
The inverse_bind that is computed on load_gltf().
uint16_t spot_light_count
#define MAX_LIGHTS
Maximum amount of Lights to be pushed per frame (used for SSBO sizing).
vec3 world_min
Unused but uploaded to main shader.
Globals GLOBALS
Engine Globals.
size_t * node_indices
The indices of MeshNodes spawned from this instance inside of Globals.mesh_nodes.
size_t first_index
The first index that this SubMesh refers to (Mesh.tris count * 3).
int * joints
The joints for skeletal animating.
GLTexture depth_texture
The normal depth texture, if there is one.
LPV LOADED_LIGHTING_PV[6]
Load slots for lighting ProbeVolumes.
Vector reflection_probes
ReflectionProbes in the scene.
int ssbo_offset
The offset into JOINT_SSBO.
float probe_spacing
The spacing between lighting probes.
uint8_t opaque
How opaque a Material is.
uint32_t * mesh_light_indices
Buffer used when calling determine_light_visibility_per_mesh.
vec3 q_right
The current knee position for right leg.
Camera LIGHT_CAM[4]
DIRECTIONAL_LIGHT Cameras for shadowmaps
uint16_t mesh_id
The Mesh.
Vector lighting_probe_volumes
All of the lighting probe volumes, regardless of if they have been loaded yet.
struct RProbeUBO::Align16 probe_indices[4]
#define MAX_LIGHTS_PER_MESH
Max directional + spot Lights to push at one time for a Mesh.
MaterialGPU materials[256]
Vector audio_probe_volumes
All of the AudioProbe% volumes, regardless of if they have been loaded yet.
uint64_t sort_key
The key that is sorted in create_and_sort_draw_commands().
size_t node_count
The amount of MeshNodes in this instance.
size_t material
The Material.
GLTexture texture[6]
The textures bound to this fbo.
uint16_t point_light_offset
vec3 q_left
The current knee position for left leg.
uvec2 directional_lights
Directional Lights count and offset.
size_t uv_island
What island inside of LightmapData.islands that this MeshFace refers to.
uint16_t skin_offset
The offset into JOINT_SSBO.
mat4 view
The view matrix.
Vector materials
Materials.
mat4 * final_mat
The transformation after update_skin_matrices().
#define VIEW_FAR
Far plane for player.
GLuint64 handle
The handle for the bindless texture.
uint32_t sm_id
The SubMesh.
GLuint i
The handle for the texture.
#define MAX_JOINT_MATRICES
Maximum joints in a scene (used for SSBO sizing).
uint32_t instance_count
Used to be used to find the instance being rendered, but now that's on the transform data itself.
uint32_t lm_offset
The lightmap offset into LIGHTMAP_SSBO where this mesh node starts.
uint32_t skin_offset
The GLTFSkin matrix offset for this transform.
#define BUFFER_FRAMES
Triple buffer count.
int pv_id
The ProbeVolume in SceneData.lighting_probe_volume.
bool LOADED_LIGHTING_PV_FLAG[6]
Flags that indicate if the slot is loaded.
float scattering_coefficients[6]
uint32_t element_offset
The offset into INDIRECT_ELEMENTS_COMMAND_BUFFER.
GLuint fbo
The handle for this fbo.
uint16_t directional_light_offset
#define MAX_INSTANCES
Maximum amount of TransformGPU instances to push in one frame (used for SSBO sizing).
uint32_t index_count
How many indices in this SubMesh.
#define MAX_MESH_NODES
Maximum MeshNodes in a scene (used for SSBO sizing).
mat4 proj
The projection matrix.
#define PROBE_VOLUME_DEPTH_PADDED
Padding to avoid leaking on edges in Z.
uint8_t gbuffer_shader
The shader for the DEPTH_PRE_PASS_SHADER.
vec3 left_hip_pos
The left hip pos, offset by left_leg_offset.
size_t draw_offset
Currently the same index as SubMesh.lm_offset.
LightmapData lightmap_data
The loaded lightmap and lightmap configuration for the scene.
uint16_t point_light_count
vec4 tangent
The tangent for TBN construction.
Vector islands
The UVIslands on the current lightmap.
Uniform uniforms[32]
Uniforms for shader data.
vec4 cam_pos
The position of the Camera (padded).
size_t * skin_indices
The indices of GLTFSkins spawned from this instance inside of Globals.skins.
The structure of an Skeletatal Animation loaded in from GLTFAnimation.
A instance of an Asset that retains its node structure but can be duplicated into multiple instances ...
The structure uploaded to the GPU for providing render data for a Camera.
The camera structure for players and entities.
The structure used for debug wireframes.
The structure used to sort unique submeshes by materials, and shaders in the main render pass.
The abstraction for a framebuffer in OpenGL.
The structure of an Skeletatal Animation loaded in from GLTFAnimation.
Where Material textures are saved upon loading from file.
Simply the size we use to allocate the INSTANCE_VBO (unused).
The GPU side structure for Lights padded for GPU.
The metadata for the lightmap settings.
The structure that stores lightmap uvs.
The GPU side padded structure for Materials.
MeshNode structure padded for GPU (MESH_NODE_SSBO).
MeshNode buffer structure for MESH_NODE_SSBO.
GPU side structure for an OBB UBO.
The UBO structure for pushing the closest ReflectionProbes to the main shader.
ReflectionProbes used for parallax corrected cubemaps.
The data for the current scene.
OpenGL ShaderPrograms: vertex, fragment, geometry, and compute.
The structure used for uploading matrices for directional Lights used when rendering shadowmaps.
Sections of Meshes that are divided based on Material for batching and DrawCommand ordering purposes.
The structure used for rendering TextBoxes.
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.
mat4 compose_trs_from_mesh_node(MeshNode *mn)
Vector FONTS
All loaded Fonts.
Functions that modify TextBoxes and load Fonts.
ivec3 resolution
The resolution in X, Y, Z.
OBB obb
The OBB that defines the size.
#define AUDIO_NUM_BANDS
The amount of bands to use for audio probe baking.
The ProbeVolumes for APVs and LPVs, controlled by OBBs.
vec3 pos
The position of the AudioEmitter .
vec3 pos
The position of the AudioPortal.
#define MAX_AUDIO_EMITTERS
The maximum amount of AudioEmitters.
An AudioEmitter that plays audio possibily from a certain position or at a certain time.
AudioPortals used for determining paths to transmit sound when emitter and listener are occluded.
DebugView current_debug_view
float DOF_max_blur_radius
float render_framerate_target
The target framerate for rendering and processing ui events (a cap).
bool lighting_probe_volume_overlay
bool wireframe_toggled
Shows wireframes around many structures: Lights, ReflectionProbes, AudioProbes, AudioPortals,...
int selected_ui_element_id
PostprocessDView pp_dview
vec3 rotation_axis
The rotation axis for rotation operations in the editor.
bool audio_probe_volume_overlay
#define EDITOR_AUDIO_EMITTER_SIZE
#define EDITOR_APROBE_SIZE
#define EDITOR_LIGHT_SIZE
#define EDITOR_APORTAL_SIZE
Convex Hulls that are generated via incremental hull for non-static meshes.
float intensity
The intensity of the Light.
int fwd_shader
The corresponding forward rendering shader branch in DYNAMIC_SHADER.
size_t id
The ID inside of Globals.mesh_nodes.
vec3 pos
Position of light.
int skin
The GLTFSkin it controls.
uint32_t layer
Which layer a DIRECTIONAL_LIGHT corresponds to in the SHADOW_MAP_FBO.
LightType light_type
The type of Light.
float normal_scale
Unused - Used to determine how much of the texture normal to use.
size_t offset
Offset into the MAIN_VBO.
size_t directional_light_count
bool override_transparent
If we are overriding transparency of this Material.
uint32_t skin_offset
The offset into the JOINT_SSBO, comes from DrawCommand.
vec3 dir
Direction for lights that are not POINT_LIGHTs.
float inner_angle
Starting angle for SPOT_LIGHTs.
float surface_area
The surface area of the triangle.
bool sm_dirty
If a point light needs a new shadowmap.
int tri
The MeshFace this corresponds to.
float outer_angle
Outer angle for SPOT_LIGHTs.
size_t point_light_offset
size_t directional_light_offset
bool free
If the MeshNode can be replaced.
int children[128]
The children to this node, a global index into Globals.mesh_nodes.
float cone_angle
Cone angle for SPOT_LIGHTs.
float penumbra
Penumbra (opening) for SPOT_LIGHTs.
int mesh
The Mesh it references.
int parent
The parent to this node, a global index into Globals.mesh_nodes.
float radius
The radius of the Light.
int mesh
The MeshNode this corresponds to.
bool override_arm
If we override the ARM texture and bind a dummy instead.
int child_count
The amount of children.
vec3 rgb
Color of the light.
UVMapping * uv_map
The mapping between MeshNodes and UVIslands for uv lightmapping.
vec4 ks
Specular (unused).
uint32_t mesh_data_id[32]
float threshold
The threshold (how far a light reaches).
size_t count
Count of vertices pushed into the MAIN_VBO.
int gbuffer_shader
The corresponding gbuffer rendering shader branch in DEPTH_PRE_PASS_SHADER or DEPTH_PRE_PASS_SHADER_M...
uint32_t entity_id
Entity ID into ENTITIES.
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.
DrawArraysIndirect commands are used for static meshes (eg.
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 ...
bool mask
If the UIElements and TextBoxes contained should not be rendered if outside.
float h
The height of the box after pseudo-rendering in determine_text_box_dimensions().
float angle
Angle of rotation.
float w
The width of the box after pseudo-rendering in determine_text_box_dimensions().
float angle
The angle to transform this box to.
int xadvance
How much the x advances when it is typed.
int font_id
The Font ID inside of FONTS.
int container
The UIContainer this UIElement may control.
TextBox text_boxes[1024]
The TextBoxes.
vec2 size
Size of the SDF.
vec2 start
The start of the text in relation to .
UIElement elements[1024]
The UIElements.
Glyph * glyphs
Glyphs for each character.
vec2 translation
X and Y coords where Y+ is down.
vec2 translation
Where to place the center of the TextBox on the GPU.
vec4 padding
The padding before UIElements and TextBoxes are wrapped or masked.
vec2 shadow_dir
Which direction to offset the drop shadow in.
int parent_container
The UIContainer that contains this UIElement.
int menu
The UIMenu this UIElement is inside.
vec4 color
The color of the text.
uint32_t layer
The layer of the UIElement.
UIContainer containers[1024]
The UIContainers.
int xoffset
The x offset before the character.
int parent_container
The UIContainer that contains this TextBox.
int yoffset
The y offset before the character.
uint32_t uID
The ID inside of UIMenu.text_boxes.
char * text
The characters to render.
vec4 fill
The fill of the text.
size_t glyph_count
The amount of Glyphs.
int element
Which UIElement owns this UIContainer.
vec2 scale
The scale for this box on the GPU.
bool free
If this TextBox is empty and can be overwritten.
bool free
If the UIElement can be replaced or is empty.
uint32_t uID
The ID inside of UIMenu.
size_t texture
The Image ID.
int menu
The UIMenu that this box is within.
float radius
The radius of the circle OR the radius of a rectangle's corners.
float text_size
The size to render the Font.
vec4 color
Color of the shape.
float shadow_dist
How far the drop shadow is.
#define MAX_UI_CONTAINERS
bool container_is_valid(int container, int menu)
Checks if a UIContainer and UIMenu ID pairing is valid.
@ UISTATE_SELECTED
If the UIElement is selected in the Editor.
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.
The GPU-side representation of a TextBox.
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...
The GPU-side representation of a UIElement.
Important globals for the entire engine and initialization functions that are mainly called on engine...
#define MAX_ASSET_INSTANCES
size_t meshes_in_frame[MAX_MESH_NODES]
uint32_t TEXT_INDEX_COUNT
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.
bool static_mesh
This Mesh is static and must create a BVH or if not it must perform incremental_hull.
AABB aabb
The AABB of the mesh.
size_t count
The count pushed into MAIN_VBO.
Vector submeshes
The SubMeshes split via Materials.
size_t offset
The offset into MAIN_VBO.
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.
ShaderProgram INDIRECT_PREFIX_SHADER
render/indirect_prefix.comp
GLuint gbuffer_queries[QUERY_FRAMES]
GLuint INDIRECT_ARRAYS_COMMAND_BUFFER
uint8_t * indirect_elements_ptr
GLuint DIRECTIONAL_MAP_TEXTURE
ShaderProgram TEXT_SHADER
ui/text.vert ui/text.frag
LightmapSSBO LIGHTMAP_DATA
ShaderProgram SSAO_BLUR_SHADER
render/ssao_blur.frag
GLuint MESH_SSBO
Instances (Transforms): Needs the Model Matrix, Inverse Model Matrix (crucial for transforming rays i...
Framebuffer GBUFFER_RESOLVE_FBO
GLuint INDIRECT_ARRAYS_COMMAND_BUFFER_OUT
size_t mesh_light_ssbo_size
int DIRECTIONAL_LIGHT_COUNT
GLuint GLOBAL_INSTANCE_SSBO
uint8_t * probe_volume_ubo_ptr
size_t instance_ssbo_size
uint8_t * mesh_light_ssbo_ptr
DrawCommand DRAW_COMMANDS[512]
AudioEmitter AUDIO_EMITTERS[1024]
GLuint RPROBE_CUBE_MAP_ARRAY
size_t ui_instance_vbo_size
ShaderProgram UI_SHADER
ui/ui.vert ui/ui.frag
GLuint bloom_queries[QUERY_FRAMES]
GLuint HISTORY_TEXTURE[2]
ShaderProgram COC_SHADER
render/coc.frag
double time_since_last_render
Computes the dot product or discrete sum over an array range.
GLuint render_queries[QUERY_FRAMES]
GLuint ssao_queries[QUERY_FRAMES]
float frame_time
The actual frame time in s.
GLuint MATERIAL_SSBO
Material Data: Roughness, emission multipliers, albedo colors for each instance.
ShaderProgram DEPTH_PRE_PASS_SHADER[1]
render/depth_pre_pass.vert render/depth_pre_pass.frag
GLuint GLOBAL_LIGHT_INDICES_SSBO
GLuint INDIRECT_ELEMENTS_COMMAND_BUFFER
size_t probe_volume_ubo_padded
ShaderProgram CULL_DRAW_CALLS_SHADER
render/cull_draw_calls.comp
ShaderProgram POSTPROCESS_SHADER[128]
render/postprocess.vert render/postprocess.frag
GLuint MESH_BVH_SSBO
Mesh BVH Nodes: Flattened array of nodes.
size_t mesh_node_ssbo_size
uint8_t * ui_instance_vbo_ptr
size_t text_box_ssbo_size
EditorSettings EDITOR_SETTINGS
ShaderProgram CULL_POINT_LIGHT_SHADOWS_SHADER
render/cull_point_light_shadows.comp
ShaderProgram DEPTH_DOWNSAMPLE_SHADER
render/depth_downsample.frag
uint8_t * text_box_ssbo_ptr
int PERFORMANCE_OVERLAY_MENU
ShaderProgram SKY_SHADER
render/sky.vert render/sky.frag
float time
The frame time but wrapping at 1.0.
GLuint taa_queries[QUERY_FRAMES]
uint32_t PP_SHADER_VERSIONS
ShaderProgram SSR_HISTORY_SHADER
ShaderProgram CULL_CLUSTERS_SHADER
render/cull_clusters.comp
uint8_t * indirect_arrays_ptr
Framebuffer BLOOM_PYRAMID[6]
ShaderProgram BLOOM_DOWNSCALE_SHADER
render/bloom_downscale.frag
GLuint pl_queries[QUERY_FRAMES]
ShaderProgram SHADOW_MAP_SHADER
render/shadow.vert render/shadow.frag
GLuint TRI_SSBO
Indices (Tris): uvec3 for triangle lookups.
ShaderProgram POINT_LIGHT_SHADOW_SHADER
render/point_light_shadows.vert render/point_light_shadows.geom render/point_light_shadows....
GLuint SSAO_NOISE_TEXTURE
GLuint INDIRECT_ELEMENTS_COMMAND_BUFFER_OUT
bool draw_dirty
If we need to reupload and resort transforms in create_and_sort_draw_commands() and upload_instance_d...
GLuint sm_queries[QUERY_FRAMES]
uint8_t * instance_vbo_ptr
GLuint cull_queries[QUERY_FRAMES]
GLuint main_queries[QUERY_FRAMES]
AssetInstance ASSET_INSTANCES[MAX_ASSET_INSTANCES]
ShaderProgram WIREFRAME_SHADER
render/wireframe.vert render/wireframe.frag
ShaderProgram ELEMENTS_PREFIX_SHADER
render/elements_prefix.comp
ShaderProgram BLOOM_SHADER
render/bloom.frag
Framebuffer SSAO_BLUR_FBO
uint8_t * light_cam_ubo_ptr
GLuint SCENE_BVH_SSBO
Scene BVH Nodes (TLAS): Same structure as above, but pointing to instances instead of triangles.
Framebuffer DEPTH_DOWNSAMPLE_FBO
ShaderProgram BLOOM_UPSCALE_SHADER
render/bloom_upscale.frag
ShaderProgram SSAO_SHADER
render/ssao.frag
Framebuffer SHADOW_MAP_FBO
GLuint ssr_queries[QUERY_FRAMES]
vec3 CAM_POS
Shorthand variable for the camera position.
uint8_t * instance_ssbo_ptr
Framebuffer MAIN_RESOLVE_FBO
ShaderProgram DYNAMIC_SHADER[32]
render/dynamic.vert render/dynamic.frag
DebugVertex DEBUG_LINES[DEBUG_LINES_MAX]
GLuint dof_queries[QUERY_FRAMES]
size_t light_cam_ubo_padded
uint8_t * mesh_node_ssbo_ptr
Player player
The Player data.
ShaderProgram DEPTH_PRE_PASS_SHADER_MSAA[1]
render/depth_pre_pass_no_gbuffer.vert render/depth_pre_pass_no_gbuffer.frag
MaterialData MATERIAL_DATA
GLuint VERTEX_SSBO
Vertices: vec4 (x, y, z, padding) or just float arrays.
Framebuffer POINT_LIGHT_SHADOWS_FBO
ShaderProgram BOKEH_SHADER
render/bokeh.frag
ShaderProgram FOCAL_DISTANCE_SHADER
render/focal_distance.comp
vec3 vec3_lerp(vec3 a, vec3 b, float t)
float vec3_dot(vec3 a, vec3 b)
vec4 vec4_add(vec4 a, vec4 b)
mat4 m4_mul(mat4 a, mat4 b)
vec3 vec3_scale(vec3 a, float b)
vec4 vec4_sub(vec4 a, vec4 b)
vec3 vec3_sub(vec3 a, vec3 b)
vec3 vec3_add(vec3 a, vec3 b)
vec2 vec2_sub(vec2 a, vec2 b)
float vec3_length(vec3 v)
AABB aabb
The bounding box of all of this node's children.
Nodes for the acceleration structures of BVHs.
void update_scene_nodes()
void create_and_sort_draw_commands(int *dc_cnt, DrawCommand *dcs)
Creates all DrawCommands based on unique SubMeshes and sorts them via DrawCommand....
void obb_to_vertices(DebugVertex *out, OBB *obb)
size_t fill_buffer_with_mesh_tri(Mesh *mesh, MainVertex *verts, size_t offset)
void render_mesh_aabbs_from_root(MeshNode *mn)
Adds Mesh AABBs for each MeshNode child recursively to DEBUG_LINES.
int shadow_draw_call_count
void write_point_light_shadows()
ShadowmapUBO SHADOWMAP_FRAME_DATA
void add_text_box(Vector *tvs, Vector *tis, TextBox *tb, int current_box)
Adds a TextBox to a vertex and index buffer, to be uploaded to TEXT_VBO and TEXT_EBO.
int draw_command_offsets[MAX_DRAW_COMMANDS]
void upload_parent_container(UIElement *el, UIContainer *cs, UIElement *els, int *el_count, size_t offset)
size_t shadow_meshes_this_frame
void update_node_global(MeshNode *nodes, int idx, mat4 parent)
int shadow_draw_command_counts[MAX_DRAW_COMMANDS]
size_t allocate_lightmap_ssbo()
void render_bvh(BVHNode *nodes, int node_count, mat4 tr)
void upload_lights()
Uploads all current Lights inside of Globals.lights to the GPU in a triple buffered LIGHT_SSBO.
LightGPU GPU_LIGHTS[MAX_LIGHTS]
void bind_baking_ssbos()
Binds SSBOs required for baking.
void upload_instance_data(int *draw_calls, int *in_off, int dc_counts[MAX_DRAW_COMMANDS], int dc_off[MAX_DRAW_COMMANDS], int *draw_command_cnt, DrawCommand *dcs, MeshNodeSSBO *mn_data, uint8_t *instance_ptr, int current_frame_offset)
InstanceData shadow_instance_matrices[MAX_INSTANCES]
void bind_dynamic_shader(int shader, bool probe_bake)
int compare_draw_commands(const void *a, const void *b)
void GPU_upload_ui_elements()
size_t calc_mesh_index_size(Mesh *m)
int shadow_draw_command_offsets[MAX_DRAW_COMMANDS]
int compare_uid_pair(const void *a, const void *b)
void bind_material(Material *mat)
void determine_light_visibility_per_mesh()
void get_view_planes(vec4 planes[6], Camera *cam)
void render_all_draw_commands(bool probe_bake)
DrawElementsIndirectCommand elements_indirect[MAX_MESH_NODES]
int draw_command_counts[MAX_DRAW_COMMANDS]
void render()
The main render pass.
uint32_t UI_UID_OUT[MAX_UI_ELEMENTS]
size_t calc_mesh_size(Mesh *m)
void render_tree(BVHNode *nodes, BVHNode *node, mat4 tr, DebugVertex *points, int *count, int depth, int max_depth, vec3 start_color, vec3 end_color)
void unbind_baking_ssbos()
Unbinds SSBOs required for baking.
void determine_mesh_visibility(Camera *camera, size_t *meshes_frame, size_t *meshes_frame_cnt)
size_t shadow_meshes_in_frame[MAX_MESH_NODES]
void upload_material_data()
Uploads Material data to the GPU as MaterialGPU.
UIUIDPair UI_UIDS[MAX_UI_ELEMENTS]
void copy_light_to_gpu_light(LightGPU *lgpu, Light *l)
Transfers a Light to a LightGPU.
void determine_closest_rprobes()
void GPU_upload_singular_element(UIContainer *cs, UIElement *el, int *ui_el_count, int *el_count)
float compute_ui_scale(int base_w, int base_h, int target_w, int target_h)
void add_mesh_to_buffer(Mesh *m, VertexLayout *layout)
Adds a single Mesh to the MAIN_VBO.
void bind_render_ssbos()
Binds SSBOs required for rendering.
void upload_joint_matrices()
RProbeUBO RPROBE_UBO_DATA
size_t fill_vertex_buffer_mesh(Mesh *mesh, MainVertex *verts, size_t offset, size_t *lm_offset)
TransformGPU transforms[MAX_MESH_NODES *MAX_INSTANCES]
void render_probe_volume(ProbeVolume *pv, bool audio)
TextBoxGPU TB_GPU[MAX_TEXT_BOXES]
MeshNodeSSBO mesh_node_data_gpu
void populate_draw_commands(DrawCommand *dcs, int *draw_command_cnt)
DrawArraysIndirectCommand arrays_indirect[MAX_MESH_NODES]
void aabb_to_vertices(DebugVertex *out, AABB *aabb, vec3 offset)
Transfers an AABB to DebufVertex for a wireframe (GL_LINES).
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.
InstanceData instance_matrices[MAX_INSTANCES]
void GPU_upload_singular_text_box(UIContainer *cs, TextBox *tb, int *TC)
int shadow_instance_offset
void render_to_cubemap_face(Camera *rprobe_cam, GLuint render_fbo, int render_width, int render_height, bool probe_bake)
Uploads per-frame data to GPU and renders main render pass to a target FBO (omits Text,...
int find_depth(BVHNode *nodes, BVHNode *node, int depth)
mat4 JOINT_MATS[MAX_JOINT_MATRICES]
size_t fill_index_buffer_mesh(Mesh *mesh, uint32_t *indices, size_t vertex_offset, size_t offset, size_t *lm_uv_offset)
UIElementGPU UI_GPU[MAX_UI_ELEMENTS]
void draw_arrays_elements(ShaderProgram *s, int start_arr, size_t start_array_offset, uint32_t array_count, int start_ele, size_t start_element_offset, uint32_t element_count)
void add_all_meshes_to_buffer(VertexLayout *layout)
Adds all Meshes that have valid MeshNodes.
void update_skin_matrices()
The main render pass, data GPU uploads, and SSBO management.
The standalone UI library that controls text rendering, ui rendering, and events.
void init_vector(Vector *v, size_t i, size_t type_size)
void * vector_expand(Vector *v, size_t i)
mat4 compose_2d_transform(vec2 transform, float angle, vec2 scale)
vec4 vec3_to_vec4(vec3 v)
#define CAST_VEC(vec, type)
vec3 mat4_mul_point(mat4 m, vec3 v)