Commit: 4a1feaa5558ed60388fd3be41db74fbc54f2ab08
Author: Dalai Felinto
Date:   Thu Sep 22 13:20:44 2016 +0000
Branches: blender2.8
https://developer.blender.org/rB4a1feaa5558ed60388fd3be41db74fbc54f2ab08

immediate mode: Triple Buffer and two new shaders for TEXTURE_2D and 
TEXTURE_RECT

Use the same vertex shader for both fragment shaders

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

M       source/blender/gpu/CMakeLists.txt
M       source/blender/gpu/GPU_shader.h
M       source/blender/gpu/gawain/immediate.c
M       source/blender/gpu/gawain/immediate.h
M       source/blender/gpu/intern/gpu_shader.c
A       source/blender/gpu/shaders/gpu_shader_2D_texture_2D_frag.glsl
A       source/blender/gpu/shaders/gpu_shader_2D_texture_rect_frag.glsl
A       source/blender/gpu/shaders/gpu_shader_2D_texture_vert.glsl
M       source/blender/windowmanager/intern/wm_draw.c

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

diff --git a/source/blender/gpu/CMakeLists.txt 
b/source/blender/gpu/CMakeLists.txt
index a0b236d..e8e0a7b 100644
--- a/source/blender/gpu/CMakeLists.txt
+++ b/source/blender/gpu/CMakeLists.txt
@@ -125,6 +125,9 @@ data_to_c_simple(shaders/gpu_shader_2D_no_color_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_3D_no_color_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 9b3077e..0b618d1 100644
--- a/source/blender/gpu/GPU_shader.h
+++ b/source/blender/gpu/GPU_shader.h
@@ -101,6 +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,
 } GPUBuiltinShader;
 
 GPUShader *GPU_shader_get_builtin_shader(GPUBuiltinShader shader);
diff --git a/source/blender/gpu/gawain/immediate.c 
b/source/blender/gpu/gawain/immediate.c
index bcc84c1..9c3904f 100644
--- a/source/blender/gpu/gawain/immediate.c
+++ b/source/blender/gpu/gawain/immediate.c
@@ -650,3 +650,14 @@ void immUniformColor4ubv(const unsigned char rgba[4])
        const float scale = 1.0f / 255.0f;
        immUniform4f("color", scale * rgba[0], scale * rgba[1], scale * 
rgba[2], rgba[3]);
        }
+
+void immUniform1i(const char *name, const unsigned int data)
+       {
+       int loc = glGetUniformLocation(imm.bound_program, name);
+
+#if TRUST_NO_ONE
+       assert(loc != -1);
+#endif
+
+       glUniform1i(loc, data);
+       }
\ No newline at end of file
diff --git a/source/blender/gpu/gawain/immediate.h 
b/source/blender/gpu/gawain/immediate.h
index d33f680..84fb076 100644
--- a/source/blender/gpu/gawain/immediate.h
+++ b/source/blender/gpu/gawain/immediate.h
@@ -72,3 +72,5 @@ void immUniform4f(const char* name, float x, float y, float 
z, float w);
 // TODO: treat as sRGB?
 void immUniformColor3ubv(const unsigned char data[3]);
 void immUniformColor4ubv(const unsigned char data[4]);
+
+void immUniform1i(const char *name, const unsigned int data);
diff --git a/source/blender/gpu/intern/gpu_shader.c 
b/source/blender/gpu/intern/gpu_shader.c
index fbb9c9e..41a4537 100644
--- a/source/blender/gpu/intern/gpu_shader.c
+++ b/source/blender/gpu/intern/gpu_shader.c
@@ -53,6 +53,9 @@ extern char datatoc_gpu_shader_2D_no_color_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_no_color_vert_glsl[];
 extern char datatoc_gpu_shader_3D_flat_color_vert_glsl[];
 extern char datatoc_gpu_shader_3D_smooth_color_vert_glsl[];
@@ -88,6 +91,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 simple 2D drawing */
                GPUShader *uniform_color_2D;
                GPUShader *flat_color_2D;
