ARB_ubo/referenced-by-shader: pass if shader compiler moves UBOs between shaders
[piglit.git] / tests / spec / gl-1.5 / vertex-buffer-offsets.c
blob51662688ed7dcb2de8ff540dde0871c742b173c1
1 /*
2 * Copyright 2015 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.
25 * Test interleaved vertex arrays with unusual element offsets and strides.
27 * The game Flockers (from Steam) uses some unusual vertex arrays.
28 * For example: glVertexAttribPointerARB(index = 1, size = 3, type = GL_FLOAT,
29 * normalized = GL_FALSE, stride = 87, pointer = 0x4b). Note that the
30 * offset to the float[3] attribute is 75 (0x4b) bytes and the stride between
31 * vertices is 87 bytes.
33 * According to the OpenGL specification, OpenGL 1.5, page 33:
34 * "Clients must align data elements consistent with the requirements of the
35 * client platform, with an additional base-level requirement that an offset
36 * within a buffer to a datum comprising N basic machine units be a multiple
37 * of N."
39 * However, the spec does not say what might happen if that requirement is
40 * not met. There is no language about raising a GL error or undefined
41 * behavior.
43 * This test exercises float[3] attributes at unusual offsets/strides.
44 * If a failure is detected we generate "warn" instead of "fail" since
45 * according to the spec, the failure is allowed, but there are apps (such
46 * as Flockers) that will hit this issue.
48 * If a failure/warning is reported, the OpenGL implementor will have to
49 * decide if conformance or app support is more important.
51 * Brian Paul
54 #include "piglit-util-gl.h"
56 PIGLIT_GL_TEST_CONFIG_BEGIN
57 config.supports_gl_compat_version = 15;
58 config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DOUBLE;
59 config.khr_no_error_support = PIGLIT_NO_ERRORS;
60 PIGLIT_GL_TEST_CONFIG_END
63 void
64 piglit_init(int argc, char **argv)
66 /* nothing */
70 static bool
71 test_offset_stride(int color_offset, int stride)
73 static const GLfloat vertex[4][2] = {
74 { -1, -1 },
75 { 1, -1 },
76 { 1, 1 },
77 { -1, 1 }
79 static const GLfloat color[4] = { 0.0, 1.0, 0.5, 1.0 };
80 GLubyte buffer[1000];
81 GLuint buf;
82 int i, pos;
83 bool p;
85 assert(color_offset >= sizeof(vertex[0]));
86 assert(stride >= color_offset + sizeof(color));
88 pos = 0;
89 for (i = 0; i < 4; i++) {
90 /* copy vertex position into buffer */
91 memcpy(buffer + pos, vertex[i], sizeof(vertex[i]));
93 /* copy vertex color into buffer at unusual offset */
94 memcpy(buffer + pos + color_offset, color, sizeof(color));
96 pos += stride;
98 assert(pos <= sizeof(buffer));
100 glGenBuffers(1, &buf);
101 glBindBuffer(GL_ARRAY_BUFFER, buf);
102 glBufferData(GL_ARRAY_BUFFER, sizeof(buffer),
103 buffer, GL_STATIC_DRAW);
105 glVertexPointer(2, GL_FLOAT, stride, (void *) 0);
106 glColorPointer(4, GL_FLOAT, stride, (void *) (size_t) color_offset);
107 glEnable(GL_VERTEX_ARRAY);
108 glEnable(GL_COLOR_ARRAY);
110 glClear(GL_COLOR_BUFFER_BIT);
111 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
113 p = piglit_probe_rect_rgba(0, 0, piglit_width, piglit_height, color);
115 if (!p) {
116 printf("Failure for color_offset %d, stride %d\n",
117 color_offset, stride);
120 piglit_present_results();
122 glDeleteBuffers(1, &buf);
124 return p;
128 enum piglit_result
129 piglit_display(void)
131 bool pass = true;
133 /* test nice values */
134 pass = test_offset_stride(8, 24) && pass;
135 pass = test_offset_stride(12, 28) && pass;
137 /* NOTE: if any of the following tests fail on non-x86 systems it
138 * may be due to unaligned loads of floats (typically a bus error).
141 /* test unusual offset */
142 pass = test_offset_stride(9, 32) && pass;
144 /* test unusual stride */
145 pass = test_offset_stride(8, 27) && pass;
147 /* test unusual offset, unusual stride */
148 pass = test_offset_stride(9, 25) && pass;
149 pass = test_offset_stride(10, 26) && pass;
150 pass = test_offset_stride(11, 27) && pass;
152 /* Report warn, not fail (see comments above) */
153 return pass ? PIGLIT_PASS : PIGLIT_WARN;