Clean up Matrix handling and rl* functions to follow convention (#5505)

- Use named fields in rlTranslatef and rlScalef instead of array literals
- Label implicit row-major to column-major transpose in MatrixToFloatV
- Update rlSetUniformMatrix to use rlMatrixToFloat convention
This commit is contained in:
nate
2026-01-23 22:53:57 +10:00
committed by GitHub
parent 594f5429b2
commit e16467e8b6

View File

@ -1270,12 +1270,12 @@ void rlLoadIdentity(void)
// Multiply the current matrix by a translation matrix // Multiply the current matrix by a translation matrix
void rlTranslatef(float x, float y, float z) void rlTranslatef(float x, float y, float z)
{ {
Matrix matTranslation = { Matrix matTranslation = rlMatrixIdentity();
1.0f, 0.0f, 0.0f, x,
0.0f, 1.0f, 0.0f, y, // Set translation component of matrix
0.0f, 0.0f, 1.0f, z, matTranslation.m12 = x;
0.0f, 0.0f, 0.0f, 1.0f matTranslation.m13 = y;
}; matTranslation.m14 = z;
// NOTE: We transpose matrix with multiplication order // NOTE: We transpose matrix with multiplication order
*RLGL.State.currentMatrix = rlMatrixMultiply(matTranslation, *RLGL.State.currentMatrix); *RLGL.State.currentMatrix = rlMatrixMultiply(matTranslation, *RLGL.State.currentMatrix);
@ -1329,12 +1329,12 @@ void rlRotatef(float angle, float x, float y, float z)
// Multiply the current matrix by a scaling matrix // Multiply the current matrix by a scaling matrix
void rlScalef(float x, float y, float z) void rlScalef(float x, float y, float z)
{ {
Matrix matScale = { Matrix matScale = rlMatrixIdentity();
x, 0.0f, 0.0f, 0.0f,
0.0f, y, 0.0f, 0.0f, // Set scale component of matrix
0.0f, 0.0f, z, 0.0f, matScale.m0 = x;
0.0f, 0.0f, 0.0f, 1.0f matScale.m5 = y;
}; matScale.m10 = z;
// NOTE: We transpose matrix with multiplication order // NOTE: We transpose matrix with multiplication order
*RLGL.State.currentMatrix = rlMatrixMultiply(matScale, *RLGL.State.currentMatrix); *RLGL.State.currentMatrix = rlMatrixMultiply(matScale, *RLGL.State.currentMatrix);
@ -1344,6 +1344,7 @@ void rlScalef(float x, float y, float z)
void rlMultMatrixf(const float *matf) void rlMultMatrixf(const float *matf)
{ {
// Matrix creation from array // Matrix creation from array
// Conversion from column-major to row-major memory order
Matrix mat = { matf[0], matf[4], matf[8], matf[12], Matrix mat = { matf[0], matf[4], matf[8], matf[12],
matf[1], matf[5], matf[9], matf[13], matf[1], matf[5], matf[9], matf[13],
matf[2], matf[6], matf[10], matf[14], matf[2], matf[6], matf[10], matf[14],
@ -4463,13 +4464,7 @@ void rlSetVertexAttributeDefault(int locIndex, const void *value, int attribType
void rlSetUniformMatrix(int locIndex, Matrix mat) void rlSetUniformMatrix(int locIndex, Matrix mat)
{ {
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2) #if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
float matfloat[16] = { glUniformMatrix4fv(locIndex, 1, false, rlMatrixToFloat(mat));
mat.m0, mat.m1, mat.m2, mat.m3,
mat.m4, mat.m5, mat.m6, mat.m7,
mat.m8, mat.m9, mat.m10, mat.m11,
mat.m12, mat.m13, mat.m14, mat.m15
};
glUniformMatrix4fv(locIndex, 1, false, matfloat);
#endif #endif
} }
@ -5255,17 +5250,17 @@ static int rlGetPixelDataSize(int width, int height, int format)
// Get identity matrix // Get identity matrix
static Matrix rlMatrixIdentity(void) static Matrix rlMatrixIdentity(void)
{ {
Matrix result = { Matrix matIdentity = { 0 };
1.0f, 0.0f, 0.0f, 0.0f, matIdentity.m0 = 1.0f;
0.0f, 1.0f, 0.0f, 0.0f, matIdentity.m5 = 1.0f;
0.0f, 0.0f, 1.0f, 0.0f, matIdentity.m10 = 1.0f;
0.0f, 0.0f, 0.0f, 1.0f matIdentity.m15 = 1.0f;
};
return result; return matIdentity;
} }
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2) #if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
// Get float array of matrix data // Get float array of matrix data
// Explicit conversion to column-major memory layout
static rl_float16 rlMatrixToFloatV(Matrix mat) static rl_float16 rlMatrixToFloatV(Matrix mat)
{ {
rl_float16 result = { 0 }; rl_float16 result = { 0 };