Untitled
Loading...
Searching...
No Matches
load.c File Reference
#include "load.h"
#include <stdio.h>
#include <string.h>
#include "load/init.h"
#include "light/lightmap.h"
#include "utilities/types.h"
#include "stb/stb_image.h"
#include "render/render.h"
#include "audio/audio.h"
#include "ui/fonts.h"
#include "editor/editor.h"

Go to the source code of this file.

Functions

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.
GLuint load_cubemap (const char *path)
 Loads a cubemap in OpenGL naming convention (must be HDR).
GLuint load_3d_lut (const char *filepath)
 Loads a 3D LUT for postprocessing.
unsigned char * open_image (Image *image)
 Opens an image in bytes via stb.
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_ui (const char *name)
void load_ui (const char *name)
void reallocate_rprobe_array ()
 Reallocates RPROBE_CUBE_MAP_ARRAY to new dimensions or when loading.
void write_mesh_node (MeshNode *mn, FILE *f)
void write_skin (GLTFSkin *skin, FILE *f)
void scene_save (const char *name)
 Saves an entire scene into separate files.
void read_mesh_node (MeshNode *mn, FILE *f)
void read_skin (GLTFSkin *skin, FILE *f)
void read_vector (Vector *v, size_t byte_size, FILE *f)
void read_alloc_vector (Vector *v, size_t byte_size, FILE *f)
void free_mesh_node (MeshNode *mn)
void free_skin (GLTFSkin *skin)
void scene_load (const char *name)
 Loads an entire scene from separate files in FileDirectoryRegistry directories.
void scene_save_volumes (const char *name)
 Saves only AudioProbes, AudioPortals, and ReflectionProbes.
void scene_load_volumes (const char *name)
 Loads only AudioProbes, AudioPortals, and ReflectionProbes.
void save_vector (const char *filename, Vector *vec)
void load_vector (const char *filename, Vector *vec)
void save_rprobes (const char *filename, Vector *vec)
void load_rprobes (const char *filename, Vector *vec)
void save_lprobes (const char *filename, Vector *vec)
void load_lprobes (const char *filename, Vector *vec)
void save_aportals (const char *filename, Vector *vec)
void load_aportals (const char *filename, Vector *vec)
void save_aprobes (const char *filename)
void load_aprobes (const char *filename)

Function Documentation

◆ load_texture()

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.

Parameters
pathThe path and name of the texture.
See also
https://registry.khronos.org/OpenGL-Refpages/gl4/html/glTexParameter.xhtml
Parameters
sRGBIndicates if we load this as sRGB.
Returns
Handle to the texture.

Definition at line 19 of file load.c.

References load_texture(), and MIN.

Referenced by add_image_to_registry(), load_texture(), and scene_load().

◆ load_cubemap()

GLuint load_cubemap ( const char * path)

Loads a cubemap in OpenGL naming convention (must be HDR).

Parameters
pathPath to cubemap folder.
Returns
Handle to the cubemap.

Definition at line 160 of file load.c.

References load_cubemap().

Referenced by init(), and load_cubemap().

◆ load_3d_lut()

GLuint load_3d_lut ( const char * filepath)

Loads a 3D LUT for postprocessing.

Parameters
filePathThe path to the LUT.
Returns
Handle to the 3D texture.

Definition at line 221 of file load.c.

References load_3d_lut().

Referenced by init(), and load_3d_lut().

◆ open_image()

unsigned char * open_image ( Image * image)

Opens an image in bytes via stb.

Parameters
imagePointer to Image.

Definition at line 275 of file load.c.

References Image::channels, Image::height, open_image(), Image::path, and Image::width.

Referenced by open_image().

◆ add_image_to_registry()

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.

Parameters
filenameThe name and path to the image.
See also
https://registry.khronos.org/OpenGL-Refpages/gl4/html/glTexParameter.xhtml
Parameters
sRGBIndicates if we load this as sRGB.
Returns
Index of the texture in Globals.images.

Definition at line 292 of file load.c.

References add_image_to_registry(), Image::buf, Image::channels, Vector::count, GLOBALS, Image::handle, Image::i, Globals::images, load_texture(), Image::path, Image::sRGB, and vector_expand().

Referenced by add_image_to_registry(), init_globals(), and load_gltf_texture().

◆ save_ui()

◆ load_ui()

◆ reallocate_rprobe_array()

◆ write_mesh_node()

◆ write_skin()

