[Piglit] [PATCH 2/2] getteximage-luminance: test readback of GL_LUMINANCE textures
Anuj Phogat
anuj.phogat at gmail.com
Thu Mar 8 14:12:14 PST 2012
On Thu, Mar 8, 2012 at 7:22 AM, Brian Paul <brianp at vmware.com> wrote:
> Test various combinations of getting a luminance texture.
>
> See https://bugs.freedesktop.org/show_bug.cgi?id=46679
> ---
> tests/all.tests | 1 +
> tests/texturing/CMakeLists.gl.txt | 1 +
> tests/texturing/getteximage-luminance.c | 198
> +++++++++++++++++++++++++++++++
> 3 files changed, 200 insertions(+), 0 deletions(-)
> create mode 100644 tests/texturing/getteximage-luminance.c
>
> diff --git a/tests/all.tests b/tests/all.tests
> index e4d56b8..1231559 100644
> --- a/tests/all.tests
> +++ b/tests/all.tests
> @@ -669,6 +669,7 @@ add_plain_test(texturing, 'gen-nonzero-unit')
> add_plain_test(texturing, 'gen-texsubimage')
> add_plain_test(texturing, 'getteximage-formats')
> add_plain_test(texturing, 'getteximage-simple')
> +add_plain_test(texturing, 'getteximage-luminance')
>
> texturing['incomplete-texture-fixed'] =
> concurrent_test('incomplete-texture -auto fixed')
> texturing['incomplete-texture-arb_fp'] =
> concurrent_test('incomplete-texture -auto arb_fp')
> diff --git a/tests/texturing/CMakeLists.gl.txt
> b/tests/texturing/CMakeLists.gl.txt
> index 6e12cc0..b60503d 100644
> --- a/tests/texturing/CMakeLists.gl.txt
> +++ b/tests/texturing/CMakeLists.gl.txt
> @@ -31,6 +31,7 @@ add_executable (gen-teximage gen-teximage.c)
> add_executable (gen-texsubimage gen-texsubimage.c)
> add_executable (getteximage-simple getteximage-simple.c)
> add_executable (getteximage-formats getteximage-formats.c)
> +add_executable (getteximage-luminance getteximage-luminance.c)
> add_executable (incomplete-texture incomplete-texture.c)
> add_executable (fragment-and-vertex-texturing
> fragment-and-vertex-texturing.c)
> add_executable (levelclamp levelclamp.c)
> diff --git a/tests/texturing/getteximage-luminance.c
> b/tests/texturing/getteximage-luminance.c
> new file mode 100644
> index 0000000..3da5549
> --- /dev/null
> +++ b/tests/texturing/getteximage-luminance.c
> @@ -0,0 +1,198 @@
> +/*
> + * Copyright (c) 2012 VMware, Inc.
> + *
> + * 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
> + * on the rights to use, copy, modify, merge, publish, distribute, sub
> + * license, 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
> + * NON-INFRINGEMENT. IN NO EVENT SHALL VMWARE AND/OR THEIR SUPPLIERS
> + * 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.
> + */
> +
> +/*
> + * Test glGetTexImage for luminance formats.
> + * Brian Paul
> + * 8 Mar 2012
> + */
> +
> +#include "piglit-util.h"
> +
> +int piglit_width = 100, piglit_height = 100;
> +int piglit_window_mode = GLUT_RGBA | GLUT_DOUBLE;
> +static const char *TestName = "getteximage-luminance";
> +static float tolerance = 2.0 / 255.0;
> +
> +
> +static bool
> +rgba_equal(const float *c1, const float *c2)
> +{
> + return ((fabs(c1[0] - c2[0]) < tolerance) &&
> + (fabs(c1[1] - c2[1]) < tolerance) &&
> + (fabs(c1[2] - c2[2]) < tolerance) &&
> + (fabs(c1[3] - c2[3]) < tolerance));
> +}
> +
> +
> +static bool
> +lum_equal(const float *l1, const float *l2)
> +{
> + return fabs(*l1 - *l2) < tolerance;
> +}
> +
> +
> +/*
> + * Test reading back a luminance texture as luminance and RGBA.
> + */
> +static bool
> +test_luminance(void)
> +{
> + static const GLfloat lumImage[2*2] = { 0.25, 0.25, 0.25, 0.25 };
> + static const GLfloat rgbaImage[4] = { 0.25, 0.0, 0.0, 1.0 };
> + GLuint tex;
> + GLfloat test[2*2*4];
> +
> + /* create 2x2 GL_LUMINANCE texture */
> + glGenTextures(1, &tex);
> + glBindTexture(GL_TEXTURE_2D, tex);
> + glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 2, 2, 0,
> + GL_LUMINANCE, GL_FLOAT, lumImage);
> +
> + /* Get and check luminance image */
> + glGetTexImage(GL_TEXTURE_2D, 0, GL_LUMINANCE, GL_FLOAT, test);
> + if (!lum_equal(lumImage, test)) {
> + printf("%s: glGetTexImage(GL_LUMINANCE as"
> + " GL_LUMINANCE) failed\n", TestName);
> + printf(" Expected %g Found %g\n", lumImage[0], test[0]);
> + return false;
> + }
> +
> + /* Get and check rgba image */
> + glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_FLOAT, &test);
> + if (!rgba_equal(rgbaImage, test)) {
> + printf("%s: glGetTexImage(GL_LUMINANCE as GL_RGBA)
> failed\n",
> + TestName);
> + printf(" Expected %g, %g, %g, %g Found %g, %g, %g, %g\n",
> + rgbaImage[0], rgbaImage[1], rgbaImage[2],
> rgbaImage[3],
> + test[0], test[1], test[2], test[3]);
> + return false;
> + }
> +
> + return true;
> +}
> +
> +
> +/*
> + * Test reading back an RGBA texture as luminance.
> + */
> +static bool
> +test_rgba(void)
> +{
> + static const GLfloat rgbaImage[4] = { 0.5, 0.25, 0.125, 1.0 };
> + static const GLfloat lumImage[1] = { 0.5 };
>
I think expected value should be: l = 0.5 + 0.25 + 0.125
I'm getting this failure on Sandybridge:
getteximage-luminance: glGetTexImage(GL_RGBA as GL_LUMINANCE) failed
Expected 0.5 Found 0.878431
There is another failure for which i'll send out a patch:
getteximage-luminance: glReadPixels(GL_LUMINANCE as GL_RGBA) failed
Expected 0.25, 0, 0, 1 Found 0.25098, 0.25098, 0.25098, 1
+ GLuint tex;
> + GLfloat test[2*2*4];
> +
> + /* create 1x1 GL_RGBA texture */
> + glGenTextures(1, &tex);
> + glBindTexture(GL_TEXTURE_2D, tex);
> + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0,
> + GL_RGBA, GL_FLOAT, rgbaImage);
> +
> + /* Get and check luminance image */
> + glGetTexImage(GL_TEXTURE_2D, 0, GL_LUMINANCE, GL_FLOAT, test);
> + if (!lum_equal(lumImage, test)) {
> + printf("%s: glGetTexImage(GL_RGBA as GL_LUMINANCE)
> failed\n",
> + TestName);
> + printf(" Expected %g Found %g\n", lumImage[0], test[0]);
> + return false;
> + }
> +
> + return true;
> +}
> +
> +
> +/*
> + * Test reading back a luminance texture via FBO + glReadPixels.
> + */
> +static bool
> +test_fbo_readpixels(void)
> +{
> + static const GLfloat lumImage[2*2] = { 0.25, 0.25, 0.25, 0.25 };
> + static const GLfloat rgbaImage[4] = { 0.25, 0.0, 0.0, 1.0 };
> + GLuint tex, fbo;
> + GLfloat test[2*2*4];
> + GLenum status;
> +
> + if (!piglit_is_extension_supported("GL_ARB_framebuffer_object"))
> + return true;
> +
> + /* create 2x2 GL_LUMINANCE texture */
> + glGenTextures(1, &tex);
> + glBindTexture(GL_TEXTURE_2D, tex);
> + glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 2, 2, 0,
> + GL_LUMINANCE, GL_FLOAT, lumImage);
> +
> + /* create an FBO to wrap the texture so we can read it back
> + * with glReadPixels
> + */
> + glGenFramebuffers(1, &fbo);
> + glBindFramebuffer(GL_FRAMEBUFFER, fbo);
> + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0_EXT,
> + GL_TEXTURE_2D, tex, 0);
> +
> + status = glCheckFramebufferStatus(GL_FRAMEBUFFER_EXT);
> + if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
> + /* can't test glReadPixels from a luminance fbo/texture */
> + if (!piglit_automatic) {
> + printf("Skipping FBO ReadPixels test\n");
> + }
> + return true;
> + }
> +
> + /* get rgba image */
> + glReadPixels(0, 0, 1, 1, GL_RGBA, GL_FLOAT, test);
> + if (!rgba_equal(rgbaImage, test)) {
> + printf("%s: glReadPixels(GL_LUMINANCE as GL_RGBA)
> failed\n",
> + TestName);
> + printf(" Expected %g, %g, %g, %g Found %g, %g, %g, %g\n",
> + rgbaImage[0], rgbaImage[1], rgbaImage[2],
> rgbaImage[3],
> + test[0], test[1], test[2], test[3]);
> + return false;
> + }
> +
> + return true;
> +}
> +
> +
> +
> +enum piglit_result
> +piglit_display(void)
> +{
> + bool pass = true;
> +
> + pass = test_luminance() && pass;
> + pass = test_rgba() && pass;
> + pass = test_fbo_readpixels() && pass;
> +
> + return pass ? PIGLIT_PASS : PIGLIT_FAIL;
> +}
> +
> +
> +void
> +piglit_init(int argc, char **argv)
> +{
> + glewInit();
> +}
> --
> 1.7.3.4
>
> _______________________________________________
> Piglit mailing list
> Piglit at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/piglit
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/piglit/attachments/20120308/d905029a/attachment.html>
More information about the Piglit
mailing list