Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Erwin <significant.bit@gmail.com>2016-10-12 04:13:13 +0300
committerMike Erwin <significant.bit@gmail.com>2016-10-12 04:16:26 +0300
commit06d4aca87956a8d276f97dedce7a021d86fc03f6 (patch)
tree76b55f17f167f360f12fb53587c92e5e41990969
parentc330f3713563fff855bfe69e44b070a956925d24 (diff)
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
-rw-r--r--source/blender/gpu/GPU_matrix.h13
-rw-r--r--source/blender/gpu/intern/gpu_matrix.c29
2 files changed, 35 insertions, 7 deletions
diff --git a/source/blender/gpu/GPU_matrix.h b/source/blender/gpu/GPU_matrix.h
index 73566292799..3c3acc08f58 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 579c1de181f..a1921a1c638 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;
}