Untitled
Loading...
Searching...
No Matches
init.c File Reference
#include <SDL2/SDL.h>
#include <GL/glew.h>
#include <SDL2/SDL_events.h>
#include <SDL2/SDL_mouse.h>
#include <SDL2/SDL_video.h>
#include "SDL2/SDL_atomic.h"
#include "SDL2/SDL_mutex.h"
#include "SDL2/SDL_opengl.h"
#include "editor/editor.h"
#include "fftw3.h"
#include "utilities/mathf.h"
#include <complex.h>
#include <math.h>
#include <stdatomic.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "init.h"
#include "core/mesh.h"
#include "render/render.h"
#include "core/engine_types.h"
#include "ui/ui.h"
#include "core/shaders.h"
#include "stb/stb_image.h"
#include "utilities/utilities.h"
#include "core/acceleration.h"
#include "ECS/entity.h"
#include "load/load.h"
#include "ui/fonts.h"
#include "nuklear/nuklear.h"
#include "nuklear/nuklear_sdl_gl3.h"
#include "audio/audio.h"
#include "audio/audio_ir.h"
#include "ui/ui_callbacks.h"

Go to the source code of this file.

Macros

#define MN_STARTING_SIZE   10000
#define SKIN_STARTING_SIZE   10000
#define CROSSFADE_FRAMES   512

Functions

Material * init_new_material (const char *filename)
 Expands Globals.materials and initializes a material to default.
void init_mesh (Mesh *mesh)
 Initializes a static or dynamic Mesh.
void MN_INIT ()
void SKIN_INIT ()
MeshNode * find_free_mn ()
void * find_free_in_vector (Vector *v, size_t byte_size, size_t free_byte_offset, size_t id_byte_offset)
Asset * retrieve_asset_by_name (const char *asset_name)
Mesh * retrieve_mesh_by_name (const char *asset_name, const char *mesh_name)
 Searches Globals.assets for a certain Mesh.
void set_mn_components_to_children (MeshNode *mns, MeshNode *mn, MeshNode *parent)
AssetInstance * init_new_asset_instance (const char *asset_name, vec3 tr, vec4 rot, vec3 scale)
 Initializes and spawns a new AssetInstance based on an Asset name, and places the AssetInstance.model at a certain transformation.
void destroy_asset_instance (uint32_t id)
 Destroys and frees an AssetInstance.
void init_player_PC (PhysicsComponent *pc, Player *player)
void init_player ()
void GPU_unwrap_mesh_to_buffers (Mesh *m, Vector *vertices, Vector *tris, Vector *nodes)
void GPU_upload_scene_data ()
 Uploads current Globals and SceneData structures to the GPU for baking SSBOs.
void GPU_init_cluster_aabbs ()
 Initializes AABBs on the GPU for clustered forward shading.
void init_default_textures ()
 Initializes dummy default textures inside of Globals.images that are used as fallback for empty Materials.
bool init_globals ()
bool init_vertex_layouts ()
void precompute_fbm_texture ()
void precompute_ssao_kernel ()
int generate_gl_texture (GLTexture tex)
GLTexture init_gl_texture (GLenum target, GLint internal_format, GLenum format, GLenum type, GLint min_filter, GLint mag_filter, GLint wrap_s, GLint wrap_t, GLint wrap_r, int w, int h, int d, int levels, DepthMode dm)
void init_fbo (Framebuffer *fbo)
void change_fbo_resolution (Framebuffer *fbo, int w, int h, bool skip_depth)
 Changes Framebuffer's resolution, and deletes the old textures.
void init_sdl_audio ()
void convolver_node_process_pcm_frames (ma_node *pNode, const float **ppFramesIn, ma_uint32 *pFrameCountIn, float **ppFramesOut, ma_uint32 *pFrameCountOut)
void init_audio_scratch_buffers ()
void deallocate_fbo (Framebuffer *fbo)
void init_gl_renderbuffer (GLRenderbuffer *rbo, GLint internal_format, GLsizei w, GLsizei h, bool multisampled, int samples)
void allocate_main_fbo ()
 Allocates the main FBO, changes if MSAA is enabled.
void allocate_gbuffer_msaa ()
 Allocated a gbuffer with multisampled textures.
