diff options
author | Henri Verbeet <hverbeet@gmail.com> | 2011-03-08 21:19:07 +0100 |
---|---|---|
committer | Henri Verbeet <hverbeet@gmail.com> | 2011-03-08 21:27:04 +0100 |
commit | 6e86df5109c4d1c3163d848b2ae7c4c34ceb63d2 (patch) | |
tree | 1bdc614f2c5edcabc8d290206b9444e2c3d6f096 | |
parent | be2d7c8c2a2799147f86f210eae8d99d3b3690f5 (diff) |
Add a test for FBO blits between RGB and sRGB formats.
-rw-r--r-- | tests/all.tests | 1 | ||||
-rw-r--r-- | tests/fbo/CMakeLists.gl.txt | 1 | ||||
-rw-r--r-- | tests/fbo/fbo-srgb-blit.c | 122 |
3 files changed, 124 insertions, 0 deletions
diff --git a/tests/all.tests b/tests/all.tests index 77e402464..a3ec4f153 100644 --- a/tests/all.tests +++ b/tests/all.tests @@ -148,6 +148,7 @@ add_plain_test(fbo, 'fbo-readdrawpix') add_plain_test(fbo, 'fbo-readpixels') add_plain_test(fbo, 'fbo-scissor-bitmap') add_plain_test(fbo, 'fbo-srgb') +add_plain_test(fbo, 'fbo-srgb-blit') add_plain_test(fbo, 'fbo-storage-formats') add_plain_test(fbo, 'fbo-storage-completeness') add_plain_test(fbo, 'fbo-pbo-readpixels-small') diff --git a/tests/fbo/CMakeLists.gl.txt b/tests/fbo/CMakeLists.gl.txt index 2de41f3d0..f267346cd 100644 --- a/tests/fbo/CMakeLists.gl.txt +++ b/tests/fbo/CMakeLists.gl.txt @@ -62,6 +62,7 @@ add_executable (fbo-nostencil-test fbo-nostencil-test.c) add_executable (fbo-readpixels fbo-readpixels.c) add_executable (fbo-rg fbo-rg.c) add_executable (fbo-srgb fbo-srgb.c) +add_executable (fbo-srgb-blit fbo-srgb-blit.c) IF (UNIX) target_link_libraries (fbo-srgb m) ENDIF (UNIX) diff --git a/tests/fbo/fbo-srgb-blit.c b/tests/fbo/fbo-srgb-blit.c new file mode 100644 index 000000000..712640107 --- /dev/null +++ b/tests/fbo/fbo-srgb-blit.c @@ -0,0 +1,122 @@ +/* + * Copyright © 2011 Henri Verbeet <hverbeet@gmail.com> + * + * 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 fbo-srgb-blit.c + * + * Test FBO blits between sRGB and linear textures. Blits should happen in + * linear color space. + */ + +#include "piglit-util.h" + +int piglit_width = 128; +int piglit_height = 128; +int piglit_window_mode = GLUT_DOUBLE | GLUT_RGB; + +static GLuint src_tex, dst_tex; +static GLuint src_fbo, dst_fbo; +static uint32_t *tex_data; + +static void blit_rect(GLenum src_format, GLenum dst_format, float x, float y, float w, float h, bool stretch) +{ + glBindTexture(GL_TEXTURE_2D, src_tex); + glTexImage2D(GL_TEXTURE_2D, 0, src_format, 16, 16, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, tex_data); + + glBindTexture(GL_TEXTURE_2D, dst_tex); + glTexImage2D(GL_TEXTURE_2D, 0, dst_format, 16, 16, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL); + + glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, src_fbo); + glFramebufferTexture2DEXT(GL_READ_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, src_tex, 0); + + glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, dst_fbo); + glFramebufferTexture2DEXT(GL_DRAW_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, dst_tex, 0); + + if (stretch) + glBlitFramebufferEXT(7, 7, 9, 9, 0, 0, 16, 16, GL_COLOR_BUFFER_BIT, GL_LINEAR); + else + glBlitFramebufferEXT(0, 0, 16, 16, 0, 0, 16, 16, GL_COLOR_BUFFER_BIT, GL_LINEAR); + + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); + + glBindTexture(GL_TEXTURE_2D, dst_tex); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); + glEnable(GL_TEXTURE_2D); + + piglit_draw_rect_tex(x, y, w, h, 0.0f, 0.0f, 1.0f, 1.0f); +} + +enum piglit_result piglit_display(void) +{ + static const struct + { + int x; + int y; + float color[3]; + } + expected[] = + { + {32, 32, {0.11f, 0.16f, 0.21f}}, + {32, 96, {0.37f, 0.44f, 0.50f}}, + {96, 96, {0.11f, 0.16f, 0.21f}}, + {96, 32, {0.37f, 0.44f, 0.50f}}, + }; + GLboolean pass = GL_TRUE; + unsigned int i; + + blit_rect(GL_RGBA8, GL_SRGB8_ALPHA8, -1.0f, -1.0f, 1.0f, 1.0f, false); + blit_rect(GL_SRGB8_ALPHA8, GL_RGBA8, -1.0f, 0.0f, 1.0f, 1.0f, true); + blit_rect(GL_RGBA8, GL_SRGB8_ALPHA8, 0.0f, 0.0f, 1.0f, 1.0f, true); + blit_rect(GL_SRGB8_ALPHA8, GL_RGBA8, 0.0f, -1.0f, 1.0f, 1.0f, false); + + for (i = 0; i < sizeof(expected) / sizeof(*expected); ++i) + { + pass &= piglit_probe_pixel_rgb(expected[i].x, expected[i].y, expected[i].color); + } + + glutSwapBuffers(); + + return pass ? PIGLIT_SUCCESS : PIGLIT_FAILURE; +} + +void piglit_init(int argc, char **argv) +{ + unsigned int i; + + piglit_require_extension("GL_EXT_framebuffer_object"); + piglit_require_extension("GL_EXT_framebuffer_blit"); + piglit_require_extension("GL_EXT_texture_sRGB"); + + tex_data = malloc(16 * 16 * sizeof(*tex_data)); + for (i = 0; i < 16 * 16; ++i) + { + tex_data[i] = 0xff5f6f7f; + } + + glGenTextures(1, &src_tex); + glGenTextures(1, &dst_tex); + glGenFramebuffersEXT(1, &src_fbo); + glGenFramebuffersEXT(1, &dst_fbo); +} |