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
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.
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.h"
43 int piglit_width
= 300, piglit_height
= 300;
44 int piglit_window_mode
= GLUT_RGB
| GLUT_DOUBLE
;
48 piglit_init(int argc
, char **argv
)
50 GLfloat red
[4] = {1, 0, 0, 1};
54 glMaterialfv(GL_FRONT_AND_BACK
, GL_DIFFUSE
, red
);
56 glEnable(GL_DEPTH_TEST
);
57 glEnable(GL_LIGHTING
);
60 glEnable(GL_NORMALIZE
);
62 glClearColor(0.5, 0.5, 0.5, 0.5);
65 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
66 printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
72 draw_quad(GLboolean normals
, GLboolean rangeElements
)
74 static GLfloat norms
[4][3] = {
80 static GLfloat verts
[4][3] = {
86 static GLuint indexes
[4] = { 0, 1, 2, 3 };
89 glNormalPointer(GL_FLOAT
, 0, norms
);
90 glEnableClientState(GL_NORMAL_ARRAY
);
95 glVertexPointer(3, GL_FLOAT
, 0, verts
);
96 glEnableClientState(GL_VERTEX_ARRAY
);
98 glDrawRangeElements(GL_QUADS
, 0, 3, 4, GL_UNSIGNED_INT
, indexes
);
100 glDrawElements(GL_QUADS
, 4, GL_UNSIGNED_INT
, indexes
);
102 glDisableClientState(GL_VERTEX_ARRAY
);
103 glDisableClientState(GL_NORMAL_ARRAY
);
110 const GLfloat expected1
[3] = { 1.0, 0.039, 0.039, };
111 const GLfloat expected2
[3] = { 0.615, 0.039, 0.039, };
113 GLboolean pass
= GL_TRUE
;
115 glViewport(0, 0, piglit_width
, piglit_height
);
116 glMatrixMode(GL_PROJECTION
);
118 glOrtho(0, piglit_width
, 0, piglit_height
, -1.0, 1.0);
120 glMatrixMode(GL_MODELVIEW
);
123 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
125 /* first row = glDrawElements, second row = glDrawRangeElements */
126 for (row
= 0; row
< 2; row
++) {
127 GLint x0
= piglit_width
/4;
128 GLint x1
= piglit_width
/2;
129 GLint x2
= piglit_width
*3/4;
130 GLint y
= (piglit_height
/ 3) * (row
+ 1);
131 GLboolean rangeElements
= row
== 1;
133 /* quad with per-vertex normals */
136 glTranslatef(x0
, y
, 0);
137 draw_quad(GL_TRUE
, rangeElements
);
142 /* quad with one normal */
145 glTranslatef(x1
, y
, 0);
146 glNormal3f(1, 0.5, 0.25);
147 draw_quad(GL_FALSE
, rangeElements
);
152 /* another quad with per-vertex normals */
155 glTranslatef(x2
, y
, 0);
156 draw_quad(GL_TRUE
, rangeElements
);
161 pass
= piglit_probe_pixel_rgb(x0
, y
, expected1
) && pass
;
164 pass
= piglit_probe_pixel_rgb(x1
, y
, expected2
) && pass
;
167 pass
= piglit_probe_pixel_rgb(x2
, y
, expected1
) && pass
;
172 return pass
? PIGLIT_SUCCESS
: PIGLIT_FAILURE
;