From 5e26deb12f32dffe91f71333028a653ce448b1d3 Mon Sep 17 00:00:00 2001 From: mgood7123 Date: Wed, 17 Nov 2021 22:42:37 +1000 Subject: [PATCH] fix bug in rlMatrixMode in GL_33 and ES2, the matrix mode would always set the model matrix to modelview matrix this leads to incorrectly setting the matrix when a matrix has been pushed when a matrix is pushed, the model matrix is set to the transform matrix if a matrixMode is done on the model matrix then the model matrix is set to the modelview matrix instead of the transform matrix when a matrix is popped, if zero count, the model matrix gets set to modelview NOTE: GL_11 uses a seperate stack for each matrix, GL_33 and ES2 implementation combines this to a single stack making this not set in the following case ``` // set current matrix to model rlMatrixMode(RL_MODELVIEW); // push to model stack // this sets current matrix to transform since we are in model rlPushMatrix(); // set current matrix to projection rlMatrixMode(RL_PROJECTION); // push to projection stack // this sets current matrix to projection rlPushMatrix(); // set current matrix to transform rlMatrixMode(RL_MODELVIEW); // pop from model stack // this fails to set the model back to model view since // the stack depth is not 0 as the GL_33 and ES2 // stack implementation represents a combined stack // instead of seperate stacks // the matrix is instead set to the projection matrix that we just pushed rlPopMatrix(); ``` --- src/rlgl.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/rlgl.h b/src/rlgl.h index 2ef923ea8..278f164b9 100644 --- a/src/rlgl.h +++ b/src/rlgl.h @@ -1034,7 +1034,13 @@ void rlMultMatrixf(float *matf) { glMultMatrixf(matf); } void rlMatrixMode(int mode) { if (mode == RL_PROJECTION) RLGL.State.currentMatrix = &RLGL.State.projection; - else if (mode == RL_MODELVIEW) RLGL.State.currentMatrix = &RLGL.State.modelview; + else if (mode == RL_MODELVIEW) { + if (RLGL.State.stackCounter == 0) { + RLGL.State.currentMatrix = &RLGL.State.modelview; + } else { + RLGL.State.currentMatrix = &RLGL.State.transform; + } + } //else if (mode == RL_TEXTURE) // Not supported RLGL.State.currentMatrixMode = mode;