[Bf-blender-cvs] [3f11be3f7de] blender2.8: Get rid of glMatrixMode calls

Sergey Sharybin noreply at git.blender.org
Wed Apr 19 15:23:08 CEST 2017


Commit: 3f11be3f7de90517826cb114f648b06fc85b67d4
Author: Sergey Sharybin
Date:   Wed Apr 19 10:46:05 2017 +0200
Branches: blender2.8
https://developer.blender.org/rB3f11be3f7de90517826cb114f648b06fc85b67d4

Get rid of glMatrixMode calls

With the explicit calls we don't need to worry about current state
outside of the GPU module now. In fact. we don't need to worry about
current matrix mode in core profile at all.

Legacy OpenGL now has some code which ensures current matrix mode
when using explicit calls to push/pop matrix.

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

M	source/blender/editors/interface/interface.c
M	source/blender/editors/space_node/drawnode.c
M	source/blender/editors/space_view3d/view3d_draw_legacy.c
M	source/blender/gpu/GPU_matrix.h
M	source/blender/gpu/intern/gpu_matrix.c
M	source/blender/windowmanager/intern/wm_playanim.c

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

diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index 365ebfc17c4..75ccdece799 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -1377,9 +1377,7 @@ void UI_block_draw(const bContext *C, uiBlock *block)
 	ui_but_to_pixelrect(&rect, ar, block, NULL);
 	
 	/* pixel space for AA widgets */
-	glMatrixMode(GL_PROJECTION);
 	gpuPushProjectionMatrix();
-	glMatrixMode(GL_MODELVIEW);
 	gpuPushMatrix();
 	gpuLoadIdentity();
 
@@ -1406,9 +1404,7 @@ void UI_block_draw(const bContext *C, uiBlock *block)
 	}
 	
 	/* restore matrix */
-	glMatrixMode(GL_PROJECTION);
 	gpuPopProjectionMatrix();
-	glMatrixMode(GL_MODELVIEW);
 	gpuPopMatrix();
 
 	if (multisample_enabled)
diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c
index 3b3a11f3269..a6550b32265 100644
--- a/source/blender/editors/space_node/drawnode.c
+++ b/source/blender/editors/space_node/drawnode.c
@@ -3175,9 +3175,7 @@ void draw_nodespace_back_pix(const bContext *C, ARegion *ar, SpaceNode *snode, b
 	if (ibuf) {
 		float x, y; 
 
-		glMatrixMode(GL_PROJECTION);
 		gpuPushProjectionMatrix();
-		glMatrixMode(GL_MODELVIEW);
 		gpuPushMatrix();
 
 		/* somehow the offset has to be calculated inverse */
@@ -3263,9 +3261,7 @@ void draw_nodespace_back_pix(const bContext *C, ARegion *ar, SpaceNode *snode, b
 			}
 		}
 
-		glMatrixMode(GL_PROJECTION);
 		gpuPopProjectionMatrix();
-		glMatrixMode(GL_MODELVIEW);
 		gpuPopMatrix();
 	}
 	
