ext_transform_feedback: document missing mode in usage
[piglit.git] / tests / general / clear-varray-2.0.c
blobab230e44635f408a16d6fb02f2440fc472959b02
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.
23 * Authors:
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.
32 * fd.o bug #21638
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 =
49 "!!ARBvp1.0\n"
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"
56 "END"
59 static const GLchar *const fp_code =
60 "!!ARBfp1.0\n"
61 "MOV result.color, fragment.color;\n"
62 "END"
65 enum piglit_result
66 piglit_display(void)
68 GLboolean pass = GL_TRUE;
69 float vertices[4][4];
70 int i;
71 float green[4] = {0, 1, 0, 0};
72 float blue[4] = {0, 0, 1, 0};
74 vertices[0][0] = 10;
75 vertices[0][1] = 10;
76 vertices[0][2] = 0;
77 vertices[0][3] = 1;
79 vertices[1][0] = 20;
80 vertices[1][1] = 10;
81 vertices[1][2] = 0;
82 vertices[1][3] = 1;
84 vertices[2][0] = 20;
85 vertices[2][1] = 20;
86 vertices[2][2] = 0;
87 vertices[2][3] = 1;
89 vertices[3][0] = 10;
90 vertices[3][1] = 20;
91 vertices[3][2] = 0;
92 vertices[3][3] = 1;
94 /* Clear red. */
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),
100 vertices);
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);
132 void
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);