I am working on a small test project to compare per vertex and per pixel shaded meshes, because I was interested if there are some use cases in which one technique has advantages over the other. For example, regarding the download size of the assets.
So I build a small test scene and swap out the models in the scene to compare things like the size of the models/textures, VRAM usage, render time etc. But I have some troubles to figure out, how to free the VRAM again. As I don’t want to create a new scene for every mesh I thought, that I just spawn the different models programmatically. Check the stats from the debugger, switch to the next model and delete the first entity.
But the VRAM usage stays the same after I destroy the entity with .destroy()
After a while I figured out, that I can reduce the VRAM usage, if I also destroy the applied textures manually like this:
// Get the material of the model var material = entity.model.model.meshInstances.material; // and its diffuse, to free the used resources var diffuse = material.diffuseMap; if(diffuse !== null) diffuse.destroy();
But this causes, that the material stays black, if I create the entity again. The diffuse texture is still applied to the material and I also tried to upload and reassign the texture to the material, or to update the material itself, but the result stays the same.
Another thing that I noticed is, that the profiler displays a negative VRAM usage if I call the destroy function multiple times on the texture. Any ideas how I can correctly free the VRAM, if I want to swap between multiple objects in the scene, while just seeing the stats of the currently enabled/existing object in the scene?