diff --git a/source/blender/editors/space_view3d/view3d_draw_legacy.c b/source/blender/editors/space_view3d/view3d_draw_legacy.c
index 0d59b9afb14..88ba8439980 100644
--- a/source/blender/editors/space_view3d/view3d_draw_legacy.c
+++ b/source/blender/editors/space_view3d/view3d_draw_legacy.c
@@ -754,9 +754,7 @@ static void view3d_draw_bgpic(Scene *scene, ARegion *ar, View3D *v3d,
 			glEnable(GL_BLEND);
 			glBlendFunc(GL_SRC_ALPHA,  GL_ONE_MINUS_SRC_ALPHA);
 
-			glMatrixMode(GL_PROJECTION);
 			gpuPushProjectionMatrix();
-			glMatrixMode(GL_MODELVIEW);
 			gpuPushMatrix();
 			ED_region_pixelspace(ar);
 
@@ -777,9 +775,7 @@ static void view3d_draw_bgpic(Scene *scene, ARegion *ar, View3D *v3d,
 			immDrawPixelsTex(&state, x1 - centx, y1 - centy, ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, GL_LINEAR, ibuf->rect,
 			                 zoomx, zoomy, col);
 
-			glMatrixMode(GL_PROJECTION);
 			gpuPopProjectionMatrix();
-			glMatrixMode(GL_MODELVIEW);
 			gpuPopMatrix();
 
 			glDisable(GL_BLEND);
@@ -1822,10 +1818,8 @@ void ED_view3d_draw_offscreen(
 		GPU_free_images_anim();
 	}
 
-	glMatrixMode(GL_PROJECTION);
 	gpuPushProjectionMatrix();
 	gpuLoadIdentity();
-	glMatrixMode(GL_MODELVIEW);
 	gpuPushMatrix();
 	gpuLoadIdentity();
 
@@ -1886,9 +1880,7 @@ void ED_view3d_draw_offscreen(
 	ar->winy = bwiny;
 	ar->winrct = brect;
 
-	glMatrixMode(GL_PROJECTION);
 	gpuPopMatrix();
-	glMatrixMode(GL_MODELVIEW);
 	gpuPopMatrix();
 
 	UI_Theme_Restore(&theme_state);
@@ -2532,10 +2524,8 @@ void view3d_main_region_draw_legacy(const bContext *C, ARegion *ar)
 	bool render_border = ED_view3d_calc_render_border(scene, v3d, ar, &border_rect);
 	bool clip_border = (render_border && !BLI_rcti_compare(&ar->drawrct, &border_rect));
 
-	glMatrixMode(GL_PROJECTION);
 	gpuPushProjectionMatrix();
-	gpuLoadIdentity();
-	glMatrixMode(GL_MODELVIEW);
+	gpuLoadIdentityProjectionMatrix();
 	gpuPushMatrix();
 	gpuLoadIdentity();
 
@@ -2564,9 +2554,7 @@ void view3d_main_region_draw_legacy(const bContext *C, ARegion *ar)
 
 	view3d_main_region_draw_info(C, scene, ar, v3d, grid_unit, render_border);
 
-	glMatrixMode(GL_PROJECTION);
 	gpuPopProjectionMatrix();
-	glMatrixMode(GL_MODELVIEW);
 	gpuPopMatrix();
 
 	v3d->flag |= V3D_INVALID_BACKBUF;
diff --git a/source/blender/gpu/GPU_matrix.h b/source/blender/gpu/GPU_matrix.h
index 749784c9a2c..2d43d1ad573 100644
--- a/source/blender/gpu/GPU_matrix.h
+++ b/source/blender/gpu/GPU_matrix.h
@@ -94,6 +94,7 @@ void gpuPopProjectionMatrix(void);
 
 /* 3D Projection Matrix */
 
+void gpuLoadIdentityProjectionMatrix(void);
 void gpuLoadProjectionMatrix(const float m[4][4]);
 
 void gpuOrtho(float left, float right, float bottom, float top, float near, float far);
diff --git a/source/blender/gpu/intern/gpu_matrix.c b/source/blender/gpu/intern/gpu_matrix.c
index deb920c2582..8bf17653850 100644
--- a/source/blender/gpu/intern/gpu_matrix.c
+++ b/source/blender/gpu/intern/gpu_matrix.c
@@ -119,7 +119,18 @@ void gpuPushMatrix(void)
 {
 #if SUPPORT_LEGACY_MATRIX
 	{
+		GLenum mode;
+		glGetIntegerv(GL_MATRIX_MODE, (GLint*)&mode);
+		if (mode != GL_MODELVIEW) {
+			glMatrixMode(GL_MODELVIEW);
+		}
+
 		glPushMatrix();
+
+		if (mode != GL_MODELVIEW) {
+			glMatrixMode(mode); /* restore */
+		}
+
 		state.dirty = true;
 		return;
 	}
@@ -134,7 +145,18 @@ void gpuPopMatrix(void)
 {
 #if SUPPORT_LEGACY_MATRIX
 	{
+		GLenum mode;
+		glGetIntegerv(GL_MATRIX_MODE, (GLint*)&mode);
+		if (mode != GL_MODELVIEW) {
+			glMatrixMode(GL_MODELVIEW);
+		}
+
 		glPopMatrix();
+
+		if (mode != GL_MODELVIEW) {
+			glMatrixMode(mode); /* restore */
+		}
+
 		state.dirty = true;
 		return;
 	}
@@ -149,7 +171,18 @@ void gpuPushProjectionMatrix(void)
 {
 #if SUPPORT_LEGACY_MATRIX
 	{
+		GLenum mode;
+		glGetIntegerv(GL_MATRIX_MODE, (GLint*)&mode);
+		if (mode != GL_PROJECTION) {
+			glMatrixMode(GL_PROJECTION);
+		}
+
 		glPushMatrix();
+
+		if (mode != GL_PROJECTION) {
+			glMatrixMode(mode); /* restore */
+		}
+
 		state.dirty = true;
 		return;
 	}
@@ -164,7 +197,18 @@ void gpuPopProjectionMatrix(void)
 {
 #if SUPPORT_LEGACY_MATRIX
 	{
+		GLenum mode;
+		glGetIntegerv(GL_MATRIX_MODE, (GLint*)&mode);
+		if (mode != GL_PROJECTION) {
+			glMatrixMode(GL_PROJECTION);
+		}
+
 		glPopMatrix();
+
+		if (mode != GL_PROJECTION) {
+			glMatrixMode(mode); /* restore */
+		}
+
 		state.dirty = true;
 		return;
 	}
@@ -190,6 +234,32 @@ void gpuLoadMatrix(const float m[4][4])
 	state.dirty = true;
 }
 
+void gpuLoadIdentityProjectionMatrix(void)
+{
+#if SUPPORT_LEGACY_MATRIX
+	{
+		GLenum mode;
+		glGetIntegerv(GL_MATRIX_MODE, (GLint*)&mode);
+		if (mode != GL_PROJECTION) {
+			glMatrixMode(GL_PROJECTION);
+		}
+
+		glLoadIdentity();
+
+		if (mode != GL_PROJECTION_MATRIX) {
+			glMatrixMode(mode); /* restore */
+		}
+
+		state.dirty = true;
+		return;
+	}
+#endif
+
+	unit_m4(Projection);
+	CHECKMAT(Projection3D);
+	state.dirty = true;
+}
+
 void gpuLoadProjectionMatrix(const float m[4][4])
 {
 #if SUPPORT_LEGACY_MATRIX
diff --git a/source/blender/windowmanager/intern/wm_playanim.c b/source/blender/windowmanager/intern/wm_playanim.c
index ebc79986198..373e0bf10ad 100644
--- a/source/blender/windowmanager/intern/wm_playanim.c
+++ b/source/blender/windowmanager/intern/wm_playanim.c
@@ -360,10 +360,8 @@ static void playanim_toscreen(PlayState *ps, PlayAnimPict *picture, struct ImBuf
 		float fac = ps->picture->frame / (double)(((PlayAnimPict *)picsbase.last)->frame - ((PlayAnimPict *)picsbase.first)->frame);
 
 		fac = 2.0f * fac - 1.0f;
-		glMatrixMode(GL_PROJECTION); /* TODO: convert this nasty code */
 		gpuPushProjectionMatrix();
-		gpuLoadIdentity();
-		glMatrixMode(GL_MODELVIEW);
+		gpuLoadIdentityProjectionMatrix();
 		gpuPushMatrix();
 		gpuLoadIdentity();
 
@@ -380,9 +378,7 @@ static void playanim_toscreen(PlayState *ps, PlayAnimPict *picture, struct ImBuf
 		immUnbindProgram();
 
 		gpuPopMatrix();
-		glMatrixMode(GL_PROJECTION);
 		gpuPopProjectionMatrix();
-		glMatrixMode(GL_MODELVIEW);
 	}
 
 	GHOST_SwapWindowBuffers(g_WS.ghost_window);




More information about the Bf-blender-cvs mailing list