summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author3gg <3gg@shellblade.net>2024-02-17 15:46:13 -0800
committer3gg <3gg@shellblade.net>2024-02-17 15:46:13 -0800
commit4f1d07f9a873ca3b6670fa0393483034e4fdf1e4 (patch)
treedac2a6e9011a2d0688ab559da2b8791f760ca6d3
parent25cad97b0b265885d6abc56fefb3f6d58984bc0a (diff)
Fix constness in model loader.
-rw-r--r--gfx/src/asset/model.c20
1 files changed, 8 insertions, 12 deletions
diff --git a/gfx/src/asset/model.c b/gfx/src/asset/model.c
index e0df078..73ce731 100644
--- a/gfx/src/asset/model.c
+++ b/gfx/src/asset/model.c
@@ -673,7 +673,7 @@ static void load_textures_lazy(
673/// the texture, and then defines the sampler shader uniform. 673/// the texture, and then defines the sampler shader uniform.
674static bool load_texture_and_uniform( 674static bool load_texture_and_uniform(
675 const cgltf_data* data, Gfx* gfx, const cgltf_texture_view* texture_view, 675 const cgltf_data* data, Gfx* gfx, const cgltf_texture_view* texture_view,
676 TextureType texture_type, Texture** textures, 676 TextureType texture_type, const Texture** textures,
677 LoadTextureCmd* load_texture_cmds, int* next_uniform, MaterialDesc* desc) { 677 LoadTextureCmd* load_texture_cmds, int* next_uniform, MaterialDesc* desc) {
678 assert(data); 678 assert(data);
679 assert(gfx); 679 assert(gfx);
@@ -726,7 +726,7 @@ static bool load_texture_and_uniform(
726/// materials and the textures used by them. 726/// materials and the textures used by them.
727static bool load_materials( 727static bool load_materials(
728 const cgltf_data* data, Gfx* gfx, LoadTextureCmd* load_texture_cmds, 728 const cgltf_data* data, Gfx* gfx, LoadTextureCmd* load_texture_cmds,
729 Texture** textures, Material** materials) { 729 const Texture** textures, Material** materials) {
730 assert(data); 730 assert(data);
731 assert(gfx); 731 assert(gfx);
732 assert(materials); 732 assert(materials);
@@ -946,8 +946,10 @@ static bool load_meshes(
946 const cgltf_accessor* accessor = prim->indices; 946 const cgltf_accessor* accessor = prim->indices;
947 const cgltf_buffer_view* view = prim->indices->buffer_view; 947 const cgltf_buffer_view* view = prim->indices->buffer_view;
948 const cgltf_size buffer_index = view->buffer - data->buffers; 948 const cgltf_size buffer_index = view->buffer - data->buffers;
949
949 assert(buffer_index < data->buffers_count); 950 assert(buffer_index < data->buffers_count);
950 const Buffer* buffer = buffers[buffer_index]; 951 Buffer* buffer = buffers[buffer_index];
952
951 const cgltf_size component_size = 953 const cgltf_size component_size =
952 get_component_size(accessor->component_type); 954 get_component_size(accessor->component_type);
953 switch (component_size) { 955 switch (component_size) {
@@ -984,8 +986,9 @@ static bool load_meshes(
984 const cgltf_buffer_view* view = accessor->buffer_view; 986 const cgltf_buffer_view* view = accessor->buffer_view;
985 const cgltf_size offset = accessor->offset + view->offset; 987 const cgltf_size offset = accessor->offset + view->offset;
986 const cgltf_size buffer_index = view->buffer - data->buffers; 988 const cgltf_size buffer_index = view->buffer - data->buffers;
989
987 assert(buffer_index < data->buffers_count); 990 assert(buffer_index < data->buffers_count);
988 const Buffer* buffer = buffers[buffer_index]; 991 Buffer* buffer = buffers[buffer_index];
989 992
990 BufferView2d* buffer_view_2d = 0; 993 BufferView2d* buffer_view_2d = 0;
991 BufferView3d* buffer_view_3d = 0; 994 BufferView3d* buffer_view_3d = 0;
@@ -1532,7 +1535,7 @@ static Model* load_scene(
1532 Buffer** tangent_buffers = 0; 1535 Buffer** tangent_buffers = 0;
1533 Buffer** buffers = 0; 1536 Buffer** buffers = 0;
1534 LoadTextureCmd* load_texture_cmds = 0; 1537 LoadTextureCmd* load_texture_cmds = 0;
1535 Texture** textures = 0; 1538 const Texture** textures = 0; // Textures are owned by asset cache.
1536 Material** materials = 0; 1539 Material** materials = 0;
1537 Geometry** geometries = 0; 1540 Geometry** geometries = 0;
1538 Mesh** meshes = 0; 1541 Mesh** meshes = 0;
@@ -1659,13 +1662,6 @@ cleanup:
1659 free(load_texture_cmds); 1662 free(load_texture_cmds);
1660 } 1663 }
1661 if (textures) { 1664 if (textures) {
1662 if (!success) {
1663 for (cgltf_size i = 0; i < data->textures_count; ++i) {
1664 if (textures[i]) {
1665 gfx_destroy_texture(render_backend, &textures[i]);
1666 }
1667 }
1668 }
1669 free(textures); 1665 free(textures);
1670 } 1666 }
1671 if (materials) { 1667 if (materials) {