From bb743e8c6ec1ab50bd5ab0f12e10a48da702d76a Mon Sep 17 00:00:00 2001 From: Ray <raysan5@gmail.com> Date: Tue, 20 Apr 2021 12:16:16 +0200 Subject: [PATCH] ADDED: UpdateMeshBuffer() --- src/models.c | 24 +++++++++++++++--------- src/raylib.h | 3 ++- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/models.c b/src/models.c index 3dc6c3d5f..d03d10403 100644 --- a/src/models.c +++ b/src/models.c @@ -829,13 +829,13 @@ void UploadMesh(Mesh *mesh, bool dynamic) mesh->vboId = (unsigned int *)RL_CALLOC(MAX_MESH_VERTEX_BUFFERS, sizeof(unsigned int)); mesh->vaoId = 0; // Vertex Array Object - mesh->vboId[0] = 0; // Vertex positions VBO - mesh->vboId[1] = 0; // Vertex texcoords VBO - mesh->vboId[2] = 0; // Vertex normals VBO - mesh->vboId[3] = 0; // Vertex colors VBO - mesh->vboId[4] = 0; // Vertex tangents VBO - mesh->vboId[5] = 0; // Vertex texcoords2 VBO - mesh->vboId[6] = 0; // Vertex indices VBO + mesh->vboId[0] = 0; // Vertex buffer: positions + mesh->vboId[1] = 0; // Vertex buffer: texcoords + mesh->vboId[2] = 0; // Vertex buffer: normals + mesh->vboId[3] = 0; // Vertex buffer: colors + mesh->vboId[4] = 0; // Vertex buffer: tangents + mesh->vboId[5] = 0; // Vertex buffer: texcoords2 + mesh->vboId[6] = 0; // Vertex buffer: indices #if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2) mesh->vaoId = rlLoadVertexArray(); @@ -925,6 +925,12 @@ void UploadMesh(Mesh *mesh, bool dynamic) #endif } +// Update mesh vertex data in GPU for a specific buffer index +void UpdateMeshBuffer(Mesh mesh, int index, void *data, int dataSize, int offset) +{ + rlUpdateVertexBuffer(mesh->vboId[index], data, dataSize, offset); +} + // Draw a 3d mesh with material and transform void DrawMesh(Mesh mesh, Material material, Matrix transform) { @@ -1528,9 +1534,9 @@ Mesh GenMeshDefault(int vertexCount) mesh.normals = (float *)RL_CALLOC(mesh.vertexCount*3, sizeof(float)); mesh.colors = (unsigned char *)RL_CALLOC(mesh.vertexCount*4, sizeof(unsigned char)); - // Upload vertex data to GPU (static mesh) + // Upload vertex data to GPU (dynamic mesh) // NOTE: mesh.vboId array is allocated inside UploadMesh() - UploadMesh(&mesh, false); + UploadMesh(&mesh, true); return mesh; } diff --git a/src/raylib.h b/src/raylib.h index 4c70e48af..abe7d8a1d 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -1381,7 +1381,8 @@ RLAPI void UnloadModel(Model model); RLAPI void UnloadModelKeepMeshes(Model model); // Unload model (but not meshes) from memory (RAM and/or VRAM) // Mesh loading/unloading functions -RLAPI void UploadMesh(Mesh *mesh, bool dynamic); // Upload vertex data into GPU and provided VAO/VBO ids +RLAPI void UploadMesh(Mesh *mesh, bool dynamic); // Upload mesh vertex data in GPU and provide VAO/VBO ids +RLAPI void UpdateMeshBuffer(Mesh mesh, int index, void *data, int dataSize, int offset); // Update mesh vertex data in GPU for a specific buffer index RLAPI void DrawMesh(Mesh mesh, Material material, Matrix transform); // Draw a 3d mesh with material and transform RLAPI void DrawMeshInstanced(Mesh mesh, Material material, Matrix *transforms, int instances); // Draw multiple mesh instances with material and different transforms RLAPI void UnloadMesh(Mesh mesh); // Unload mesh data from CPU and GPU