Add more structure constructor tests.
[piglit/hramrach.git] / tests / shaders / vp-clipdistance-03.c
blob03e3832d8a2add0c19b88933116a54e3b5585752
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-clipdistance-03.c
26 * Validate that writes to Y, Z, and W of result.clip has no effect.
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 1
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 "MOV result.clip[0], vertex.texcoord[0].yxxx;\n"
50 PIGLIT_VERTEX_PROGRAM_MVP_TRANSFORM
51 "END\n"
54 static const char fragment_source[] =
55 "!!ARBfp1.0\n"
56 "MOV result.color, {0.0, 1.0, 0.0, 1.0};\n"
57 "END"
60 /**
61 * \name Handles to programs.
63 /*@{*/
64 static GLint progs[TEST_COLS];
65 static GLint frag_prog;
66 /*@}*/
69 static const GLfloat clear_color[4] = { 0.5, 0.5, 0.5, 1.0 };
72 enum piglit_result
73 piglit_display(void)
75 static const GLfloat color[4] = { 0.0, 1.0, 0.0, 1.0 };
76 enum piglit_result result = PIGLIT_SUCCESS;
77 unsigned i;
79 glClear(GL_COLOR_BUFFER_BIT);
81 for (i = 0; i < ELEMENTS(progs); i++) {
82 const int x = 1 + (i * (BOX_SIZE + 1));
84 glBindProgramARB(GL_VERTEX_PROGRAM_ARB, progs[i]);
85 glEnable(GL_CLIP_PLANE0 + i);
86 piglit_draw_rect_tex(x, 1, BOX_SIZE, BOX_SIZE,
87 1.0, 1.0, -2.0, 0.0);
88 glDisable(GL_CLIP_PLANE0 + i);
90 if (!piglit_probe_pixel_rgb(x + (BOX_SIZE / 2),
91 1 + (BOX_SIZE / 2),
92 color)) {
93 result = PIGLIT_FAILURE;
97 glutSwapBuffers();
98 return result;
102 void
103 piglit_init(int argc, char **argv)
105 unsigned i;
107 (void) argc;
108 (void) argv;
110 piglit_require_vertex_program();
111 piglit_require_fragment_program();
112 piglit_require_extension("GL_NV_vertex_program2_option");
113 piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
115 for (i = 0; i < ELEMENTS(progs); i++) {
116 char shader_source[1024];
118 snprintf(shader_source, sizeof(shader_source),
119 vertex_source_template, i);
121 progs[i] = piglit_compile_program(GL_VERTEX_PROGRAM_ARB,
122 shader_source);
125 glEnable(GL_FRAGMENT_PROGRAM_ARB);
126 glEnable(GL_VERTEX_PROGRAM_ARB);
128 frag_prog = piglit_compile_program(GL_FRAGMENT_PROGRAM_ARB,
129 fragment_source);
130 glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, frag_prog);
132 glClearColor(clear_color[0],
133 clear_color[1],
134 clear_color[2],
135 clear_color[3]);