[Piglit] [PATCH 2/4] ATI_fs: add render tests

Miklós Máté mtmkls at gmail.com
Tue Nov 21 00:04:22 UTC 2017


These mainly check the state machine. Compiler checks will come later.

Signed-off-by: Miklós Máté <mtmkls at gmail.com>
---
 tests/spec/ati_fragment_shader/render-constants.c  |  98 +++++++++++++++
 tests/spec/ati_fragment_shader/render-default.c    |  81 +++++++++++++
 tests/spec/ati_fragment_shader/render-fog.c        |  95 +++++++++++++++
 tests/spec/ati_fragment_shader/render-notexture.c  |  71 +++++++++++
 tests/spec/ati_fragment_shader/render-precedence.c | 118 ++++++++++++++++++
 tests/spec/ati_fragment_shader/render-sources.c    | 132 +++++++++++++++++++++
 tests/spec/ati_fragment_shader/render-textargets.c |  89 ++++++++++++++
 7 files changed, 684 insertions(+)
 create mode 100644 tests/spec/ati_fragment_shader/render-constants.c
 create mode 100644 tests/spec/ati_fragment_shader/render-default.c
 create mode 100644 tests/spec/ati_fragment_shader/render-fog.c
 create mode 100644 tests/spec/ati_fragment_shader/render-notexture.c
 create mode 100644 tests/spec/ati_fragment_shader/render-precedence.c
 create mode 100644 tests/spec/ati_fragment_shader/render-sources.c
 create mode 100644 tests/spec/ati_fragment_shader/render-textargets.c