void allocate_gbuffer ()
 Allocates a gbuffer without multisampled textures.
bool init (SDL_Window **window, SDL_GLContext *context)
 Initializes the engine, including SDL, OpenGL, GLEW, Nuklear, and engine-specific systems.

Variables

vec3 * fbm_tex = NULL
int estimated_frame_count = 0
ma_node_vtable my_custom_node_vtable

Macro Definition Documentation

◆ MN_STARTING_SIZE

#define MN_STARTING_SIZE   10000

Definition at line 121 of file init.c.

Referenced by MN_INIT().

◆ SKIN_STARTING_SIZE

#define SKIN_STARTING_SIZE   10000

Definition at line 137 of file init.c.

Referenced by SKIN_INIT().

◆ CROSSFADE_FRAMES

#define CROSSFADE_FRAMES   512

Definition at line 1405 of file init.c.

Referenced by convolver_node_process_pcm_frames().

Function Documentation

◆ init_new_material()

Material * init_new_material ( const char * filename)

◆ init_mesh()

◆ MN_INIT()

void MN_INIT ( )

◆ SKIN_INIT()

void SKIN_INIT ( )

◆ find_free_mn()

MeshNode * find_free_mn ( )

◆ find_free_in_vector()

void * find_free_in_vector ( Vector * v,
size_t byte_size,
size_t free_byte_offset,
size_t id_byte_offset )

◆ retrieve_asset_by_name()

Asset * retrieve_asset_by_name ( const char * asset_name)

◆ retrieve_mesh_by_name()

Mesh * retrieve_mesh_by_name ( const char * asset_name,
const char * mesh_name )

Searches Globals.assets for a certain Mesh.

Parameters
asset_nameThe Asset name.
mesh_nameThe Mesh name.
Returns
Pointer to the Mesh.

Definition at line 242 of file init.c.

References Globals::assets, CAST_VEC, Vector::count, GLOBALS, Asset::mesh_indices, Globals::meshes, Mesh::name, Asset::path, and retrieve_mesh_by_name().

Referenced by retrieve_mesh_by_name().

◆ set_mn_components_to_children()

void set_mn_components_to_children ( MeshNode * mns,
MeshNode * mn,
MeshNode * parent )

◆ init_new_asset_instance()

AssetInstance * init_new_asset_instance ( const char * asset_name,
vec3 tr,
vec4 rot,
vec3 scale )

Initializes and spawns a new AssetInstance based on an Asset name, and places the AssetInstance.model at a certain transformation.

Parameters
asset_nameThe name of the Asset.
trThe translation.
rotThe rotation.
scaleThe scale.

Definition at line 304 of file init.c.

References Asset::aabb, AssetInstance::aabb, GLTFSkin::animation_indices, Asset::asset_id, AssetInstance::asset_id, MeshNode::asset_instance, ASSET_INSTANCES, Globals::assets, CAST_VEC, MeshNode::child_count, MeshNode::children, compose_trs_from_vectors(), Vector::count, create_entity(), MeshNode::ent, GLTFSkin::final_mat, find_free_in_vector(), AssetInstance::first_skin, AssetInstance::free, GLTFSkin::free, MeshNode::free, GLOBALS, AssetInstance::id, GLTFSkin::id, MeshNode::id, init_new_asset_instance(), GLTFSkin::inverse_bind, GLTFSkin::joint_count, GLTFSkin::joints, MeshNode::local_id, MAX_ANIMATION_INDICES, MAX_ASSET_INSTANCES, Globals::mesh_nodes, AssetInstance::model, GLTFSkin::name, MeshNode::name, Asset::node_count, AssetInstance::node_count, AssetInstance::node_indices, Asset::nodes, MeshNode::parent, MeshNode::pc, MeshNode::physics_mode, retrieve_asset_by_name(), AssetInstance::rot, rot(), AssetInstance::scale, set_mn_components_to_children(), MeshNode::skin, Asset::skin_count, AssetInstance::skin_count, AssetInstance::skin_indices, Asset::skins, Globals::skins, MeshNode::skip_directional_uv_lighting, AssetInstance::tr, and MeshNode::uv_map.

Referenced by init_new_asset_instance(), main(), and render_main_menu().

