[Bf-blender-cvs] [1e7475a5d7] blender2.8: Opengl glaDrawPixels removal: More descriptive setup.

Clément Foucault noreply at git.blender.org
Fri Feb 24 12:40:49 CET 2017


Commit: 1e7475a5d7878642057ea0cb313b5ee0d4a8545e
Author: Clément Foucault
Date:   Fri Feb 24 11:11:43 2017 +0100
Branches: blender2.8
https://developer.blender.org/rB1e7475a5d7878642057ea0cb313b5ee0d4a8545e

Opengl glaDrawPixels removal: More descriptive setup.

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

M	source/blender/editors/include/BIF_glutil.h
M	source/blender/editors/interface/interface_draw.c
M	source/blender/editors/interface/interface_icons.c
M	source/blender/editors/mask/mask_draw.c
M	source/blender/editors/render/render_internal.c
M	source/blender/editors/render/render_preview.c
M	source/blender/editors/screen/glutil.c
M	source/blender/editors/space_file/file_draw.c
M	source/blender/editors/space_image/image_draw.c
M	source/blender/editors/space_node/drawnode.c
M	source/blender/editors/space_node/node_draw.c
M	source/blender/editors/space_view3d/view3d_draw_legacy.c
M	source/blender/windowmanager/intern/wm_dragdrop.c
M	source/blender/windowmanager/intern/wm_gesture.c

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

