From aa1e89cc9213dad28c0b576a03f782e5551c6180 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Kol=C3=A5s?= Date: Mon, 10 Mar 2008 23:07:22 +0000 Subject: [PATCH] * tests/test-shader.c: improved readability of fragment shader examples by factoring out common bits into FRAGMENT_SHADER_BEGIN and FRAGMENT_SHADER_END macros. --- ChangeLog | 6 ++ tests/test-shader.c | 190 ++++++++++++++++++++------------------------ 2 files changed, 91 insertions(+), 105 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9ff204cee..d8a3b295d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2008-03-10 Øyvind Kolås + + * tests/test-shader.c: improved readability of fragment shader + examples by factoring out common bits into FRAGMENT_SHADER_BEGIN and + FRAGMENT_SHADER_END macros. + 2008-03-09 Matthew Allum * clutter/clutter-id-pool.c: (clutter_id_pool_free): diff --git a/tests/test-shader.c b/tests/test-shader.c index 5f290ff10..67916120e 100644 --- a/tests/test-shader.c +++ b/tests/test-shader.c @@ -17,128 +17,108 @@ typedef struct gchar *source; } ShaderSource; +/* a couple of boilerplate defines that are common amongst all the + * sample shaders + */ + +/* FRAGMENT_SHADER_BEGIN: generate boilerplate with a local vec4 color already initialized, + * from a sampler2DRect in a variable tex. + */ +#define FRAGMENT_SHADER_BEGIN \ + "uniform sampler2DRect tex;" \ + "void main (){" \ + " vec4 color = texture2DRect (tex, vec2(gl_TexCoord[0].st));" + +/* FRAGMENT_SHADER_END: apply the changed color to the output buffer correctly blended + * with the gl specified color (makes the opacity of actors work correctly). + */ +#define FRAGMENT_SHADER_END \ + " gl_FragColor = color;" \ + " gl_FragColor = gl_FragColor * gl_Color;" \ + "}" + static ShaderSource shaders[]= { {"brightness-contrast", - - "uniform float brightness;" - "uniform float contrast;" - "uniform sampler2DRect pend_s3_tex;" - "" - "void main()" - "{" - " vec4 pend_s4_result;" - " pend_s4_result = texture2DRect(pend_s3_tex, gl_TexCoord[0].xy);" - " pend_s4_result.x = (pend_s4_result.x - 0.5)*contrast + brightness + 0.5;" - " pend_s4_result.y = (pend_s4_result.y - 0.5)*contrast + brightness + 0.5;" - " pend_s4_result.z = (pend_s4_result.z - 0.5)*contrast + brightness + 0.5;" - " gl_FragColor = pend_s4_result;" - " gl_FragColor = gl_FragColor * gl_Color;" - "}", + "uniform float brightness, contrast;" + FRAGMENT_SHADER_BEGIN + " color.rgb = (color.rgb - vec3(0.5, 0.5, 0.5)) * contrast + vec3 (brightness + 0.5, brightness + 0.5, brightness + 0.5);" + FRAGMENT_SHADER_END }, + {"box-blur", #if GPU_SUPPORTS_DYNAMIC_BRANCHING - "uniform float radius ;" - "uniform sampler2DRect rectTexture;" - "" - "void main()" - "{" - " vec4 color = texture2DRect(rectTexture, gl_TexCoord[0].st);" - " float u;" - " float v;" - " int count = 1;" - " for (u=-radius;u