[Bf-blender-cvs] [f3d33a1] master: GPU: Fix for glDrawPixels drawing w/ glsl shader

Campbell Barton noreply at git.blender.org
Tue Jun 7 20:12:44 CEST 2016


Commit: f3d33a1a0f1dd4092d35760027f495bc21d1e4be
Author: Campbell Barton
Date:   Wed Jun 8 04:03:25 2016 +1000
Branches: master
https://developer.blender.org/rBf3d33a1a0f1dd4092d35760027f495bc21d1e4be

GPU: Fix for glDrawPixels drawing w/ glsl shader

The basic shader needs to be temporarily disabled in this case.
Add macros for temp store/restoring the state.

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

M	source/blender/editors/interface/interface_icons.c
M	source/blender/editors/screen/glutil.c
M	source/blender/gpu/GPU_basic_shader.h
M	source/blender/windowmanager/intern/wm_gesture.c

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

diff --git a/source/blender/editors/interface/interface_icons.c b/source/blender/editors/interface/interface_icons.c
index 0a25a8f..222b036 100644
--- a/source/blender/editors/interface/interface_icons.c
+++ b/source/blender/editors/interface/interface_icons.c
@@ -1220,8 +1220,13 @@ static void icon_draw_rect(float x, float y, int w, int h, float UNUSED(aspect),
 		glaDrawPixelsSafe(draw_x, draw_y, draw_w, draw_h, draw_w, GL_RGBA, GL_UNSIGNED_BYTE, rect);
 	}
 	else {
+		int bound_options;
+		GPU_BASIC_SHADER_DISABLE_AND_STORE(bound_options);
+
 		glRasterPos2f(draw_x, draw_y);
 		glDrawPixels(draw_w, draw_h, GL_RGBA, GL_UNSIGNED_BYTE, rect);
+
+		GPU_BASIC_SHADER_ENABLE_AND_RESTORE(bound_options);
 	}
 
 	if (ima)
diff --git a/source/blender/editors/screen/glutil.c b/source/blender/editors/screen/glutil.c
index cbf8706..0142682 100644
--- a/source/blender/editors/screen/glutil.c
+++ b/source/blender/editors/screen/glutil.c
@@ -579,6 +579,10 @@ void glaDrawPixelsSafe(float x, float y, int img_w, int img_h, int row_w, int fo
 	draw_h = min_ii(img_h - off_y, ceil((scissor[3] - rast_y) / yzoom));
 
 	if (draw_w > 0 && draw_h > 0) {
+
+		int bound_options;
+		GPU_BASIC_SHADER_DISABLE_AND_STORE(bound_options);
+
 		/* Don't use safe RasterPos (slower) if we can avoid it. */
 		if (rast_x >= 0 && rast_y >= 0) {
 			glRasterPos2f(rast_x, rast_y);
@@ -610,6 +614,8 @@ void glaDrawPixelsSafe(float x, float y, int img_w, int img_h, int row_w, int fo
 		}
 		
 		glPixelStorei(GL_UNPACK_ROW_LENGTH,  0);
+
+		GPU_BASIC_SHADER_ENABLE_AND_RESTORE(bound_options);
 	}
 }
 
diff --git a/source/blender/gpu/GPU_basic_shader.h b/source/blender/gpu/GPU_basic_shader.h
index 11d87ce..f30b40c 100644
--- a/source/blender/gpu/GPU_basic_shader.h
+++ b/source/blender/gpu/GPU_basic_shader.h
@@ -76,6 +76,22 @@ void GPU_basic_shaders_exit(void);
 void GPU_basic_shader_bind(int options);
 int GPU_basic_shader_bound_options(void);
 
+/* Only use for small blocks of code that don't support glsl shader. */
+#define GPU_BASIC_SHADER_DISABLE_AND_STORE(bound_options) \
+if (GPU_basic_shader_use_glsl_get()) { \
+	if ((bound_options = GPU_basic_shader_bound_options())) { \
+		GPU_basic_shader_bind(0); \
+	} \
+} \
+else { bound_options = 0; } ((void)0)
+#define GPU_BASIC_SHADER_ENABLE_AND_RESTORE(bound_options) \
+if (GPU_basic_shader_use_glsl_get()) { \
+	if (bound_options) { \
+		GPU_basic_shader_bind(bound_options); \
+	} \
+} ((void)0)
+
+
 void GPU_basic_shader_colors(const float diffuse[3], const float specular[3],
 	int shininess, float alpha);
 
diff --git a/source/blender/windowmanager/intern/wm_gesture.c b/source/blender/windowmanager/intern/wm_gesture.c
index 26d1d4c..db933ad 100644
--- a/source/blender/windowmanager/intern/wm_gesture.c
+++ b/source/blender/windowmanager/intern/wm_gesture.c
@@ -281,6 +281,9 @@ static void draw_filled_lasso(wmWindow *win, wmGesture *gt)
 		       (const int (*)[2])moves, tot,
 		       draw_filled_lasso_px_cb, &lasso_fill_data);
 
+		int bound_options;
+		GPU_BASIC_SHADER_DISABLE_AND_STORE(bound_options);
+
 		glEnable(GL_BLEND);
 		// glColor4f(1.0, 1.0, 1.0, 0.05);
 
@@ -288,6 +291,8 @@ static void draw_filled_lasso(wmWindow *win, wmGesture *gt)
 
 		glDrawPixels(w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixel_buf);
 
+		GPU_BASIC_SHADER_ENABLE_AND_RESTORE(bound_options);
+
 		glDisable(GL_BLEND);
 		MEM_freeN(pixel_buf);
 	}




More information about the Bf-blender-cvs mailing list