From 219cb607651251ef406cf9bdb07f3bb17dcdda1a Mon Sep 17 00:00:00 2001 From: Neil Roberts Date: Mon, 27 Feb 2012 11:27:26 +0000 Subject: [PATCH] New test for reading back data from a GL_LUMINANCE texture There is currently a bug in Mesa where reading back values from a GL_LUMINANCE texture via a framebuffer object with glReadPixels sets all three of the RGB components to the luminance value where according to the spec it should only set the R component. https://bugs.freedesktop.org/show_bug.cgi?id=46679 --- tests/all.tests | 1 + tests/texturing/CMakeLists.gl.txt | 1 + tests/texturing/luminance-texture.c | 180 +++++++++++++++++++++++++++++++++++ 3 files changed, 182 insertions(+), 0 deletions(-) create mode 100644 tests/texturing/luminance-texture.c diff --git a/tests/all.tests b/tests/all.tests index e4d56b8..493b1c5 100644 --- a/tests/all.tests +++ b/tests/all.tests @@ -709,6 +709,7 @@ add_plain_test(texturing, 'texture-integer') add_plain_test(texturing, 'texture-packed-formats') add_plain_test(texturing, 'texture-rg') add_plain_test(texturing, 'tex-srgb') +add_plain_test(texturing, 'luminance-texture') def texwrap_test(args): test = PlainExecTest(args + ['-fbo']) diff --git a/tests/texturing/CMakeLists.gl.txt b/tests/texturing/CMakeLists.gl.txt index 6e12cc0..9935243 100644 --- a/tests/texturing/CMakeLists.gl.txt +++ b/tests/texturing/CMakeLists.gl.txt @@ -82,5 +82,6 @@ add_executable (texsubimage texsubimage.c) add_executable (texture-al texture-al.c) add_executable (texture-rg texture-rg.c) add_executable (texwrap texwrap.c) +add_executable (luminance-texture luminance-texture.c) # vim: ft=cmake: diff --git a/tests/texturing/luminance-texture.c b/tests/texturing/luminance-texture.c new file mode 100644 index 0000000..e2e942a --- /dev/null +++ b/tests/texturing/luminance-texture.c @@ -0,0 +1,180 @@ +/* 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 INd 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. + */ + +#include "piglit-util.h" + +/** + * @file luminance-texture.c + * + * Tests on reading back pixels from a texture and framebuffer in + * GL_LUMINANCE format. + * + * There is currently a bug in Mesa's glReadPixels where mapping the + * internal components of a luminance framebuffer to RGBA assigns the + * luminance value to all three RGB components where it should + * apparently only assign to the R component. + * + * https://bugs.freedesktop.org/show_bug.cgi?id=46679 + */ + +int piglit_width = 32; +int piglit_height = 32; +int piglit_window_mode = GLUT_DOUBLE | GLUT_RGB | GLUT_ALPHA; + +enum piglit_result +piglit_display() +{ + /* UNREACHED */ + return PIGLIT_FAIL; +} + +static bool +try_read_pixels(GLuint tex) +{ + bool pass = true; + GLuint fbo; + GLenum status; + + glGenFramebuffersEXT(1, &fbo); + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo); + glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, + GL_COLOR_ATTACHMENT0_EXT, + GL_TEXTURE_2D, + tex, 0); + + status = glCheckFramebufferStatus(GL_FRAMEBUFFER_EXT); + if (status != GL_FRAMEBUFFER_COMPLETE_EXT) { + printf("Skipping glReadPixels test " + "(luminance FBO not supported)\n"); + } else { + GLubyte luminance_value = 0x00; + GLubyte rgba_value[4] = { 0x00, 0x00, 0x00, 0x00 }; + + glReadPixels(0, 0, 1, 1, + GL_LUMINANCE, GL_UNSIGNED_BYTE, + &luminance_value); + if (luminance_value != 0x01) { + printf("luminance value of framebuffer: " + "expected: 0x01, " + "received: 0x%02x\n", + luminance_value); + } + + glReadPixels(0, 0, 1, 1, + GL_RGBA, GL_UNSIGNED_BYTE, + rgba_value); + + if (rgba_value[0] != 0x01 || + rgba_value[1] != 0x00 || + rgba_value[2] != 0x00 || + rgba_value[3] != 0xff) { + printf("rgba value of framebuffer: " + "expected: 0x010000ff, " + "received: 0x%02x%02x%02x%02x\n", + rgba_value[0], + rgba_value[1], + rgba_value[2], + rgba_value[3]); + pass = false; + } + } + + glDeleteFramebuffersEXT(1, &fbo); + + return pass; +} + +void +piglit_init(int argc, char **argv) +{ + bool pass = true; + GLuint tex; + GLubyte luminance_value = 0x01; + GLubyte rgba_value[4]; + + /* Generate a 1x1 luminance texture with the single texel + value 0x1 */ + glGenTextures(1, &tex); + glBindTexture(GL_TEXTURE_2D, tex); + + glTexImage2D(GL_TEXTURE_2D, + 0, /* level */ + GL_LUMINANCE, /* internal format */ + 1, 1, /* width/height */ + 0, /* border */ + GL_LUMINANCE, /* data format */ + GL_UNSIGNED_BYTE, /* data type */ + &luminance_value); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + + /* Read back the texture as GL_LUMINANCE. This should give + back exactly what we put in */ + luminance_value = 0x00; + glGetTexImage(GL_TEXTURE_2D, + 0, /* level */ + GL_LUMINANCE, + GL_UNSIGNED_BYTE, + &luminance_value); + + if (luminance_value != 0x01) { + printf("luminance value of texture: expected: 0x01, " + "received: 0x%02x\n", + luminance_value); + pass = false; + } + + /* Read back the texture as RGBA. This should only fill in the + R component */ + memset(rgba_value, 0xde, sizeof (rgba_value)); + glGetTexImage(GL_TEXTURE_2D, + 0, /* level */ + GL_RGBA, + GL_UNSIGNED_BYTE, + rgba_value); + + if (rgba_value[0] != 0x01 || + rgba_value[1] != 0x00 || + rgba_value[2] != 0x00 || + rgba_value[3] != 0xff) { + printf("rgba value of texture: expected: 0x010000ff, " + "received: 0x%02x%02x%02x%02x\n", + rgba_value[0], + rgba_value[1], + rgba_value[2], + rgba_value[3]); + pass = false; + } + + /* Try the same thing using glReadPixels through a + framebuffer */ + if (!piglit_is_extension_supported("EXT_framebuffer_object")) { + printf("Skipping glReadPixels test (no FBO extension)\n"); + } else { + if (!try_read_pixels(tex)) { + pass = false; + } + } + + glDeleteTextures(1, &tex); + + piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL); +} -- 1.7.3.16.g9464b