From d71eccfd0b7244cf277478a05ded33a7d42cba94 Mon Sep 17 00:00:00 2001 From: bjorn Date: Tue, 12 Jun 2018 02:05:19 -0700 Subject: [PATCH] Ensure Mesh attachments are unmapped before drawing; --- src/graphics/graphics.c | 4 ---- src/graphics/mesh.c | 9 +++++++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/graphics/graphics.c b/src/graphics/graphics.c index df91c459..54d81d2f 100644 --- a/src/graphics/graphics.c +++ b/src/graphics/graphics.c @@ -1104,10 +1104,6 @@ void lovrGraphicsDraw(Mesh* mesh, mat4 transform, DefaultShader defaultShader, i lovrGraphicsUseProgram(shader->program); lovrShaderBind(shader); - - lovrGraphicsBindVertexArray(mesh->vao); - lovrMeshUnmapVertices(mesh); - lovrMeshUnmapIndices(mesh); lovrMeshBind(mesh, shader); size_t start = mesh->rangeStart; diff --git a/src/graphics/mesh.c b/src/graphics/mesh.c index 4f14f1e1..4693e718 100644 --- a/src/graphics/mesh.c +++ b/src/graphics/mesh.c @@ -77,12 +77,21 @@ void lovrMeshBind(Mesh* mesh, Shader* shader) { MeshAttachment layout[MAX_ATTACHMENTS]; memset(layout, 0, MAX_ATTACHMENTS * sizeof(MeshAttachment)); + lovrGraphicsBindVertexArray(mesh->vao); + lovrMeshUnmapVertices(mesh); + lovrMeshUnmapIndices(mesh); + if (mesh->indexCount > 0) { + lovrGraphicsBindIndexBuffer(mesh->ibo); + } + while ((key = map_next(&mesh->attachments, &iter)) != NULL) { int location = lovrShaderGetAttributeId(shader, key); if (location >= 0) { MeshAttachment* attachment = map_get(&mesh->attachments, key); layout[location] = *attachment; + lovrMeshUnmapVertices(attachment->mesh); + lovrMeshUnmapIndices(attachment->mesh); } }