[Bf-blender-cvs] [74434beb1c] blender2.8: OpenGL: more legacy support for matrix routines
Mike Erwin
noreply at git.blender.org
Tue Mar 21 06:42:45 CET 2017
Commit: 74434beb1c50dcdf3174f29c80e25c6d75ccfae7
Author: Mike Erwin
Date: Mon Mar 20 17:19:21 2017 -0400
Branches: blender2.8
https://developer.blender.org/rB74434beb1c50dcdf3174f29c80e25c6d75ccfae7
OpenGL: more legacy support for matrix routines
For the sake of forward progress on T49450
We can now replace legacy gl* matrix function calls with their gpu equivalents. "Inactive" in this code means we're using the legacy matrix stacks, not our own. Setting up the proper gpuMatrixBegin2D/3D/End calls can be done afterward.
Most or all of this will be removed after the transition to core profile.
===================================================================
M source/blender/gpu/intern/gpu_matrix.c
===================================================================
diff --git a/source/blender/gpu/intern/gpu_matrix.c b/source/blender/gpu/intern/gpu_matrix.c
index c022301d6a..de443dce56 100644
--- a/source/blender/gpu/intern/gpu_matrix.c
+++ b/source/blender/gpu/intern/gpu_matrix.c
@@ -135,6 +135,13 @@ static void checkmat(cosnt float *m)
void gpuPushMatrix(void)
{
+#if SUPPORT_LEGACY_MATRIX
+ if (state.mode == MATRIX_MODE_INACTIVE) {
+ glPushMatrix();
+ return;
+ }
+#endif
+
BLI_assert(state.mode != MATRIX_MODE_INACTIVE);
BLI_assert(state.top < MATRIX_STACK_DEPTH);
state.top++;
@@ -146,6 +153,13 @@ void gpuPushMatrix(void)
void gpuPopMatrix(void)
{
+#if SUPPORT_LEGACY_MATRIX
+ if (state.mode == MATRIX_MODE_INACTIVE) {
+ glPopMatrix();
+ return;
+ }
+#endif
+
BLI_assert(state.mode != MATRIX_MODE_INACTIVE);
BLI_assert(state.top > 0);
state.top--;
@@ -154,6 +168,13 @@ void gpuPopMatrix(void)
void gpuLoadMatrix3D(const float m[4][4])
{
+#if SUPPORT_LEGACY_MATRIX
+ if (state.mode == MATRIX_MODE_INACTIVE) {
+ glLoadMatrixf((const float*) m);
+ return;
+ }
+#endif
+
BLI_assert(state.mode == MATRIX_MODE_3D);
copy_m4_m4(ModelView3D, m);
CHECKMAT(ModelView3D);
@@ -177,6 +198,11 @@ void gpuLoadIdentity(void)
case MATRIX_MODE_2D:
unit_m3(ModelView2D);
break;
+#if SUPPORT_LEGACY_MATRIX
+ case MATRIX_MODE_INACTIVE:
+ glLoadIdentity();
+ break;
+#endif
default:
BLI_assert(false);
}
@@ -185,6 +211,13 @@ void gpuLoadIdentity(void)
void gpuTranslate2f(float x, float y)
{
+#if SUPPORT_LEGACY_MATRIX
+ if (state.mode == MATRIX_MODE_INACTIVE) {
+ glTranslatef(x, y, 0.0f);
+ return;
+ }
+#endif
+
Mat3 m;
unit_m3(m);
m[2][0] = x;
@@ -199,6 +232,13 @@ void gpuTranslate2fv(const float vec[2])
void gpuTranslate3f(float x, float y, float z)
{
+#if SUPPORT_LEGACY_MATRIX
+ if (state.mode == MATRIX_MODE_INACTIVE) {
+ glTranslatef(x, y, z);
+ return;
+ }
+#endif
+
BLI_assert(state.mode == MATRIX_MODE_3D);
#if 1
translate_m4(ModelView3D, x, y, z);
@@ -244,6 +284,11 @@ void gpuScaleUniform(float factor)
gpuMultMatrix2D(m);
break;
}
+#if SUPPORT_LEGACY_MATRIX
+ case MATRIX_MODE_INACTIVE:
+ glScalef(factor, factor, factor); /* always scale Z since we can't distinguish 2D from 3D */
+ break;
+#endif
default:
BLI_assert(false);
}
@@ -251,6 +296,13 @@ void gpuScaleUniform(float factor)
void gpuScale2f(float x, float y)
{
+#if SUPPORT_LEGACY_MATRIX
+ if (state.mode == MATRIX_MODE_INACTIVE) {
+ glScalef(x, y, 1.0f);
+ return;
+ }
+#endif
+
Mat3 m = {{0.0f}};
m[0][0] = x;
m[1][1] = y;
@@ -265,6 +317,13 @@ void gpuScale2fv(const float vec[2])
void gpuScale3f(float x, float y, float z)
{
+#if SUPPORT_LEGACY_MATRIX
+ if (state.mode == MATRIX_MODE_INACTIVE) {
+ glScalef(x, y, z);
+ return;
+ }
+#endif
+
Mat4 m = {{0.0f}};
m[0][0] = x;
m[1][1] = y;
@@ -280,6 +339,13 @@ void gpuScale3fv(const float vec[3])
void gpuMultMatrix3D(const float m[4][4])
{
+#if SUPPORT_LEGACY_MATRIX
+ if (state.mode == MATRIX_MODE_INACTIVE) {
+ glMultMatrixf((const float*) m);
+ return;
+ }
+#endif
+
BLI_assert(state.mode == MATRIX_MODE_3D);
mul_m4_m4_post(ModelView3D, m);
CHECKMAT(ModelView3D);
@@ -302,6 +368,13 @@ void gpuRotate3f(float deg, float x, float y, float z)
void gpuRotate3fv(float deg, const float axis[3])
{
+#if SUPPORT_LEGACY_MATRIX
+ if (state.mode == MATRIX_MODE_INACTIVE) {
+ glRotatef(deg, axis[0], axis[1], axis[2]);
+ return;
+ }
+#endif
+
Mat4 m;
axis_angle_to_mat4(m, axis, DEG2RADF(deg));
gpuMultMatrix3D(m);
@@ -309,6 +382,20 @@ void gpuRotate3fv(float deg, const float axis[3])
void gpuRotateAxis(float deg, char axis)
{
+#if SUPPORT_LEGACY_MATRIX
+ if (state.mode == MATRIX_MODE_INACTIVE) {
+ float a[3] = { 0.0f };
+ switch (axis) {
+ case 'X': a[0] = 1.0f; break;
+ case 'Y': a[1] = 1.0f; break;
+ case 'Z': a[2] = 1.0f; break;
+ default: BLI_assert(false); /* bad axis */
+ }
+ glRotatef(deg, a[0], a[1], a[2]);
+ return;
+ }
+#endif
+
BLI_assert(state.mode == MATRIX_MODE_3D);
#if 1 /* rotate_m4 works in place, right? */
rotate_m4(ModelView3D, axis, DEG2RADF(deg));
More information about the Bf-blender-cvs
mailing list