Add more structure constructor tests.
[piglit/hramrach.git] / tests / shaders / vp-clipdistance-04.c
blob7e27b50ec7e7ed0f3632d1defec3a46df8ab88c2
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-04.c
26 * Validate that result.clip[] is pre-initialized with 0.
28 * Each block enables one clip plane but writes a distance for a different
29 * clip plane. Since clipping only happens for clip distances < 0, there
30 * should be no clipping.
32 * \author Ian Romanick <ian.d.romanick@intel.com>
35 #include "piglit-util.h"
36 #include "piglit-framework.h"
38 #define ELEMENTS(x) (sizeof(x) / sizeof(x[0]))
40 #define TEST_ROWS 1
41 #define TEST_COLS 6
42 #define BOX_SIZE 32
45 int piglit_window_mode = GLUT_DOUBLE;
46 int piglit_width = (((BOX_SIZE+1)*TEST_COLS)+1);
47 int piglit_height = (((BOX_SIZE+1)*TEST_ROWS)+1);
50 static const char vertex_source_template[] =
51 "!!ARBvp1.0\n"
52 "OPTION NV_vertex_program2;\n"
53 "MOV result.clip[%d], vertex.texcoord[0].x;\n"
54 PIGLIT_VERTEX_PROGRAM_MVP_TRANSFORM
55 "END\n"
58 static const char fragment_source[] =
59 "!!ARBfp1.0\n"
60 "MOV result.color, {0.0, 1.0, 0.0, 1.0};\n"
61 "END"
64 /**
65 * \name Handles to programs.
67 /*@{*/
68 static GLint progs[TEST_COLS];
69 static GLint frag_prog;
70 /*@}*/
73 static const GLfloat clear_color[4] = { 0.5, 0.5, 0.5, 1.0 };
76 enum piglit_result
77 piglit_display(void)
79 static const GLfloat color[4] = { 0.0, 1.0, 0.0, 1.0 };
80 enum piglit_result result = PIGLIT_SUCCESS;
81 unsigned i;
83 glClear(GL_COLOR_BUFFER_BIT);
85 for (i = 0; i < ELEMENTS(progs); i++) {
86 const int x = 1 + (i * (BOX_SIZE + 1));
87 const GLenum p = GL_CLIP_PLANE0 + ((i + 1) % 6);
89 glBindProgramARB(GL_VERTEX_PROGRAM_ARB, progs[i]);
90 glEnable(p);
91 piglit_draw_rect_tex(x, 1, BOX_SIZE, BOX_SIZE,
92 1.0, 1.0, -2.0, 0.0);
93 glDisable(p);
95 if (!piglit_probe_pixel_rgb(x + (BOX_SIZE / 2),
96 1 + (BOX_SIZE / 2),
97 color)) {
98 result = PIGLIT_FAILURE;
102 glutSwapBuffers();
103 return result;
107 void
108 piglit_init(int argc, char **argv)
110 unsigned i;
112 (void) argc;
113 (void) argv;
115 piglit_require_vertex_program();
116 piglit_require_fragment_program();
117 piglit_require_extension("GL_NV_vertex_program2_option");
118 piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
120 for (i = 0; i < ELEMENTS(progs); i++) {
121 char shader_source[1024];
123 snprintf(shader_source, sizeof(shader_source),
124 vertex_source_template, i);
126 progs[i] = piglit_compile_program(GL_VERTEX_PROGRAM_ARB,
127 shader_source);
130 glEnable(GL_FRAGMENT_PROGRAM_ARB);
131 glEnable(GL_VERTEX_PROGRAM_ARB);
133 frag_prog = piglit_compile_program(GL_FRAGMENT_PROGRAM_ARB,
134 fragment_source);
135 glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, frag_prog);
137 glClearColor(clear_color[0],
138 clear_color[1],
139 clear_color[2],
140 clear_color[3]);