diff options
| author | raysan5 <raysan5@gmail.com> | 2016-05-10 18:24:28 +0200 |
|---|---|---|
| committer | raysan5 <raysan5@gmail.com> | 2016-05-10 18:24:28 +0200 |
| commit | 1ddf594d15f31f1502eeb18f0f0c8039799fff01 (patch) | |
| tree | e88dc87a51d4fec5516a64d27a0951ef52a7af02 /src/models.c | |
| parent | ac44db26a2a2bed901c7e75d96e215fa09bd3705 (diff) | |
| download | raylib-1ddf594d15f31f1502eeb18f0f0c8039799fff01.tar.gz raylib-1ddf594d15f31f1502eeb18f0f0c8039799fff01.zip | |
Added support for indexed mesh data
Diffstat (limited to 'src/models.c')
| -rw-r--r-- | src/models.c | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/src/models.c b/src/models.c index 7d24e383..41150179 100644 --- a/src/models.c +++ b/src/models.c @@ -553,7 +553,7 @@ Model LoadModel(const char *fileName) if (model.mesh.vertexCount == 0) TraceLog(WARNING, "Model could not be loaded"); else { - rlglLoadMesh(&model.mesh); // Upload vertex data to GPU + rlglLoadMesh(&model.mesh); // Upload vertex data to GPU model.transform = MatrixIdentity(); model.material = LoadDefaultMaterial(); @@ -567,7 +567,9 @@ Model LoadModelEx(Mesh data) { Model model = { 0 }; - rlglLoadMesh(&data); // Upload vertex data to GPU + model.mesh = data; + + rlglLoadMesh(&model.mesh); // Upload vertex data to GPU model.transform = MatrixIdentity(); model.material = LoadDefaultMaterial(); @@ -693,12 +695,13 @@ Model LoadCubicmap(Image cubicmap) void UnloadModel(Model model) { // Unload mesh data - free(model.mesh.vertices); - free(model.mesh.texcoords); + if (model.mesh.vertices != NULL) free(model.mesh.vertices); + if (model.mesh.texcoords != NULL) free(model.mesh.texcoords); if (model.mesh.normals != NULL) free(model.mesh.normals); if (model.mesh.colors != NULL) free(model.mesh.colors); if (model.mesh.tangents != NULL) free(model.mesh.tangents); if (model.mesh.texcoords2 != NULL) free(model.mesh.texcoords2); + if (model.mesh.indices != NULL) free(model.mesh.indices); TraceLog(INFO, "Unloaded model data from RAM (CPU)"); @@ -708,8 +711,11 @@ void UnloadModel(Model model) rlDeleteBuffers(model.mesh.vboId[3]); // colors rlDeleteBuffers(model.mesh.vboId[4]); // tangents rlDeleteBuffers(model.mesh.vboId[5]); // texcoords2 + rlDeleteBuffers(model.mesh.vboId[6]); // indices rlDeleteVertexArrays(model.mesh.vaoId); + + UnloadMaterial(model.material); } // Load material data (from file) @@ -743,6 +749,13 @@ Material LoadDefaultMaterial(void) return material; } +void UnloadMaterial(Material material) +{ + rlDeleteTextures(material.texDiffuse.id); + rlDeleteTextures(material.texNormal.id); + rlDeleteTextures(material.texSpecular.id); +} + // Link a texture to a model void SetModelTexture(Model *model, Texture2D texture) { |
