mirror of
				https://github.com/raysan5/raylib.git
				synced 2025-11-04 01:34:19 +00:00 
			
		
		
		
	ADDED: UpdateMeshBuffer()
This commit is contained in:
		
							
								
								
									
										24
									
								
								src/models.c
									
									
									
									
									
								
							
							
						
						
									
										24
									
								
								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->vboId = (unsigned int *)RL_CALLOC(MAX_MESH_VERTEX_BUFFERS, sizeof(unsigned int));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    mesh->vaoId = 0;        // Vertex Array Object
 | 
					    mesh->vaoId = 0;        // Vertex Array Object
 | 
				
			||||||
    mesh->vboId[0] = 0;     // Vertex positions VBO
 | 
					    mesh->vboId[0] = 0;     // Vertex buffer: positions
 | 
				
			||||||
    mesh->vboId[1] = 0;     // Vertex texcoords VBO
 | 
					    mesh->vboId[1] = 0;     // Vertex buffer: texcoords
 | 
				
			||||||
    mesh->vboId[2] = 0;     // Vertex normals VBO
 | 
					    mesh->vboId[2] = 0;     // Vertex buffer: normals
 | 
				
			||||||
    mesh->vboId[3] = 0;     // Vertex colors VBO
 | 
					    mesh->vboId[3] = 0;     // Vertex buffer: colors
 | 
				
			||||||
    mesh->vboId[4] = 0;     // Vertex tangents VBO
 | 
					    mesh->vboId[4] = 0;     // Vertex buffer: tangents
 | 
				
			||||||
    mesh->vboId[5] = 0;     // Vertex texcoords2 VBO
 | 
					    mesh->vboId[5] = 0;     // Vertex buffer: texcoords2
 | 
				
			||||||
    mesh->vboId[6] = 0;     // Vertex indices VBO
 | 
					    mesh->vboId[6] = 0;     // Vertex buffer: indices
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
 | 
					#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
 | 
				
			||||||
    mesh->vaoId = rlLoadVertexArray();
 | 
					    mesh->vaoId = rlLoadVertexArray();
 | 
				
			||||||
@@ -925,6 +925,12 @@ void UploadMesh(Mesh *mesh, bool dynamic)
 | 
				
			|||||||
#endif
 | 
					#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
 | 
					// Draw a 3d mesh with material and transform
 | 
				
			||||||
void DrawMesh(Mesh mesh, Material material, Matrix 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.normals = (float *)RL_CALLOC(mesh.vertexCount*3, sizeof(float));
 | 
				
			||||||
    mesh.colors = (unsigned char *)RL_CALLOC(mesh.vertexCount*4, sizeof(unsigned char));
 | 
					    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()
 | 
					    // NOTE: mesh.vboId array is allocated inside UploadMesh()
 | 
				
			||||||
    UploadMesh(&mesh, false);
 | 
					    UploadMesh(&mesh, true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return mesh;
 | 
					    return mesh;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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)
 | 
					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 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 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 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
 | 
					RLAPI void UnloadMesh(Mesh mesh);                                                           // Unload mesh data from CPU and GPU
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user