[Bf-blender-cvs] [70ff63e] blender2.8: OpenGL: tweak image shaders & code that uses them

Mike Erwin noreply at git.blender.org
Tue Oct 18 06:12:43 CEST 2016


Commit: 70ff63e63fc3a63dccc6a6c567bbc347c64d6c7d
Author: Mike Erwin
Date:   Tue Oct 18 00:08:34 2016 -0400
Branches: blender2.8
https://developer.blender.org/rB70ff63e63fc3a63dccc6a6c567bbc347c64d6c7d

OpenGL: tweak image shaders & code that uses them

- rename image shaders to describe exactly what they do
- rename inputs to match other built-in shaders
- set & use active texture unit
- no need to enable/disable textures with GLSL
- pull vertex format setup out of loops

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

M	source/blender/editors/space_view3d/drawobject.c
M	source/blender/gpu/CMakeLists.txt
M	source/blender/gpu/GPU_shader.h
M	source/blender/gpu/intern/gpu_shader.c
D	source/blender/gpu/shaders/gpu_shader_2D_texture_vert.glsl
A	source/blender/gpu/shaders/gpu_shader_3D_image_vert.glsl
R056	source/blender/gpu/shaders/gpu_shader_2D_texture_2D_frag.glsl	source/blender/gpu/shaders/gpu_shader_image_modulate_alpha_frag.glsl
R055	source/blender/gpu/shaders/gpu_shader_2D_texture_rect_frag.glsl	source/blender/gpu/shaders/gpu_shader_image_rect_modulate_alpha_frag.glsl
M	source/blender/windowmanager/intern/wm_draw.c
M	source/blender/windowmanager/intern/wm_stereo.c

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

diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c
index 408d27e..02702af 100644
--- a/source/blender/editors/space_view3d/drawobject.c
+++ b/source/blender/editors/space_view3d/drawobject.c
@@ -675,11 +675,11 @@ static void draw_empty_image(Object *ob, const short dflag, const unsigned char
 		}
 
 		VertexFormat *format = immVertexFormat();
-		unsigned pos = add_attrib(format, "position", GL_FLOAT, 2, KEEP_FLOAT);
-		unsigned texCoord = add_attrib(format, "texcoord", GL_FLOAT, 2, KEEP_FLOAT);
-		immBindBuiltinProgram(GPU_SHADER_2D_TEXTURE_2D); /* TODO: rename GPU_SHADER_3D_IMAGE_2D_MODULATE_ALPHA */
+		unsigned pos = add_attrib(format, "pos", GL_FLOAT, 2, KEEP_FLOAT);
+		unsigned texCoord = add_attrib(format, "texCoord", GL_FLOAT, 2, KEEP_FLOAT);
+		immBindBuiltinProgram(GPU_SHADER_3D_IMAGE_MODULATE_ALPHA);
 		immUniform1f("alpha", ob_alpha);
-		immUniform1i("texture_map", texUnit); /* TODO: rename "image" */
+		immUniform1i("image", texUnit);
 
 		immBegin(GL_TRIANGLE_FAN, 4);
 		immAttrib2f(texCoord, 0.0f, 0.0f);
diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt
index b2a7c78..e960a81 100644
--- a/source/blender/gpu/CMakeLists.txt
+++ b/source/blender/gpu/CMakeLists.txt
@@ -133,9 +133,9 @@ data_to_c_simple(shaders/gpu_shader_2D_vert.glsl SRC)
 data_to_c_simple(shaders/gpu_shader_2D_flat_color_vert.glsl SRC)
 data_to_c_simple(shaders/gpu_shader_2D_smooth_color_vert.glsl SRC)
 data_to_c_simple(shaders/gpu_shader_2D_smooth_color_frag.glsl SRC)
-data_to_c_simple(shaders/gpu_shader_2D_texture_2D_frag.glsl SRC)
-data_to_c_simple(shaders/gpu_shader_2D_texture_rect_frag.glsl SRC)
-data_to_c_simple(shaders/gpu_shader_2D_texture_vert.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_image_modulate_alpha_frag.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_image_rect_modulate_alpha_frag.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_3D_image_vert.glsl SRC)
 data_to_c_simple(shaders/gpu_shader_3D_vert.glsl SRC)
 data_to_c_simple(shaders/gpu_shader_3D_flat_color_vert.glsl SRC)
 data_to_c_simple(shaders/gpu_shader_3D_smooth_color_vert.glsl SRC)
