cl: Don't use device_infos if num_device_infos == 0
[piglit.git] / tests / shaders / vp-clipdistance-02.c
blobaadcd7b2905bf295e9c0be398c7f4a106d9c04b2
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-02.c
26 * Test disabling a clip plane, but writing a clip distance for that plane.
28 * For each test square, all of the clip planes except one are enabled. For
29 * all of the enabled plane a positive value is written. For the one disabled
30 * plane a negative value is written. No clipping should occur.
32 * \author Ian Romanick <ian.d.romanick@intel.com>
35 #include "piglit-util-gl.h"
37 #define TEST_ROWS 1
38 #define TEST_COLS 6
39 #define BOX_SIZE 32
41 PIGLIT_GL_TEST_CONFIG_BEGIN
43 config.supports_gl_compat_version = 10;
45 config.window_width = (((BOX_SIZE+1)*TEST_COLS)+1);
46 config.window_height = (((BOX_SIZE+1)*TEST_ROWS)+1);
47 config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
49 PIGLIT_GL_TEST_CONFIG_END
51 static const char vertex_source_template[] =
52 "!!ARBvp1.0\n"
53 "OPTION NV_vertex_program2;\n"
54 "MOV result.clip[0].x, vertex.texcoord[0].y;\n"
55 "MOV result.clip[1].x, vertex.texcoord[0].y;\n"
56 "MOV result.clip[2].x, vertex.texcoord[0].y;\n"
57 "MOV result.clip[3].x, vertex.texcoord[0].y;\n"
58 "MOV result.clip[4].x, vertex.texcoord[0].y;\n"
59 "MOV result.clip[5].x, vertex.texcoord[0].y;\n"
60 "MOV result.clip[%d].x, vertex.texcoord[0].x;\n"
61 PIGLIT_VERTEX_PROGRAM_MVP_TRANSFORM
62 "END\n"
65 static const char fragment_source[] =
66 "!!ARBfp1.0\n"
67 "MOV result.color, {0.0, 1.0, 0.0, 1.0};\n"
68 "END"
71 /**
72 * \name Handles to programs.
74 /*@{*/
75 static GLint progs[TEST_COLS];
76 static GLint frag_prog;
77 /*@}*/
80 static const GLfloat clear_color[4] = { 0.5, 0.5, 0.5, 1.0 };
83 enum piglit_result
84 piglit_display(void)
86 static const GLfloat color[4] = { 0.0, 1.0, 0.0, 1.0 };
87 enum piglit_result result = PIGLIT_PASS;
88 unsigned i;
90 glClear(GL_COLOR_BUFFER_BIT);
92 /* Initially, enable all of the clip planes.
94 for (i = 0; i < 6; i++)
95 glEnable(GL_CLIP_PLANE0 + i);
97 for (i = 0; i < ARRAY_SIZE(progs); i++) {
98 const int x = 1 + (i * (BOX_SIZE + 1));
100 glBindProgramARB(GL_VERTEX_PROGRAM_ARB, progs[i]);
101 glDisable(GL_CLIP_PLANE0 + i);
102 piglit_draw_rect_tex(x, 1, BOX_SIZE, BOX_SIZE,
103 1.0, 1.0, -2.0, 0.0);
104 glEnable(GL_CLIP_PLANE0 + i);
106 if (!piglit_probe_pixel_rgb(x + (BOX_SIZE / 2),
107 1 + (BOX_SIZE / 2),
108 color)) {
109 result = PIGLIT_FAIL;
113 piglit_present_results();
114 return result;
118 void
119 piglit_init(int argc, char **argv)
121 unsigned i;
123 (void) argc;
124 (void) argv;
126 piglit_require_vertex_program();
127 piglit_require_fragment_program();
128 piglit_require_extension("GL_NV_vertex_program2_option");
129 piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
131 for (i = 0; i < ARRAY_SIZE(progs); i++) {
132 char shader_source[1024];
134 snprintf(shader_source, sizeof(shader_source),
135 vertex_source_template, i);
137 progs[i] = piglit_compile_program(GL_VERTEX_PROGRAM_ARB,
138 shader_source);
141 glEnable(GL_FRAGMENT_PROGRAM_ARB);
142 glEnable(GL_VERTEX_PROGRAM_ARB);
144 frag_prog = piglit_compile_program(GL_FRAGMENT_PROGRAM_ARB,
145 fragment_source);
146 glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, frag_prog);
148 glClearColor(clear_color[0],
149 clear_color[1],
150 clear_color[2],
151 clear_color[3]);