[Piglit] [PATCH 2/3] ati_fs: Use enums instead of magic numbers in the render tests.

Eric Anholt eric at anholt.net
Thu Dec 7 20:08:10 UTC 2017


Signed-off-by: Eric Anholt <eric at anholt.net>
---
 tests/spec/ati_fragment_shader/render-notexture.c | 13 +++++---
 tests/spec/ati_fragment_shader/render-sources.c   | 36 +++++++++++++----------
 2 files changed, 30 insertions(+), 19 deletions(-)

diff --git a/tests/spec/ati_fragment_shader/render-notexture.c b/tests/spec/ati_fragment_shader/render-notexture.c
index 12dfe6de6afe..d85d030dee81 100644
--- a/tests/spec/ati_fragment_shader/render-notexture.c
+++ b/tests/spec/ati_fragment_shader/render-notexture.c
@@ -40,6 +40,11 @@ static const float color1[] = {0.2, 0.3, 0.8};
 static const float texcoord[] = {0.2, 0.7, 0.4};
 static const float black[] = {0.0, 0.0, 0.0};
 
+enum {
+	SHADER_TEXCOORD = 1,
+	SHADER_TEX,
+};
+
 enum piglit_result
 piglit_display(void)
 {
@@ -54,9 +59,9 @@ piglit_display(void)
 	glTexCoord3fv(texcoord);
 
 	glEnable(GL_FRAGMENT_SHADER_ATI);
-	glBindFragmentShaderATI(6);
+	glBindFragmentShaderATI(SHADER_TEXCOORD);
 	piglit_draw_rect(0, 0, piglit_width / 4, piglit_height);
-	glBindFragmentShaderATI(42);
+	glBindFragmentShaderATI(SHADER_TEX);
 	piglit_draw_rect(piglit_width / 4, 0, piglit_width / 4, piglit_height);
 	glGenTextures(1, &tex);
 	glBindTexture(GL_TEXTURE_2D, tex);
@@ -89,14 +94,14 @@ piglit_init(int argc, char **argv)
 {
 	piglit_require_extension("GL_ATI_fragment_shader");
 
-	glBindFragmentShaderATI(6);
+	glBindFragmentShaderATI(SHADER_TEXCOORD);
 	glBeginFragmentShaderATI();
 	glPassTexCoordATI(GL_REG_1_ATI, GL_TEXTURE0_ARB, GL_SWIZZLE_STR_ATI);
 	glColorFragmentOp1ATI(GL_MOV_ATI, GL_REG_0_ATI, GL_NONE, GL_NONE,
 			GL_REG_1_ATI, GL_NONE, GL_NONE);
 	glEndFragmentShaderATI();
 
-	glBindFragmentShaderATI(42);
+	glBindFragmentShaderATI(SHADER_TEX);
 	glBeginFragmentShaderATI();
 	glSampleMapATI(GL_REG_0_ATI, GL_TEXTURE0_ARB, GL_SWIZZLE_STR_ATI);
 	glColorFragmentOp1ATI(GL_MOV_ATI, GL_REG_0_ATI, GL_NONE, GL_NONE,
diff --git a/tests/spec/ati_fragment_shader/render-sources.c b/tests/spec/ati_fragment_shader/render-sources.c
index da70b0cce14c..ccc4247c70c8 100644
--- a/tests/spec/ati_fragment_shader/render-sources.c
+++ b/tests/spec/ati_fragment_shader/render-sources.c
@@ -48,12 +48,18 @@ static const float color2[] = {0.9, 0.8, 0.3};
 static const float texcoord[] = {0.2, 0.7, 0.4};
 static const float texcolor[] = {0.8, 0.1, 0.7};
 
-static float result6[] = {0.0, 0.0, 0.0};
-static float result13[] = {0.0, 0.0, 0.0};
-static float result42[] = {0.0, 0.0, 0.0};
+static float result_const[] = {0.0, 0.0, 0.0};
+static float result_tex[] = {0.0, 0.0, 0.0};
+static float result_color[] = {0.0, 0.0, 0.0};
 
 static GLuint tex;
 
+enum {
+	SHADER_TEX = 1,
+	SHADER_CONST,
+	SHADER_COLOR,
+};
+
 enum piglit_result
 piglit_display(void)
 {
@@ -73,20 +79,20 @@ piglit_display(void)
 	glEnable(GL_FRAGMENT_SHADER_ATI);
 	glBindFragmentShaderATI(0);
 	piglit_draw_rect(0, 0, piglit_width / 4, piglit_height);
-	glBindFragmentShaderATI(6);
+	glBindFragmentShaderATI(SHADER_CONST);
 	piglit_draw_rect(piglit_width / 4, 0, piglit_width / 4, piglit_height);
-	glBindFragmentShaderATI(42);
+	glBindFragmentShaderATI(SHADER_COLOR);
 	piglit_draw_rect(2 * piglit_width / 4, 0, piglit_width / 4, piglit_height);
-	glBindFragmentShaderATI(13);
+	glBindFragmentShaderATI(SHADER_TEX);
 	piglit_draw_rect(3 * piglit_width / 4, 0, piglit_width / 4, piglit_height);
 	glDisable(GL_FRAGMENT_SHADER_ATI);
 
 	/* Mesa uses fixed-function when the shader is invalid, but
 	 * it's undefined */
 	/*pass = pass && piglit_probe_rect_rgb(0, 0, piglit_width / 4, piglit_height, color1*texcolor);*/
-	pass = pass && piglit_probe_rect_rgb(piglit_width / 4, 0, piglit_width / 4, piglit_height, result6);
-	pass = pass && piglit_probe_rect_rgb(2 * piglit_width / 4, 0, piglit_width / 4, piglit_height, result42);
-	pass = pass && piglit_probe_rect_rgb(3 * piglit_width / 4, 0, piglit_width / 4, piglit_height, result13);
+	pass = pass && piglit_probe_rect_rgb(piglit_width / 4, 0, piglit_width / 4, piglit_height, result_const);
+	pass = pass && piglit_probe_rect_rgb(2 * piglit_width / 4, 0, piglit_width / 4, piglit_height, result_color);
+	pass = pass && piglit_probe_rect_rgb(3 * piglit_width / 4, 0, piglit_width / 4, piglit_height, result_tex);
 
 	piglit_present_results();
 
@@ -106,7 +112,7 @@ piglit_init(int argc, char **argv)
 	 * texcoord, sample, const, zero, one, pri&sec color
 	 */
 
-	glBindFragmentShaderATI(13);
+	glBindFragmentShaderATI(SHADER_TEX);
 	glBeginFragmentShaderATI();
 	glPassTexCoordATI(GL_REG_1_ATI, GL_TEXTURE0_ARB, GL_SWIZZLE_STR_ATI);
 	glSampleMapATI(GL_REG_0_ATI, GL_TEXTURE0_ARB, GL_SWIZZLE_STR_ATI);
@@ -115,7 +121,7 @@ piglit_init(int argc, char **argv)
 			GL_REG_1_ATI, GL_NONE, GL_NONE);
 	glEndFragmentShaderATI();
 
-	glBindFragmentShaderATI(6);
+	glBindFragmentShaderATI(SHADER_CONST);
 	glBeginFragmentShaderATI();
 	glColorFragmentOp3ATI(GL_LERP_ATI, GL_REG_0_ATI, GL_NONE, GL_NONE,
 			GL_CON_1_ATI, GL_NONE, GL_NONE,
@@ -124,7 +130,7 @@ piglit_init(int argc, char **argv)
 	glSetFragmentShaderConstantATI(GL_CON_1_ATI, color2);
 	glEndFragmentShaderATI();
 
-	glBindFragmentShaderATI(42);
+	glBindFragmentShaderATI(SHADER_COLOR);
 	glBeginFragmentShaderATI();
 	glColorFragmentOp2ATI(GL_MUL_ATI, GL_REG_0_ATI, GL_NONE, GL_NONE,
 			GL_SECONDARY_INTERPOLATOR_ATI, GL_NONE, GL_NONE,
@@ -144,9 +150,9 @@ piglit_init(int argc, char **argv)
 	/* compute the expected results */
 
 	for (u=0; u<3; u++) {
-		result6[u] = color2[u];
-		result13[u] = texcoord[u]*texcolor[u];
-		result42[u] = color1[u]*color2[u];
+		result_const[u] = color2[u];
+		result_tex[u] = texcoord[u] * texcolor[u];
+		result_color[u] = color1[u] * color2[u];
 	}
 
 	if (!piglit_check_gl_error(GL_NO_ERROR))
-- 
2.15.0



More information about the Piglit mailing list