diff --git a/tests/spec/ati_fragment_shader/render-constants.c b/tests/spec/ati_fragment_shader/render-constants.c
new file mode 100644
index 000000000..6e1e4fd8c
--- /dev/null
+++ b/tests/spec/ati_fragment_shader/render-constants.c
@@ -0,0 +1,98 @@
+/* TODO license header */
+
+/**
+ * Tests rendering with GL_ATI_fragment_shader:
+ * - using local and global constants
+ * - updating global constants
+ */
+
+#include "piglit-util-gl.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+	config.supports_gl_compat_version = 10;
+	config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+static const float color1[] = {0.4, 0.2, 0.6};
+static const float color2[] = {0.7, 0.2, 0.3};
+static const float color3[] = {0.1, 0.7, 0.2};
+static const float color4[] = {0.8, 0.1, 0.7};
+
+static float result1p3[] = {0.0, 0.0, 0.0};
+static float result2p3[] = {0.0, 0.0, 0.0};
+static float result4p3[] = {0.0, 0.0, 0.0};
+
+#define check_gl_error(err) if (!piglit_check_gl_error(err)) piglit_report_result(PIGLIT_FAIL)
+
+enum piglit_result
+piglit_display(void)
+{
+	bool pass = true;
+
+	piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
+
+	glClearColor(1.0, 0.0, 0.0, 1.0);
+	glClear(GL_COLOR_BUFFER_BIT);
+
+	glEnable(GL_FRAGMENT_SHADER_ATI);
+	glSetFragmentShaderConstantATI(GL_CON_7_ATI, color2);
+	glSetFragmentShaderConstantATI(GL_CON_4_ATI, color3);
+	glBindFragmentShaderATI(13);
+	piglit_draw_rect(0, 0, piglit_width/4, piglit_height); /* 2+3 */
+	glBindFragmentShaderATI(42);
+	piglit_draw_rect(piglit_width/4, 0, piglit_width/4, piglit_height); /* 1+3 */
+	glBindFragmentShaderATI(13);
+	glSetFragmentShaderConstantATI(GL_CON_7_ATI, color4);
+	piglit_draw_rect(2*piglit_width/4, 0, piglit_width/4, piglit_height); /* 4+3 */
+	glBindFragmentShaderATI(42);
+	piglit_draw_rect(3*piglit_width/4, 0, piglit_width/4, piglit_height); /*1+3 */
+	glDisable(GL_FRAGMENT_SHADER_ATI);
+
+	pass = pass && piglit_probe_rect_rgb(0, 0, piglit_width/4, piglit_height, result2p3);
+	pass = pass && piglit_probe_rect_rgb(piglit_width/4, 0, piglit_width/4, piglit_height, result1p3);
+	pass = pass && piglit_probe_rect_rgb(2*piglit_width/4, 0, piglit_width/4, piglit_height, result4p3);
+	pass = pass && piglit_probe_rect_rgb(3*piglit_width/4, 0, piglit_width/4, piglit_height, result1p3);
+
+	piglit_present_results();
+
+	check_gl_error(GL_NO_ERROR);
+
+	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+	unsigned u;
+
+	piglit_require_extension("GL_ATI_fragment_shader");
+
+	/* create identical shaders, but one of them has a local constant */
+
+	glBindFragmentShaderATI(13);
+	glBeginFragmentShaderATI();
+	glColorFragmentOp2ATI(GL_ADD_ATI, GL_REG_0_ATI, GL_NONE, GL_NONE,
+			GL_CON_7_ATI, GL_NONE, GL_NONE,
+			GL_CON_4_ATI, GL_NONE, GL_NONE);
+	glEndFragmentShaderATI();
+
+	glBindFragmentShaderATI(42);
+	glBeginFragmentShaderATI();
+	glColorFragmentOp2ATI(GL_ADD_ATI, GL_REG_0_ATI, GL_NONE, GL_NONE,
+			GL_CON_7_ATI, GL_NONE, GL_NONE,
+			GL_CON_4_ATI, GL_NONE, GL_NONE);
+	glSetFragmentShaderConstantATI(GL_CON_7_ATI, color1);
+	glEndFragmentShaderATI();
+
+	/* compute the expected results */
+
+	for (u=0; u<3; u++) {
+		result1p3[u] = color1[u]+color3[u];
+		result2p3[u] = color2[u]+color3[u];
+		result4p3[u] = color4[u]+color3[u];
+	}
+
+	check_gl_error(GL_NO_ERROR);
+}
diff --git a/tests/spec/ati_fragment_shader/render-default.c b/tests/spec/ati_fragment_shader/render-default.c
new file mode 100644
index 000000000..314a21810
--- /dev/null
+++ b/tests/spec/ati_fragment_shader/render-default.c
@@ -0,0 +1,81 @@
+/* TODO license header */
+
+/**
+ * Tests rendering with GL_ATI_fragment_shader: enable, disable, default fragment shader.
+ */
+
+#include "piglit-util-gl.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+	config.supports_gl_compat_version = 10;
+	config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+static const float color[] = {0.2, 0.3, 0.8};
+static const float texcoord[] = {0.2, 0.7, 0.4};
+
+#define check_gl_error(err) if (!piglit_check_gl_error(err)) piglit_report_result(PIGLIT_FAIL)
+
+enum piglit_result
+piglit_display(void)
+{
+	bool pass = true;
+	GLuint tex;
+
+	piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
+
+	glClearColor(1.0, 0.0, 0.0, 1.0);
+	glClear(GL_COLOR_BUFFER_BIT);
+
+	glColor3fv(color);
+	glTexCoord3fv(texcoord);
+
+	//TODO swrast: passtexcoord only works when there is a bound texture AND texturing is enabled
+	/*glEnable(GL_TEXTURE_2D);
+	glGenTextures(1, &tex);
+	glBindTexture(GL_TEXTURE_2D, tex);
+	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1, 1, 0, GL_RGB, GL_FLOAT, (void*)color);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+	check_gl_error(GL_NO_ERROR);*/
+
+
+	glDisable(GL_FRAGMENT_SHADER_ATI);
+	piglit_draw_rect(0, 0, piglit_width/4, piglit_height);
+	glEnable(GL_FRAGMENT_SHADER_ATI);
+	piglit_draw_rect(piglit_width/4, 0, piglit_width/4, piglit_height);
+	glDisable(GL_FRAGMENT_SHADER_ATI);
+	piglit_draw_rect(2*piglit_width/4, 0, piglit_width/4, piglit_height);
+	glEnable(GL_FRAGMENT_SHADER_ATI);
+	piglit_draw_rect(3*piglit_width/4, 0, piglit_width/4, piglit_height);
+
+	pass = pass && piglit_probe_rect_rgb(0, 0, piglit_width/4, piglit_height, color);
+	pass = pass && piglit_probe_rect_rgb(piglit_width/4, 0, piglit_width/4, piglit_height, texcoord);
+	pass = pass && piglit_probe_rect_rgb(2*piglit_width/4, 0, piglit_width/4, piglit_height, color);
+	pass = pass && piglit_probe_rect_rgb(3*piglit_width/4, 0, piglit_width/4, piglit_height, texcoord);
+
+	piglit_present_results();
+
+	check_gl_error(GL_NO_ERROR);
+
+	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+	piglit_require_extension("GL_ATI_fragment_shader");
+
+	/* create a default shader that does something different than fixed-function */
+	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();
+
+	check_gl_error(GL_NO_ERROR);
+}
diff --git a/tests/spec/ati_fragment_shader/render-fog.c b/tests/spec/ati_fragment_shader/render-fog.c
new file mode 100644
index 000000000..a7b72c502
--- /dev/null
+++ b/tests/spec/ati_fragment_shader/render-fog.c
@@ -0,0 +1,95 @@
+/* TODO license header */
+
+/**
+ * Tests rendering with GL_ATI_fragment_shader: using fog.
+ */
+
+#include "piglit-util-gl.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+	config.supports_gl_compat_version = 10;
+	config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+static const float color1[] = {0.2, 0.3, 0.8};
+static const float color2[] = {0.9, 0.8, 0.3};
+
+static float resultLin[] = {0.0, 0.0, 0.0};
+static float resultExp[] = {0.0, 0.0, 0.0};
+static float resultEx2[] = {0.0, 0.0, 0.0};
+
+static const float z = 0.8;
+static const float dens = 0.4;
+
+#define check_gl_error(err) if (!piglit_check_gl_error(err)) piglit_report_result(PIGLIT_FAIL)
+
+enum piglit_result
+piglit_display(void)
+{
+	bool pass = true;
+
+	piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
+
+	glClearColor(1.0, 0.0, 0.0, 1.0);
+	glClear(GL_COLOR_BUFFER_BIT);
+
+	glColor3fv(color2);
+
+	glFogfv(GL_FOG_COLOR, color1);
+	glFogf(GL_FOG_DENSITY, dens);
+	glFogf(GL_FOG_START, 0.0);
+	glFogf(GL_FOG_END, 1.0);
+	glHint(GL_FOG_HINT, GL_NICEST);
+
+	glEnable(GL_FRAGMENT_SHADER_ATI);
+	glEnable(GL_FOG);
+	glFogi(GL_FOG_MODE, GL_LINEAR);
+	piglit_draw_rect_z(z, 0, 0, piglit_width/4, piglit_height);
+	glFogi(GL_FOG_MODE, GL_EXP);
+	piglit_draw_rect_z(z, piglit_width/4, 0, piglit_width/4, piglit_height);
+	glFogi(GL_FOG_MODE, GL_EXP2);
+	piglit_draw_rect_z(z, 2*piglit_width/4, 0, piglit_width/4, piglit_height);
+	glDisable(GL_FOG);
+	piglit_draw_rect_z(z, 3*piglit_width/4, 0, piglit_width/4, piglit_height);
+	glDisable(GL_FRAGMENT_SHADER_ATI);
+
+	pass = pass && piglit_probe_rect_rgb(0, 0, piglit_width/4, piglit_height, resultLin);
+	pass = pass && piglit_probe_rect_rgb(piglit_width/4, 0, piglit_width/4, piglit_height, resultExp);
+	pass = pass && piglit_probe_rect_rgb(2*piglit_width/4, 0, piglit_width/4, piglit_height, resultEx2);
+	pass = pass && piglit_probe_rect_rgb(3*piglit_width/4, 0, piglit_width/4, piglit_height, color2);
+
+	piglit_present_results();
+
+	check_gl_error(GL_NO_ERROR);
+
+	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+	unsigned u;
+	float f;
+
+	piglit_require_extension("GL_ATI_fragment_shader");
+
+	glBeginFragmentShaderATI();
+	glColorFragmentOp1ATI(GL_MOV_ATI, GL_REG_0_ATI, GL_NONE, GL_NONE,
+			GL_PRIMARY_COLOR_ARB, GL_NONE, GL_NONE);
+	glEndFragmentShaderATI();
+
+	/* compute the expected results */
+
+	for (u=0; u<3; u++) {
+		f = (1.0-z)/(1.0-0.0);
+		resultLin[u] = f*color2[u] + (1.0-f)*color1[u];
+		f = exp(-dens*z);
+		resultExp[u] = f*color2[u] + (1.0-f)*color1[u];
+		f = exp(-pow(dens*z,2.0));
+		resultEx2[u] = f*color2[u] + (1.0-f)*color1[u];
+	}
+
+	check_gl_error(GL_NO_ERROR);
+}
diff --git a/tests/spec/ati_fragment_shader/render-notexture.c b/tests/spec/ati_fragment_shader/render-notexture.c
new file mode 100644
index 000000000..2d9aefe09
--- /dev/null
+++ b/tests/spec/ati_fragment_shader/render-notexture.c
@@ -0,0 +1,71 @@
+/* TODO license header */
+
+/**
+ * Tests rendering with GL_ATI_fragment_shader: when no texture is bound
+ * - glPassTexCoordATI() should work as normal
+ * - glSampleMapATI() should return all zeros (technically this is undefined)
+ */
+
+#include "piglit-util-gl.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+	config.supports_gl_compat_version = 10;
+	config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+static const float texcoord[] = {0.2, 0.7, 0.4};
+
+#define check_gl_error(err) if (!piglit_check_gl_error(err)) piglit_report_result(PIGLIT_FAIL)
+
+enum piglit_result
+piglit_display(void)
+{
+	bool pass = true;
+
+	piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
+
+	glClearColor(1.0, 0.0, 0.0, 1.0);
+	glClear(GL_COLOR_BUFFER_BIT);
+
+	glTexCoord3fv(texcoord);
+
+	glEnable(GL_FRAGMENT_SHADER_ATI);
+	glBindFragmentShaderATI(6);
+	piglit_draw_rect(0, 0, piglit_width/2, piglit_height);
+	glBindFragmentShaderATI(42);
+	piglit_draw_rect(piglit_width/2, 0, piglit_width/2, piglit_height);
+	glDisable(GL_FRAGMENT_SHADER_ATI);
+
+	pass = pass && piglit_probe_rect_rgb(0, 0, piglit_width/2, piglit_height, texcoord);
+	/* the right hand side is undefined */
+
+	piglit_present_results();
+
+	check_gl_error(GL_NO_ERROR);
+
+	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+	piglit_require_extension("GL_ATI_fragment_shader");
+
+	glBindFragmentShaderATI(6);
+	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);
+	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,
+			GL_REG_0_ATI, GL_NONE, GL_NONE);
+	glEndFragmentShaderATI();
+
+	check_gl_error(GL_NO_ERROR);
+}
diff --git a/tests/spec/ati_fragment_shader/render-precedence.c b/tests/spec/ati_fragment_shader/render-precedence.c
new file mode 100644
index 000000000..9d1b9d0af
--- /dev/null
+++ b/tests/spec/ati_fragment_shader/render-precedence.c
@@ -0,0 +1,118 @@
+/* TODO license header */
+
+/**
+ * Tests rendering with GL_ATI_fragment_shader:
+ * - precedence between ATI_fragment_shader, ARB_fragment_program, GLSL
+ *   - ARB_fragment_program overrides ATI_fragment_shader
+ *   - GLSL overrides both
+ */
+
+#include "piglit-util-gl.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+	config.supports_gl_compat_version = 10;
+	config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+static const float color1[] = {0.2, 0.3, 0.8};
+static const float color2[] = {0.9, 0.8, 0.3};
+static const float texcoord[] = {0.2, 0.7, 0.4};
+
+static bool have_fp = false;
+static bool have_fs = false;
+
+static GLuint glslprog;
+
+#define check_gl_error(err) if (!piglit_check_gl_error(err)) piglit_report_result(PIGLIT_FAIL)
+
+enum piglit_result
+piglit_display(void)
+{
+	bool pass = true;
+
+	piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
+
+	glClearColor(1.0, 0.0, 0.0, 1.0);
+	glClear(GL_COLOR_BUFFER_BIT);
+
+	glColor3fv(color1);
+	glSecondaryColor3fvEXT(color2);
+	glTexCoord3fv(texcoord);
+	//glEnable(GL_COLOR_SUM);
+
+	glEnable(GL_FRAGMENT_SHADER_ATI);
+	piglit_draw_rect(0, 0, piglit_width/4, piglit_height);
+	if (have_fp) {
+		glEnable(GL_FRAGMENT_PROGRAM_ARB);
+		piglit_draw_rect(piglit_width/4, 0, piglit_width/4, piglit_height);
+		glDisable(GL_FRAGMENT_PROGRAM_ARB);
+	}
+	if (have_fs) {
+		glUseProgram(glslprog);
+		piglit_draw_rect(2*piglit_width/4, 0, piglit_width/4, piglit_height);
+		glUseProgram(0);
+	}
+	if (have_fp && have_fs) {
+		glUseProgram(glslprog);
+		glEnable(GL_FRAGMENT_PROGRAM_ARB);
+		piglit_draw_rect(3*piglit_width/4, 0, piglit_width/4, piglit_height);
+		glUseProgram(0);
+		glDisable(GL_FRAGMENT_PROGRAM_ARB);
+	}
+	glDisable(GL_FRAGMENT_SHADER_ATI);
+
+	pass = pass && piglit_probe_rect_rgb(0, 0, piglit_width/4, piglit_height, color2);
+	if (have_fp)
+		pass = pass && piglit_probe_rect_rgb(piglit_width/4, 0, piglit_width/4, piglit_height, texcoord);
+	if (have_fs)
+		pass = pass && piglit_probe_rect_rgb(2*piglit_width/4, 0, piglit_width/4, piglit_height, color1);
+	if (have_fp && have_fs)
+		pass = pass && piglit_probe_rect_rgb(3*piglit_width/4, 0, piglit_width/4, piglit_height, color1);
+
+	piglit_present_results();
+
+	check_gl_error(GL_NO_ERROR);
+
+	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
+
+const char *arbfp_str =
+"!!ARBfp1.0\n"
+"MOV result.color, fragment.texcoord[0];\n"
+//"MOV result.color, fragment.color.secondary;\n"
+"END";
+
+const char *glslfs_str =
+"void main() { gl_FragColor = gl_Color; }";
+//"void main() { gl_FragColor = gl_SecondaryColor; }";
+
+void
+piglit_init(int argc, char **argv)
+{
+	piglit_require_extension("GL_ATI_fragment_shader");
+
+	/* create shaders */
+
+	//TODO swrast only has secondary color in ATI_fs if at least one of these is true:
+	//	GL_COLOR_SUM is enabled
+	//	an ARB_fp was compiled that uses secondary color
+	//	a GLSL fragment shader was compiled that uses secondary color
+	glBeginFragmentShaderATI();
+	glColorFragmentOp1ATI(GL_MOV_ATI, GL_REG_0_ATI, GL_NONE, GL_NONE,
+			GL_SECONDARY_INTERPOLATOR_ATI, GL_NONE, GL_NONE);
+	glEndFragmentShaderATI();
+
+	if (piglit_is_extension_supported("GL_ARB_fragment_program")) {
+		have_fp = true;
+		piglit_compile_program(GL_FRAGMENT_PROGRAM_ARB, arbfp_str);
+	}
+
+	if (piglit_is_extension_supported("GL_ARB_fragment_shader")) {
+		have_fs = true;
+		glslprog = piglit_build_simple_program(NULL, glslfs_str);
+	}
+
+	check_gl_error(GL_NO_ERROR);
+}
diff --git a/tests/spec/ati_fragment_shader/render-sources.c b/tests/spec/ati_fragment_shader/render-sources.c
new file mode 100644
index 000000000..d9e80eef9
--- /dev/null
+++ b/tests/spec/ati_fragment_shader/render-sources.c
@@ -0,0 +1,132 @@
+/* TODO license header */
+
+/**
+ * Tests rendering with GL_ATI_fragment_shader:
+ * - various data sources for calculations in fragment shader
+ *   - texture coordinates
+ *   - texture sample
+ *   - constant
+ *   - primary color
+ *   - secondary interpolator
+ *   - one, zero
+ * - switch between named fragment shaders
+ * - use undefined default shader (rendering is undefined but shouldn't crash)
+ */
+
+#include "piglit-util-gl.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+	config.supports_gl_compat_version = 10;
+	config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+static const float color1[] = {0.2, 0.3, 0.8};
+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 GLuint tex;
+
+#define check_gl_error(err) if (!piglit_check_gl_error(err)) piglit_report_result(PIGLIT_FAIL)
+
+enum piglit_result
+piglit_display(void)
+{
+	bool pass = true;
+
+	piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
+
+	glClearColor(1.0, 0.0, 0.0, 1.0);
+	glClear(GL_COLOR_BUFFER_BIT);
+
+	glColor3fv(color1);
+	glSecondaryColor3fvEXT(color2);
+	glTexCoord3fv(texcoord);
+
+	glEnable(GL_TEXTURE_2D);
+	//glEnable(GL_COLOR_SUM); //TODO swrast only has secondary color if this is enabled
+
+	glEnable(GL_FRAGMENT_SHADER_ATI);
+	glBindFragmentShaderATI(0);
+	piglit_draw_rect(0, 0, piglit_width/4, piglit_height);
+	glBindFragmentShaderATI(6);
+	piglit_draw_rect(piglit_width/4, 0, piglit_width/4, piglit_height);
+	glBindFragmentShaderATI(42);
+	piglit_draw_rect(2*piglit_width/4, 0, piglit_width/4, piglit_height);
+	glBindFragmentShaderATI(13);
+	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);
+
+	piglit_present_results();
+
+	check_gl_error(GL_NO_ERROR);
+
+	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+	unsigned u;
+
+	piglit_require_extension("GL_ATI_fragment_shader");
+
+	/* create shaders that use all possible input sources: texcoord, sample, const, zero, one, pri&sec color */
+
+	glBindFragmentShaderATI(13);
+	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);
+	glColorFragmentOp2ATI(GL_MUL_ATI, GL_REG_0_ATI, GL_NONE, GL_NONE,
+			GL_REG_0_ATI, GL_NONE, GL_NONE,
+			GL_REG_1_ATI, GL_NONE, GL_NONE);
+	glEndFragmentShaderATI();
+
+	glBindFragmentShaderATI(6);
+	glBeginFragmentShaderATI();
+	glColorFragmentOp3ATI(GL_LERP_ATI, GL_REG_0_ATI, GL_NONE, GL_NONE,
+			GL_CON_1_ATI, GL_NONE, GL_NONE,
+			GL_ONE, GL_NONE, GL_NONE,
+			GL_ZERO, GL_NONE, GL_NONE);
+	glSetFragmentShaderConstantATI(GL_CON_1_ATI, color2);
+	glEndFragmentShaderATI();
+
+	glBindFragmentShaderATI(42);
+	glBeginFragmentShaderATI();
+	glColorFragmentOp2ATI(GL_MUL_ATI, GL_REG_0_ATI, GL_NONE, GL_NONE,
+			GL_SECONDARY_INTERPOLATOR_ATI, GL_NONE, GL_NONE,
+			GL_PRIMARY_COLOR_ARB, GL_NONE, GL_NONE);
+	glEndFragmentShaderATI();
+
+	/* create a texture */
+
+	glGenTextures(1, &tex);
+	glBindTexture(GL_TEXTURE_2D, tex);
+	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1, 1, 0, GL_RGB, GL_FLOAT, (void*)texcolor);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+
+	/* 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];
+	}
+
+	check_gl_error(GL_NO_ERROR);
+}
diff --git a/tests/spec/ati_fragment_shader/render-textargets.c b/tests/spec/ati_fragment_shader/render-textargets.c
new file mode 100644
index 000000000..b45b2e422
--- /dev/null
+++ b/tests/spec/ati_fragment_shader/render-textargets.c
@@ -0,0 +1,89 @@
+/* TODO license header */
+
+/**
+ * Tests rendering with GL_ATI_fragment_shader: using different texture targets with the same shader.
+ */
+
+#include "piglit-util-gl.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+	config.supports_gl_compat_version = 10;
+	config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+static const float color1[] = {0.2, 0.3, 0.8};
+static const float color2[] = {0.9, 0.8, 0.3};
+static const float texcoord[] = {0.2, 0.7, 0.4};
+
+static GLuint tex2D;
+static GLuint texCUBE;
+
+#define check_gl_error(err) if (!piglit_check_gl_error(err)) piglit_report_result(PIGLIT_FAIL)
+
+enum piglit_result
+piglit_display(void)
+{
+	bool pass = true;
+
+	piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
+
+	glClearColor(1.0, 0.0, 0.0, 1.0);
+	glClear(GL_COLOR_BUFFER_BIT);
+
+	glTexCoord3fv(texcoord);
+
+	glEnable(GL_FRAGMENT_SHADER_ATI);
+	glEnable(GL_TEXTURE_2D);
+	glBindTexture(GL_TEXTURE_2D, tex2D);
+	piglit_draw_rect(0, 0, piglit_width/2, piglit_height);
+	glDisable(GL_TEXTURE_2D);
+	glEnable(GL_TEXTURE_CUBE_MAP);
+	glBindTexture(GL_TEXTURE_CUBE_MAP, texCUBE);
+	piglit_draw_rect(piglit_width/2, 0, piglit_width/2, piglit_height);
+	glDisable(GL_TEXTURE_CUBE_MAP);
+	glDisable(GL_FRAGMENT_SHADER_ATI);
+
+	pass = pass && piglit_probe_rect_rgb(0, 0, piglit_width/2, piglit_height, color1);
+	pass = pass && piglit_probe_rect_rgb(piglit_width/2, 0, piglit_width/2, piglit_height, color2);
+
+	piglit_present_results();
+
+	check_gl_error(GL_NO_ERROR);
+
+	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+	piglit_require_extension("GL_ATI_fragment_shader");
+
+	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,
+			GL_REG_0_ATI, GL_NONE, GL_NONE);
+	glEndFragmentShaderATI();
+
+	glGenTextures(1, &tex2D);
+	glBindTexture(GL_TEXTURE_2D, tex2D);
+	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1, 1, 0, GL_RGB, GL_FLOAT, (void*)color1);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+
+	glGenTextures(1, &texCUBE);
+	glBindTexture(GL_TEXTURE_CUBE_MAP, texCUBE);
+	glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGB, 1, 1, 0, GL_RGB, GL_FLOAT, (void*)color2);
+	glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGB, 1, 1, 0, GL_RGB, GL_FLOAT, (void*)color2);
+	glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGB, 1, 1, 0, GL_RGB, GL_FLOAT, (void*)color2);
+	glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGB, 1, 1, 0, GL_RGB, GL_FLOAT, (void*)color2);
+	glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGB, 1, 1, 0, GL_RGB, GL_FLOAT, (void*)color2);
+	glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGB, 1, 1, 0, GL_RGB, GL_FLOAT, (void*)color2);
+	glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+	glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+
+	check_gl_error(GL_NO_ERROR);
+}
-- 
2.15.0.rc0



More information about the Piglit mailing list