fbo-mrt-alphatest: Actually require MRTs to be available.
[piglit.git] / tests / general / array-stride.c
blob287ce6361832c72ee0592ade75e1ad378908e01d
1 /*
2 * Copyright (c) 2011 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 DEALINGS
21 * IN THE SOFTWARE.
25 * Test some unusual vertex array strides.
26 * Brian Paul
27 * June 14, 2011
30 #include "piglit-util-gl.h"
32 PIGLIT_GL_TEST_CONFIG_BEGIN
34 config.supports_gl_compat_version = 10;
36 config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
37 config.khr_no_error_support = PIGLIT_NO_ERRORS;
39 PIGLIT_GL_TEST_CONFIG_END
41 static const char *TestName = "array-stride";
44 #define ROWS 10
45 #define COLS 10
46 #define NUM_VERTS (ROWS * COLS * 4)
48 static GLfloat Verts[ROWS][COLS][4][2];
51 static void
52 gen_vertices(void)
54 float dx = 9.0, dy = 9.0;
55 int i, j;
56 for (i = 0; i < ROWS; i++) {
57 float y = i * 10.0;
58 for (j = 0; j < COLS; j++) {
59 float x = j * 10.0;
60 Verts[i][j][0][0] = x;
61 Verts[i][j][0][1] = y;
62 Verts[i][j][1][0] = x + dx;
63 Verts[i][j][1][1] = y;
64 Verts[i][j][2][0] = x + dx;
65 Verts[i][j][2][1] = y + dy;
66 Verts[i][j][3][0] = x;
67 Verts[i][j][3][1] = y + dy;
73 static void
74 draw_simple_stride(void)
76 static GLushort elements[NUM_VERTS];
77 int i;
79 for (i = 0; i < ARRAY_SIZE(elements); i++)
80 elements[i] = i;
82 glVertexPointer(2, GL_FLOAT, 2 * sizeof(GLfloat), Verts);
83 glEnableClientState(GL_VERTEX_ARRAY);
84 glDrawElements(GL_QUADS, NUM_VERTS, GL_UNSIGNED_SHORT, elements);
85 glDisableClientState(GL_VERTEX_ARRAY);
89 /**
90 * Use a stride that's less than the vertex element size.
91 * Use scaled indices in the element array.
92 * Should render the same as the simple stride case above.
94 static void
95 draw_unusual_stride(int stride)
97 static GLushort elements[NUM_VERTS];
98 int i;
100 for (i = 0; i < ARRAY_SIZE(elements); i++)
101 elements[i] = i * 8 / stride;
103 glVertexPointer(2, GL_FLOAT, stride, Verts);
104 glEnableClientState(GL_VERTEX_ARRAY);
105 glDrawElements(GL_QUADS, NUM_VERTS, GL_UNSIGNED_SHORT, elements);
106 glDisableClientState(GL_VERTEX_ARRAY);
110 enum piglit_result
111 piglit_display(void)
113 GLubyte *buf0, *buf1;
114 enum piglit_result result = PIGLIT_PASS;
115 int stride;
117 gen_vertices();
119 buf0 = (GLubyte *) malloc(piglit_width * piglit_height * 4);
120 buf1 = (GLubyte *) malloc(piglit_width * piglit_height * 4);
122 /* draw reference image */
123 glClear(GL_COLOR_BUFFER_BIT);
124 draw_simple_stride();
125 glReadPixels(0, 0, piglit_width, piglit_height,
126 GL_RGBA, GL_UNSIGNED_BYTE, buf0);
128 /* draw w/ unusual strides */
129 for (stride = 1; stride <= 8; stride *= 2) {
130 glClear(GL_COLOR_BUFFER_BIT);
131 draw_unusual_stride(stride);
132 glReadPixels(0, 0, piglit_width, piglit_height,
133 GL_RGBA, GL_UNSIGNED_BYTE, buf1);
135 piglit_present_results();
137 /* compare bufs */
138 if (memcmp(buf0, buf1, piglit_width * piglit_height * 4) != 0) {
139 printf("%s: image comparison failed at stride = %d\n",
140 TestName, stride);
141 result = PIGLIT_FAIL;
145 free(buf0);
146 free(buf1);
148 return result;
152 void
153 piglit_init(int argc, char**argv)
155 glOrtho(-1.0, 101.0, -1.0, 101.0, -1.0, 1.0);