|
|
|
@ -1690,11 +1690,9 @@ void DrawMesh(Mesh mesh, Material material, Matrix transform) |
|
|
|
} |
|
|
|
|
|
|
|
// Draw multiple mesh instances with material and different transforms |
|
|
|
void DrawMeshInstanced(Mesh mesh, Material material, const n">Matrix *transforms, int instances) |
|
|
|
void DrawMeshInstancedColumnMajor(Mesh mesh, Material material, const kt">void * transforms, int instances) |
|
|
|
{ |
|
|
|
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2) |
|
|
|
// Instancing required variables |
|
|
|
float16 *instanceTransforms = NULL; |
|
|
|
unsigned int instancesVboId = 0; |
|
|
|
|
|
|
|
// Bind shader program |
|
|
|
@ -1742,11 +1740,7 @@ void DrawMeshInstanced(Mesh mesh, Material material, const Matrix *transforms, i |
|
|
|
if (material.shader.locs[SHADER_LOC_MATRIX_VIEW] != -1) rlSetUniformMatrix(material.shader.locs[SHADER_LOC_MATRIX_VIEW], matView); |
|
|
|
if (material.shader.locs[SHADER_LOC_MATRIX_PROJECTION] != -1) rlSetUniformMatrix(material.shader.locs[SHADER_LOC_MATRIX_PROJECTION], matProjection); |
|
|
|
|
|
|
|
// Create instances buffer |
|
|
|
instanceTransforms = (float16 *)RL_MALLOC(instances*sizeof(float16)); |
|
|
|
|
|
|
|
// Fill buffer with instances transformations as float16 arrays |
|
|
|
for (int i = 0; i < instances; i++) instanceTransforms[i] = MatrixToFloatV(transforms[i]); |
|
|
|
|
|
|
|
// Enable mesh VAO to attach new buffer |
|
|
|
rlEnableVertexArray(mesh.vaoId); |
|
|
|
@ -1755,7 +1749,7 @@ void DrawMeshInstanced(Mesh mesh, Material material, const Matrix *transforms, i |
|
|
|
// It isn't clear which would be reliably faster in all cases and on all platforms, |
|
|
|
// anecdotally glMapBuffer() seems very slow (syncs) while glBufferSubData() seems |
|
|
|
// no faster, since we're transferring all the transform matrices anyway |
|
|
|
instancesVboId = rlLoadVertexBuffer(instanceTransforms, instances*sizeof(float16), false); |
|
|
|
instancesVboId = rlLoadVertexBuffer(transforms, instances*sizeof(float16), false); |
|
|
|
|
|
|
|
// Instances transformation matrices are sent to shader attribute location: SHADER_LOC_VERTEX_INSTANCE_TX |
|
|
|
if (material.shader.locs[SHADER_LOC_VERTEX_INSTANCE_TX] != -1) |
|
|
|
@ -1933,10 +1927,22 @@ void DrawMeshInstanced(Mesh mesh, Material material, const Matrix *transforms, i |
|
|
|
|
|
|
|
// Remove instance transforms buffer |
|
|
|
rlUnloadVertexBuffer(instancesVboId); |
|
|
|
RL_FREE(instanceTransforms); |
|
|
|
#endif |
|
|
|
} |
|
|
|
|
|
|
|
void DrawMeshInstanced(Mesh mesh, Material material, const Matrix *transforms, int instances) |
|
|
|
{ |
|
|
|
// Create instances buffer |
|
|
|
float16 *instanceTransforms = NULL; |
|
|
|
instanceTransforms = (float16 *)RL_MALLOC(instances*sizeof(float16)); |
|
|
|
|
|
|
|
// Fill buffer with instances transformations as float16 arrays |
|
|
|
for (int i = 0; i < instances; i++) instanceTransforms[i] = MatrixToFloatV(transforms[i]); |
|
|
|
DrawMeshInstancedColumnMajor(mesh, material, instanceTransforms, instances); |
|
|
|
|
|
|
|
RL_FREE(instanceTransforms); |
|
|
|
} |
|
|
|
|
|
|
|
// Unload mesh from memory (RAM and VRAM) |
|
|
|
void UnloadMesh(Mesh mesh) |
|
|
|
{ |
|
|
|
|