Add a negative test for bitwise not used in a larger expression.
[piglit/hramrach.git] / tests / general / draw-elements-vs-inputs.c
blobd11df6639137987a73ab4cf81f050f02548ce7b6
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.h"
43 int piglit_width = 300, piglit_height = 300;
44 int piglit_window_mode = GLUT_RGB | GLUT_DOUBLE;
47 void
48 piglit_init(int argc, char **argv)
50 GLfloat red[4] = {1, 0, 0, 1};
52 glewInit();
54 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, red);
56 glEnable(GL_DEPTH_TEST);
57 glEnable(GL_LIGHTING);
58 glEnable(GL_LIGHT0);
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));
71 static void
72 draw_quad(GLboolean normals, GLboolean rangeElements)
74 static GLfloat norms[4][3] = {
75 { -0.1, -0.1, 1 },
76 { 0.1, -0.1, 1 },
77 { 0.1, 0.1, 1 },
78 { -0.1, 0.1, 1 }
80 static GLfloat verts[4][3] = {
81 { -25, -25, 0.0 },
82 { 25, -25, 0.0 },
83 { 25, 25, 0.0 },
84 { -25, 25, 0.0 }
86 static GLuint indexes[4] = { 0, 1, 2, 3 };
88 if (normals) {
89 glNormalPointer(GL_FLOAT, 0, norms);
90 glEnableClientState(GL_NORMAL_ARRAY);
92 else {
93 glNormal3f(1, 1, 1);
95 glVertexPointer(3, GL_FLOAT, 0, verts);
96 glEnableClientState(GL_VERTEX_ARRAY);
97 if (rangeElements)
98 glDrawRangeElements(GL_QUADS, 0, 3, 4, GL_UNSIGNED_INT, indexes);
99 else
100 glDrawElements(GL_QUADS, 4, GL_UNSIGNED_INT, indexes);
102 glDisableClientState(GL_VERTEX_ARRAY);
103 glDisableClientState(GL_NORMAL_ARRAY);
107 enum piglit_result
108 piglit_display(void)
110 const GLfloat expected1[3] = { 1.0, 0.039, 0.039, };
111 const GLfloat expected2[3] = { 0.615, 0.039, 0.039, };
112 GLint row;
113 GLboolean pass = GL_TRUE;
115 glViewport(0, 0, piglit_width, piglit_height);
116 glMatrixMode(GL_PROJECTION);
117 glLoadIdentity();
118 glOrtho(0, piglit_width, 0, piglit_height, -1.0, 1.0);
120 glMatrixMode(GL_MODELVIEW);
121 glLoadIdentity();
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 */
134 if (1) {
135 glPushMatrix();
136 glTranslatef(x0, y, 0);
137 draw_quad(GL_TRUE, rangeElements);
138 glPopMatrix();
139 glFlush();
142 /* quad with one normal */
143 if (1) {
144 glPushMatrix();
145 glTranslatef(x1, y, 0);
146 glNormal3f(1, 0.5, 0.25);
147 draw_quad(GL_FALSE, rangeElements);
148 glPopMatrix();
149 glFlush();
152 /* another quad with per-vertex normals */
153 if (1) {
154 glPushMatrix();
155 glTranslatef(x2, y, 0);
156 draw_quad(GL_TRUE, rangeElements);
157 glPopMatrix();
160 /* left quad */
161 pass = piglit_probe_pixel_rgb(x0, y, expected1) && pass;
163 /* middle quad */
164 pass = piglit_probe_pixel_rgb(x1, y, expected2) && pass;
166 /* right quad */
167 pass = piglit_probe_pixel_rgb(x2, y, expected1) && pass;
170 glutSwapBuffers();
172 return pass ? PIGLIT_SUCCESS : PIGLIT_FAILURE;