Added DrawMeshInstancedColumnMajor
This commit is contained in:
parent
a8c75f2bc5
commit
4f19b69f16
|
|
@ -1591,6 +1591,7 @@ RLAPI void UpdateMeshBuffer(Mesh mesh, int index, const void *data, int dataSize
|
|||
RLAPI void UnloadMesh(Mesh mesh); // Unload mesh data from CPU and GPU
|
||||
RLAPI void DrawMesh(Mesh mesh, Material material, Matrix transform); // Draw a 3d mesh with material and transform
|
||||
RLAPI void DrawMeshInstanced(Mesh mesh, Material material, const Matrix *transforms, int instances); // Draw multiple mesh instances with material and different transforms
|
||||
RLAPI void DrawMeshInstancedColumnMajor(Mesh mesh, Material material, const void *transforms, int instances); // Draw multiple mesh instances with material and different transforms
|
||||
RLAPI BoundingBox GetMeshBoundingBox(Mesh mesh); // Compute mesh bounding box limits
|
||||
RLAPI void GenMeshTangents(Mesh *mesh); // Compute mesh tangents
|
||||
RLAPI bool ExportMesh(Mesh mesh, const char *fileName); // Export mesh data to file, returns true on success
|
||||
|
|
|
|||
|
|
@ -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 Matrix *transforms, int instances)
|
||||
void DrawMeshInstancedColumnMajor(Mesh mesh, Material material, const 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)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user