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
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
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
[] = {
71 #define TEST_COLS (ARRAY_SIZE(attrib) / 2)
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
[] =
86 "OPTION NV_vertex_program2;\n"
87 "PARAM colors[] = { program.env[0..3] };\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
99 * \name Handles to programs.
102 static GLint progs
[TEST_COLS
* TEST_ROWS
];
106 static void generate_shader_source(char *source
, size_t source_len
,
107 unsigned component_mask
, const GLfloat
*attr
);
111 set_attribute(unsigned component
, GLuint index
, GLfloat value
)
115 /* Set all of the components to something invalid. Then set one
116 * component to the desried, valid value.
122 v
[component
] = value
;
124 glVertexAttrib4fvARB(index
, v
);
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
;
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),
162 if (! piglit_automatic
) {
164 generate_shader_source(src
,
169 printf("shader %u failed with "
170 "attributes %.1f, %.1f:\n%s\n",
177 result
= PIGLIT_FAIL
;
182 piglit_present_results();
188 generate_shader_source(char *source
, size_t source_len
, unsigned component_mask
,
191 static const char components
[] = "xyzw";
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];
207 offset
[0] = -offset
[0];
214 offset
[1] = -offset
[1];
219 snprintf(source
, source_len
, vertex_source_template
,
220 comp
[0], direction
[0], offset
[0],
221 comp
[1], direction
[1], offset
[1]);
226 piglit_init(int argc
, char **argv
)
228 GLint max_address_registers
;
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 "
254 piglit_report_result(PIGLIT_FAIL
);
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
),
271 piglit_compile_program(GL_VERTEX_PROGRAM_ARB
,
276 glEnable(GL_VERTEX_PROGRAM_ARB
);
278 glClearColor(0.5, 0.5, 0.5, 1.0);