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
This commit is contained in:
Adel Gadllah 2011-03-13 12:52:30 +01:00
parent 057348763b
commit 43cf60f563

View File

@ -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"
" 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 if (fade_bottom) {\n"
" ratio = ratio_bottom;\n"
" }\n"
"\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"
" }\n"
" else { \n"
" cogl_color_out = color;\n"
" }\n"
"}\n";
"}";
struct _StScrollViewFade
{