diff --git a/gm82gltf.gej b/gm82gltf.gej index 6fe2b4e..5285fc4 100644 --- a/gm82gltf.gej +++ b/gm82gltf.gej @@ -191,10 +191,10 @@ "returntype": 2 }, { - "name": "gltf_destroy", + "name": "__gltf_destroy", "extname": "", "calltype": 12, - "helpline": "gltf_destroy(gltf)", + "helpline": "__gltf_destroy(gltf)", "hidden": false, "argtypes": [ 2 @@ -1177,6 +1177,17 @@ ], "returntype": 2 }, + { + "name": "gltf_destroy", + "extname": "", + "calltype": 2, + "helpline": "gltf_destroy(gltf)", + "hidden": false, + "argtypes": [ + 2 + ], + "returntype": 2 + }, { "name": "gltf_set_environment_map", "extname": "", diff --git a/gm82gltf.gml b/gm82gltf.gml index 000186a..423ef4f 100644 --- a/gm82gltf.gml +++ b/gm82gltf.gml @@ -133,6 +133,37 @@ return __gltf +#define gltf_destroy + ///gltf_destroy(gltf) + var __i,__j,__k,__mesh,__primitive; + // free textures + __i=0 repeat (gltf_texture_count(argument0)) { + background_delete(__gm82gltf_backgrounds[argument0,__i]) + } + // free vertex buffers + __i=0 repeat (gltf_mesh_count(argument0)) { + __mesh=__gm82gltf_meshes[argument0,__i] + __j=0 repeat (gltf_mesh_primitive_count(argument0,__i)) { + __primitive=__gm82gltf_primitives[__mesh,__j] + if (gltf_mesh_primitive_indices_accessor(argument0,__i,__j)) + index_buffer_delete(__gm82gltf_meshindices[__mesh,__j]) + vertex_format_delete(__gm82gltf_meshformats[__mesh,__j]) + __k=0 repeat (gltf_mesh_primitive_attribute_count(argument0,__i,__j)) { + vertex_buffer_delete(__gm82gltf_primitivebuffers[__primitive,__k]) + __k+=1 + } + __k=0 repeat (gltf_mesh_primitive_morph_count(__gltf,__i,__j)*3) { + vertex_buffer_delete(__gm82gltf_primitivebuffers[__primitive,__k]) + __k+=1 + } + __j+=1 + } + __i+=1 + } + // delete the gltf + __gltf_destroy(argument0) + + #define __gltf_format_add ///__gltf_format_add(type,comptype,normalized,semantic,slot):usage var __type; diff --git a/src/root.zig b/src/root.zig index e0a65f9..aa1d7b0 100644 --- a/src/root.zig +++ b/src/root.zig @@ -374,7 +374,7 @@ export fn __gltf_load(filename: [*:0]const u8) f64 { return -1; } -export fn gltf_destroy(id: f64) f64 { +export fn __gltf_destroy(id: f64) f64 { const entry = g_gltfs.fetchSwapRemove(@intFromFloat(id)) orelse return 0; entry.value.deinit(); return 0; @@ -1121,7 +1121,7 @@ test "gltf stuff" { try testing.expectEqual(1, gltf_node_child(1, 0, 0)); try testing.expectEqual(648, g_gltfs.get(1).?.buffers[0].len); try testing.expectEqualStrings("NORMAL", std.mem.span(gltf_mesh_primitive_attribute_semantic(1, 0, 0, 0))); - try testing.expectEqual(0, gltf_destroy(1)); + try testing.expectEqual(0, __gltf_destroy(1)); } test "matrices" {