Untitled
Loading...
Searching...
No Matches
render.h File Reference

The main render pass, data GPU uploads, and SSBO management. More...

#include "core/engine_types.h"
#include "ui/ui.h"

Go to the source code of this file.

Functions

void bind_baking_ssbos ()
 Binds SSBOs required for baking.
void unbind_baking_ssbos ()
 Unbinds SSBOs required for baking.
void bind_render_ssbos ()
 Binds SSBOs required for rendering.
void aabb_to_vertices (DebugVertex *out, AABB *aabb, vec3 offset)
 Transfers an AABB to DebufVertex for a wireframe (GL_LINES).
void render_mesh_aabbs_from_root (MeshNode *mn)
 Adds Mesh AABBs for each MeshNode child recursively to DEBUG_LINES.
void upload_material_data ()
 Uploads Material data to the GPU as MaterialGPU.
void copy_light_to_gpu_light (LightGPU *lgpu, Light *l)
 Transfers a Light to a LightGPU.
void upload_lights ()
 Uploads all current Lights inside of Globals.lights to the GPU in a triple buffered LIGHT_SSBO.
void add_mesh_to_buffer (Mesh *m, VertexLayout *layout)
 Adds a single Mesh to the MAIN_VBO.
void add_all_meshes_to_buffer (VertexLayout *layout)
 Adds all Meshes that have valid MeshNodes.
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.
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 create_and_sort_draw_commands (int *dc_cnt, DrawCommand *dcs)
 Creates all DrawCommands based on unique SubMeshes and sorts them via DrawCommand.sort_key.
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, UI, and postprocessing that occurs after).
void render ()
 The main render pass.

Detailed Description

The main render pass, data GPU uploads, and SSBO management.

Definition in file render.h.

Function Documentation

◆ bind_baking_ssbos()

void bind_baking_ssbos ( )

◆ unbind_baking_ssbos()

◆ bind_render_ssbos()

◆ aabb_to_vertices()

void aabb_to_vertices ( DebugVertex * out,
AABB * aabb,
vec3 offset )

Transfers an AABB to DebufVertex for a wireframe (GL_LINES).

Parameters
outThe outgoing vertices.
aabbThe input AABB.
offsetThe offset in world space.
Todo
Make a matrix transform instead of an offset. Or instance the AABBs and transform on the GPU.

Definition at line 475 of file render.c.

References aabb_to_vertices(), AABB::center, DebugVertex::pos, and vec3_add().

Referenced by aabb_to_vertices(), ray_traverse_scene_bvh(), render(), render_mesh_aabbs_from_root(), render_probe_volume(), render_tree(), and update_physics_components().

◆ render_mesh_aabbs_from_root()

◆ upload_material_data()

◆ copy_light_to_gpu_light()

◆ upload_lights()

◆ add_mesh_to_buffer()

void add_mesh_to_buffer ( Mesh * m,
VertexLayout * layout )

◆ add_all_meshes_to_buffer()

void add_all_meshes_to_buffer ( VertexLayout * layout)

◆ add_text_box()

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.

Parameters
tvsThe out vertex Vector.
tisThe out index Vector.
tbThe TextBox to upload.
current_boxThe index within the entire buffer, meaning a running count through each individual UIMenus.
Todo
This current_box variable makes it so we can never reorder our TEXT_BOX_SSBO or else every vertex will be pointing to the wrong data. Resolve this.

Definition at line 1154 of file render.c.

References add_text_box(), CAST_VEC, TextBox::color, Vector::count, TextBox::fill, TextBox::font_id, FONTS, Font::glyph_count, Font::glyphs, Glyph::height, TextBox::start, TextBox::text, TextBox::text_size, Glyph::u0, Glyph::u1, Glyph::v0, Glyph::v1, vector_expand(), Glyph::width, vec2::x, Glyph::xadvance, Glyph::xoffset, vec2::y, and Glyph::yoffset.

Referenced by add_all_text_boxes_to_draw_buffer(), and add_text_box().

◆ add_all_text_boxes_to_draw_buffer()

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.

Note
This function is currently called on TextBox text change. Text should always be pre-loaded because this should not be called during "game-time."

Definition at line 1220 of file render.c.

References add_all_text_boxes_to_draw_buffer(), add_text_box(), Vector::buffer, CAST_VEC, Vector::count, init_vector(), MAX_TEXT_BOXES, MENUS, UIMenu::text_boxes, TEXT_EBO, TEXT_INDEX_COUNT, and TEXT_VBO.

Referenced by add_all_text_boxes_to_draw_buffer(), execute_text_box_undo(), execute_ui_element_undo(), main(), render_text_menu(), render_ui_menu(), scene_load(), and update_performance_overlay().

◆ create_and_sort_draw_commands()

void create_and_sort_draw_commands ( int * dc_cnt,
DrawCommand * dcs )

Creates all DrawCommands based on unique SubMeshes and sorts them via DrawCommand.sort_key.

Parameters
dc_cntThe output count of DrawCommands.
dcsThe output DrawCommands.

