Add more structure constructor tests.
[piglit/hramrach.git] / tests / shaders / vp-address-06.c
bloba761bb63a69e2dc7f7e593ee9ee45cf8d44d3124
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-06.c
26 * Simple test of the ARA instruction from GL_NV_vertex_program2_option.
28 * \author Ian Romanick <ian.d.romanick@intel.com>
31 #include "piglit-util.h"
32 #include "piglit-framework.h"
34 #define ELEMENTS(x) (sizeof(x) / sizeof(x[0]))
36 #define TEST_ROWS 1
37 #define TEST_COLS 2
38 #define BOX_SIZE 32
41 int piglit_window_mode = GLUT_DOUBLE;
42 int piglit_width = (((BOX_SIZE+1)*TEST_COLS)+1);
43 int piglit_height = (((BOX_SIZE+1)*TEST_ROWS)+1);
46 static const char vertex_source_template[] =
47 "!!ARBvp1.0\n"
48 "OPTION NV_vertex_program2;\n"
49 "PARAM colors[] = { program.env[0..3] };\n"
50 "ADDRESS A0;\n"
51 "\n"
52 "ARL A0, vertex.attrib[1];\n"
53 "ARA A0, A0;\n"
54 "ADD result.color, colors[A0.%c], colors[A0.%c];\n"
55 PIGLIT_VERTEX_PROGRAM_MVP_TRANSFORM
56 "END\n"
60 /**
61 * \name Handles to programs.
63 /*@{*/
64 static GLint progs[TEST_COLS];
65 /*@}*/
68 enum piglit_result
69 piglit_display(void)
71 static const GLfloat color[4] = { 0.0, 0.5, 0.0, 0.5 };
72 static const GLfloat bad_color[4] = { 1.0, 0.0, 0.0, 1.0 };
73 static const GLfloat good_color[4] = { 0.0, 1.0, 0.0, 1.0 };
74 static const GLfloat attrib[4][4] = {
75 { 1.0, -37.0, 1.0, 68.2 },
76 { -37.0, 1.0, 68.2, 1.0 },
78 enum piglit_result result = PIGLIT_SUCCESS;
79 unsigned i;
81 glClear(GL_COLOR_BUFFER_BIT);
83 glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, 0, bad_color);
84 glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, 1, bad_color);
85 glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, 2, color);
86 glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, 3, bad_color);
88 for (i = 0; i < ELEMENTS(progs); i++) {
89 const int x = 1 + (i * (BOX_SIZE + 1));
91 glBindProgramARB(GL_VERTEX_PROGRAM_ARB, progs[i]);
93 glVertexAttrib4fvARB(1, attrib[i]);
95 piglit_draw_rect(x, 1, BOX_SIZE, BOX_SIZE);
97 if (!piglit_probe_pixel_rgb(x + (BOX_SIZE / 2),
98 1 + (BOX_SIZE / 2),
99 good_color)) {
100 result = PIGLIT_FAILURE;
104 glutSwapBuffers();
105 return result;
109 void
110 piglit_init(int argc, char **argv)
112 static const char components[] = "xyzw";
113 unsigned i;
115 (void) argc;
116 (void) argv;
118 piglit_require_vertex_program();
119 piglit_require_fragment_program();
120 piglit_require_extension("GL_NV_vertex_program2_option");
121 piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
123 for (i = 0; i < ELEMENTS(progs); i++) {
124 char shader_source[1024];
126 snprintf(shader_source, sizeof(shader_source),
127 vertex_source_template,
128 components[i + 0],
129 components[i + 2]);
131 progs[i] = piglit_compile_program(GL_VERTEX_PROGRAM_ARB,
132 shader_source);
135 glEnable(GL_FRAGMENT_PROGRAM_ARB);
136 glEnable(GL_VERTEX_PROGRAM_ARB);
137 glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, piglit_ARBfp_pass_through);
139 glClearColor(0.5, 0.5, 0.5, 1.0);