◆ scene_save()

void scene_save ( const char * name)

Saves an entire scene into separate files.

Parameters
nameThe name of the scene.
Note
The scene directories and bin suffixes are prepended and appended, only the name is needed.

Definition at line 502 of file load.c.

References Asset::aabb, AssetInstance::aabb, ConvexHull::aabb, Entity::aabb, Mesh::aabb, PhysicsComponent::aabb, SceneData::aabb, Material::absorption_coefficients, AnimationTrack::active, TriangleAdjacency::adjacent_indices, Material::alpha_cutoff, Material::alpha_mode, PhysicsComponent::angular_velocity, ANIM_TARGET_BOOL, ANIM_TARGET_FLOAT, ANIM_TARGET_INT, ANIM_TARGET_VEC3, ANIMATION_COMPONENTS, Asset::animation_count, Asset::animations, Material::ao_strength, Material::ao_tex, aportal_registry, aprobe_registry, Material::arm_tex, Animation::asset_id, Asset::asset_id, AssetInstance::asset_id, Mesh::asset_id, ASSET_INSTANCES, Globals::assets, PhysicsComponent::at_rest, LightmapData::atlas, AUDIO_NUM_BANDS, Globals::audio_portals, LightmapAtlas::block_size, Vector::buffer, Mesh::bvh_indices, SceneData::bvh_indices, SceneData::bvh_indices_count, SceneData::bvh_nodes, Mesh::bvh_prim, CAST_VEC, PhysicsComponent::cd, PhysicsComponent::center_of_mass, ConvexHull::centroid, Animation::channel_count, Animation::channels, AnimationSampler::count, Vector::count, AnimationTrack::current_time, AnimationTrack::data_byte_offset, AnimationTrack::data_index_offset, AnimationTrack::data_type, DEFAULT_TEXTURES, Material::diffuse_tex, FileDirectoryRegistry::directory, Material::double_sided, AnimationTrack::duration, AnimationSampler::elem_count, Material::emissive_strength, Material::emissive_tex, AnimationComponent::ent, PhysicsComponent::ent, ENTITIES, ConvexHull::faces, AssetInstance::first_skin, FONTS, AnimationComponent::free, AssetInstance::free, Entity::free, PhysicsComponent::free, Material::fwd_shader, Material::gbuffer_shader, GLOBALS, Font::glyph_count, Font::glyphs, LightmapAtlas::height, ConvexHull::hull_faces, Mesh::hulls, AssetInstance::id, Entity::id, Mesh::id, PhysicsComponent::id, Globals::images, LightBVH::indices, Entity::instance, AnimationSampler::interpolation, PhysicsComponent::inverse_inertia, PhysicsComponent::inverse_world, LightmapData::islands, Material::ka, Material::kd, Material::ke, AnimationTrack::kf, AnimationTrack::kf_count, Material::ks, SceneData::light_bvh, light_registry, SceneData::lightmap_data, lightmap_registry, Globals::lights, LightBVH::lights, AnimationTrack::loop, lprobe_registry, Image::mag_filter, PhysicsComponent::mass, Globals::materials, MAX_ANIMATION_COMPONENTS, MAX_ASSET_INSTANCES, MAX_ENTITIES, MAX_PHYSICS_COMPONENTS, Asset::mesh_indices, Entity::mesh_node, UVIsland::mesh_node, Globals::mesh_nodes, Globals::meshes, Material::metallic, Image::mime_type, Image::min_filter, Material::mr_tex, PhysicsComponent::mu, Animation::name, Image::name, Material::name, Mesh::name, SceneData::name, Globals::noclip, Asset::node_count, AssetInstance::node_count, Asset::nodes, LightBVH::nodes, Mesh::nodes, UVIsland::normal, Material::normal_scale, Material::normal_tex, LightmapAtlas::occupied, Asset::path, Image::path, Entity::pc, PHYSICS_COMPONENTS, PhysicsComponent::player_pc, Globals::probe_spacing, Globals::probe_tex_size, UVIsland::rect, SceneData::reflection_probes, PhysicsComponent::restitution, Material::roughness, rprobe_registry, LightmapData::sample_cubemap, Animation::sampler_count, Animation::samplers, save_aportals(), save_aprobes(), save_lightmap_to_binary(), save_rprobes(), save_vector(), Material::scattering_coefficients, scene_apv_registry, Globals::scene_data, scene_registry, scene_save(), Entity::skin, Asset::skin_count, AssetInstance::skin_count, Asset::skins, Globals::skins, Image::sRGB, Mesh::static_mesh, Mesh::submeshes, AnimationKeyframe::time, AnimationSampler::times, AnimationComponent::track_count, AnimationComponent::tracks, Mesh::tri_aabbs, Mesh::tri_adjacency, Mesh::tris, UVIsland::tris, AnimationTrack::type, UVIsland::uvs, AnimationKeyframe::val, AnimationSampler::values, PhysicsComponent::vel, ConvexHull::vertices, Mesh::vertices, LightmapAtlas::width, Globals::world_min, Globals::world_size, Image::wrap_s, Image::wrap_t, write_mesh_node(), and write_skin().

