glx-multithread-texture: Avoid front-buffer rendering.
[piglit.git] / tests / shaders / vp-address-04.c
blob44401dd3b022166db73a1f3803d8a1a67874bae8
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-04.c
26 * Validate vectored address registers with various constant offsets.
28 * This is something of a combination of vp-address-02 and vp-address-03.
29 * GL_NV_vertex_program2_option requires at least two address registers. Base
30 * GL_ARB_vertex_program implementations can also support more than one, but
31 * only one is required.
33 * \author Ian Romanick <ian.d.romanick@intel.com>
36 #include "piglit-util-gl.h"
38 static const GLfloat attrib[] = {
39 0.0, 0.0,
40 0.0, 1.0,
41 0.0, 2.0,
42 0.0, -1.0,
43 0.0, -2.0,
45 1.0, 0.0,
46 1.0, 1.0,
47 1.0, 2.0,
48 1.0, -1.0,
49 1.0, -2.0,
51 2.0, 0.0,
52 2.0, 1.0,
53 2.0, 2.0,
54 2.0, -1.0,
55 2.0, -2.0,
57 -1.0, 0.0,
58 -1.0, 1.0,
59 -1.0, 2.0,
60 -1.0, -1.0,
61 -1.0, -2.0,
63 -2.0, 0.0,
64 -2.0, 1.0,
65 -2.0, 2.0,
66 -2.0, -1.0,
67 -2.0, -2.0,
70 #define TEST_ROWS 16
71 #define TEST_COLS (ARRAY_SIZE(attrib) / 2)
72 #define BOX_SIZE 16
74 PIGLIT_GL_TEST_CONFIG_BEGIN
76 config.supports_gl_compat_version = 10;
78 config.window_width = (((BOX_SIZE+1)*TEST_COLS)+1);
79 config.window_height = (((BOX_SIZE+1)*TEST_ROWS)+1);
80 config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
82 PIGLIT_GL_TEST_CONFIG_END
84 static const char vertex_source_template[] =
85 "!!ARBvp1.0\n"
86 "OPTION NV_vertex_program2;\n"
87 "PARAM colors[] = { program.env[0..3] };\n"
88 "ADDRESS A0, A1;\n"
89 "\n"
90 "ARL A0, vertex.attrib[1];\n"
91 "ARL A1, vertex.attrib[2];\n"
92 "ADD result.color, colors[A0.%c %c %u], colors[A1.%c %c %u];\n"
93 PIGLIT_VERTEX_PROGRAM_MVP_TRANSFORM
94 "END\n"
98 /**
99 * \name Handles to programs.
101 /*@{*/
102 static GLint progs[TEST_COLS * TEST_ROWS];
103 /*@}*/
106 static void generate_shader_source(char *source, size_t source_len,
107 unsigned component_mask, const GLfloat *attr);
110 static void
111 set_attribute(unsigned component, GLuint index, GLfloat value)
113 GLfloat v[4];
115 /* Set all of the components to something invalid. Then set one
116 * component to the desried, valid value.
118 v[0] = -value;
119 v[1] = -value;
120 v[2] = -value;
121 v[3] = -value;
122 v[component] = value;
124 glVertexAttrib4fvARB(index, v);
128 enum piglit_result
129 piglit_display(void)
131 static const GLfloat color[4] = { 0.0, 0.5, 0.0, 0.5 };
132 static const GLfloat good_color[4] = { 0.0, 1.0, 0.0, 1.0 };
133 static const GLfloat bad_color[4] = { 1.0, 0.0, 0.0, 1.0 };
134 enum piglit_result result = PIGLIT_PASS;
135 unsigned i;
136 unsigned j;
138 glClear(GL_COLOR_BUFFER_BIT);
140 glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, 0, bad_color);
141 glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, 1, color);
142 glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, 2, bad_color);
143 glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, 3, bad_color);
145 for (i = 0; i < TEST_ROWS; i++) {
146 const int y = 1 + (i * (BOX_SIZE + 1));
148 for (j = 0; j < TEST_COLS; j++) {
149 const int x = 1 + (j * (BOX_SIZE + 1));
150 const unsigned idx = (i * TEST_COLS) + j;
152 glBindProgramARB(GL_VERTEX_PROGRAM_ARB, progs[idx]);
154 set_attribute( i & 0x03, 1, attrib[(j * 2) + 0]);
155 set_attribute((i >> 2) & 0x03, 2, attrib[(j * 2) + 1]);
157 piglit_draw_rect(x, y, BOX_SIZE, BOX_SIZE);
159 if (!piglit_probe_pixel_rgb(x + (BOX_SIZE / 2),
160 y + (BOX_SIZE / 2),
161 good_color)) {
162 if (! piglit_automatic) {
163 char src[1024];
164 generate_shader_source(src,
165 sizeof(src),
167 & attrib[j * 2]);
169 printf("shader %u failed with "
170 "attributes %.1f, %.1f:\n%s\n",
171 idx,
172 attrib[(j * 2) + 0],
173 attrib[(j * 2) + 1],
174 src);
177 result = PIGLIT_FAIL;
182 piglit_present_results();
183 return result;
187 void
188 generate_shader_source(char *source, size_t source_len, unsigned component_mask,
189 const GLfloat *attr)
191 static const char components[] = "xyzw";
192 char comp[2];
193 int offset[2];
194 char direction[2];
196 comp[0] = components[component_mask & 0x03];
197 comp[1] = components[(component_mask >> 2) & 0x03];
199 /* We want the constant offset in the instruction plus
200 * the value read from the attribute to be 1.
202 offset[0] = 1 - (int) attr[0];
203 offset[1] = 1 - (int) attr[1];
205 if (offset[0] < 0) {
206 direction[0] = '-';
207 offset[0] = -offset[0];
208 } else {
209 direction[0] = '+';
212 if (offset[1] < 0) {
213 direction[1] = '-';
214 offset[1] = -offset[1];
215 } else {
216 direction[1] = '+';
219 snprintf(source, source_len, vertex_source_template,
220 comp[0], direction[0], offset[0],
221 comp[1], direction[1], offset[1]);
225 void
226 piglit_init(int argc, char **argv)
228 GLint max_address_registers;
229 unsigned i;
230 unsigned j;
232 (void) argc;
233 (void) argv;
235 piglit_require_vertex_program();
236 piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
238 glGetProgramivARB(GL_VERTEX_PROGRAM_ARB,
239 GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB,
240 & max_address_registers);
241 if (max_address_registers == 0) {
242 /* we have to have at least one address register */
243 if (! piglit_automatic)
244 printf("GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB == 0\n");
246 piglit_report_result(PIGLIT_FAIL);
247 } else if (max_address_registers == 1) {
248 if (piglit_is_extension_supported("GL_NV_vertex_program2_option")) {
249 /* this extension requires two address regs */
250 if (! piglit_automatic)
251 printf("GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB "
252 "== 1\n");
254 piglit_report_result(PIGLIT_FAIL);
255 } else {
256 piglit_report_result(PIGLIT_SKIP);
260 for (i = 0; i < TEST_ROWS; i++) {
261 for (j = 0; j < TEST_COLS; j++) {
262 char shader_source[1024];
263 const unsigned idx = (i * TEST_COLS) + j;
266 generate_shader_source(shader_source,
267 sizeof(shader_source),
269 &attrib[2 * j]);
270 progs[idx] =
271 piglit_compile_program(GL_VERTEX_PROGRAM_ARB,
272 shader_source);
276 glEnable(GL_VERTEX_PROGRAM_ARB);
278 glClearColor(0.5, 0.5, 0.5, 1.0);