@@ -623,6 +629,22 @@ 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,
+                                       NULL, NULL, NULL, 0, 0, 0);
+                       retval = GG.shaders.texture_2D;
+                       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,
+                               NULL, NULL, NULL, 0, 0, 0);
+                       retval = GG.shaders.texture_rect;
+                       break;
                case GPU_SHADER_2D_UNIFORM_COLOR:
                        if (!GG.shaders.uniform_color_2D)
                                GG.shaders.uniform_color_2D = GPU_shader_create(
@@ -795,6 +817,16 @@ 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.texture_rect) {
+               GPU_shader_free(GG.shaders.texture_rect);
+               GG.shaders.texture_rect = NULL;
+       }
+
        if (GG.shaders.uniform_color_2D) {
                GPU_shader_free(GG.shaders.uniform_color_2D);
                GG.shaders.uniform_color_2D = NULL;
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_texture_2D_frag.glsl 
b/source/blender/gpu/shaders/gpu_shader_2D_texture_2D_frag.glsl
new file mode 100644
index 0000000..6029fd8
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_2D_texture_2D_frag.glsl
@@ -0,0 +1,14 @@
+#if __VERSION__ == 120
+  varying vec2 texture_coord;
+  #define fragColor gl_FragColor
+#else
+  in vec2 texture_coord;
+  out vec4 fragColor;
+#endif
+
+uniform sampler2D texture_map;
+
+void main()
+{
+       fragColor = texture2D(texture_map, texture_coord);
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_texture_rect_frag.glsl 
b/source/blender/gpu/shaders/gpu_shader_2D_texture_rect_frag.glsl
new file mode 100644
index 0000000..d32b8ba
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_2D_texture_rect_frag.glsl
@@ -0,0 +1,14 @@
+#if __VERSION__ == 120
+  varying vec2 texture_coord;
+  #define fragColor gl_FragColor
+#else
+  in vec2 texture_coord;
+  out vec4 fragColor;
+#endif
+
+uniform sampler2DRect texture_map;
+
+void main()
+{
+       fragColor = texture2DRect(texture_map, texture_coord);
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_texture_vert.glsl 
b/source/blender/gpu/shaders/gpu_shader_2D_texture_vert.glsl
new file mode 100644
index 0000000..8c0d761
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_2D_texture_vert.glsl
@@ -0,0 +1,14 @@
+#if __VERSION__ == 120
+  varying vec2 texture_coord;
+#else
+  out vec2 texture_coord;
+#endif
+
+in vec2 texcoord;
+in vec3 position;
+
+void main()
+{
+       gl_Position = gl_ModelViewProjectionMatrix * vec4(position.xyz, 1.0f);
+       texture_coord = texcoord;
+}
diff --git a/source/blender/windowmanager/intern/wm_draw.c 
b/source/blender/windowmanager/intern/wm_draw.c
index b0586e8..4303ce3 100644
--- a/source/blender/windowmanager/intern/wm_draw.c
+++ b/source/blender/windowmanager/intern/wm_draw.c
@@ -59,6 +59,7 @@
 #include "GPU_extensions.h"
 #include "GPU_glew.h"
 #include "GPU_basic_shader.h"
+#include "GPU_immediate.h"
 
 #include "RE_engine.h"
 
@@ -445,28 +446,36 @@ void wm_triple_draw_textures(wmWindow *win, wmDrawTriple 
*triple, float alpha)
                halfy /= triple->y;
        }
 
-       GPU_basic_shader_bind((triple->target == GL_TEXTURE_2D) ? 
GPU_SHADER_TEXTURE_2D : GPU_SHADER_TEXTURE_RECT);
+       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);
+       immBindBuiltinProgram((triple->target == GL_TEXTURE_2D) ? 
GPU_SHADER_2D_TEXTURE_2D : GPU_SHADER_2D_TEXTURE_RECT);
 
        glBindTexture(triple->target, triple->bind);
 
-       glColor4f(1.0f, 1.0f, 1.0f, alpha);
-       glBegin(GL_QUADS);
-       glTexCoord2f(halfx, halfy);
-       glVertex2f(0, 0);
+       immUniform1i("texture_map", 0);
 
-       glTexCoord2f(ratiox + halfx, halfy);
-       glVertex2f(sizex, 0);
+       immBegin(GL_QUADS, 4);
 
-       glTexCoord2f(ratiox + halfx, ratioy + halfy);
-       glVertex2f(sizex, sizey);
+       immAttrib2f(texcoord, halfx, halfy);
+       immVertex2f(pos, 0.0f, 0.0f);
 
-       glTexCoord2f(halfx, ratioy + halfy);
-       glVertex2f(0, sizey);
-       glEnd();
+       immAttrib2f(texcoord, ratiox + halfx, halfy);
+       immVertex2f(pos, sizex, 0.0f);
 
-       glBindTexture(triple->target, 0);
+       immAttrib2f(texcoord, ratiox + halfx, ratioy + halfy);
+       immVertex2f(pos, sizex, sizey);
+
+       immAttrib2f(texcoord, halfx, ratioy + halfy);
+       immVertex2f(pos, 0.0f, sizey);
 
-       GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
+       immEnd();
+       immUnbindProgram();
+
+       glBindTexture(triple->target, 0);
+       glDisable(triple->target);
 }
 
 static void wm_triple_copy_textures(wmWindow *win, wmDrawTriple *triple)

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to