Definition at line 1132 of file render.c.

References compare_draw_commands(), create_and_sort_draw_commands(), and populate_draw_commands().

Referenced by create_and_sort_draw_commands(), and render_to_cubemap_face().

◆ render_to_cubemap_face()

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, UI, and postprocessing that occurs after).

Parameters
rprobe_camThe Camera to upload for the CAM_UBO.
render_fboThe main target FBO.
render_widthThe width of the target FBO.
probe_bakeIf this is baking ReflectionProbes. This flag controls if ReflectionProbes are sampled so that there is no accumulation.
Note
This is used by the main pass and the ReflectionProbe cubemap rendering.

Definition at line 2278 of file render.c.

References mat3::a0, mat3::a1, mat3::a2, array_offset, DrawCommand::array_offset, OBBGPU::axis_x, OBBGPU::axis_y, OBBGPU::axis_z, mat3::b0, mat3::b1, mat3::b2, EditorSettings::BLOOM, BLOOM_DOWNSCALE_SHADER, BLOOM_PYRAMID, bloom_queries, BLOOM_SHADER, BLOOM_UPSCALE_SHADER, BOKEH_FBO, BOKEH_SHADER, BUFFER_FRAMES, mat3::c0, mat3::c1, mat3::c2, Camera::cam_data, CAM_UBO, cam_ubo_padded, cam_ubo_ptr, CAST_VEC, OBB::center, OBBGPU::center, COC_FBO, COC_SHADER, Vector::count, create_and_sort_draw_commands(), CULL_CLUSTERS_SHADER, CULL_DRAW_CALLS_SHADER, cull_queries, cur_history, current_frame, current_query_frame, DEPTH_DOWNSAMPLE_FBO, DEPTH_DOWNSAMPLE_SHADER, DEPTH_PRE_PASS_SHADER, DEPTH_PRE_PASS_SHADER_MSAA, Framebuffer::depth_texture, determine_closest_rprobes(), determine_light_visibility_per_mesh(), DIRECTIONAL_LIGHT_COUNT, EditorSettings::DOF, EditorSettings::DOF_focal_length, EditorSettings::DOF_fstop, DOF_HEIGHT, EditorSettings::DOF_max_blur_radius, dof_queries, EditorSettings::DOF_sensor_height, DOF_WIDTH, draw_arrays_elements(), draw_call_count, draw_command_count, draw_command_counts, draw_command_offsets, DRAW_COMMANDS, draw_dirty, EDITOR_SETTINGS, DrawCommand::element_offset, element_offset, ELEMENTS_PREFIX_SHADER, OBB::extents, OBBGPU::extents, Framebuffer::fbo, FOCAL_DISTANCE_SHADER, EditorSettings::FULL_GBUFFER, DrawCommand::fwd_shader, GALBEDO, GBUFFER_FBO, gbuffer_queries, GBUFFER_RESOLVE_FBO, DrawCommand::gbuffer_shader, get_view_planes(), GEXTRA, GLOBAL_INSTANCE_SSBO, GLOBALS, GNORMAL, GPOMDEPTH, GRID_X, GRID_Y, GRID_Z, GVEL, Framebuffer::h, GLTexture::i, INDIRECT_ARRAYS_COMMAND_BUFFER, INDIRECT_ARRAYS_COMMAND_BUFFER_OUT, INDIRECT_ELEMENTS_COMMAND_BUFFER, INDIRECT_ELEMENTS_COMMAND_BUFFER_OUT, INDIRECT_PREFIX_SHADER, instance_offset, INSTANCE_VBO, instance_vbo_ptr, JITTER_OFFSET, LIGHT_CAM, LIGHT_CAM_UBO, light_cam_ubo_padded, light_cam_ubo_ptr, SceneData::lighting_probe_volumes, Globals::lights, Globals::lights_dirty, OBBGPU::loaded, SceneData::LOADED_LIGHTING_PV, SceneData::LOADED_LIGHTING_PV_FLAG, Uniform::location, LPV_SLOTS, MAIN_EBO, MAIN_FBO, MAIN_RESOLVE_FBO, MAIN_VAO, MAIN_VBO, MAX_LIGHTS_PER_CLUSTER, mesh_node_data_gpu, Globals::mesh_nodes, Globals::meshes, EditorSettings::MSAA, ProbeVolume::obb, ProbeVolumeUBO::obb, DrawCommand::opaque, pl_queries, planes, probe_bake, PROBE_VOLUME_UBO, probe_volume_ubo_padded, probe_volume_ubo_ptr, ShaderProgram::program, CamData::proj, ShadowmapUBO::proj, LPV::pv_id, render_all_draw_commands(), RENDER_HEIGHT, render_queries, render_to_cubemap_face(), RENDER_WIDTH, OBB::rot, RPROBE_UBO, RPROBE_UBO_DATA, rprobe_ubo_padded, rprobe_ubo_ptr, Globals::scene_data, SHADOW_MAP_FBO, SHADOW_MAP_SHADER, SHADOWMAP_FRAME_DATA, SKY_SHADER, SKY_VAO, SKY_VBO, SKYBOX, sm_queries, EditorSettings::SSAO, SSAO_BLUR_FBO, SSAO_BLUR_SHADER, SSAO_FBO, SSAO_HEIGHT, SSAO_NOISE_TEXTURE, ssao_queries, SSAO_SHADER, SSAO_WIDTH, EditorSettings::SSR, SSR_FBO, SSR_HEIGHT, SSR_HISTORY_SHADER, ssr_queries, SSR_SHADER, SSR_WIDTH, DrawCommand::static_mesh, EditorSettings::TAA, TAA_FBO, taa_queries, Framebuffer::texture, time, time_since_last_render, transform_count, ShaderProgram::uniforms, update_scene_nodes(), update_skin_matrices(), upload_instance_data(), upload_instances(), upload_joint_matrices(), upload_lights(), CamData::view, ShadowmapUBO::view, VIEW_FAR, VIEW_NEAR, Framebuffer::w, write_point_light_shadows(), vec2::x, and vec2::y.

