perf/pixel-rate: new pixel throughput microbenchmark
[piglit.git] / tests / shaders / vp-address-02.c
bloba04cac66c3e9d1d6ed07ec4c9f4631a7c165abca
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-02.c
26 * Validate address registers with various constant offsets.
28 * Much like vp-address-01, but this test utilizes multiple address registers.
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 1.0, 1.0,
40 2.0, 2.0,
41 0.0, 0.0,
42 1.0, 0.0,
43 -1.0, 0.0,
44 0.0, 1.0,
45 0.0, -1.0,
46 2.0, -1.0,
47 -2.0, -1.0,
48 2.0, -2.0,
51 #define TEST_ROWS 1
52 #define TEST_COLS (ARRAY_SIZE(attrib) / 2)
53 #define BOX_SIZE 32
55 PIGLIT_GL_TEST_CONFIG_BEGIN
57 config.supports_gl_compat_version = 10;
59 config.window_width = (((BOX_SIZE+1)*TEST_COLS)+1);
60 config.window_height = (((BOX_SIZE+1)*TEST_ROWS)+1);
61 config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
63 PIGLIT_GL_TEST_CONFIG_END
65 static const char vertex_source_template[] =
66 "!!ARBvp1.0\n"
67 "PARAM colors[] = { program.env[0..3] };\n"
68 "ADDRESS A0, A1;\n"
69 "\n"
70 "ARL A0.x, vertex.attrib[1].x;\n"
71 "ARL A1.x, vertex.attrib[1].y;\n"
72 "ADD result.color, colors[A0.x %c %u], colors[A1.x %c %u];\n"
73 PIGLIT_VERTEX_PROGRAM_MVP_TRANSFORM
74 "END\n"
78 /**
79 * \name Handles to programs.
81 /*@{*/
82 static GLint progs[TEST_COLS];
83 /*@}*/
86 enum piglit_result
87 piglit_display(void)
89 static const GLfloat color[4] = { 0.0, 0.5, 0.0, 0.5 };
90 static const GLfloat good_color[4] = { 0.0, 1.0, 0.0, 1.0 };
91 static const GLfloat bad_color[4] = { 1.0, 0.0, 0.0, 1.0 };
92 enum piglit_result result = PIGLIT_PASS;
93 unsigned i;
95 glClear(GL_COLOR_BUFFER_BIT);
97 glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, 0, bad_color);
98 glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, 1, color);
99 glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, 2, bad_color);
100 glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, 3, bad_color);
102 for (i = 0; i < ARRAY_SIZE(progs); i++) {
103 const int x = 1 + (i * (BOX_SIZE + 1));
105 glBindProgramARB(GL_VERTEX_PROGRAM_ARB, progs[i]);
107 glVertexAttrib2fvARB(1, & attrib[i * 2]);
109 piglit_draw_rect(x, 1, BOX_SIZE, BOX_SIZE);
111 if (!piglit_probe_pixel_rgb(x + (BOX_SIZE / 2),
112 1 + (BOX_SIZE / 2),
113 good_color)) {
114 if (! piglit_automatic)
115 printf("shader %u failed with attributes "
116 "%.1f, %.1f\n",
118 attrib[(i * 2) + 0],
119 attrib[(i * 2) + 1]);
121 result = PIGLIT_FAIL;
125 piglit_present_results();
126 return result;
130 void
131 piglit_init(int argc, char **argv)
133 GLint max_address_registers;
134 unsigned i;
136 (void) argc;
137 (void) argv;
139 piglit_require_vertex_program();
140 piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
142 glGetProgramivARB(GL_VERTEX_PROGRAM_ARB,
143 GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB,
144 & max_address_registers);
145 if (max_address_registers == 0) {
146 /* we have to have at least one address register */
147 if (! piglit_automatic)
148 printf("GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB == 0\n");
150 piglit_report_result(PIGLIT_FAIL);
151 } else if (max_address_registers == 1) {
152 if (piglit_is_extension_supported("GL_NV_vertex_program2_option")) {
153 /* this extension requires two address regs */
154 if (! piglit_automatic)
155 printf("GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB "
156 "== 1\n");
158 piglit_report_result(PIGLIT_FAIL);
159 } else {
160 piglit_report_result(PIGLIT_SKIP);
164 for (i = 0; i < ARRAY_SIZE(progs); i++) {
165 char shader_source[1024];
166 int offset[2];
167 char direction[2];
169 /* We want the constant offset in the instruction plus the
170 * value read from the attribute to be 1.
172 offset[0] = 1 - (int) attrib[(2 * i) + 0];
173 offset[1] = 1 - (int) attrib[(2 * i) + 1];
175 if (offset[0] < 0) {
176 direction[0] = '-';
177 offset[0] = -offset[0];
178 } else {
179 direction[0] = '+';
182 if (offset[1] < 0) {
183 direction[1] = '-';
184 offset[1] = -offset[1];
185 } else {
186 direction[1] = '+';
189 snprintf(shader_source, sizeof(shader_source),
190 vertex_source_template,
191 direction[0], offset[0],
192 direction[1], offset[1]);
194 progs[i] = piglit_compile_program(GL_VERTEX_PROGRAM_ARB,
195 shader_source);
198 glEnable(GL_VERTEX_PROGRAM_ARB);
200 glClearColor(0.5, 0.5, 0.5, 1.0);