[gnome-shell] StScrollViewFade: Fix GLSL shader to work on r300 hardware



commit 43cf60f5636e7883bd5012e4c89ed5d57e28200c
Author: Adel Gadllah <adel gadllah gmail com>
Date:   Sun Mar 13 12:52:30 2011 +0100

    StScrollViewFade: Fix GLSL shader to work on r300 hardware
    
    The number instructions in a shader is limited to 64 on r300 hardware,
    the fade shader in StScrollViewFade was ending up using 97 instructions
    which is way over the limit.
    
    So refactor the shader to use less instructions by precomputing as many
    values as possible outside of the conditionals. The resulting shader
    ends up using 34 instructions which is well within the hardware limits.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=644589

 src/st/st-scroll-view-fade.c |   26 ++++++++++++++------------
 1 files changed, 14 insertions(+), 12 deletions(-)
---
diff --git a/src/st/st-scroll-view-fade.c b/src/st/st-scroll-view-fade.c
index 3d6639a..74e430d 100644
--- a/src/st/st-scroll-view-fade.c
+++ b/src/st/st-scroll-view-fade.c
@@ -49,21 +49,23 @@ static const gchar *fade_glsl_shader =
 " vec4 color = cogl_color_in * texture2D (tex, vec2 (cogl_tex_coord_in[0].xy));\n"
 " float y = height * cogl_tex_coord_in[0].y;\n"
 " float x = width * cogl_tex_coord_in[0].x;\n"
-" float ratio = 0.0;\n"
+" float ratio = 1.0;\n"
 " float fade_bottom_start = height - offset_bottom;\n"
-" \n"
-" if (offset_top != 0.0 && y < offset_top && ((rtl && x > scrollbar_width) || (!rtl && x < (width - scrollbar_width)))) {\n"
-"  ratio = y / offset_top;\n"
-"  cogl_color_out = color * ratio;\n"
-" }\n"
-" else if (offset_bottom != 0.0 && y > fade_bottom_start && ((rtl && x > scrollbar_width) || (!rtl && x < (width - scrollbar_width)))) {\n"
-"  ratio = (height - y)/(height - fade_bottom_start);\n"
-"  cogl_color_out = color * ratio;\n"
+" float ratio_top = y / offset_top;\n"
+" float ratio_bottom = (height - y)/(height - fade_bottom_start);\n"
+" bool in_scroll_area = ((rtl && x > scrollbar_width) || (!rtl && x < (width - scrollbar_width)));\n"
+" bool fade_top = y < offset_top && in_scroll_area;\n"
+" bool fade_bottom = y > fade_bottom_start && in_scroll_area;\n"
+"\n"
+" if (fade_top) {\n"
+"  ratio = ratio_top;\n"
 " }\n"
-" else { \n"
-"  cogl_color_out = color;\n"
+" else if (fade_bottom) {\n"
+"  ratio = ratio_bottom;\n"
 " }\n"
-"}\n";
+"\n"
+"  cogl_color_out = color * ratio;\n"
+"}";
 
 struct _StScrollViewFade
 {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]