◆ destroy_asset_instance()

◆ init_player_PC()

◆ init_player()

◆ GPU_unwrap_mesh_to_buffers()

◆ GPU_upload_scene_data()

◆ GPU_init_cluster_aabbs()

void GPU_init_cluster_aabbs ( )

Initializes AABBs on the GPU for clustered forward shading.

Definition at line 778 of file init.c.

References GPU_init_cluster_aabbs(), GRID_X, GRID_Y, GRID_Z, INIT_CLUSTER_AABBS_SHADER, RENDER_HEIGHT, RENDER_WIDTH, VIEW_FAR, and VIEW_NEAR.

Referenced by GPU_init_cluster_aabbs(), and main().

◆ init_default_textures()

void init_default_textures ( )

◆ init_globals()

bool init_globals ( )

<The maximum amount of Manifolds in MANIFOLDS.

Definition at line 920 of file init.c.

References Manifold::a, Material::absorption_coefficients, EditorSettings::ACES, add_image_to_registry(), ANIMATION_COMPONENTS, EditorSettings::ao_iterations, EditorSettings::ao_threshold, SceneData::APV_FILE, Material::arm_tex, asset_dir, ASSET_INSTANCES, Globals::assets, PhysicsComponent::at_rest, AUDIO_EMITTERS, AUDIO_NUM_BANDS, Globals::audio_portals, EditorSettings::audio_probe_bounces, EditorSettings::audio_probe_iterations, SceneData::audio_probe_volumes, Globals::audio_probes, AW, Manifold::b, EditorSettings::BLOOM, Vector::buffer, SceneData::bvh_indices, SceneData::bvh_nodes, AABB::center, AnimationTrack::completion_data, create_entity(), AnimationTrack::data, DEFAULT_ARM, DEFAULT_DIFFUSE, DEFAULT_EMISSIVE, DEFAULT_NORMAL, DEPTH_PRE_PASS_SHADER, Material::diffuse_tex, Light::dir, DIRECTIONAL_LIGHT, DIRECTIONAL_MAP_NORMALIZE_SHADER, EditorSettings::DOF, EditorSettings::DOF_focal_length, EditorSettings::DOF_fstop, EditorSettings::DOF_max_blur_radius, EditorSettings::DOF_sensor_height, DYNAMIC_SHADER, EditorSettings::editor_mode, EDITOR_SETTINGS, Material::emissive_tex, ENTITIES, Light::entity_id, EW, AABB::extents, AnimationComponent::free, AssetInstance::free, AudioEmitter::free, Entity::free, Manifold::free, PhysicsComponent::free, EditorSettings::FULL_GBUFFER, Material::fwd_shader, Material::gbuffer_shader, GBUFFER_VERSIONS, GLOBALS, AssetInstance::id, AudioEmitter::id, Entity::id, PhysicsComponent::id, Globals::images, LightBVH::indices, init_default_textures(), init_globals(), init_new_material(), init_vector(), Light::intensity, LightmapData::islands, SceneData::light_bvh, Light::light_type, SceneData::lighting_probe_volumes, LIGHTMAP_BOUNCE_SHADER, LIGHTMAP_DATA, SceneData::lightmap_data, LIGHTMAP_DENOISE_SHADER, LIGHTMAP_DILATE_SHADER, LIGHTMAP_SHADER, Globals::lights, LightBVH::lights, Globals::lights_dirty, EditorSettings::lm_aabb, EditorSettings::lm_iterations, SceneData::LOADED_AUDIO_PV, SceneData::LOADED_AUDIO_PV_FLAG, SceneData::LOADED_LIGHTING_PV, SceneData::LOADED_LIGHTING_PV_FLAG, SceneData::LPV_FILE, LPV_SLOTS, EditorSettings::LUT, MANIFOLDS, Globals::materials, MAX_ANIMATION_COMPONENTS, MAX_ASSET_INSTANCES, MAX_AUDIO_EMITTERS, MAX_AUDIO_PROBE_VOLUMES, MAX_ENTITIES, MAX_LIGHTS_PER_MESH, MAX_MANIFOLDS, MAX_MESH_NODES, MAX_PHYSICS_COMPONENTS, MAX_PORTALS, MAX_TRACKS, EditorSettings::MBLUR, MESH_BVH_DATA, MESH_DATA, Globals::mesh_light_indices, Globals::meshes, MeshData::meshes, EditorSettings::mfactor, EditorSettings::mfactor_enabled, AStarWorkspace::min_heap, MN_INIT(), Material::mr_tex, EditorSettings::MSAA, Globals::msaa_samples, Font::name, BVHGPU::nodes, LightBVH::nodes, EditorSettings::NOISE, Material::normal_tex, AStarWorkspace::path, AStarWorkspace::path_count, PHYSICS_COMPONENTS, POINT_LIGHT, POINT_LIGHT_SHADOW_SHADER, Light::pos, POSTPROCESS_SHADER, PROBE_BAKE_SHADER, EditorSettings::probe_iterations, Globals::probe_spacing, Globals::probe_tex_size, PROBE_UNPACK_SHADER, PROBE_VOLUME_DEPTH, PROBE_VOLUME_HEIGHT, PROBE_VOLUME_WIDTH, ShaderProgram::program, read_json_msdf(), SceneData::reflection_probes, EditorSettings::render_framerate_target, EditorSettings::reverb_wet, Light::rgb, rprobe_dir, Material::scattering_coefficients, SCENE_BVH_DATA, Globals::scene_data, EditorSettings::selected_audio_emitter_id, EditorSettings::selected_r_probe, EditorSettings::SELMODE, SELMODE_LIGHT, SHADOW_MAP_SHADER, SKIN_INIT(), SKY_SHADER, Light::sm_dirty, EditorSettings::SSAO, SSAO_BLUR_SHADER, SSAO_SHADER, EditorSettings::SSR, SSR_BLUR_SHADER, SSR_SHADER, AStarWorkspace::stack, EditorSettings::TAA, EditorSettings::texels_per_uv_unit, TEXT_SHADER, Font::texture, Light::threshold, AnimationComponent::track_count, AnimationComponent::tracks, TRI_DATA, TriData::tris, UBERSHADER_VERSIONS, EditorSettings::UI, EditorSettings::undo_stack_max_byte_size, LightmapSSBO::uvs, vec3_normalize(), vector_expand(), VERTEX_DATA, Globals::vertex_layouts, VertexData::vertices, WIREFRAME_SHADER, and EditorSettings::wireframe_toggled.

