diff options
author | Laura Ekstrand <laura@jlekstrand.net> | 2015-01-14 14:13:43 -0800 |
---|---|---|
committer | Laura Ekstrand <laura@jlekstrand.net> | 2015-04-02 17:57:40 -0700 |
commit | 84101c74758befd68dc8b0e8047882a7e04d8422 (patch) | |
tree | 473efa11dbd4dc5da819deaf3fc183bbd4523d28 | |
parent | 6198e41f28f971e788665d818d93a6e307668a1f (diff) |
arb_direct_state_access: Testing MapNamedBuffer.
-rw-r--r-- | tests/all.py | 1 | ||||
-rw-r--r-- | tests/spec/arb_direct_state_access/CMakeLists.gl.txt | 1 | ||||
-rw-r--r-- | tests/spec/arb_direct_state_access/mapnamedbuffer-pbo-readpixels.c | 128 |
3 files changed, 130 insertions, 0 deletions
diff --git a/tests/all.py b/tests/all.py index 4cd0f534b..d0289460a 100644 --- a/tests/all.py +++ b/tests/all.py @@ -4244,6 +4244,7 @@ with profile.group_manager( g(['arb_direct_state_access-namedbuffersubdata-vbo-sync'], 'namedbuffersubdata-vbo-sync') g(['arb_direct_state_access-clearnamedbufferdata-invalid-internal-format'], 'clearnamedbufferdata-invalid-internal-format') g(['arb_direct_state_access-clearnamedbuffersubdata-invalid-size'], 'clearnamedbuffersubdata-invalid-size') + g(['arb_direct_state_access-mapnamedbuffer-pbo-readpixels'], 'mapnamedbuffer-pbo-readpixels') with profile.group_manager( PiglitGLTest, diff --git a/tests/spec/arb_direct_state_access/CMakeLists.gl.txt b/tests/spec/arb_direct_state_access/CMakeLists.gl.txt index ffaa125b5..fa3bc5aa1 100644 --- a/tests/spec/arb_direct_state_access/CMakeLists.gl.txt +++ b/tests/spec/arb_direct_state_access/CMakeLists.gl.txt @@ -20,6 +20,7 @@ piglit_add_executable (arb_direct_state_access-namedbufferstorage-persistent nam piglit_add_executable (arb_direct_state_access-namedbuffersubdata-vbo-sync namedbuffersubdata-vbo-sync.c) piglit_add_executable (arb_direct_state_access-clearnamedbufferdata-invalid-internal-format clearnamedbufferdata-invalid-internal-format.c) piglit_add_executable (arb_direct_state_access-clearnamedbuffersubdata-invalid-size clearnamedbuffersubdata-invalid-size.c) +piglit_add_executable (arb_direct_state_access-mapnamedbuffer-pbo-readpixels mapnamedbuffer-pbo-readpixels.c) piglit_add_executable (arb_direct_state_access-dsa-textures dsa-textures.c dsa-utils.c) piglit_add_executable (arb_direct_state_access-texturesubimage texturesubimage.c) piglit_add_executable (arb_direct_state_access-bind-texture-unit bind-texture-unit.c) diff --git a/tests/spec/arb_direct_state_access/mapnamedbuffer-pbo-readpixels.c b/tests/spec/arb_direct_state_access/mapnamedbuffer-pbo-readpixels.c new file mode 100644 index 000000000..1d83eabe2 --- /dev/null +++ b/tests/spec/arb_direct_state_access/mapnamedbuffer-pbo-readpixels.c @@ -0,0 +1,128 @@ +/* + * Copyright © 2009, 2015 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. + * + * Authors: + * Eric Anholt <eric@anholt.net> + * + * Adapted to test MapNamedBuffer by Laura Ekstrand <laura@jlekstrand.net>, + * January 2015. + */ + +/** @file mapnamedbuffer-pbo-readpixels.c + * + * Tests that reading 2x2 BGRA UNSIGNED_BYTE buffers work correctly. + */ + +#include "piglit-util-gl.h" + +PIGLIT_GL_TEST_CONFIG_BEGIN + + config.supports_gl_compat_version = 10; + config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE; + +PIGLIT_GL_TEST_CONFIG_END + +static GLboolean +probe(int x, int y, uint32_t expected, uint32_t observed) +{ + if ((expected & 0xffffff) != (observed & 0xffffff)) { + printf("Probe color at (%i,%i)\n", x, y); + printf(" Expected: 0x%08x\n", expected); + printf(" Observed: 0x%08x\n", observed); + + return GL_FALSE; + } else { + return GL_TRUE; + } +} + +enum piglit_result +piglit_display(void) +{ + GLboolean pass = GL_TRUE; + uint32_t *addr; + GLuint pbo; + + glClearColor(0.0, 0.0, 0.0, 0.0); + glClear(GL_COLOR_BUFFER_BIT); + + glCreateBuffers(1, &pbo); + glNamedBufferData(pbo, 4 * 4, NULL, GL_STREAM_DRAW); + glPixelStorei(GL_PACK_ALIGNMENT, 1); + + glViewport(0, 0, 2, 2); + piglit_ortho_projection(2, 2, GL_FALSE); + glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo); + + /* bottom: green. top: blue. */ + glColor4f(0.0, 1.0, 0.0, 0.0); + piglit_draw_rect(0, 0, 2, 1); + glColor4f(0.0, 0.0, 1.0, 0.0); + piglit_draw_rect(0, 1, 2, 1); + + /* Read the whole buffer. */ + glReadPixels(0, 0, 2, 2, + GL_BGRA, GL_UNSIGNED_BYTE, (void *)(uintptr_t)0); + addr = glMapNamedBuffer(pbo, GL_READ_ONLY); + pass &= probe(0, 0, 0x0000ff00, addr[0]); + pass &= probe(1, 0, 0x0000ff00, addr[1]); + pass &= probe(0, 1, 0x000000ff, addr[2]); + pass &= probe(1, 1, 0x000000ff, addr[3]); + glUnmapNamedBuffer(pbo); + + /* Read with an offset. */ + glReadPixels(1, 0, 1, 1, + GL_BGRA, GL_UNSIGNED_BYTE, (void *)(uintptr_t)4); + addr = glMapNamedBuffer(pbo, GL_READ_ONLY); + pass &= probe(1, 0, 0x0000ff00, addr[1]); + glUnmapNamedBuffer(pbo); + + /* Read with an offset. */ + glReadPixels(1, 1, 1, 1, + GL_BGRA, GL_UNSIGNED_BYTE, (void *)(uintptr_t)4); + addr = glMapNamedBuffer(pbo, GL_READ_ONLY); + pass &= probe(1, 1, 0x000000ff, addr[1]); + glUnmapNamedBuffer(pbo); + + piglit_present_results(); + + glDeleteBuffers(1, &pbo); + + return pass ? PIGLIT_PASS : PIGLIT_FAIL; +} + + +static void reshape(int width, int height) +{ + piglit_width = width; + piglit_height = height; + + piglit_ortho_projection(width, height, GL_FALSE); +} + +void +piglit_init(int argc, char **argv) +{ + reshape(piglit_width, piglit_height); + piglit_require_extension("GL_ARB_pixel_buffer_object"); + piglit_require_extension("GL_ARB_direct_state_access"); +} |