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
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
25 * \file vp-clipdistance-01.c
26 * Basic validation of NV_vertex_program2 result.clip[].
28 * \author Ian Romanick <ian.d.romanick@intel.com>
31 #include "piglit-util-gl.h"
37 PIGLIT_GL_TEST_CONFIG_BEGIN
39 config
.supports_gl_compat_version
= 10;
41 config
.window_width
= (((BOX_SIZE
+1)*TEST_COLS
)+1);
42 config
.window_height
= (((BOX_SIZE
+1)*TEST_ROWS
)+1);
43 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
| PIGLIT_GL_VISUAL_DOUBLE
;
45 PIGLIT_GL_TEST_CONFIG_END
47 static const char vertex_source_template
[] =
49 "OPTION NV_vertex_program2;\n"
50 "PARAM colors[] = { program.env[0..3] };\n"
53 "MOV result.clip[%d].x, vertex.texcoord[0].x;\n"
54 "MOV result.color, vertex.texcoord[0].x;\n"
55 PIGLIT_VERTEX_PROGRAM_MVP_TRANSFORM
59 static const char fragment_source
[] =
62 "MOV R0, {0.0, 0.0, 0.0, 1.0};\n"
63 "SGE R0.y, fragment.color, {0.0}.x;\n"
64 "SLT R0.x, fragment.color, {0.0}.x;\n"
65 "MOV result.color, R0;\n"
70 * \name Handles to programs.
73 static GLint progs
[TEST_COLS
];
74 static GLint frag_prog
;
78 static const GLfloat clear_color
[4] = { 0.5, 0.5, 0.5, 1.0 };
84 static const GLfloat color
[4] = { 0.0, 1.0, 0.0, 1.0 };
85 static const GLfloat bad_color
[4] = { 1.0, 0.0, 0.0, 1.0 };
86 enum piglit_result result
= PIGLIT_PASS
;
89 glClear(GL_COLOR_BUFFER_BIT
);
91 glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB
, 0, bad_color
);
92 glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB
, 1, color
);
93 glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB
, 2, color
);
94 glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB
, 3, color
);
96 for (i
= 0; i
< ARRAY_SIZE(progs
); i
++) {
97 const int x
= 1 + (i
* (BOX_SIZE
+ 1));
99 glBindProgramARB(GL_VERTEX_PROGRAM_ARB
, progs
[i
]);
100 glEnable(GL_CLIP_PLANE0
+ i
);
101 piglit_draw_rect_tex(x
, 1, BOX_SIZE
, BOX_SIZE
,
102 1.0, 1.0, -2.0, 0.0);
103 glDisable(GL_CLIP_PLANE0
+ i
);
105 if (!piglit_probe_pixel_rgb(x
+ (BOX_SIZE
/ 2) - 2,
108 result
= PIGLIT_FAIL
;
111 if (!piglit_probe_pixel_rgb(x
+ (BOX_SIZE
/ 2) + 2,
114 result
= PIGLIT_FAIL
;
118 piglit_present_results();
124 piglit_init(int argc
, char **argv
)
131 piglit_require_vertex_program();
132 piglit_require_fragment_program();
133 piglit_require_extension("GL_NV_vertex_program2_option");
134 piglit_ortho_projection(piglit_width
, piglit_height
, GL_FALSE
);
136 for (i
= 0; i
< ARRAY_SIZE(progs
); i
++) {
137 char shader_source
[1024];
139 snprintf(shader_source
, sizeof(shader_source
),
140 vertex_source_template
, i
);
142 progs
[i
] = piglit_compile_program(GL_VERTEX_PROGRAM_ARB
,
146 glEnable(GL_FRAGMENT_PROGRAM_ARB
);
147 glEnable(GL_VERTEX_PROGRAM_ARB
);
149 frag_prog
= piglit_compile_program(GL_FRAGMENT_PROGRAM_ARB
,
151 glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB
, frag_prog
);
153 glClearColor(clear_color
[0],