Referenced by render_main_menu(), and scene_save().

◆ read_mesh_node()

◆ read_skin()

◆ read_vector()

void read_vector ( Vector * v,
size_t byte_size,
FILE * f )

◆ read_alloc_vector()

void read_alloc_vector ( Vector * v,
size_t byte_size,
FILE * f )

Definition at line 1224 of file load.c.

References Vector::buffer, Vector::capacity, Vector::count, init_vector(), and read_alloc_vector().

Referenced by read_alloc_vector(), and scene_load().

◆ free_mesh_node()

void free_mesh_node ( MeshNode * mn)

Definition at line 1248 of file load.c.

References free_mesh_node(), and MeshNode::uv_map.

Referenced by free_mesh_node(), and scene_load().

◆ free_skin()

void free_skin ( GLTFSkin * skin)

Definition at line 1254 of file load.c.

References GLTFSkin::final_mat, free_skin(), GLTFSkin::inverse_bind, and GLTFSkin::joints.

Referenced by free_skin(), and scene_load().

◆ scene_load()

void scene_load ( const char * name)

Loads an entire scene from separate files in FileDirectoryRegistry directories.

Parameters
nameThe name of the scene.
Note
The scene directories and bin suffixes are prepended and appended, only the name is needed.

Definition at line 1262 of file load.c.