diff --git a/source/blender/editors/include/BIF_glutil.h b/source/blender/editors/include/BIF_glutil.h
index a3161b49d4..0b85517f33 100644
--- a/source/blender/editors/include/BIF_glutil.h
+++ b/source/blender/editors/include/BIF_glutil.h
@@ -210,6 +210,12 @@ void glaDrawPixelsTex(float x, float y, int img_w, int img_h, int format, int ty
 void glaDrawPixelsTex_clipping(float x, float y, int img_w, int img_h, int format, int type, int zoomfilter, void *rect,
                                float clip_min_x, float clip_min_y, float clip_max_x, float clip_max_y);
 #endif
+
+/* To be used before calling immDrawPixelsTex
+ * Default shader is GPU_SHADER_2D_IMAGE_COLOR
+ * Returns a shader to be able to set uniforms */
+struct GPUShader *immDrawPixelsTexSetup(int builtin);
+
 /**
  * immDrawPixelsTex - Functions like a limited glDrawPixels, but actually draws the
  * image using textures, which can be tremendously faster on low-end
@@ -217,6 +223,8 @@ void glaDrawPixelsTex_clipping(float x, float y, int img_w, int img_h, int forma
  * clipped when offscreen. Pixel unpacking parameters and
  * the glPixelZoom values are _not_ respected.
  *
+ * \attention Use immDrawPixelsTexSetup before calling this function.
+ *
  * \attention This routine makes many assumptions: the rect data
  * is expected to be in RGBA byte or float format, and the
  * modelview and projection matrices are assumed to define a
diff --git a/source/blender/editors/interface/interface_draw.c b/source/blender/editors/interface/interface_draw.c
index b48eb4d79d..64f7b1adc3 100644
--- a/source/blender/editors/interface/interface_draw.c
+++ b/source/blender/editors/interface/interface_draw.c
@@ -501,6 +501,7 @@ void ui_draw_but_IMAGE(ARegion *UNUSED(ar), uiBut *but, uiWidgetColors *UNUSED(w
 		facy = (float)h / (float)ibuf->y;
 	}
 
+	immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
 	immDrawPixelsTex((float)rect->xmin, (float)rect->ymin, ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST, ibuf->rect,
 	                 facx, facy, NULL);
 	
@@ -1735,7 +1736,7 @@ void ui_draw_but_TRACKPREVIEW(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wc
 				UI_draw_roundbox_gl_mode(GL_TRIANGLE_FAN, rect.xmin - 1, rect.ymin, rect.xmax + 1, rect.ymax + 1, 3.0f, color);
 			}
 
-			GPU_shader_unbind(); /* make sure there is no program bound */
+			immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
 			immDrawPixelsTex(rect.xmin, rect.ymin + 1, drawibuf->x, drawibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, GL_LINEAR, drawibuf->rect, 1.0f, 1.0f, NULL);
 
 			/* draw cross for pixel position */
diff --git a/source/blender/editors/interface/interface_icons.c b/source/blender/editors/interface/interface_icons.c
index 3def3e3598..ef394899ac 100644
--- a/source/blender/editors/interface/interface_icons.c
+++ b/source/blender/editors/interface/interface_icons.c
@@ -1009,6 +1009,7 @@ static void icon_draw_rect(float x, float y, int w, int h, float UNUSED(aspect),
 	/* draw */
 #if 0
 	if (is_preview) {
+		immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
 		immDrawPixelsTex(draw_x, draw_y, draw_w, draw_h, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST, rect,
 		                 1.0f, 1.0f, col);
 	}
@@ -1017,6 +1018,7 @@ static void icon_draw_rect(float x, float y, int w, int h, float UNUSED(aspect),
 		int bound_options;
 		GPU_BASIC_SHADER_DISABLE_AND_STORE(bound_options);
 
+		immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
 		immDrawPixelsTex(draw_x, draw_y, draw_w, draw_h, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST, rect,
 		                 1.0f, 1.0f, col);
 
diff --git a/source/blender/editors/mask/mask_draw.c b/source/blender/editors/mask/mask_draw.c
index f431efd80e..e1d303965b 100644
--- a/source/blender/editors/mask/mask_draw.c
+++ b/source/blender/editors/mask/mask_draw.c
@@ -753,6 +753,7 @@ void ED_mask_draw_region(Mask *mask, ARegion *ar,
 	}
 
 	if (draw_flag & MASK_DRAWFLAG_OVERLAY) {
+		float red[4] = {1.0f, 0.0f, 0.0f, 0.0f};
 		float *buffer = threaded_mask_rasterize(mask, width, height);
 
 		if (overlay_mode != MASK_OVERLAY_ALPHACHANNEL) {
@@ -767,12 +768,10 @@ void ED_mask_draw_region(Mask *mask, ARegion *ar,
 		if (stabmat) {
 			glMultMatrixf((const float *) stabmat);
 		}
-		GPUShader *shader = GPU_shader_get_builtin_shader(GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR);
-		GPU_shader_bind(shader);
-		float red[4] = {1.0f, 0.0f, 0.0f, 0.0f};
+		GPUShader *shader = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR);
 		GPU_shader_uniform_vector(shader, GPU_shader_get_uniform(shader, "shuffle"), 4, 1, red);
 		immDrawPixelsTex(0.0f, 0.0f, width, height, GL_RED, GL_FLOAT, GL_NEAREST, buffer, 1.0f, 1.0f, NULL);
-		GPU_shader_unbind();
+
 		glPopMatrix();
 
 		if (overlay_mode != MASK_OVERLAY_ALPHACHANNEL) {
diff --git a/source/blender/editors/render/render_internal.c b/source/blender/editors/render/render_internal.c
index abb65d1ef1..a28e9e4b4a 100644
--- a/source/blender/editors/render/render_internal.c
+++ b/source/blender/editors/render/render_internal.c
@@ -81,6 +81,7 @@
 #include "IMB_colormanagement.h"
 #include "IMB_imbuf_types.h"
 
+#include "GPU_shader.h"
 
 #include "BIF_gl.h"
 #include "BIF_glutil.h"
@@ -1537,7 +1538,7 @@ void render_view3d_draw(RenderEngine *engine, const bContext *C)
 		if (force_fallback == false) {
 			if (IMB_colormanagement_setup_glsl_draw(&scene->view_settings, &scene->display_settings, dither, true)) {
 				glEnable(GL_BLEND);
-				glUseProgram(0); /* immDrawPixelsTex use it's own shader */
+				immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
 				immDrawPixelsTex(xof, yof, rres.rectx, rres.recty,
 				                 GL_RGBA, GL_FLOAT, GL_NEAREST, rres.rectf,
 				                 scale_x, scale_y, NULL);;
@@ -1557,7 +1558,7 @@ void render_view3d_draw(RenderEngine *engine, const bContext *C)
 			                                              4, dither, &scene->view_settings, &scene->display_settings);
 
 			glEnable(GL_BLEND);
-			glUseProgram(0); /* immDrawPixelsTex use it's own shader */
+			immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
 			immDrawPixelsTex(xof, yof, rres.rectx, rres.recty,
 			                 GL_RGBA, GL_UNSIGNED_BYTE,
 			                 GL_NEAREST, display_buffer,
diff --git a/source/blender/editors/render/render_preview.c b/source/blender/editors/render/render_preview.c
index c651cfdce0..7cc3ca79b1 100644
--- a/source/blender/editors/render/render_preview.c
+++ b/source/blender/editors/render/render_preview.c
@@ -86,6 +86,7 @@
 #include "BIF_gl.h"
 #include "BIF_glutil.h"
 
+#include "GPU_shader.h"
 
 #include "RE_pipeline.h"
 #include "RE_engine.h"
@@ -599,6 +600,7 @@ static bool ed_preview_draw_rect(ScrArea *sa, int split, int first, rcti *rect,
 				if (re)
 					RE_AcquiredResultGet32(re, &rres, (unsigned int *)rect_byte, 0);
 
+				immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
 				immDrawPixelsTex(fx, fy, rres.rectx, rres.recty, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST, rect_byte,
 				                 1.0f, 1.0f, NULL);
 				
diff --git a/source/blender/editors/screen/glutil.c b/source/blender/editors/screen/glutil.c
index a4befa48ee..580592bf6e 100644
--- a/source/blender/editors/screen/glutil.c
+++ b/source/blender/editors/screen/glutil.c
@@ -620,11 +620,34 @@ void glaDrawPixelsAuto(float x, float y, int img_w, int img_h, int format, int t
 }
 #endif
 
-/* Use the currently bound shader if there is one.
- * To let it draw without other shaders use glUseProgram(0)
- * or GPU_shader_unbind() before calling immDrawPixelsTex.
+/* To be used before calling immDrawPixelsTex
+ * Default shader is GPU_SHADER_2D_IMAGE_COLOR
+ * You can still set uniforms with :
+ * GPU_shader_uniform_int(shader, GPU_shader_get_uniform(shader, "name"), 0);
+ * */
+GPUShader *immDrawPixelsTexSetup(int builtin)
+{
+	GPUShader *shader = GPU_shader_get_builtin_shader(builtin);
+	/* Shader will be unbind by immUnbindProgram in immDrawPixelsTexScaled_clipping */
+	GPU_shader_bind(shader);
+	GPU_shader_uniform_int(shader, GPU_shader_get_uniform(shader, "image"), 0);
+
+	return shader;
+}
+
+/* Use the currently bound shader.
+ *
+ * Use immDrawPixelsTexSetup to bind the shader you
+ * want before calling immDrawPixelsTex.
+ *
+ * If using a special shader double check it uses the same
+ * attributes "pos" "texCoord" and uniform "image".
  *
- * If color is NULL then use white by default */
+ * If color is NULL then use white by default
+ *
+ * Be also aware that this function unbinds the shader when
+ * it's finished.
+ * */
 void immDrawPixelsTexScaled_clipping(float x, float y, int img_w, int img_h,
                                      int format, int type, int zoomfilter, void *rect,
                                      float scaleX, float scaleY,
@@ -692,19 +715,19 @@ void immDrawPixelsTexScaled_clipping(float x, float y, int img_w, int img_h,
 
 	unsigned int program = glaGetOneInt(GL_CURRENT_PROGRAM);
 
-	if (program) {
-		immBindProgram(program);
+	/* This is needed for the OCIO case.
+	 * Shader program is set outside of blender and
+	 * we need it in imm module to do all attrib /
+	 * uniform bindings. */
 
-		/* optionnal */
-		if (glGetUniformLocation(program, "color") != -1)
-			immUniform4fv("color", (color) ? color : white);
-	}
-	else {
-		immBindBuiltinProgram(GPU_SHADER_2D_IMAGE_COLOR);
-		immUniform1i("image", 0);
-		immUniform4fv("color", (color) ? color : white);
-	}
+	/* A program is already bound.
+	 * set it in imm.bound_program to be able to use imm functions */
+	BLI_assert(program);
+	immBindProgram(program);
 
+	/* optionnal */
+	if (glGetUniformLocation(program, "color") != -1)
+		immUniform4fv("color", (color) ? color : white);
 
 	for (subpart_y = 0; subpart_y < nsubparts_y; subpart_y++) {
 		for (subpart_x = 0; subpart_x < nsubparts_x; subpart_x++) {
@@ -1118,7 +1141,7 @@ void glaDrawImBuf_glsl_clipping(ImBuf *ibuf, float x, float y, int zoomfilter,
 		display_buffer = IMB_display_buffer_acquire(ibuf, view_settings, display_settings, &cache_handle);
 
 		if (display_buffer) {
-			GPU_shader_unbind(); /* Make sure no shader is bound */
+			immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
 			immDrawPixelsTex_clipping(x, y, ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE,
 			                          zoomfilter, display_buffer,
 			    

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list