Add more structure constructor tests.
[piglit/hramrach.git] / tests / general / varray-disabled.c
blobdec93c671032d11d31c460f654745109f3ca53c7
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 /**
29 * @file varray-disabled.c
31 * Test whether no vertices are drawn when we call DrawArrays with no
32 * vertex array enabled.
34 * http://bugs.freedesktop.org/show_bug.cgi?id=19911
37 #include "piglit-util.h"
39 int piglit_width = 128, piglit_height = 128;
40 int piglit_window_mode = GLUT_RGB | GLUT_DOUBLE;
42 static void
43 set_colors(GLfloat *color_array, GLfloat *color)
45 int i;
47 for (i = 0; i < 4; i++) {
48 color_array[i * 4 + 0] = color[0];
49 color_array[i * 4 + 1] = color[1];
50 color_array[i * 4 + 2] = color[2];
51 color_array[i * 4 + 3] = 1.0;
55 enum piglit_result
56 piglit_display(void)
58 GLfloat vertices[4][2];
59 GLfloat colors[16];
60 GLboolean pass = GL_TRUE;
61 GLfloat red[3] = {1.0, 0.0, 0.0};
62 GLfloat green[3] = {0.0, 1.0, 0.0};
63 GLfloat blue[3] = {0.0, 0.0, 1.0};
64 GLfloat black[3] = {0.0, 0.0, 0.0};
66 glClearColor(0.0, 0.0, 0.0, 0.0);
67 glClear(GL_COLOR_BUFFER_BIT);
69 glColorPointer(4, GL_FLOAT, 0, colors);
70 glEnableClientState(GL_COLOR_ARRAY);
72 /* Draw the vertices enabled once on the left side for sanity */
73 vertices[0][0] = 0.0;
74 vertices[0][1] = 0.0;
75 vertices[1][0] = 0.3;
76 vertices[1][1] = 0.0;
77 vertices[2][0] = 0.3;
78 vertices[2][1] = 1.0;
79 vertices[3][0] = 0.0;
80 vertices[3][1] = 1.0;
81 glVertexPointer(2, GL_FLOAT, 0, vertices);
82 glEnableClientState(GL_VERTEX_ARRAY);
83 set_colors(colors, red);
84 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
86 /* Now disable and draw again. */
87 vertices[0][0] = 0.3;
88 vertices[0][1] = 0.0;
89 vertices[1][0] = 0.7;
90 vertices[1][1] = 0.0;
91 vertices[2][0] = 0.7;
92 vertices[2][1] = 1.0;
93 vertices[3][0] = 0.3;
94 vertices[3][1] = 1.0;
95 /* This NULL pointer set was key in triggering the bug reported. */
96 glVertexPointer (2, GL_FLOAT, 0, NULL);
97 glDisableClientState(GL_VERTEX_ARRAY);
98 glDisableClientState(GL_COLOR_ARRAY);
99 set_colors(colors, green);
100 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
102 /* Now draw again enabled, to make sure the hardware hasn't given
103 * up on us.
105 vertices[0][0] = 0.7;
106 vertices[0][1] = 0.0;
107 vertices[1][0] = 1.0;
108 vertices[1][1] = 0.0;
109 vertices[2][0] = 1.0;
110 vertices[2][1] = 1.0;
111 vertices[3][0] = 0.7;
112 vertices[3][1] = 1.0;
113 glVertexPointer(2, GL_FLOAT, 0, vertices);
114 glEnableClientState(GL_VERTEX_ARRAY);
115 glEnableClientState(GL_COLOR_ARRAY);
116 set_colors(colors, blue);
117 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
118 glutSwapBuffers();
120 pass &= piglit_probe_pixel_rgb(piglit_width * 1 / 6,
121 piglit_height / 2, red);
122 pass &= piglit_probe_pixel_rgb(piglit_width * 3 / 6,
123 piglit_height / 2, black);
124 pass &= piglit_probe_pixel_rgb(piglit_width * 5 / 6,
125 piglit_height / 2, blue);
127 return pass ? PIGLIT_SUCCESS : PIGLIT_FAILURE;
131 static void Reshape(int width, int height)
133 piglit_width = width;
134 piglit_height = height;
135 glViewport(0, 0, width, height);
136 glMatrixMode(GL_PROJECTION);
137 glLoadIdentity();
138 glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
139 glMatrixMode(GL_MODELVIEW);
140 glLoadIdentity();
143 void
144 piglit_init(int argc, char *argv[])
146 glutReshapeFunc(Reshape);