framework/replay: disable AA accounting when comparing with no tolerance
[piglit.git] / tests / shaders / vp-address-01.c
blobbe7c1d14e2a1d9abdb5bb646150c4f1c42f3fa20
1 /*
2 * Copyright © 2009 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
24 /**
25 * \file vp-address-01.c
26 * Validate address registers with various constant offsets.
28 * \author Ian Romanick <ian.d.romanick@intel.com>
31 #include "piglit-util-gl.h"
33 static const GLfloat attrib[] = {
34 1.0,
35 2.0,
36 0.0,
37 -1.0,
38 -2.0
41 #define TEST_ROWS 1
42 #define TEST_COLS ARRAY_SIZE(attrib)
43 #define BOX_SIZE 32
45 PIGLIT_GL_TEST_CONFIG_BEGIN
47 config.supports_gl_compat_version = 10;
49 config.window_width = (((BOX_SIZE+1)*TEST_COLS)+1);
50 config.window_height = (((BOX_SIZE+1)*TEST_ROWS)+1);
51 config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
53 PIGLIT_GL_TEST_CONFIG_END
55 static const char vertex_source_template[] =
56 "!!ARBvp1.0\n"
57 "PARAM colors[] = { program.env[0..3] };\n"
58 "ADDRESS A0;\n"
59 "\n"
60 "ARL A0.x, vertex.attrib[1].x;\n"
61 "MOV result.color, colors[A0.x %c %u];\n"
62 PIGLIT_VERTEX_PROGRAM_MVP_TRANSFORM
63 "END\n"
67 /**
68 * \name Handles to programs.
70 /*@{*/
71 static GLint progs[TEST_COLS];
72 /*@}*/
75 enum piglit_result
76 piglit_display(void)
78 static const GLfloat color[4] = { 0.0, 1.0, 0.0, 1.0 };
79 static const GLfloat good_color[4] = { 0.0, 1.0, 0.0, 1.0 };
80 static const GLfloat bad_color[4] = { 1.0, 0.0, 0.0, 1.0 };
81 enum piglit_result result = PIGLIT_PASS;
82 unsigned i;
84 glClear(GL_COLOR_BUFFER_BIT);
86 glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, 0, bad_color);
87 glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, 1, color);
88 glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, 2, bad_color);
89 glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, 3, bad_color);
91 for (i = 0; i < ARRAY_SIZE(progs); i++) {
92 const int x = 1 + (i * (BOX_SIZE + 1));
94 glBindProgramARB(GL_VERTEX_PROGRAM_ARB, progs[i]);
96 glVertexAttrib1fARB(1, attrib[i]);
98 piglit_draw_rect(x, 1, BOX_SIZE, BOX_SIZE);
100 if (!piglit_probe_pixel_rgb(x + (BOX_SIZE / 2),
101 1 + (BOX_SIZE / 2),
102 good_color)) {
103 if (! piglit_automatic)
104 printf("shader %u failed with attribute "
105 "%.1f\n", i, attrib[i]);
107 result = PIGLIT_FAIL;
111 piglit_present_results();
112 return result;
116 void
117 piglit_init(int argc, char **argv)
119 GLint max_address_registers;
120 unsigned i;
122 (void) argc;
123 (void) argv;
125 piglit_require_vertex_program();
126 piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
128 glGetProgramivARB(GL_VERTEX_PROGRAM_ARB,
129 GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB,
130 & max_address_registers);
131 if (max_address_registers == 0) {
132 /* we have to have at least one address register */
133 if (! piglit_automatic)
134 printf("GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB == 0\n");
135 piglit_report_result(PIGLIT_FAIL);
138 for (i = 0; i < ARRAY_SIZE(progs); i++) {
139 char shader_source[1024];
140 int offset[2];
141 char direction[2];
143 /* We want the constant offset in the instruction plus the
144 * value read from the attribute to be 1.
146 offset[0] = 1 - (int) attrib[i];
148 if (offset[0] < 0) {
149 direction[0] = '-';
150 offset[0] = -offset[0];
151 } else {
152 direction[0] = '+';
155 snprintf(shader_source, sizeof(shader_source),
156 vertex_source_template,
157 direction[0], offset[0]);
159 progs[i] = piglit_compile_program(GL_VERTEX_PROGRAM_ARB,
160 shader_source);
163 glEnable(GL_VERTEX_PROGRAM_ARB);
165 glClearColor(0.5, 0.5, 0.5, 1.0);