Referenced by init(), and init_globals().

◆ init_vertex_layouts()

◆ precompute_fbm_texture()

void precompute_fbm_texture ( )

◆ precompute_ssao_kernel()

void precompute_ssao_kernel ( )

◆ generate_gl_texture()

◆ init_gl_texture()

GLTexture init_gl_texture ( GLenum target,
GLint internal_format,
GLenum format,
GLenum type,
GLint min_filter,
GLint mag_filter,
GLint wrap_s,
GLint wrap_t,
GLint wrap_r,
int w,
int h,
int d,
int levels,
DepthMode dm )

◆ init_fbo()

◆ change_fbo_resolution()

void change_fbo_resolution ( Framebuffer * fbo,
int w,
int h,
bool skip_depth )

Changes Framebuffer's resolution, and deletes the old textures.

Parameters
fboThe Framebuffer that changes.
wThe width.
hThe height.
skip_depthIf depth texture needs to also change.

Definition at line 1361 of file init.c.

References change_fbo_resolution(), Framebuffer::depth_texture, Framebuffer::fbo, generate_gl_texture(), Framebuffer::h, GLTexture::h, GLTexture::i, init_fbo(), Framebuffer::texture, Framebuffer::texture_count, Framebuffer::w, and GLTexture::w.

Referenced by change_bloom_res(), change_dof_res(), change_fbo_resolution(), change_render_resolution(), and change_ssao_res().

◆ init_sdl_audio()

void init_sdl_audio ( )

Definition at line 1387 of file init.c.

References AUDIO_ENGINE, estimated_frame_count, init_sdl_audio(), SDL_AUDIO_DEVICE, and SDLAudioCallback().

Referenced by init(), and init_sdl_audio().

◆ convolver_node_process_pcm_frames()

◆ init_audio_scratch_buffers()

◆ deallocate_fbo()

