Commit: 53267d2579d8fa10d76721c0bea3fbca37d739db
Author: Martijn Berger
Date:   Fri Nov 18 16:04:25 2016 +0100
Branches: blender2.8
https://developer.blender.org/rB53267d2579d8fa10d76721c0bea3fbca37d739db

convert icon_draw_texture to gawain imm mode replacements

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

M       source/blender/editors/interface/interface_icons.c
M       source/blender/gpu/CMakeLists.txt
M       source/blender/gpu/GPU_shader.h
M       source/blender/gpu/intern/gpu_shader.c
A       source/blender/gpu/shaders/gpu_shader_2D_image_vert.glsl
A       source/blender/gpu/shaders/gpu_shader_image_color_frag.glsl

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

diff --git a/source/blender/editors/interface/interface_icons.c 
b/source/blender/editors/interface/interface_icons.c
index 650ef4d..c0360d9 100644
--- a/source/blender/editors/interface/interface_icons.c
+++ b/source/blender/editors/interface/interface_icons.c
@@ -35,6 +35,7 @@
 
 #include "GPU_extensions.h"
 #include "GPU_basic_shader.h"
+#include "GPU_immediate.h"
 
 #include "BLI_blenlib.h"
 #include "BLI_utildefines.h"
@@ -1016,33 +1017,40 @@ static void icon_draw_texture(
 {
        float x1, x2, y1, y2;
 
-       if (rgb) glColor4f(rgb[0], rgb[1], rgb[2], alpha);
-       else     glColor4f(alpha, alpha, alpha, alpha);
-
        x1 = ix * icongltex.invw;
        x2 = (ix + ih) * icongltex.invw;
        y1 = iy * icongltex.invh;
        y2 = (iy + ih) * icongltex.invh;
 
-       GPU_basic_shader_bind(GPU_SHADER_TEXTURE_2D | GPU_SHADER_USE_COLOR);
-       glBindTexture(GL_TEXTURE_2D, icongltex.id);
-
        /* sharper downscaling, has no effect when scale matches with a mip 
level */
        glTexEnvf(GL_TEXTURE_FILTER_CONTROL, GL_TEXTURE_LOD_BIAS, -0.5f);
 
-       glBegin(GL_QUADS);
-       glTexCoord2f(x1, y1);
-       glVertex2f(x, y);
+       glBindTexture(GL_TEXTURE_2D, icongltex.id);
+       VertexFormat* format = immVertexFormat();
+       unsigned pos = add_attrib(format, "pos", GL_FLOAT, 2, KEEP_FLOAT);
+       unsigned texCoord = add_attrib(format, "texCoord", GL_FLOAT, 2, 
KEEP_FLOAT);
 
-       glTexCoord2f(x2, y1);
-       glVertex2f(x + w, y);
+       immBindBuiltinProgram(GPU_SHADER_2D_IMAGE_COLOR);
+       if (rgb) immUniform4f("color", rgb[0], rgb[1], rgb[2], alpha);
+       else     immUniform4f("color", alpha, alpha, alpha, alpha);
 
-       glTexCoord2f(x2, y2);
-       glVertex2f(x + w, y + h);
+       immUniform1i("image", 0);
 
-       glTexCoord2f(x1, y2);
-       glVertex2f(x, y + h);
-       glEnd();
+       immBegin(GL_TRIANGLE_STRIP, 4);
+       immAttrib2f(texCoord, x1, y2);
+       immVertex2f(pos, x, y + h);
+
+       immAttrib2f(texCoord, x1, y1);
+       immVertex2f(pos, x, y);
+
+       immAttrib2f(texCoord, x2, y2);
+       immVertex2f(pos, x + w, y + h);
+
+       immAttrib2f(texCoord, x2, y1);
+       immVertex2f(pos, x + w, y);
+       immEnd();
+
+       immUnbindProgram();
 
        glTexEnvf(GL_TEXTURE_FILTER_CONTROL, GL_TEXTURE_LOD_BIAS, 0.0f);
 
diff --git a/source/blender/gpu/CMakeLists.txt 
b/source/blender/gpu/CMakeLists.txt
index 7a7c68a..b66085b 100644
--- a/source/blender/gpu/CMakeLists.txt
+++ b/source/blender/gpu/CMakeLists.txt
@@ -134,8 +134,10 @@ 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_image_vert.glsl SRC)
 data_to_c_simple(shaders/gpu_shader_image_mask_uniform_color_frag.glsl SRC)
 data_to_c_simple(shaders/gpu_shader_image_modulate_alpha_frag.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_image_color_frag.glsl SRC)
 data_to_c_simple(shaders/gpu_shader_image_rect_modulate_alpha_frag.glsl SRC)
 data_to_c_simple(shaders/gpu_shader_image_depth_linear_frag.glsl SRC)
 data_to_c_simple(shaders/gpu_shader_3D_image_vert.glsl SRC)
diff --git a/source/blender/gpu/GPU_shader.h b/source/blender/gpu/GPU_shader.h
index 91214c3..c6e4fb5 100644
--- a/source/blender/gpu/GPU_shader.h
+++ b/source/blender/gpu/GPU_shader.h
@@ -101,6 +101,7 @@ typedef enum GPUBuiltinShader {
        GPU_SHADER_2D_UNIFORM_COLOR,
        GPU_SHADER_2D_FLAT_COLOR,
        GPU_SHADER_2D_SMOOTH_COLOR,
+       GPU_SHADER_2D_IMAGE_COLOR,
        /* for simple 3D drawing */
        GPU_SHADER_3D_UNIFORM_COLOR,
        GPU_SHADER_3D_FLAT_COLOR,
diff --git a/source/blender/gpu/intern/gpu_shader.c 
b/source/blender/gpu/intern/gpu_shader.c
index ae5aab2..5f41cda 100644
--- a/source/blender/gpu/intern/gpu_shader.c
+++ b/source/blender/gpu/intern/gpu_shader.c
@@ -54,7 +54,10 @@ 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_image_vert_glsl[];
+
 extern char datatoc_gpu_shader_3D_image_vert_glsl[];
+extern char datatoc_gpu_shader_image_color_frag_glsl[];
 extern char datatoc_gpu_shader_image_mask_uniform_color_frag_glsl[];
 extern char datatoc_gpu_shader_image_modulate_alpha_frag_glsl[];
 extern char datatoc_gpu_shader_image_rect_modulate_alpha_frag_glsl[];
@@ -635,6 +638,8 @@ GPUShader *GPU_shader_get_builtin_shader(GPUBuiltinShader 
shader)
                                               
datatoc_gpu_shader_flat_color_frag_glsl },
                [GPU_SHADER_2D_SMOOTH_COLOR] = { 
datatoc_gpu_shader_2D_smooth_color_vert_glsl,
                                                 
datatoc_gpu_shader_2D_smooth_color_frag_glsl },
+               [GPU_SHADER_2D_IMAGE_COLOR] = { 
datatoc_gpu_shader_2D_image_vert_glsl,
+                                               
datatoc_gpu_shader_image_color_frag_glsl },
                [GPU_SHADER_3D_UNIFORM_COLOR] = { 
datatoc_gpu_shader_3D_vert_glsl, datatoc_gpu_shader_uniform_color_frag_glsl },
                [GPU_SHADER_3D_FLAT_COLOR] = { 
datatoc_gpu_shader_3D_flat_color_vert_glsl,
                                               
datatoc_gpu_shader_flat_color_frag_glsl },
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_image_vert.glsl 
b/source/blender/gpu/shaders/gpu_shader_2D_image_vert.glsl
new file mode 100644
index 0000000..a6c00b0
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_2D_image_vert.glsl
@@ -0,0 +1,18 @@
+
+uniform mat4 ModelViewProjectionMatrix;
+
+#if __VERSION__ == 120
+  attribute vec2 texCoord;
+  attribute vec2 pos;
+  varying vec2 texCoord_interp;
+#else
+  in vec2 texCoord;
+  in vec2 pos;
+  out vec2 texCoord_interp;
+#endif
+
+void main()
+{
+    gl_Position = ModelViewProjectionMatrix * vec4(pos.xy, 0.0f, 1.0f);
+    texCoord_interp = texCoord;
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_image_color_frag.glsl 
b/source/blender/gpu/shaders/gpu_shader_image_color_frag.glsl
new file mode 100644
index 0000000..b7697b0
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_image_color_frag.glsl
@@ -0,0 +1,17 @@
+
+#if __VERSION__ == 120
+  varying vec2 texCoord_interp;
+  #define fragColor gl_FragColor
+#else
+  in vec2 texCoord_interp;
+  out vec4 fragColor;
+  #define texture2D texture
+#endif
+
+uniform vec4 color;
+uniform sampler2D image;
+
+void main()
+{
+       fragColor = texture2D(image, texCoord_interp) * color;
+}

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to