glsl: test loop unroll with uint overflow
[piglit.git] / tests / spec / arb_draw_elements_base_vertex / drawelements.c
blob1fa1fe3a0cb0940290f90add2014ff118d127e86
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
21 * DEALINGS IN THE SOFTWARE.
23 * Authors:
24 * Eric Anholt <eric@anholt.net>
27 /** @file draw-elements-base-vertex.c
28 * Tests ARB_draw_elements_base_vertex functionality by drawing a series of
29 * pairs of quads using different base vertices, using the same vertex and
30 * index buffers.
33 #include "piglit-util-gl.h"
35 PIGLIT_GL_TEST_CONFIG_BEGIN
37 config.supports_gl_compat_version = 10;
39 config.window_width = 300;
40 config.window_height = 300;
41 config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
42 config.khr_no_error_support = PIGLIT_NO_ERRORS;
44 PIGLIT_GL_TEST_CONFIG_END
46 #define NUM_QUADS 10
48 static uintptr_t ib_offset;
50 void
51 piglit_init(int argc, char **argv)
53 GLfloat *vb;
54 GLuint *ib;
55 GLuint vbo;
56 GLboolean user_va = GL_FALSE;
57 int i;
59 for (i = 1; i < argc; i++) {
60 if (!strcmp(argv[i], "user_varrays")) {
61 user_va = GL_TRUE;
62 puts("Testing user vertex arrays.");
66 if (!user_va)
67 piglit_require_extension("GL_ARB_vertex_buffer_object");
68 piglit_require_extension("GL_ARB_draw_elements_base_vertex");
70 glMatrixMode(GL_MODELVIEW);
71 glPushMatrix();
72 glLoadIdentity();
74 if (!user_va) {
75 glGenBuffersARB(1, &vbo);
76 glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo);
77 glBufferDataARB(GL_ARRAY_BUFFER_ARB,
78 NUM_QUADS * 8 * sizeof(GLfloat) +
79 2 * 4 * sizeof(GLuint),
80 NULL, GL_DYNAMIC_DRAW);
81 vb = glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB);
82 } else {
83 vb = malloc(NUM_QUADS * 8 * sizeof(GLfloat) +
84 2 * 4 * sizeof(GLuint));
87 for (i = 0; i < NUM_QUADS; i++) {
88 float x1 = 10;
89 float y1 = 10 + i * 20;
90 float x2 = 20;
91 float y2 = 20 + i * 20;
93 vb[i * 8 + 0] = x1; vb[i * 8 + 1] = y1;
94 vb[i * 8 + 2] = x2; vb[i * 8 + 3] = y1;
95 vb[i * 8 + 4] = x2; vb[i * 8 + 5] = y2;
96 vb[i * 8 + 6] = x1; vb[i * 8 + 7] = y2;
98 ib_offset = NUM_QUADS * 8 * sizeof(GLfloat);
99 ib = (GLuint *)((char *)vb + ib_offset);
100 for (i = 0; i < 8; i++)
101 ib[i] = i;
103 if (user_va) {
104 ib_offset = (uintptr_t)ib;
105 } else {
106 glUnmapBufferARB(GL_ARRAY_BUFFER_ARB);
107 glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, vbo);
110 glEnableClientState(GL_VERTEX_ARRAY);
111 glVertexPointer(2, GL_FLOAT, 0, user_va ? vb : NULL);
114 enum piglit_result
115 piglit_display(void)
117 GLboolean pass = GL_TRUE;
118 float white[3] = {1.0, 1.0, 1.0};
119 float clear[3] = {0.0, 0.0, 0.0};
120 int i, j;
122 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
124 glColor3fv(white);
125 /* Draw columns with each successive pair of the quads. */
126 for (i = 0; i < NUM_QUADS - 1; i++) {
127 glMatrixMode(GL_PROJECTION);
128 glPushMatrix();
129 glLoadIdentity();
130 glOrtho(0, piglit_width, 0, piglit_height, -1, 1);
131 glTranslatef(i * 20, 0, 0);
133 glDrawElementsBaseVertex(GL_QUADS, 8, GL_UNSIGNED_INT,
134 (void *)(uintptr_t)ib_offset, i * 4);
136 glPopMatrix();
139 for (i = 0; i < NUM_QUADS - 1; i++) {
140 for (j = 0; j < NUM_QUADS; j++) {
141 float *expected;
143 int x = 15 + i * 20;
144 int y = 15 + j * 20;
146 if (j == i || j == i + 1)
147 expected = white;
148 else
149 expected = clear;
150 pass = piglit_probe_pixel_rgb(x, y, expected) && pass;
154 piglit_present_results();
156 return pass ? PIGLIT_PASS : PIGLIT_FAIL;