ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / arb_copy_buffer / targets.c
blob7303c84f4f4c2b808755611d0ebf54f363fdf2e9
1 /*
2 * Copyright © 2012 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 DEALINGS
21 * IN THE SOFTWARE.
24 /** @file targets.c
26 * Tests the following piece of the GL_ARB_copy_buffer spec:
28 * "All or part of one buffer object's data store may be copied to
29 * the data store of another buffer object by calling
31 * void CopyBufferSubData(enum readtarget, enum writetarget,
32 * intptr readoffset, intptr writeoffset,
33 * sizeiptr size);
35 * with readtarget and writetarget each set to one of the targets
36 * ARRAY_BUFFER, COPY_READ_BUFFER, COPY_WRITE_BUFFER,
37 * ELEMENT_ARRAY_BUFFER, PIXEL_PACK_BUFFER, PIXEL_UNPACK_BUFFER,
38 * TEXTURE_BUFFER, TRANSFORM_FEEDBACK_BUFFER, or
39 * UNIFORM_BUFFER. While any of these targets may be used, the
40 * COPY_READ_BUFFER and COPY_WRITE_BUFFER targets are provided
41 * specifically for copies, so that they can be done without
42 * affecting other buffer binding targets that may be in use."
44 * Specifically, it walks over the available targets and makes sure
45 * that copies work for them.
48 #include "piglit-util-gl.h"
50 PIGLIT_GL_TEST_CONFIG_BEGIN
52 config.supports_gl_compat_version = 10;
54 config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
55 config.khr_no_error_support = PIGLIT_NO_ERRORS;
57 PIGLIT_GL_TEST_CONFIG_END
59 enum piglit_result
60 piglit_display(void)
62 /* uncreached */
63 return PIGLIT_FAIL;
66 static bool
67 supported(GLenum target)
69 switch (target) {
70 case GL_ARRAY_BUFFER:
71 case GL_ELEMENT_ARRAY_BUFFER:
72 return piglit_is_extension_supported("GL_ARB_vertex_buffer_object");
74 case GL_COPY_READ_BUFFER:
75 case GL_COPY_WRITE_BUFFER:
76 return true;
78 case GL_PIXEL_PACK_BUFFER:
79 case GL_PIXEL_UNPACK_BUFFER:
80 return (piglit_is_extension_supported("GL_EXT_pixel_buffer_object") ||
81 piglit_is_extension_supported("GL_ARB_pixel_buffer_object"));
83 case GL_TEXTURE_BUFFER:
84 return (piglit_is_extension_supported("GL_EXT_texture_buffer_object") ||
85 piglit_is_extension_supported("GL_ARB_texture_buffer_object"));
87 case GL_TRANSFORM_FEEDBACK_BUFFER:
88 return piglit_is_extension_supported("GL_EXT_transform_feedback");
90 case GL_UNIFORM_BUFFER:
91 return (piglit_is_extension_supported("GL_EXT_bindable_uniform") ||
92 piglit_is_extension_supported("GL_ARB_uniform_buffer_object"));
95 abort();
98 static void
99 test_copy(GLenum from, GLenum to)
101 GLuint bufs[2];
102 uint8_t data[8];
103 uint8_t bad_data[8];
104 void *ptr;
105 int i;
107 glGenBuffers(2, bufs);
109 for (i = 0; i < ARRAY_SIZE(data); i++)
110 data[i] = i;
112 memset(bad_data, 0xd0, sizeof(bad_data));
114 glBindBuffer(from, bufs[0]);
115 glBufferData(from, sizeof(data), data, GL_DYNAMIC_DRAW);
116 glBindBuffer(to, bufs[1]);
117 glBufferData(to, sizeof(bad_data), bad_data, GL_DYNAMIC_DRAW);
119 glCopyBufferSubData(from, to, 0, 0, sizeof(data));
120 ptr = glMapBuffer(to, GL_READ_ONLY);
121 if (memcmp(ptr, data, sizeof(data))) {
122 fprintf(stderr, "data not copied\n");
123 piglit_report_result(PIGLIT_FAIL);
125 glUnmapBuffer(to);
127 glDeleteBuffers(2, bufs);
131 void
132 piglit_init(int argc, char **argv)
134 int i, j;
135 GLenum targets[] = {
136 GL_ARRAY_BUFFER,
137 GL_COPY_READ_BUFFER,
138 GL_COPY_WRITE_BUFFER,
139 GL_ELEMENT_ARRAY_BUFFER,
140 GL_PIXEL_PACK_BUFFER,
141 GL_PIXEL_UNPACK_BUFFER,
142 GL_TEXTURE_BUFFER,
143 GL_TRANSFORM_FEEDBACK_BUFFER,
144 GL_UNIFORM_BUFFER,
147 piglit_require_extension("GL_ARB_copy_buffer");
149 for (i = 0; i < ARRAY_SIZE(targets); i++) {
150 GLenum from = targets[i];
152 if (!supported(from))
153 continue;
155 for (j = 0; j < ARRAY_SIZE(targets); j++) {
156 GLenum to = targets[j];
158 if (from == to)
159 continue;
160 if (!supported(to))
161 continue;
163 test_copy(from, to);
167 piglit_report_result(PIGLIT_PASS);