glx-multithread-texture: Avoid front-buffer rendering.
[piglit.git] / tests / shaders / vp-clipdistance-01.c
blobc103c39db60f118a69962a489beb64aa256d82e5
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-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"
33 #define TEST_ROWS 1
34 #define TEST_COLS 6
35 #define BOX_SIZE 32
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[] =
48 "!!ARBvp1.0\n"
49 "OPTION NV_vertex_program2;\n"
50 "PARAM colors[] = { program.env[0..3] };\n"
51 "ADDRESS A0;\n"
52 "\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
56 "END\n"
59 static const char fragment_source[] =
60 "!!ARBfp1.0\n"
61 "TEMP R0;\n"
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"
66 "END"
69 /**
70 * \name Handles to programs.
72 /*@{*/
73 static GLint progs[TEST_COLS];
74 static GLint frag_prog;
75 /*@}*/
78 static const GLfloat clear_color[4] = { 0.5, 0.5, 0.5, 1.0 };
81 enum piglit_result
82 piglit_display(void)
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;
87 unsigned i;
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,
106 1 + (BOX_SIZE / 2),
107 color)) {
108 result = PIGLIT_FAIL;
111 if (!piglit_probe_pixel_rgb(x + (BOX_SIZE / 2) + 2,
112 1 + (BOX_SIZE / 2),
113 clear_color)) {
114 result = PIGLIT_FAIL;
118 piglit_present_results();
119 return result;
123 void
124 piglit_init(int argc, char **argv)
126 unsigned i;
128 (void) argc;
129 (void) 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,
143 shader_source);
146 glEnable(GL_FRAGMENT_PROGRAM_ARB);
147 glEnable(GL_VERTEX_PROGRAM_ARB);
149 frag_prog = piglit_compile_program(GL_FRAGMENT_PROGRAM_ARB,
150 fragment_source);
151 glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, frag_prog);
153 glClearColor(clear_color[0],
154 clear_color[1],
155 clear_color[2],
156 clear_color[3]);