cl: Don't use device_infos if num_device_infos == 0
[piglit.git] / tests / general / draw-elements-vs-inputs.c
blob9e594ca99e4b50f2be057aded5505709cb399a50
1 /*
2 * Copyright © 2010 VMware, Inc.
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
21 * DEALINGS IN THE SOFTWARE.
23 * Authors:
24 * Brian Paul
28 /**
29 * @file draw-elements-vs-inputs.c
31 * Test that state validation is properly done between calls to
32 * glDrawRangeElements() / glDrawElements() when VS inputs change between
33 * calls (with regard to per-vertex vs. per-primitive values).
35 * This is a regression test for a bug in Mesa/gallium/softpipe which
36 * was fixed with commit 3cba779e16935f7c3a0bfd8af48bd5e015068e96.
40 #include "piglit-util-gl.h"
42 PIGLIT_GL_TEST_CONFIG_BEGIN
44 config.supports_gl_compat_version = 10;
46 config.window_width = 300;
47 config.window_height = 300;
48 config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
49 config.khr_no_error_support = PIGLIT_NO_ERRORS;
51 PIGLIT_GL_TEST_CONFIG_END
53 void
54 piglit_init(int argc, char **argv)
56 GLfloat red[4] = {1, 0, 0, 1};
58 piglit_require_gl_version(12);
60 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, red);
62 glEnable(GL_DEPTH_TEST);
63 glEnable(GL_LIGHTING);
64 glEnable(GL_LIGHT0);
66 glEnable(GL_NORMALIZE);
68 glClearColor(0.5, 0.5, 0.5, 0.5);
71 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
72 printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
77 static void
78 draw_quad(GLboolean normals, GLboolean rangeElements)
80 static GLfloat norms[4][3] = {
81 { -0.1, -0.1, 1 },
82 { 0.1, -0.1, 1 },
83 { 0.1, 0.1, 1 },
84 { -0.1, 0.1, 1 }
86 static GLfloat verts[4][3] = {
87 { -25, -25, 0.0 },
88 { 25, -25, 0.0 },
89 { 25, 25, 0.0 },
90 { -25, 25, 0.0 }
92 static GLuint indexes[4] = { 0, 1, 2, 3 };
94 if (normals) {
95 glNormalPointer(GL_FLOAT, 0, norms);
96 glEnableClientState(GL_NORMAL_ARRAY);
98 else {
99 glNormal3f(1, 1, 1);
101 glVertexPointer(3, GL_FLOAT, 0, verts);
102 glEnableClientState(GL_VERTEX_ARRAY);
103 if (rangeElements)
104 glDrawRangeElements(GL_QUADS, 0, 3, 4, GL_UNSIGNED_INT, indexes);
105 else
106 glDrawElements(GL_QUADS, 4, GL_UNSIGNED_INT, indexes);
108 glDisableClientState(GL_VERTEX_ARRAY);
109 glDisableClientState(GL_NORMAL_ARRAY);
113 enum piglit_result
114 piglit_display(void)
116 const GLfloat expected1[3] = { 1.0, 0.039, 0.039, };
117 const GLfloat expected2[3] = { 0.615, 0.039, 0.039, };
118 GLint row;
119 GLboolean pass = GL_TRUE;
121 glViewport(0, 0, piglit_width, piglit_height);
122 glMatrixMode(GL_PROJECTION);
123 glLoadIdentity();
124 glOrtho(0, piglit_width, 0, piglit_height, -1.0, 1.0);
126 glMatrixMode(GL_MODELVIEW);
127 glLoadIdentity();
129 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
131 /* first row = glDrawElements, second row = glDrawRangeElements */
132 for (row = 0; row < 2; row++) {
133 GLint x0 = piglit_width/4;
134 GLint x1 = piglit_width/2;
135 GLint x2 = piglit_width*3/4;
136 GLint y = (piglit_height / 3) * (row + 1);
137 GLboolean rangeElements = row == 1;
139 /* quad with per-vertex normals */
140 if (1) {
141 glPushMatrix();
142 glTranslatef(x0, y, 0);
143 draw_quad(GL_TRUE, rangeElements);
144 glPopMatrix();
145 glFlush();
148 /* quad with one normal */
149 if (1) {
150 glPushMatrix();
151 glTranslatef(x1, y, 0);
152 glNormal3f(1, 0.5, 0.25);
153 draw_quad(GL_FALSE, rangeElements);
154 glPopMatrix();
155 glFlush();
158 /* another quad with per-vertex normals */
159 if (1) {
160 glPushMatrix();
161 glTranslatef(x2, y, 0);
162 draw_quad(GL_TRUE, rangeElements);
163 glPopMatrix();
166 /* left quad */
167 pass = piglit_probe_pixel_rgb(x0, y, expected1) && pass;
169 /* middle quad */
170 pass = piglit_probe_pixel_rgb(x1, y, expected2) && pass;
172 /* right quad */
173 pass = piglit_probe_pixel_rgb(x2, y, expected1) && pass;
176 piglit_present_results();
178 return pass ? PIGLIT_PASS : PIGLIT_FAIL;