[Bf-blender-cvs] [06d4aca] blender2.8: OpenGL: matrix fixes & compatibility

Mike Erwin noreply at git.blender.org
Wed Oct 12 03:21:39 CEST 2016


Commit: 06d4aca87956a8d276f97dedce7a021d86fc03f6
Author: Mike Erwin
Date:   Tue Oct 11 21:13:13 2016 -0400
Branches: blender2.8
https://developer.blender.org/rB06d4aca87956a8d276f97dedce7a021d86fc03f6

OpenGL: matrix fixes & compatibility

Was multiplying matrices backward, so concatenation was broken. Fixed!

Also a way to mix legacy matrix stacks with the new library. Just during the transition! Anything within SUPPORT_LEGACY_MATRIX will go away after we switch to core profile.

Part of T49450

===================================================================

M	source/blender/gpu/GPU_matrix.h
M	source/blender/gpu/intern/gpu_matrix.c

===================================================================

diff --git a/source/blender/gpu/GPU_matrix.h b/source/blender/gpu/GPU_matrix.h
index 7356629..3c3acc0 100644
--- a/source/blender/gpu/GPU_matrix.h
+++ b/source/blender/gpu/GPU_matrix.h
@@ -39,6 +39,12 @@
 extern "C" {
 #endif
 
+/* For now we support the legacy matrix stack in gpuGetMatrix functions.
+ * Will remove this after switching to core profile, which can happen after
+ * we convert all code to use the API in this file. */
+#define SUPPORT_LEGACY_MATRIX 1
+
+
 void gpuMatrixInit(void); /* called by system -- make private? */
 
 
@@ -120,6 +126,13 @@ const float *gpuGetModelViewMatrix3D(float m[4][4]);
 const float *gpuGetProjectionMatrix3D(float m[4][4]);
 const float *gpuGetModelViewProjectionMatrix3D(float m[4][4]);
 
+
+#if SUPPORT_LEGACY_MATRIX
+/* copy top matrix from each legacy stack into new fresh stack */
+void gpuMatrixBegin3D_legacy(void);
+#endif
+
+
 /* set uniform values for currently bound shader */
 void gpuBindMatrices(GLuint program);
 
diff --git a/source/blender/gpu/intern/gpu_matrix.c b/source/blender/gpu/intern/gpu_matrix.c
index 579c1de..a1921a1 100644
--- a/source/blender/gpu/intern/gpu_matrix.c
+++ b/source/blender/gpu/intern/gpu_matrix.c
@@ -35,10 +35,6 @@
 #include "BLI_math_rotation.h"
 #include "BLI_math_vector.h"
 
-/* For now we support the legacy matrix stack in gpuGetMatrix functions.
- * Will remove this after switching to core profile, which can happen after
- * we convert all code to use the API in this file. */
-#define SUPPORT_LEGACY_MATRIX 1
 
 #define DEBUG_MATRIX_BIND 0
 
@@ -93,6 +89,16 @@ void gpuMatrixBegin3D()
 	gpuOrtho(-1.0f, +1.0f, -1.0f, +1.0f, -1.0f, +1.0f); // or identity?
 }
 
+#if SUPPORT_LEGACY_MATRIX
+void gpuMatrixBegin3D_legacy() {
+	/* copy top matrix from each legacy stack into new fresh stack */
+	state.mode = MATRIX_MODE_3D;
+	state.top = 0;
+	glGetFloatv(GL_MODELVIEW_MATRIX, (float*)ModelView3D);
+	glGetFloatv(GL_PROJECTION_MATRIX, (float*)Projection3D);
+}
+#endif
+
 void gpuMatrixEnd()
 {
 	state.mode = MATRIX_MODE_INACTIVE;
@@ -185,9 +191,18 @@ void gpuTranslate2fv(const float vec[2])
 
 void gpuTranslate3f(float x, float y, float z)
 {
+#if 1
 	BLI_assert(state.mode == MATRIX_MODE_3D);
 	translate_m4(ModelView3D, x, y, z);
 	CHECKMAT(ModelView3D);
+#else /* above works well in early testing, below is generic version */
+	Mat4 m;
+	unit_m4(m);
+	m[3][0] = x;
+	m[3][1] = y;
+	m[3][2] = z;
+	gpuMultMatrix3D(m);
+#endif
 }
 
 void gpuTranslate3fv(const float vec[3])
@@ -257,14 +272,14 @@ void gpuScale3fv(const float vec[3])
 void gpuMultMatrix3D(const float m[4][4])
 {
 	BLI_assert(state.mode == MATRIX_MODE_3D);
-	mul_m4_m4_post(ModelView3D, m);
+	mul_m4_m4_pre(ModelView3D, m);
 	CHECKMAT(ModelView3D);
 }
 
 void gpuMultMatrix2D(const float m[3][3])
 {
 	BLI_assert(state.mode == MATRIX_MODE_2D);
-	mul_m3_m3_post(ModelView2D, m);
+	mul_m3_m3_pre(ModelView2D, m);
 	CHECKMAT(ModelView2D);
 }
 
@@ -575,7 +590,7 @@ const float *gpuGetModelViewProjectionMatrix3D(float m[4][4])
 		m = temp;
 	}
 
-	mul_m4_m4m4(m, ModelView3D, Projection3D);
+	mul_m4_m4m4(m, Projection3D, ModelView3D);
 	return (const float*)m;
 }




More information about the Bf-blender-cvs mailing list