diff options
| author | Ray <[email protected]> | 2020-12-01 23:44:10 +0100 |
|---|---|---|
| committer | Ray <[email protected]> | 2020-12-01 23:44:10 +0100 |
| commit | 60928ec82c28fae8ea98f5f29e260b24717123ff (patch) | |
| tree | 10e54db780c6d944dbf185f8f453cd7bd87c1409 /src/models.c | |
| parent | 0481053dad5f784a2aa5c25ab6d32145bbdaa4ff (diff) | |
| download | raylib-60928ec82c28fae8ea98f5f29e260b24717123ff.tar.gz raylib-60928ec82c28fae8ea98f5f29e260b24717123ff.zip | |
ADDED: UnloadModelKeepMeshes() #1441
Diffstat (limited to 'src/models.c')
| -rw-r--r-- | src/models.c | 47 |
1 files changed, 41 insertions, 6 deletions
diff --git a/src/models.c b/src/models.c index dbc58fc0..4ce4f825 100644 --- a/src/models.c +++ b/src/models.c @@ -782,16 +782,50 @@ Model LoadModelFromMesh(Mesh mesh) return model; } -// Unload model from memory (RAM and/or VRAM) +// Unload model (meshes/materials) from memory (RAM and/or VRAM) +// NOTE: This function takes care of all model elements, for a detailed control +// over them, use UnloadMesh() and UnloadMaterial() void UnloadModel(Model model) { + // Unload meshes for (int i = 0; i < model.meshCount; i++) UnloadMesh(model.meshes[i]); - // As the user could be sharing shaders and textures between models, - // we don't unload the material but just free it's maps, the user - // is responsible for freeing models shaders and textures - for (int i = 0; i < model.materialCount; i++) RL_FREE(model.materials[i].maps); + // Unload materials maps and params + // NOTE: As the user could be sharing shaders and textures between models, + // we don't unload the material but just free it's maps and params, + // the user is responsible for freeing models shaders and textures + for (int i = 0; i < model.materialCount; i++) + { + RL_FREE(model.materials[i].maps); + RL_FREE(model.materials[i].params); + } + + // Unload arrays + RL_FREE(model.meshes); + RL_FREE(model.materials); + RL_FREE(model.meshMaterial); + + // Unload animation data + RL_FREE(model.bones); + RL_FREE(model.bindPose); + + TRACELOG(LOG_INFO, "MODEL: Unloaded model (and meshes) from RAM and VRAM"); +} + +// Unload model (but not meshes) from memory (RAM and/or VRAM) +void UnloadModelKeepMeshes(Model model) +{ + // Unload materials maps and params + // NOTE: As the user could be sharing shaders and textures between models, + // we don't unload the material but just free it's maps and params, + // the user is responsible for freeing models shaders and textures + for (int i = 0; i < model.materialCount; i++) + { + RL_FREE(model.materials[i].maps); + RL_FREE(model.materials[i].params); + } + // Unload arrays RL_FREE(model.meshes); RL_FREE(model.materials); RL_FREE(model.meshMaterial); @@ -800,7 +834,7 @@ void UnloadModel(Model model) RL_FREE(model.bones); RL_FREE(model.bindPose); - TRACELOG(LOG_INFO, "MODEL: Unloaded model from RAM and VRAM"); + TRACELOG(LOG_INFO, "MODEL: Unloaded model (but not meshes) from RAM and VRAM"); } // Load meshes from model file @@ -950,6 +984,7 @@ void UnloadMaterial(Material material) } RL_FREE(material.maps); + RL_FREE(material.params); } // Set texture for a material map type (MAP_DIFFUSE, MAP_SPECULAR...) |
