diff options
author | Eric Anholt <eric@anholt.net> | 2010-02-22 13:45:47 -0500 |
---|---|---|
committer | Eric Anholt <eric@anholt.net> | 2010-02-23 13:53:08 -0500 |
commit | 99f39eb9fad3ee1195e9ce75c46acdbbf4afe936 (patch) | |
tree | d01a4c23776010d6661f0428860586e5665cb29c | |
parent | e8dd4ade0900ed654cb64529c9c900acd206c822 (diff) |
fbo-blit: New test for EXT_framebuffer_blitting around between win/fbo.
-rw-r--r-- | tests/all.tests | 1 | ||||
-rw-r--r-- | tests/fbo/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/fbo/fbo-blit.c | 203 |
3 files changed, 205 insertions, 0 deletions
diff --git a/tests/all.tests b/tests/all.tests index eb9792233..0ef362080 100644 --- a/tests/all.tests +++ b/tests/all.tests @@ -67,6 +67,7 @@ add_plain_test(mesa, 'crossbar') fbo = Group() add_plain_test(fbo, 'fbo-1d') add_plain_test(fbo, 'fbo-3d') +add_plain_test(fbo, 'fbo-blit') add_plain_test(fbo, 'fbo-cubemap') add_plain_test(fbo, 'fbo-clearmipmap') add_plain_test(fbo, 'fbo-copyteximage') diff --git a/tests/fbo/CMakeLists.txt b/tests/fbo/CMakeLists.txt index e28ecf75d..349cf1d96 100644 --- a/tests/fbo/CMakeLists.txt +++ b/tests/fbo/CMakeLists.txt @@ -23,6 +23,7 @@ link_libraries ( add_executable (fbo-1d fbo-1d.c) add_executable (fbo-3d fbo-3d.c) +add_executable (fbo-blit fbo-blit.c) add_executable (fbo-clearmipmap fbo-clearmipmap.c) add_executable (fbo-drawbuffers fbo-drawbuffers.c) add_executable (fbo-drawbuffers2-blend fbo-drawbuffers2-blend.c) diff --git a/tests/fbo/fbo-blit.c b/tests/fbo/fbo-blit.c new file mode 100644 index 000000000..883c92647 --- /dev/null +++ b/tests/fbo/fbo-blit.c @@ -0,0 +1,203 @@ +/* + * Copyright © 2010 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> + * + */ + +/** @file fbo-blit.c + * + * Tests EXT_framebuffer_blit with various combinations of window system and + * FBO objects. Because FBOs are generally stored inverted relative to + * window system frambuffers, this could catch flipping failures in blit paths. + */ + +#include "piglit-util.h" + +int piglit_width = 100; +int piglit_height = 100; +int piglit_window_mode = GLUT_RGB | GLUT_DOUBLE; +#define PAD 10 +#define SIZE 20 + +static GLuint +make_fbo(int w, int h) +{ + GLuint tex; + GLuint fb; + GLenum status; + + glGenFramebuffersEXT(1, &fb); + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb); + + glGenTextures(1, &tex); + glBindTexture(GL_TEXTURE_2D, tex); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, + w, h, 0, + GL_RGBA, GL_UNSIGNED_BYTE, NULL); + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + + glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, + GL_COLOR_ATTACHMENT0_EXT, + GL_TEXTURE_2D, + tex, + 0); + assert(glGetError() == 0); + + status = glCheckFramebufferStatusEXT (GL_FRAMEBUFFER_EXT); + if (status != GL_FRAMEBUFFER_COMPLETE_EXT) { + fprintf(stderr, "fbo incomplete (status = 0x%04x)\n", status); + piglit_report_result(PIGLIT_SKIP); + } + + return fb; +} + +static void +draw_color_rect(int x, int y, int w, int h) +{ + int x1 = x; + int x2 = x + w / 2; + int y1 = y; + int y2 = y + h / 2; + + glColor4f(1.0, 0.0, 0.0, 0.0); + piglit_draw_rect(x1, y1, w / 2, h / 2); + glColor4f(0.0, 1.0, 0.0, 0.0); + piglit_draw_rect(x2, y1, w / 2, h / 2); + glColor4f(0.0, 0.0, 1.0, 0.0); + piglit_draw_rect(x1, y2, w / 2, h / 2); + glColor4f(1.0, 1.0, 1.0, 0.0); + piglit_draw_rect(x2, y2, w / 2, h / 2); +} + +static GLboolean +verify_color_rect(int start_x, int start_y, int w, int h) +{ + float red[] = {1, 0, 0, 0}; + float green[] = {0, 1, 0, 0}; + float blue[] = {0, 0, 1, 0}; + float white[] = {1, 1, 1, 0}; + int x, y; + + for (y = 0; y < h; y++) { + for (x = 0; x < w; x++) { + float *expected; + + if ((y < h / 2) && (x < w / 2)) + expected = red; + else if (y < h / 2) + expected = green; + else if (x < w / 2) + expected = blue; + else + expected = white; + + if (!piglit_probe_pixel_rgb(start_x + x, start_y + y, + expected)) + return GL_FALSE; + } + } + + return GL_TRUE; +} + +enum piglit_result +piglit_display(void) +{ + GLboolean pass = GL_TRUE; + GLuint fb; + int fbo_width = PAD * 2 + SIZE; + int fbo_height = PAD * 3 + SIZE * 2; + + glViewport(0, 0, piglit_width, piglit_height); + piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE); + + glClearColor(0.5, 0.5, 0.5, 0.5); + glClear(GL_COLOR_BUFFER_BIT); + + /* Draw the color rect in the window system */ + draw_color_rect(PAD, PAD, SIZE, SIZE); + + fb = make_fbo((PAD + SIZE) * 2, (PAD + SIZE) * 2); + + glBindFramebuffer(GL_DRAW_FRAMEBUFFER_EXT, fb); + glBindFramebuffer(GL_READ_FRAMEBUFFER_EXT, 0); + glViewport(0, 0, fbo_width, fbo_height); + piglit_ortho_projection(fbo_width, fbo_height, GL_FALSE); + glClearColor(1.0, 0.0, 1.0, 0.0); + glClear(GL_COLOR_BUFFER_BIT); + + /* Draw the color rect in the FBO */ + draw_color_rect(PAD, PAD, SIZE, SIZE); + + /* Now that we have correct samples, blit things around. + * FB -> WIN + */ + glBindFramebuffer(GL_DRAW_FRAMEBUFFER_EXT, 0); + glBindFramebuffer(GL_READ_FRAMEBUFFER_EXT, fb); + glBlitFramebufferEXT(PAD, PAD, + PAD + SIZE, PAD + SIZE, + PAD, PAD * 2 + SIZE, + PAD + SIZE, (PAD * 2 + SIZE) + SIZE, + GL_COLOR_BUFFER_BIT, GL_NEAREST); + + /* WIN -> FB */ + glBindFramebuffer(GL_DRAW_FRAMEBUFFER_EXT, fb); + glBindFramebuffer(GL_READ_FRAMEBUFFER_EXT, 0); + glBlitFramebufferEXT(PAD, PAD, + PAD + SIZE, PAD + SIZE, + PAD, PAD * 2 + SIZE, + PAD + SIZE, (PAD * 2 + SIZE) + SIZE, + GL_COLOR_BUFFER_BIT, GL_NEAREST); + + /* FB -> WIN back to verify WIN -> FB */ + glBindFramebuffer(GL_DRAW_FRAMEBUFFER_EXT, 0); + glBindFramebuffer(GL_READ_FRAMEBUFFER_EXT, fb); + glBlitFramebufferEXT(PAD, PAD * 2 + SIZE, + PAD + SIZE, (PAD * 2 + SIZE) + SIZE, + PAD, PAD * 3 + SIZE * 2, + PAD + SIZE, (PAD * 3 + SIZE * 2) + SIZE, + GL_COLOR_BUFFER_BIT, GL_NEAREST); + + glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0); + + pass = verify_color_rect(PAD, PAD, SIZE, SIZE) && pass; + pass = verify_color_rect(PAD, PAD * 2 + SIZE, SIZE, SIZE) && pass; + pass = verify_color_rect(PAD, PAD * 3 + SIZE * 2, SIZE, SIZE) && pass; + + glutSwapBuffers(); + + return pass ? PIGLIT_SUCCESS : PIGLIT_FAILURE; +} + +void +piglit_init(int argc, char **argv) +{ + piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE); + + piglit_require_extension("GL_EXT_framebuffer_object"); + piglit_require_extension("GL_EXT_framebuffer_blit"); +} |