diff --git a/source/blender/gpu/GPU_shader.h b/source/blender/gpu/GPU_shader.h
index d52a0a2..1fe0f6f 100644
--- a/source/blender/gpu/GPU_shader.h
+++ b/source/blender/gpu/GPU_shader.h
@@ -101,9 +101,9 @@ typedef enum GPUBuiltinShader {
 	GPU_SHADER_3D_FLAT_COLOR,
 	GPU_SHADER_3D_SMOOTH_COLOR,
 	GPU_SHADER_3D_DEPTH_ONLY,
-	/* basic 2D texture drawing */
-	GPU_SHADER_2D_TEXTURE_2D,
-	GPU_SHADER_2D_TEXTURE_RECT,
+	/* basic image drawing */
+	GPU_SHADER_3D_IMAGE_MODULATE_ALPHA,
+	GPU_SHADER_3D_IMAGE_RECT_MODULATE_ALPHA,
 	/* points */
 	GPU_SHADER_2D_POINT_FIXED_SIZE_UNIFORM_COLOR,
 	GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_SMOOTH,
diff --git a/source/blender/gpu/intern/gpu_shader.c b/source/blender/gpu/intern/gpu_shader.c
index 4641354..e8ea642 100644
--- a/source/blender/gpu/intern/gpu_shader.c
+++ b/source/blender/gpu/intern/gpu_shader.c
@@ -53,9 +53,9 @@ extern char datatoc_gpu_shader_2D_vert_glsl[];
 extern char datatoc_gpu_shader_2D_flat_color_vert_glsl[];
 extern char datatoc_gpu_shader_2D_smooth_color_vert_glsl[];
 extern char datatoc_gpu_shader_2D_smooth_color_frag_glsl[];
-extern char datatoc_gpu_shader_2D_texture_vert_glsl[];
-extern char datatoc_gpu_shader_2D_texture_2D_frag_glsl[];
-extern char datatoc_gpu_shader_2D_texture_rect_frag_glsl[];
+extern char datatoc_gpu_shader_3D_image_vert_glsl[];
+extern char datatoc_gpu_shader_image_modulate_alpha_frag_glsl[];
+extern char datatoc_gpu_shader_image_rect_modulate_alpha_frag_glsl[];
 extern char datatoc_gpu_shader_3D_vert_glsl[];
 extern char datatoc_gpu_shader_3D_flat_color_vert_glsl[];
 extern char datatoc_gpu_shader_3D_smooth_color_vert_glsl[];
@@ -105,9 +105,9 @@ static struct GPUShadersGlobal {
 		GPUShader *fx_shaders[MAX_FX_SHADERS * 2];
 		/* for drawing text */
 		GPUShader *text;
-		/* for drawing texture */
-		GPUShader *texture_2D;
-		GPUShader *texture_rect;
+		/* for drawing images */
+		GPUShader *image_modulate_alpha_3D;
+		GPUShader *image_rect_modulate_alpha_3D;
 		/* for simple 2D drawing */
 		GPUShader *uniform_color_2D;
 		GPUShader *flat_color_2D;
@@ -651,21 +651,21 @@ GPUShader *GPU_shader_get_builtin_shader(GPUBuiltinShader shader)
 				        NULL, NULL, NULL, 0, 0, 0);
 			retval = GG.shaders.text;
 			break;
-		case GPU_SHADER_2D_TEXTURE_2D:
-			if (!GG.shaders.texture_2D)
-				GG.shaders.texture_2D = GPU_shader_create(
-				        datatoc_gpu_shader_2D_texture_vert_glsl,
-				        datatoc_gpu_shader_2D_texture_2D_frag_glsl,
+		case GPU_SHADER_3D_IMAGE_MODULATE_ALPHA:
+			if (!GG.shaders.image_modulate_alpha_3D)
+				GG.shaders.image_modulate_alpha_3D = GPU_shader_create(
+				        datatoc_gpu_shader_3D_image_vert_glsl,
+				        datatoc_gpu_shader_image_modulate_alpha_frag_glsl,
 				        NULL, NULL, NULL, 0, 0, 0);
-			retval = GG.shaders.texture_2D;
+			retval = GG.shaders.image_modulate_alpha_3D;
 			break;
-		case GPU_SHADER_2D_TEXTURE_RECT:
-			if (!GG.shaders.texture_rect)
-				GG.shaders.texture_rect = GPU_shader_create(
-				datatoc_gpu_shader_2D_texture_vert_glsl,
-				datatoc_gpu_shader_2D_texture_rect_frag_glsl,
+		case GPU_SHADER_3D_IMAGE_RECT_MODULATE_ALPHA:
+			if (!GG.shaders.image_rect_modulate_alpha_3D)
+				GG.shaders.image_rect_modulate_alpha_3D = GPU_shader_create(
+				datatoc_gpu_shader_3D_image_vert_glsl,
+				datatoc_gpu_shader_image_rect_modulate_alpha_frag_glsl,
 				NULL, NULL, NULL, 0, 0, 0);
-			retval = GG.shaders.texture_rect;
+			retval = GG.shaders.image_rect_modulate_alpha_3D;
 			break;
 		case GPU_SHADER_2D_UNIFORM_COLOR:
 			if (!GG.shaders.uniform_color_2D)
@@ -917,14 +917,14 @@ void GPU_shader_free_builtin_shaders(void)
 		GG.shaders.text = NULL;
 	}
 
-	if (GG.shaders.texture_2D) {
-		GPU_shader_free(GG.shaders.texture_2D);
-		GG.shaders.texture_2D = NULL;
+	if (GG.shaders.image_modulate_alpha_3D) {
+		GPU_shader_free(GG.shaders.image_modulate_alpha_3D);
+		GG.shaders.image_modulate_alpha_3D = NULL;
 	}
 
-	if (GG.shaders.texture_rect) {
-		GPU_shader_free(GG.shaders.texture_rect);
-		GG.shaders.texture_rect = NULL;
+	if (GG.shaders.image_rect_modulate_alpha_3D) {
+		GPU_shader_free(GG.shaders.image_rect_modulate_alpha_3D);
+		GG.shaders.image_rect_modulate_alpha_3D = NULL;
 	}
 
 	if (GG.shaders.uniform_color_2D) {
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_texture_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_texture_vert.glsl
deleted file mode 100644
index 4c05cf1..0000000
--- a/source/blender/gpu/shaders/gpu_shader_2D_texture_vert.glsl
+++ /dev/null
@@ -1,19 +0,0 @@
-
-uniform mat4 ModelViewProjectionMatrix;
-
-#if __VERSION__ == 120
-  attribute vec2 texcoord;
-  attribute vec3 position;
-  varying vec2 texture_coord;
-#else
-  in vec2 texcoord;
-  in vec3 position;
-  out vec2 texture_coord;
-#endif
-
-
-void main()
-{
-	gl_Position = ModelViewProjectionMatrix * vec4(position.xyz, 1.0f);
-	texture_coord = texcoord;
-}
diff --git a/source/blender/gpu/shaders/gpu_shader_3D_image_vert.glsl b/source/blender/gpu/shaders/gpu_shader_3D_image_vert.glsl
new file mode 100644
index 0000000..e9f847f
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_3D_image_vert.glsl
@@ -0,0 +1,18 @@
+
+uniform mat4 ModelViewProjectionMatrix;
+
+#if __VERSION__ == 120
+  attribute vec2 texCoord;
+  attribute vec3 pos;
+  varying vec2 texCoord_interp;
+#else
+  in vec2 texCoord;
+  in vec3 pos;
+  out vec2 texCoord_interp;
+#endif
+
+void main()
+{
+	gl_Position = ModelViewProjectionMatrix * vec4(pos.xyz, 1.0f);
+	texCoord_interp = texCoord;
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_texture_2D_frag.glsl b/source/blender/gpu/shaders/gpu_shader_image_modulate_alpha_frag.glsl
similarity index 56%
rename from source/blender/gpu/shaders/gpu_shader_2D_texture_2D_frag.glsl
rename to source/blender/gpu/shaders/gpu_shader_image_modulate_alpha_frag.glsl
index cd4f0d2..74e1719 100644
--- a/source/blender/gpu/shaders/gpu_shader_2D_texture_2D_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_image_modulate_alpha_frag.glsl
@@ -1,17 +1,18 @@
+
 #if __VERSION__ == 120
-  varying vec2 texture_coord;
+  varying vec2 texCoord_interp;
   #define fragColor gl_FragColor
 #else
-  in vec2 texture_coord;
+  in vec2 texCoord_interp;
   out vec4 fragColor;
   #define texture2D texture
 #endif
 
 uniform float alpha;
-uniform sampler2D texture_map;
+uniform sampler2D image;
 
 void main()
 {
-	fragColor = texture2D(texture_map, texture_coord);
+	fragColor = texture2D(image, texCoord_interp);
 	fragColor.a *= alpha;
 }
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_texture_rect_frag.glsl b/source/blender/gpu/shaders/gpu_shader_image_rect_modulate_alpha_frag.glsl
similarity index 55%
rename from source/blender/gpu/shaders/gpu_shader_2D_texture_rect_frag.glsl
rename to source/blender/gpu/shaders/gpu_shader_image_rect_modulate_alpha_frag.glsl
index 9dad41d..aae3b40 100644
--- a/source/blender/gpu/shaders/gpu_shader_2D_texture_rect_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_image_rect_modulate_alpha_frag.glsl
@@ -1,17 +1,18 @@
+
 #if __VERSION__ == 120
-  varying vec2 texture_coord;
+  varying vec2 texCoord_interp;
   #define fragColor gl_FragColor
 #else
-  in vec2 texture_coord;
+  in vec2 texCoord_interp;
   out vec4 fragColor;
   #define texture2DRect texture
 #endif
 
 uniform float alpha;
-uniform sampler2DRect texture_map;
+uniform sampler2DRect image;
 
 void main()
 {
-	fragColor = texture2DRect(texture_map, texture_coord);
+	fragColor = texture2DRect(image, texCoord_interp);
 	fragColor.a *= alpha;
 }
diff --git a/source/blender/windowmanager/intern/wm_draw.c b/source/blender/windowmanager/intern/wm_draw.c
index e9eaa56..f38f1ee 100644
--- a/source/blender/windowmanager/intern/wm_draw.c
+++ b/source/blender/windowmanager/intern/wm_draw.c
@@ -447,16 +447,16 @@ void wm_triple_draw_textures(wmWindow *win, wmDrawTriple *triple, float alpha)
 	}
 
 	VertexFormat *format = immVertexFormat();
-	unsigned texcoord = add_attrib(format, "texcoord", GL_FLOAT, 2, KEEP_FLOAT);
-	unsigned pos = add_attrib(format, "position", GL_FLOAT, 2, KEEP_FLOAT);
-
-	glEnable(triple->target);

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list