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
24 * Eric Anholt <eric@anholt.net>
28 /** @file clear-varray-2.0.c
30 * Tests that enabling 2.0's vertex attributes doesn't interfere with glClear.
35 #include "piglit-util-gl.h"
37 PIGLIT_GL_TEST_CONFIG_BEGIN
39 config
.supports_gl_compat_version
= 10;
41 config
.window_width
= 200;
42 config
.window_height
= 100;
43 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
| PIGLIT_GL_VISUAL_DOUBLE
| PIGLIT_GL_VISUAL_DEPTH
;
45 PIGLIT_GL_TEST_CONFIG_END
47 /* apply MVP and set the color to blue. */
48 static const GLchar
*const vp_code
=
50 "PARAM mvp[4] = { state.matrix.mvp };\n"
51 "DP4 result.position.x, mvp[0], vertex.attrib[0];\n"
52 "DP4 result.position.y, mvp[1], vertex.attrib[0];\n"
53 "DP4 result.position.z, mvp[2], vertex.attrib[0];\n"
54 "DP4 result.position.w, mvp[3], vertex.attrib[0];\n"
55 "MOV result.color, {0, 0, 1, 0};\n"
59 static const GLchar
*const fp_code
=
61 "MOV result.color, fragment.color;\n"
68 GLboolean pass
= GL_TRUE
;
71 float green
[4] = {0, 1, 0, 0};
72 float blue
[4] = {0, 0, 1, 0};
95 glClearColor(1.0, 0.0, 0.0, 0.0);
96 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
98 /* Draw a blue rect at (10,10)-(20,20) */
99 glVertexAttribPointer(0, 4, GL_FLOAT
, GL_FALSE
, 4 * sizeof(float),
101 glEnableVertexAttribArray(0);
103 glDrawArrays(GL_TRIANGLE_FAN
, 0, 4);
105 /* Clear everything to green. Note that we left the attr enabled*/
106 glClearColor(0.0, 1.0, 0.0, 0.0);
107 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
109 /* Draw a blue rect at (30,10)-(40,20) */
110 for (i
= 0; i
< 4; i
++)
111 vertices
[i
][0] += 20;
112 glDrawArrays(GL_TRIANGLE_FAN
, 0, 4);
114 /* The second clear should have made everything green. */
115 pass
= pass
&& piglit_probe_pixel_rgb(30, 30, green
);
116 /* The first rectangle should have been cleared to green. */
117 pass
= pass
&& piglit_probe_pixel_rgb(15, 15, green
);
118 /* The second rectangle should have shown blue. */
119 pass
= pass
&& piglit_probe_pixel_rgb(35, 15, blue
);
121 piglit_present_results();
123 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
126 static void reshape(int width
, int height
)
128 glViewport(0, 0, width
, height
);
129 piglit_ortho_projection(width
, height
, GL_FALSE
);
133 piglit_init(int argc
, char **argv
)
135 GLuint vert_prog
, frag_prog
;
137 piglit_require_gl_version(20);
139 reshape(piglit_width
, piglit_height
);
141 piglit_require_extension("GL_ARB_fragment_program");
142 piglit_require_extension("GL_ARB_vertex_program");
144 glGenProgramsARB(1, &vert_prog
);
145 glBindProgramARB(GL_VERTEX_PROGRAM_ARB
, vert_prog
);
146 glProgramStringARB(GL_VERTEX_PROGRAM_ARB
, GL_PROGRAM_FORMAT_ASCII_ARB
,
147 strlen(vp_code
), vp_code
);
149 glGenProgramsARB(1, &frag_prog
);
150 glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB
, frag_prog
);
151 glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB
, GL_PROGRAM_FORMAT_ASCII_ARB
,
152 strlen(fp_code
), fp_code
);
154 glEnable(GL_VERTEX_PROGRAM_ARB
);
155 glEnable(GL_FRAGMENT_PROGRAM_ARB
);