Commit: e9b1163162d78324c118d3649451e81644b1af03
Author: Brecht Van Lommel
Date:   Tue Feb 13 18:09:58 2018 +0100
Branches: blender2.8
https://developer.blender.org/rBe9b1163162d78324c118d3649451e81644b1af03

Code cleanup: stop using rectangle textures in window draw, simplify code.

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

M       source/blender/gpu/CMakeLists.txt
M       source/blender/gpu/GPU_shader.h
M       source/blender/gpu/intern/gpu_shader.c
R060    
source/blender/gpu/shaders/gpu_shader_image_rect_modulate_alpha_frag.glsl       
source/blender/gpu/shaders/gpu_shader_image_frag.glsl
M       source/blender/gpu/shaders/gpu_shader_image_interlace_frag.glsl
M       source/blender/windowmanager/intern/wm_draw.c
M       source/blender/windowmanager/intern/wm_stereo.c
M       source/blender/windowmanager/wm_draw.h

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

diff --git a/source/blender/gpu/CMakeLists.txt 
b/source/blender/gpu/CMakeLists.txt
index 0ac842d90a0..9524c71be8e 100644
--- a/source/blender/gpu/CMakeLists.txt
+++ b/source/blender/gpu/CMakeLists.txt
@@ -142,13 +142,13 @@ 
data_to_c_simple(shaders/gpu_shader_2D_line_dashed_geom.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_frag.glsl SRC)
 data_to_c_simple(shaders/gpu_shader_image_linear_frag.glsl SRC)
 data_to_c_simple(shaders/gpu_shader_image_shuffle_color_frag.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_alpha_color_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_image_interlace_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 f2119a117e5..d25ccbc6c40 100644
--- a/source/blender/gpu/GPU_shader.h
+++ b/source/blender/gpu/GPU_shader.h
@@ -113,8 +113,10 @@ typedef enum GPUBuiltinShader {
        GPU_SHADER_2D_UNIFORM_COLOR,
        GPU_SHADER_2D_FLAT_COLOR,
        GPU_SHADER_2D_SMOOTH_COLOR,
+       GPU_SHADER_2D_IMAGE,
        GPU_SHADER_2D_IMAGE_COLOR,
        GPU_SHADER_2D_IMAGE_ALPHA_COLOR,
+       GPU_SHADER_2D_IMAGE_ALPHA,
        GPU_SHADER_2D_CHECKER,
        GPU_SHADER_2D_DIAG_STRIPES,
        /* for simple 3D drawing */
@@ -131,7 +133,6 @@ typedef enum GPUBuiltinShader {
        GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR,
        GPU_SHADER_2D_IMAGE_MASK_UNIFORM_COLOR,
        GPU_SHADER_3D_IMAGE_MODULATE_ALPHA,
-       GPU_SHADER_3D_IMAGE_RECT_MODULATE_ALPHA,
        GPU_SHADER_3D_IMAGE_DEPTH,
        /* stereo 3d */
        GPU_SHADER_2D_IMAGE_INTERLACE,
diff --git a/source/blender/gpu/intern/gpu_shader.c 
b/source/blender/gpu/intern/gpu_shader.c
index 598722d372b..f2dbf587abe 100644
--- a/source/blender/gpu/intern/gpu_shader.c
+++ b/source/blender/gpu/intern/gpu_shader.c
@@ -68,6 +68,7 @@ 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_frag_glsl[];
 extern char datatoc_gpu_shader_image_linear_frag_glsl[];
 extern char datatoc_gpu_shader_image_color_frag_glsl[];
 extern char datatoc_gpu_shader_image_alpha_color_frag_glsl[];
@@ -75,7 +76,6 @@ extern char 
datatoc_gpu_shader_image_shuffle_color_frag_glsl[];
 extern char datatoc_gpu_shader_image_interlace_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[];
 extern char datatoc_gpu_shader_image_depth_linear_frag_glsl[];
 extern char datatoc_gpu_shader_3D_vert_glsl[];
 extern char datatoc_gpu_shader_3D_normal_vert_glsl[];
@@ -710,8 +710,6 @@ GPUShader *GPU_shader_get_builtin_shader(GPUBuiltinShader 
shader)
                                                             
datatoc_gpu_shader_image_mask_uniform_color_frag_glsl },
                [GPU_SHADER_3D_IMAGE_MODULATE_ALPHA] = { 
datatoc_gpu_shader_3D_image_vert_glsl,
                                                         
datatoc_gpu_shader_image_modulate_alpha_frag_glsl },
-               [GPU_SHADER_3D_IMAGE_RECT_MODULATE_ALPHA] = { 
datatoc_gpu_shader_3D_image_vert_glsl,
-                                                             
datatoc_gpu_shader_image_rect_modulate_alpha_frag_glsl },
                [GPU_SHADER_3D_IMAGE_DEPTH] = { 
datatoc_gpu_shader_3D_image_vert_glsl,
                                                
datatoc_gpu_shader_image_depth_linear_frag_glsl },
 
@@ -728,10 +726,14 @@ GPUShader *GPU_shader_get_builtin_shader(GPUBuiltinShader 
shader)
                                                 
datatoc_gpu_shader_2D_smooth_color_frag_glsl },
                [GPU_SHADER_2D_IMAGE_LINEAR_TO_SRGB] = { 
datatoc_gpu_shader_2D_image_vert_glsl,
                                                         
datatoc_gpu_shader_image_linear_frag_glsl },
+               [GPU_SHADER_2D_IMAGE] = { datatoc_gpu_shader_2D_image_vert_glsl,
+                                         datatoc_gpu_shader_image_frag_glsl },
                [GPU_SHADER_2D_IMAGE_COLOR] = { 
datatoc_gpu_shader_2D_image_vert_glsl,
                                                
datatoc_gpu_shader_image_color_frag_glsl },
                [GPU_SHADER_2D_IMAGE_ALPHA_COLOR] = { 
datatoc_gpu_shader_2D_image_vert_glsl,
                                                      
datatoc_gpu_shader_image_alpha_color_frag_glsl },
+               [GPU_SHADER_2D_IMAGE_ALPHA] = { 
datatoc_gpu_shader_2D_image_vert_glsl,
+                                               
datatoc_gpu_shader_image_modulate_alpha_frag_glsl },
                [GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR] = { 
datatoc_gpu_shader_2D_image_vert_glsl,
                                                        
datatoc_gpu_shader_image_shuffle_color_frag_glsl },
                [GPU_SHADER_3D_UNIFORM_COLOR] = { 
datatoc_gpu_shader_3D_vert_glsl, datatoc_gpu_shader_uniform_color_frag_glsl },
diff --git 
a/source/blender/gpu/shaders/gpu_shader_image_rect_modulate_alpha_frag.glsl 
b/source/blender/gpu/shaders/gpu_shader_image_frag.glsl
similarity index 60%
rename from 
source/blender/gpu/shaders/gpu_shader_image_rect_modulate_alpha_frag.glsl
rename to source/blender/gpu/shaders/gpu_shader_image_frag.glsl
index 7d9ce9d2003..6eeab8ca7e8 100644
--- a/source/blender/gpu/shaders/gpu_shader_image_rect_modulate_alpha_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_image_frag.glsl
@@ -2,11 +2,9 @@
 in vec2 texCoord_interp;
 out vec4 fragColor;
 
-uniform float alpha;
-uniform sampler2DRect image;
+uniform sampler2D image;
 
 void main()
 {
        fragColor = texture(image, texCoord_interp);
-       fragColor.a *= alpha;
 }
diff --git a/source/blender/gpu/shaders/gpu_shader_image_interlace_frag.glsl 
b/source/blender/gpu/shaders/gpu_shader_image_interlace_frag.glsl
index 7f3e7df40ac..d95645f58e5 100644
--- a/source/blender/gpu/shaders/gpu_shader_image_interlace_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_image_interlace_frag.glsl
@@ -8,8 +8,8 @@ in vec2 texCoord_interp;
 out vec4 fragColor;
 
 uniform int interlace_id;
-uniform sampler2DRect image_a;
-uniform sampler2DRect image_b;
+uniform sampler2D image_a;
+uniform sampler2D image_b;
 
 bool interlace()
 {
diff --git a/source/blender/windowmanager/intern/wm_draw.c 
b/source/blender/windowmanager/intern/wm_draw.c
index b12dbf7b021..d103f2291bf 100644
--- a/source/blender/windowmanager/intern/wm_draw.c
+++ b/source/blender/windowmanager/intern/wm_draw.c
@@ -430,15 +430,8 @@ static void wm_draw_triple_fail(bContext *C, wmWindow *win)
 static bool wm_triple_gen_textures(wmWindow *win, wmDrawTriple *triple)
 {
        /* compute texture sizes */
-       triple->x = WM_window_pixels_x(win);
-       triple->y = WM_window_pixels_y(win);
-
-#if USE_TEXTURE_RECTANGLE
-       /* GL_TEXTURE_RECTANGLE is part of GL 3.1 so we can use it soon without 
runtime checks */
-       triple->target = GL_TEXTURE_RECTANGLE;
-#else
-       triple->target = GL_TEXTURE_2D;
-#endif
+       const int sizex = WM_window_pixels_x(win);
+       const int sizey = WM_window_pixels_y(win);
 
        /* generate texture names */
        glGenTextures(1, &triple->bind);
@@ -447,29 +440,25 @@ static bool wm_triple_gen_textures(wmWindow *win, 
wmDrawTriple *triple)
         * there is only one texture in use, which may not be the case */
        const GLint maxsize = GPU_max_texture_size();
 
-       if (triple->x > maxsize || triple->y > maxsize) {
+       if (sizex > maxsize || sizey > maxsize) {
                printf("WM: failed to allocate texture for triple buffer 
drawing "
                       "(texture too large for graphics card).\n");
                return false;
        }
 
        /* setup actual texture */
-       glBindTexture(triple->target, triple->bind);
+       glBindTexture(GL_TEXTURE_2D, triple->bind);
 
        /* no mipmaps */
-#if USE_TEXTURE_RECTANGLE
-       /* already has no mipmaps */
-#else
-       glTexParameteri(triple->target, GL_TEXTURE_MAX_LEVEL, 0);
+       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
        /* GL_TEXTURE_BASE_LEVEL = 0 by default */
-#endif
 
-       glTexParameteri(triple->target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-       glTexParameteri(triple->target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
 
-       glTexImage2D(triple->target, 0, GL_RGB8, triple->x, triple->y, 0, 
GL_RGB, GL_UNSIGNED_BYTE, NULL);
+       glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, sizex, sizey, 0, GL_RGB, 
GL_UNSIGNED_BYTE, NULL);
 
-       glBindTexture(triple->target, 0);
+       glBindTexture(GL_TEXTURE_2D, 0);
 
        return true;
 }
@@ -480,19 +469,10 @@ void wm_triple_draw_textures(wmWindow *win, wmDrawTriple 
*triple, float alpha)
        const int sizey = WM_window_pixels_y(win);
 
        /* wmOrtho for the screen has this same offset */
-       float ratiox = sizex;
-       float ratioy = sizey;
-       float halfx = GLA_PIXEL_OFS;
-       float halfy = GLA_PIXEL_OFS;
-
-#if USE_TEXTURE_RECTANGLE
-       /* texture rectangle has unnormalized coordinates */
-#else
-       ratiox /= triple->x;
-       ratioy /= triple->y;
-       halfx /= triple->x;
-       halfy /= triple->y;
-#endif
+       const float ratiox = 1.0f;
+       const float ratioy = 1.0f;
+       const float halfx = GLA_PIXEL_OFS / sizex;
+       const float halfy = GLA_PIXEL_OFS / sizey;
 
        Gwn_VertFormat *format = immVertexFormat();
        unsigned int texcoord = GWN_vertformat_attr_add(format, "texCoord", 
GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
@@ -500,16 +480,10 @@ void wm_triple_draw_textures(wmWindow *win, wmDrawTriple 
*triple, float alpha)
 
        const int activeTex = 7; /* arbitrary */
        glActiveTexture(GL_TEXTURE0 + activeTex);
-       glBindTexture(triple->target, triple->bind);
-
-#if USE_TEXTURE_RECTANGLE
-       immBindBuiltinProgram(GPU_SHADER_3D_IMAGE_RECT_MODULATE_ALPHA);
-#else
-       immBindBuiltinProgram(GPU_SHADER_3D_IMAGE_MODULATE_ALPHA);
-       /* TODO: make pure 2D version
-        * and a 2D_IMAGE (replace, not modulate) version for when alpha = 1.0
-        */
-#endif
+       glBindTexture(GL_TEXTURE_2D, triple->bind);
+
+       immBindBuiltinProgram(GPU_SHADER_2D_IMAGE_ALPHA);
+
        immUniform1f("alpha", alpha);
        imm

@@ Diff output truncated at 10240 characters. @@

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

Reply via email to