diff options
author | Eric Anholt <eric@anholt.net> | 2012-01-25 17:07:16 -0800 |
---|---|---|
committer | Eric Anholt <eric@anholt.net> | 2012-02-08 14:14:39 -0800 |
commit | 047633ed91f6194697427379ecf22f6f51bab8b1 (patch) | |
tree | f4e6f00ea9194668a638eb72067a9e32a6d50b39 /tests/spec/arb_copy_buffer | |
parent | d8bfea1215673d41bd6e402dfa1967fe3007a9b8 (diff) |
ARB_copy_buffer/targets: New test for spec behavior.
Diffstat (limited to 'tests/spec/arb_copy_buffer')
-rw-r--r-- | tests/spec/arb_copy_buffer/CMakeLists.gl.txt | 1 | ||||
-rw-r--r-- | tests/spec/arb_copy_buffer/targets.c | 162 |
2 files changed, 163 insertions, 0 deletions
diff --git a/tests/spec/arb_copy_buffer/CMakeLists.gl.txt b/tests/spec/arb_copy_buffer/CMakeLists.gl.txt index 7a6343544..b8d5fb8af 100644 --- a/tests/spec/arb_copy_buffer/CMakeLists.gl.txt +++ b/tests/spec/arb_copy_buffer/CMakeLists.gl.txt @@ -18,5 +18,6 @@ add_executable (arb_copy_buffer-overlap overlap.c) add_executable (arb_copy_buffer-negative-bound-zero negative-bound-zero.c) add_executable (arb_copy_buffer-negative-bounds negative-bounds.c) add_executable (arb_copy_buffer-negative-mapped negative-mapped.c) +add_executable (arb_copy_buffer-targets targets.c) # vim: ft=cmake: diff --git a/tests/spec/arb_copy_buffer/targets.c b/tests/spec/arb_copy_buffer/targets.c new file mode 100644 index 000000000..5d3c7f4de --- /dev/null +++ b/tests/spec/arb_copy_buffer/targets.c @@ -0,0 +1,162 @@ +/* + * Copyright © 2012 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +/** @file targets.c + * + * Tests the following piece of the GL_ARB_copy_buffer spec: + * + * "All or part of one buffer object's data store may be copied to + * the data store of another buffer object by calling + * + * void CopyBufferSubData(enum readtarget, enum writetarget, + * intptr readoffset, intptr writeoffset, + * sizeiptr size); + * + * with readtarget and writetarget each set to one of the targets + * ARRAY_BUFFER, COPY_READ_BUFFER, COPY_WRITE_BUFFER, + * ELEMENT_ARRAY_BUFFER, PIXEL_PACK_BUFFER, PIXEL_UNPACK_BUFFER, + * TEXTURE_BUFFER, TRANSFORM_FEEDBACK_BUFFER, or + * UNIFORM_BUFFER. While any of these targets may be used, the + * COPY_READ_BUFFER and COPY_WRITE_BUFFER targets are provided + * specifically for copies, so that they can be done without + * affecting other buffer binding targets that may be in use." + * + * Specifically, it walks over the available targets and makes sure + * that copies work for them. + */ + +#include "piglit-util.h" + +int piglit_width = 100, piglit_height = 100; +int piglit_window_mode = GLUT_RGB | GLUT_DOUBLE; + +enum piglit_result +piglit_display(void) +{ + /* uncreached */ + return PIGLIT_FAIL; +} + +static bool +supported(GLenum target) +{ + switch (target) { + case GL_ARRAY_BUFFER: + case GL_ELEMENT_ARRAY_BUFFER: + return piglit_is_extension_supported("GL_ARB_vertex_buffer_object"); + + case GL_COPY_READ_BUFFER: + case GL_COPY_WRITE_BUFFER: + return true; + + case GL_PIXEL_PACK_BUFFER: + case GL_PIXEL_UNPACK_BUFFER: + return (piglit_is_extension_supported("GL_EXT_pixel_buffer_object") || + piglit_is_extension_supported("GL_ARB_pixel_buffer_object")); + + case GL_TEXTURE_BUFFER: + return (piglit_is_extension_supported("GL_EXT_texture_buffer_object") || + piglit_is_extension_supported("GL_ARB_texture_buffer_object")); + + case GL_TRANSFORM_FEEDBACK_BUFFER: + return piglit_is_extension_supported("GL_EXT_transform_feedback"); + + case GL_UNIFORM_BUFFER: + return (piglit_is_extension_supported("GL_EXT_bindable_uniform") || + piglit_is_extension_supported("GL_ARB_uniform_buffer_object")); + } + + abort(); +} + +static void +test_copy(GLenum from, GLenum to) +{ + GLuint bufs[2]; + uint8_t data[8]; + uint8_t bad_data[8]; + void *ptr; + int i; + + glGenBuffers(2, bufs); + + for (i = 0; i < ARRAY_SIZE(data); i++) + data[i] = i; + + memset(bad_data, 0xd0, sizeof(bad_data)); + + glBindBuffer(from, bufs[0]); + glBufferData(from, sizeof(data), data, GL_DYNAMIC_DRAW); + glBindBuffer(to, bufs[1]); + glBufferData(to, sizeof(bad_data), bad_data, GL_DYNAMIC_DRAW); + + glCopyBufferSubData(from, to, 0, 0, sizeof(data)); + ptr = glMapBuffer(to, GL_READ_ONLY); + if (memcmp(ptr, data, sizeof(data))) { + fprintf(stderr, "data not copied\n"); + piglit_report_result(PIGLIT_FAIL); + } + glUnmapBuffer(to); + + glDeleteBuffers(2, bufs); +} + + +void +piglit_init(int argc, char **argv) +{ + int i, j; + GLenum targets[] = { + GL_ARRAY_BUFFER, + GL_COPY_READ_BUFFER, + GL_COPY_WRITE_BUFFER, + GL_ELEMENT_ARRAY_BUFFER, + GL_PIXEL_PACK_BUFFER, + GL_PIXEL_UNPACK_BUFFER, + GL_TEXTURE_BUFFER, + GL_TRANSFORM_FEEDBACK_BUFFER, + GL_UNIFORM_BUFFER, + }; + + piglit_require_extension("GL_ARB_copy_buffer"); + + for (i = 0; i < ARRAY_SIZE(targets); i++) { + GLenum from = targets[i]; + + if (!supported(from)) + continue; + + for (j = 0; j < ARRAY_SIZE(targets); j++) { + GLenum to = targets[j]; + + if (from == to) + continue; + if (!supported(to)) + continue; + + test_copy(from, to); + } + } + + piglit_report_result(PIGLIT_PASS); +} |