[Glamor] [PATCH 2/4] glamor: Use glsl "fract/mod" instead of "while" in gradient shaders.
Grigori Goronzy
greg at chown.ath.cx
Fri Jun 6 12:20:57 PDT 2014
From: Markus Wick <markus at selfnet.de>
This fixes gtkperf. It seemed to hang forever.
Signed-off-by: Eric Anholt <eric at anholt.net>
Reviewed-by: Eric Anholt <eric at anholt.net>
---
src/glamor_gradient.c | 48 ++++--------------------------------------------
1 file changed, 4 insertions(+), 44 deletions(-)
diff --git a/src/glamor_gradient.c b/src/glamor_gradient.c
index 06515b8..4802745 100644
--- a/src/glamor_gradient.c
+++ b/src/glamor_gradient.c
@@ -257,7 +257,6 @@ _glamor_create_radial_gradient_program(ScreenPtr screen, int stops_count, int dy
"{\n"\
" float t = 0.0;\n"\
" float sqrt_value;\n"\
- " int revserse = 0;\n"\
" t_invalid = 0;\n"\
" \n"\
" vec3 tmp = vec3(source_texture.x, source_texture.y, 1.0);\n"\
@@ -305,30 +304,11 @@ _glamor_create_radial_gradient_program(ScreenPtr screen, int stops_count, int dy
" }\n"\
" \n"\
" if(repeat_type == %d){\n" /* repeat normal*/\
- " while(t > 1.0) \n"\
- " t = t - 1.0; \n"\
- " while(t < 0.0) \n"\
- " t = t + 1.0; \n"\
+ " t = fract(t);\n"\
" }\n"\
" \n"\
" if(repeat_type == %d) {\n" /* repeat reflect*/\
- " while(t > 1.0) {\n"\
- " t = t - 1.0; \n"\
- " if(revserse == 0)\n"\
- " revserse = 1;\n"\
- " else\n"\
- " revserse = 0;\n"\
- " }\n"\
- " while(t < 0.0) {\n"\
- " t = t + 1.0; \n"\
- " if(revserse == 0)\n"\
- " revserse = 1;\n"\
- " else\n"\
- " revserse = 0;\n"\
- " }\n"\
- " if(revserse == 1) {\n"\
- " t = 1.0 - t; \n"\
- " }\n"\
+ " t = abs(fract(t * 0.5 + 0.5) * 2.0 - 1.0);\n"\
" }\n"\
" \n"\
" return t;\n"\
@@ -500,7 +480,6 @@ _glamor_create_linear_gradient_program(ScreenPtr screen, int stops_count, int dy
" vec4 stop_color_before;\n"\
" vec4 stop_color_after;\n"\
" float new_alpha; \n"\
- " int revserse = 0;\n"\
" vec4 gradient_color;\n"\
" float percentage; \n"\
" vec3 source_texture_trans = transform_mat * tmp;\n"\
@@ -520,30 +499,11 @@ _glamor_create_linear_gradient_program(ScreenPtr screen, int stops_count, int dy
" distance = distance - _p1_distance; \n"\
" \n"\
" if(repeat_type == %d){\n" /* repeat normal*/\
- " while(distance > _pt_distance) \n"\
- " distance = distance - (_pt_distance); \n"\
- " while(distance < 0.0) \n"\
- " distance = distance + (_pt_distance); \n"\
+ " distance = mod(distance, _pt_distance);\n"\
" }\n"\
" \n"\
" if(repeat_type == %d) {\n" /* repeat reflect*/\
- " while(distance > _pt_distance) {\n"\
- " distance = distance - (_pt_distance); \n"\
- " if(revserse == 0)\n"\
- " revserse = 1;\n"\
- " else\n"\
- " revserse = 0;\n"\
- " }\n"\
- " while(distance < 0.0) {\n"\
- " distance = distance + (_pt_distance); \n"\
- " if(revserse == 0)\n"\
- " revserse = 1;\n"\
- " else\n"\
- " revserse = 0;\n"\
- " }\n"\
- " if(revserse == 1) {\n"\
- " distance = (_pt_distance) - distance; \n"\
- " }\n"\
+ " distance = abs(mod(distance + _pt_distance, 2.0 * _pt_distance) - _pt_distance);\n"\
" }\n"\
" \n"\
" len_percentage = distance/(_pt_distance);\n"\
--
1.8.3.2
More information about the Glamor
mailing list