[Piglit] [PATCH 2/2] getteximage-luminance: test readback of GL_LUMINANCE textures

Brian Paul brian.e.paul at gmail.com
Fri Mar 9 09:46:00 PST 2012


On Fri, Mar 9, 2012 at 9:44 AM, Anuj Phogat <anuj.phogat at gmail.com> wrote:
> On Thu, Mar 8, 2012 at 2:15 PM, Brian Paul <brianp at vmware.com> wrote:
>>
>> On 03/08/2012 03:12 PM, Anuj Phogat wrote:
>>>
>>>
>>> On Thu, Mar 8, 2012 at 7:22 AM, Brian Paul <brianp at vmware.com
>>> <mailto: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
>>
>>
>> No, per the GL spec and testing with NVIDIA's driver, the result for
>> glGetTexImage() should be 0.5.  But if the texture is read back with
>> glReadPixels using an FBO wrapper, the result should be 0.5+0.25+0.125
>>  There's a test for that also, below.
>
> Thanks for explaining Brian. Test below is FBO + glReadPixels(GL_LUMINANCE
> as GL_RGBA).
> We can also add a case of FBO + glReadPixels(GL_RGBA as GL_LUMINANCE) if it
> is not tested in any other piglit test.

I'm not sure if it's tested elsewhere but I can quickly add it to this test.

-Brian


More information about the Piglit mailing list