◆ init_gl_renderbuffer()

void init_gl_renderbuffer ( GLRenderbuffer * rbo,
GLint internal_format,
GLsizei w,
GLsizei h,
bool multisampled,
int samples )

◆ allocate_main_fbo()

◆ allocate_gbuffer_msaa()

◆ allocate_gbuffer()

◆ init()

bool init ( SDL_Window ** window,
SDL_GLContext * context )

Initializes the engine, including SDL, OpenGL, GLEW, Nuklear, and engine-specific systems.

Parameters
windowSDL Window.
contextSDL Context.

Definition at line 1987 of file init.c.

References allocate_gbuffer(), allocate_gbuffer_msaa(), allocate_main_fbo(), AUDIO_ENGINE, BAND_IMPULSES, ConvolverNode::base, bind_render_ssbos(), BLENDED_RPROBE_CUBE_MAP, BLOOM_HEIGHT, BLOOM_PYRAMID, BLOOM_WIDTH, BOKEH_FBO, BRDF_FBO, BRDF_LUT, BRDF_SHADER, BUFFER_FRAMES, CAM_UBO, cam_ubo_padded, cam_ubo_ptr, CLUSTER_AABB_SSBO, CLUSTER_SSBO, COC_FBO, COLOR_GRADE_LUT, CONVOLVE_TRIANGLE_VAO, CONVOLVE_TRIANGLE_VBO, CONVOLVER_NODE, DEBUG_LINES_MAX, DEFAULT_POINT_LIGHT_SHADOWS_SIZE, DEFAULT_SHADOW_MAP_SIZE, DEPTH_DOWNSAMPLE_FBO, DEPTH_MODE_HW, DEPTH_MODE_NONE, Framebuffer::depth_rbo, Framebuffer::depth_texture, DOF_HEIGHT, DOF_WIDTH, EDITOR_SETTINGS, FBM_TEXTURE, FBM_TEXTURE_SIZE, Framebuffer::fbo, FILE_DIR_REGISTRY_INIT(), FONTS_INIT(), FOOTSTEP_EMITTER, FS_VAO, GBUFFER_FBO, GBUFFER_RESOLVE_FBO, GLOBAL_INSTANCE_SSBO, GLOBAL_LIGHT_INDICES_SSBO, Framebuffer::h, HISTORY_FBO, HISTORY_TEXTURE, HRTF_TD, GLRenderbuffer::i, GLTexture::i, INDIRECT_ARRAYS_COMMAND_BUFFER, INDIRECT_ARRAYS_COMMAND_BUFFER_OUT, indirect_arrays_out_ptr, indirect_arrays_ptr, INDIRECT_ELEMENTS_COMMAND_BUFFER, INDIRECT_ELEMENTS_COMMAND_BUFFER_OUT, indirect_elements_out_ptr, indirect_elements_ptr, init(), init_action_callbacks(), init_audio_scratch_buffers(), init_band_kernels(), init_emitter(), init_fbo(), init_gl_texture(), init_globals(), init_hover_callbacks(), init_player(), init_sdl_audio(), init_vertex_layouts(), INSTANCE_SSBO, instance_ssbo_ptr, instance_ssbo_size, INSTANCE_VBO, instance_vbo_ptr, instance_vbo_size, HRTFThreadData::ir_swap_lock, JOINT_SSBO, joint_ssbo_ptr, joint_ssbo_size, LIGHT_CAM_UBO, light_cam_ubo_padded, light_cam_ubo_ptr, LIGHT_SSBO, light_ssbo_ptr, light_ssbo_size, LIGHTMAP_FBO, LIGHTMAP_HEIGHT, LIGHTMAP_ID_TEXTURE, LIGHTMAP_NORM_TEXTURE, LIGHTMAP_POS_TEXTURE, LIGHTMAP_SSBO, LIGHTMAP_VAO, LIGHTMAP_VBO, LIGHTMAP_WIDTH, load_3d_lut(), load_cubemap(), load_hrtf_from_binary(), ConvolverNode::lock, LPV_SLOTS, LPV_TEXTURE, MAIN_EBO, MAIN_FBO, MAIN_RESOLVE_FBO, MAIN_VAO, MAIN_VBO, MATERIAL_SSBO, MAX_DIRECTIONAL_LIGHTS, MAX_INSTANCES, MAX_JOINT_MATRICES, MAX_LIGHTS, MAX_LIGHTS_PER_CLUSTER, MAX_LIGHTS_PER_MESH, MAX_MESH_NODES, MAX_POINT_LIGHT_SHADOWS_CMA, MAX_RPROBE_MIPS, MAX_TEXT_BOX_CHARACTERS, MAX_TEXT_BOXES, MAX_UI_ELEMENTS, MESH_BVH_SSBO, MESH_LIGHT_SSBO, mesh_light_ssbo_ptr, mesh_light_ssbo_size, MESH_NODE_SSBO, mesh_node_ssbo_ptr, mesh_node_ssbo_size, MESH_SSBO, EditorSettings::MSAA, my_custom_node_vtable, NK_CTX, play_emitter(), POINT_LIGHT_SHADOWS_FBO, precompute_fbm_texture(), precompute_ssao_kernel(), PROBE_SSBO, PROBE_VOLUME_DEPTH_PADDED, PROBE_VOLUME_HEIGHT, PROBE_VOLUME_UBO, probe_volume_ubo_padded, probe_volume_ubo_ptr, PROBE_VOLUME_WIDTH, ShaderProgram::program, rand(), Framebuffer::rbo_count, RENDER_HEIGHT, RENDER_UBO, RENDER_WIDTH, RPROBE_BACK_FBO, RPROBE_BACK_TEXTURE, RPROBE_CUBE_MAP_ARRAY, RPROBE_DEPTH_TEXTURE, RPROBE_FBO, RPROBE_HEIGHT, RPROBE_SSBO, RPROBE_UBO, rprobe_ubo_padded, rprobe_ubo_ptr, RPROBE_WIDTH, SCENE_BVH_SSBO, SCREEN_HEIGHT, SCREEN_WIDTH, SDL_AUDIO_DEVICE, SH_MAX, SHADERS_INIT(), SHADOW_MAP_FBO, SKY_VAO, SKY_VBO, SKYBOX, SOBEL_FBO, SOBEL_TEXTURE, SSAO_BLUR_FBO, SSAO_FBO, SSAO_HEIGHT, SSAO_KERNEL, SSAO_KERNEL_SIZE, SSAO_KERNEL_UBO, SSAO_NOISE_TEXTURE, SSAO_WIDTH, SSR_BLUR_FBO, SSR_FBO, SSR_HEIGHT, SSR_WIDTH, STATES_INIT(), TAA_FBO, TEMP_RPROBE_CUBE_MAP, TEXT_BOX_SSBO, text_box_ssbo_ptr, text_box_ssbo_size, TEXT_EBO, TEXT_FBO, TEXT_HEIGHT, TEXT_VAO, TEXT_VBO, text_vbo_size, TEXT_WIDTH, Framebuffer::texture, Framebuffer::texture_count, TOTAL_CLUSTERS, TRI_SSBO, UI_INIT(), UI_INSTANCE_VBO, ui_instance_vbo_ptr, ui_instance_vbo_size, UI_SSBO, ui_ssbo_ptr, ui_ssbo_size, UI_VAO, UI_VBO, ui_vbo_ptr, ui_vbo_size, UNDO_INIT(), VERTEX_SSBO, Framebuffer::w, window, WIREFRAME_VAO, and WIREFRAME_VBO.

Referenced by init(), and main().

Variable Documentation

◆ fbm_tex

vec3* fbm_tex = NULL

Definition at line 1180 of file init.c.

Referenced by precompute_fbm_texture().

◆ estimated_frame_count

int estimated_frame_count = 0

Definition at line 1386 of file init.c.

Referenced by init_sdl_audio().

◆ my_custom_node_vtable

ma_node_vtable my_custom_node_vtable
Initial value:
=
{
NULL,
2,
1,
0
}
void convolver_node_process_pcm_frames(ma_node *pNode, const float **ppFramesIn, ma_uint32 *pFrameCountIn, float **ppFramesOut, ma_uint32 *pFrameCountOut)
Definition init.c:1409

Definition at line 1592 of file init.c.

Referenced by init().