ADDED: UnloadModelKeepMeshes() #1441
This commit is contained in:
parent
0481053dad
commit
60928ec82c
2 changed files with 43 additions and 7 deletions
47
src/models.c
47
src/models.c
|
@ -782,16 +782,25 @@ Model LoadModelFromMesh(Mesh mesh)
|
||||||
return model;
|
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)
|
void UnloadModel(Model model)
|
||||||
{
|
{
|
||||||
|
// Unload meshes
|
||||||
for (int i = 0; i < model.meshCount; i++) UnloadMesh(model.meshes[i]);
|
for (int i = 0; i < model.meshCount; i++) UnloadMesh(model.meshes[i]);
|
||||||
|
|
||||||
// As the user could be sharing shaders and textures between models,
|
// Unload materials maps and params
|
||||||
// we don't unload the material but just free it's maps, the user
|
// NOTE: As the user could be sharing shaders and textures between models,
|
||||||
// is responsible for freeing models shaders and textures
|
// we don't unload the material but just free it's maps and params,
|
||||||
for (int i = 0; i < model.materialCount; i++) RL_FREE(model.materials[i].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);
|
||||||
|
RL_FREE(model.materials[i].params);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unload arrays
|
||||||
RL_FREE(model.meshes);
|
RL_FREE(model.meshes);
|
||||||
RL_FREE(model.materials);
|
RL_FREE(model.materials);
|
||||||
RL_FREE(model.meshMaterial);
|
RL_FREE(model.meshMaterial);
|
||||||
|
@ -800,7 +809,32 @@ void UnloadModel(Model model)
|
||||||
RL_FREE(model.bones);
|
RL_FREE(model.bones);
|
||||||
RL_FREE(model.bindPose);
|
RL_FREE(model.bindPose);
|
||||||
|
|
||||||
TRACELOG(LOG_INFO, "MODEL: Unloaded model from RAM and VRAM");
|
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);
|
||||||
|
|
||||||
|
// Unload animation data
|
||||||
|
RL_FREE(model.bones);
|
||||||
|
RL_FREE(model.bindPose);
|
||||||
|
|
||||||
|
TRACELOG(LOG_INFO, "MODEL: Unloaded model (but not meshes) from RAM and VRAM");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load meshes from model file
|
// Load meshes from model file
|
||||||
|
@ -950,6 +984,7 @@ void UnloadMaterial(Material material)
|
||||||
}
|
}
|
||||||
|
|
||||||
RL_FREE(material.maps);
|
RL_FREE(material.maps);
|
||||||
|
RL_FREE(material.params);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set texture for a material map type (MAP_DIFFUSE, MAP_SPECULAR...)
|
// Set texture for a material map type (MAP_DIFFUSE, MAP_SPECULAR...)
|
||||||
|
|
|
@ -1321,7 +1321,8 @@ RLAPI void DrawGizmo(Vector3 position);
|
||||||
// Model loading/unloading functions
|
// Model loading/unloading functions
|
||||||
RLAPI Model LoadModel(const char *fileName); // Load model from files (meshes and materials)
|
RLAPI Model LoadModel(const char *fileName); // Load model from files (meshes and materials)
|
||||||
RLAPI Model LoadModelFromMesh(Mesh mesh); // Load model from generated mesh (default material)
|
RLAPI Model LoadModelFromMesh(Mesh mesh); // Load model from generated mesh (default material)
|
||||||
RLAPI void UnloadModel(Model model); // Unload model from memory (RAM and/or VRAM)
|
RLAPI void UnloadModel(Model model); // Unload model (including meshes) from memory (RAM and/or VRAM)
|
||||||
|
RLAPI void UnloadModelKeepMeshes(Model model); // Unload model (but not meshes) from memory (RAM and/or VRAM)
|
||||||
|
|
||||||
// Mesh loading/unloading functions
|
// Mesh loading/unloading functions
|
||||||
RLAPI Mesh *LoadMeshes(const char *fileName, int *meshCount); // Load meshes from model file
|
RLAPI Mesh *LoadMeshes(const char *fileName, int *meshCount); // Load meshes from model file
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue