Skip to content

Commit

Permalink
improve gltf_destroy
Browse files Browse the repository at this point in the history
  • Loading branch information
skyfloogle committed Aug 27, 2024
1 parent ff9530b commit 8e71a67
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
15 changes: 13 additions & 2 deletions gm82gltf.gej
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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": "",
Expand Down
31 changes: 31 additions & 0 deletions gm82gltf.gml
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/root.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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" {
Expand Down

0 comments on commit 8e71a67

Please sign in to comment.