References Asset::aabb, AssetInstance::aabb, ConvexHull::aabb, Entity::aabb, Mesh::aabb, PhysicsComponent::aabb, SceneData::aabb, Material::absorption_coefficients, AnimationTrack::active, add_all_meshes_to_buffer(), add_all_text_boxes_to_draw_buffer(), TriangleAdjacency::adjacent_indices, Material::alpha_cutoff, Material::alpha_mode, PhysicsComponent::angular_velocity, ANIM_TARGET_BOOL, ANIM_TARGET_FLOAT, ANIM_TARGET_INT, ANIM_TARGET_VEC3, ANIMATION_COMPONENTS, Asset::animation_count, Asset::animations, Material::ao_strength, Material::ao_tex, aportal_registry, aprobe_registry, Material::arm_tex, Animation::asset_id, Asset::asset_id, AssetInstance::asset_id, Mesh::asset_id, ASSET_INSTANCES, Globals::assets, PhysicsComponent::at_rest, LightmapData::atlas, AUDIO_NUM_BANDS, Globals::audio_portals, LightmapAtlas::block_size, Image::buf, Vector::buffer, Mesh::bvh_indices, SceneData::bvh_indices, SceneData::bvh_indices_count, SceneData::bvh_nodes, Mesh::bvh_prim, Vector::capacity, CAST_VEC, PhysicsComponent::cd, PhysicsComponent::center_of_mass, ConvexHull::centroid, Animation::channel_count, Animation::channels, Image::channels, AnimationTrack::completion_data, AnimationSampler::count, Vector::count, create_performance_overlay(), AnimationTrack::current_time, AnimationTrack::data, AnimationTrack::data_byte_offset, AnimationTrack::data_index_offset, AnimationTrack::data_type, DEFAULT_TEXTURES, Material::diffuse_tex, FileDirectoryRegistry::directory, Material::double_sided, draw_dirty, AnimationTrack::duration, AnimationSampler::elem_count, Material::emissive_strength, Material::emissive_tex, AnimationComponent::ent, PhysicsComponent::ent, ENTITIES, ConvexHull::faces, GLTFSkin::final_mat, AssetInstance::first_skin, FONTS, AnimationComponent::free, AssetInstance::free, Entity::free, PhysicsComponent::free, free_mesh_node(), free_skin(), Material::fwd_shader, Material::gbuffer_shader, GLOBALS, Font::glyph_count, Font::glyphs, GPU_upload_scene_data(), Image::handle, LightmapAtlas::height, ConvexHull::hull_faces, Mesh::hulls, Image::i, Entity::id, Mesh::id, PhysicsComponent::id, Globals::images, LightBVH::indices, init_vector(), Entity::instance, AnimationSampler::interpolation, GLTFSkin::inverse_bind, PhysicsComponent::inverse_inertia, PhysicsComponent::inverse_world, LightmapData::islands, GLTFSkin::joints, Material::ka, Material::kd, Material::ke, AnimationTrack::kf, AnimationTrack::kf_count, Material::ks, SceneData::light_bvh, light_registry, SceneData::lightmap_data, lightmap_registry, Globals::lights, LightBVH::lights, load_aportals(), load_aprobes(), load_lightmap_from_binary(), load_rprobes(), load_texture(), load_vector(), AnimationTrack::loop, lprobe_registry, Image::mag_filter, PhysicsComponent::mass, Globals::materials, MAX_ANIMATION_COMPONENTS, MAX_ASSET_INSTANCES, MAX_ENTITIES, MAX_PHYSICS_COMPONENTS, Asset::mesh_indices, Entity::mesh_node, UVIsland::mesh_node, Globals::mesh_nodes, Globals::meshes, Material::metallic, Image::mime_type, Image::min_filter, Material::mr_tex, PhysicsComponent::mu, Animation::name, Image::name, Material::name, Mesh::name, SceneData::name, Globals::noclip, Asset::node_count, AssetInstance::node_count, Asset::nodes, LightBVH::nodes, Mesh::nodes, UVIsland::normal, Material::normal_scale, Material::normal_tex, LightmapAtlas::occupied, Asset::path, Image::path, Entity::pc, PHYSICS_COMPONENTS, PhysicsComponent::player_pc, Globals::probe_spacing, Globals::probe_tex_size, read_alloc_vector(), read_mesh_node(), read_skin(), read_vector(), reallocate_rprobe_array(), UVIsland::rect, SceneData::reflection_probes, PhysicsComponent::restitution, Material::roughness, rprobe_registry, LightmapData::sample_cubemap, Animation::sampler_count, Animation::samplers, Material::scattering_coefficients, scene_apv_registry, Globals::scene_data, scene_load(), scene_registry, Entity::skin, Asset::skin_count, AssetInstance::skin_count, Asset::skins, Globals::skins, Image::sRGB, Mesh::static_mesh, Mesh::submeshes, AnimationKeyframe::time, AnimationSampler::times, AnimationComponent::track_count, AnimationComponent::tracks, Mesh::tri_aabbs, Mesh::tri_adjacency, Mesh::tris, UVIsland::tris, AnimationTrack::type, upload_lights(), upload_material_data(), MeshNode::uv_map, UVIsland::uvs, AnimationKeyframe::val, AnimationSampler::values, PhysicsComponent::vel, Globals::vertex_layouts, ConvexHull::vertices, Mesh::vertices, LightmapAtlas::width, Globals::world_min, Globals::world_size, Image::wrap_s, and Image::wrap_t.

Referenced by render_main_menu(), and scene_load().

◆ scene_save_volumes()

void scene_save_volumes ( const char * name)

◆ scene_load_volumes()

◆ save_vector()

void save_vector ( const char * filename,
Vector * vec )

◆ load_vector()

void load_vector ( const char * filename,
Vector * vec )

Definition at line 2529 of file load.c.

References load_vector(), read_vector(), and Vector::type_size.

Referenced by load_vector(), render_light_menu(), scene_load(), and scene_load_volumes().

◆ save_rprobes()

void save_rprobes ( const char * filename,
Vector * vec )

Definition at line 2543 of file load.c.

References Vector::buffer, Vector::count, save_rprobes(), and Vector::type_size.

Referenced by save_rprobes(), scene_save(), and scene_save_volumes().

◆ load_rprobes()

void load_rprobes ( const char * filename,
Vector * vec )

◆ save_lprobes()

void save_lprobes ( const char * filename,
Vector * vec )

◆ load_lprobes()

void load_lprobes ( const char * filename,
Vector * vec )

◆ save_aportals()

void save_aportals ( const char * filename,
Vector * vec )

◆ load_aportals()

◆ save_aprobes()

void save_aprobes ( const char * filename)

◆ load_aprobes()