Referenced by bake_reflection_probes(), render(), and render_to_cubemap_face().

◆ render()

void render ( )

The main render pass.

Calls render_to_cubemap_face() and then renders wireframes, text, ui, and postprocessing.

Definition at line 3057 of file render.c.

References ReflectionProbe::aabb, aabb_to_vertices(), EditorSettings::ACES, animation_length(), AUDIO_EMITTERS, EditorSettings::audio_menu_open, Globals::audio_portals, SceneData::audio_probe_volumes, EditorSettings::BLOOM, BLOOM_PYRAMID, BOKEH_FBO, BUFFER_FRAMES, SceneData::bvh_nodes, cam, ReflectionProbe::capture_pos, CAST_VEC, AABB::center, COC_FBO, DebugVertex::color, COLOR_GRADE_LUT, Vector::count, cur_history, current_frame, current_query_frame, DEBUG_LINE_COUNT, DEBUG_LINES, DEBUG_LINES_MAX, Framebuffer::depth_texture, EditorSettings::DOF, EditorSettings::DOF_focal_length, EditorSettings::DOF_fstop, EditorSettings::DOF_max_blur_radius, EditorSettings::DOF_sensor_height, EDITOR_APORTAL_SIZE, EDITOR_AUDIO_EMITTER_SIZE, EDITOR_LIGHT_SIZE, EDITOR_SETTINGS, AABB::extents, FBM_TEXTURE, Framebuffer::fbo, find_animation(), FONTS, frame_time, GBUFFER_RESOLVE_FBO, GLOBALS, GPU_upload_ui_elements(), GVEL, Framebuffer::h, HISTORY_TEXTURE, Mesh::hulls, GLTexture::i, Image::i, Globals::images, LightmapData::islands, Skeleton::left_hip_pos, SceneData::lighting_probe_volumes, SceneData::lightmap_data, Globals::lights, Uniform::location, EditorSettings::LUT, MAIN_FBO, main_queries, MAIN_RESOLVE_FBO, make_ortho(), master_frame, MAX_AUDIO_EMITTERS, MAX_UI_ELEMENTS, EditorSettings::MBLUR, Player::mesh, EditorSettings::mesh_node_menu_open, Globals::mesh_nodes, Globals::meshes, EditorSettings::MSAA, EditorSettings::NOISE, Skeleton::p_left, Skeleton::p_right, perm(), play_animation(), player, AudioEmitter::pos, AudioPortal::pos, DebugVertex::pos, Light::pos, POSTPROCESS_SHADER, PP_ACES, PP_BLOOM, PP_DOF, EditorSettings::pp_dview, PP_LUT, PP_MBLUR, PP_NOISE, PP_SHADER_VERSIONS, PPDVIEW_DEFAULT, ShaderProgram::program, Skeleton::q_left, Skeleton::q_right, SceneData::reflection_probes, render(), RENDER_FENCE, EditorSettings::render_framerate_target, RENDER_HEIGHT, render_probe_volume(), render_to_cubemap_face(), RENDER_WIDTH, Light::rgb, Skeleton::right_hip_pos, EditorSettings::rotation_axis, Globals::scene_data, SCREEN_HEIGHT, SCREEN_WIDTH, EditorSettings::selected_mn_id, Player::skeleton, SSR_FBO, EditorSettings::TAA, TAA_FBO, TEXT_EBO, TEXT_FBO, TEXT_INDEX_COUNT, TEXT_SHADER, TEXT_VAO, TEXT_VBO, Font::texture, Framebuffer::texture, LightmapData::texture_id, time, MeshNode::translation, ui_element_count, UI_SHADER, UI_VAO, ShaderProgram::uniforms, vec3_add(), vec3_sub(), Framebuffer::w, WIREFRAME_SHADER, EditorSettings::wireframe_toggled, WIREFRAME_VAO, and WIREFRAME_VBO.

Referenced by main(), and render().