On Thu, Mar 8, 2012 at 2:15 PM, Brian Paul <span dir="ltr">&lt;<a href="mailto:brianp@vmware.com">brianp@vmware.com</a>&gt;</span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div class="im">On 03/08/2012 03:12 PM, Anuj Phogat wrote:<br>
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
<br>
On Thu, Mar 8, 2012 at 7:22 AM, Brian Paul &lt;<a href="mailto:brianp@vmware.com" target="_blank">brianp@vmware.com</a><br></div><div><div class="h5">
&lt;mailto:<a href="mailto:brianp@vmware.com" target="_blank">brianp@vmware.com</a>&gt;&gt; wrote:<br>
<br>
    Test various combinations of getting a luminance texture.<br>
<br>
    See <a href="https://bugs.freedesktop.org/show_bug.cgi?id=46679" target="_blank">https://bugs.freedesktop.org/<u></u>show_bug.cgi?id=46679</a><br>
    ---<br>
      tests/all.tests                         |    1 +<br>
      tests/texturing/CMakeLists.gl.<u></u>txt       |    1 +<br>
      tests/texturing/getteximage-<u></u>luminance.c |  198<br>
    ++++++++++++++++++++++++++++++<u></u>+<br>
      3 files changed, 200 insertions(+), 0 deletions(-)<br>
      create mode 100644 tests/texturing/getteximage-<u></u>luminance.c<br>
<br>
    diff --git a/tests/all.tests b/tests/all.tests<br>
    index e4d56b8..1231559 100644<br>
    --- a/tests/all.tests<br>
    +++ b/tests/all.tests<br>
    @@ -669,6 +669,7 @@ add_plain_test(texturing, &#39;gen-nonzero-unit&#39;)<br>
      add_plain_test(texturing, &#39;gen-texsubimage&#39;)<br>
      add_plain_test(texturing, &#39;getteximage-formats&#39;)<br>
      add_plain_test(texturing, &#39;getteximage-simple&#39;)<br>
    +add_plain_test(texturing, &#39;getteximage-luminance&#39;)<br>
<br>
      texturing[&#39;incomplete-texture-<u></u>fixed&#39;] =<br>
    concurrent_test(&#39;incomplete-<u></u>texture -auto fixed&#39;)<br>
      texturing[&#39;incomplete-texture-<u></u>arb_fp&#39;] =<br>
    concurrent_test(&#39;incomplete-<u></u>texture -auto arb_fp&#39;)<br>
    diff --git a/tests/texturing/CMakeLists.<u></u>gl.txt<br>
    b/tests/texturing/CMakeLists.<u></u>gl.txt<br>
    index 6e12cc0..b60503d 100644<br>
    --- a/tests/texturing/CMakeLists.<u></u>gl.txt<br>
    +++ b/tests/texturing/CMakeLists.<u></u>gl.txt<br>
    @@ -31,6 +31,7 @@ add_executable (gen-teximage gen-teximage.c)<br>
      add_executable (gen-texsubimage gen-texsubimage.c)<br>
      add_executable (getteximage-simple getteximage-simple.c)<br>
      add_executable (getteximage-formats getteximage-formats.c)<br>
    +add_executable (getteximage-luminance getteximage-luminance.c)<br>
      add_executable (incomplete-texture incomplete-texture.c)<br>
      add_executable (fragment-and-vertex-texturing<br>
    fragment-and-vertex-texturing.<u></u>c)<br>
      add_executable (levelclamp levelclamp.c)<br>
    diff --git a/tests/texturing/getteximage-<u></u>luminance.c<br>
    b/tests/texturing/getteximage-<u></u>luminance.c<br>
    new file mode 100644<br>
    index 0000000..3da5549<br>
    --- /dev/null<br>
    +++ b/tests/texturing/getteximage-<u></u>luminance.c<br>
    @@ -0,0 +1,198 @@<br>
    +/*<br>
    + * Copyright (c) 2012 VMware, Inc.<br>
    + *<br>
    + * Permission is hereby granted, free of charge, to any person<br>
    obtaining a<br>
    + * copy of this software and associated documentation files (the<br>
    &quot;Software&quot;),<br>
    + * to deal in the Software without restriction, including without<br>
    limitation<br>
    + * on the rights to use, copy, modify, merge, publish,<br>
    distribute, sub<br>
    + * license, and/or sell copies of the Software, and to permit<br>
    persons to whom<br>
    + * the Software is furnished to do so, subject to the following<br>
    conditions:<br>
    + *<br>
    + * The above copyright notice and this permission notice<br>
    (including the next<br>
    + * paragraph) shall be included in all copies or substantial<br>
    portions of the<br>
    + * Software.<br>
    + *<br>
    + * THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND,<br>
    + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF<br>
    + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND<br>
    + * NON-INFRINGEMENT.  IN NO EVENT SHALL VMWARE AND/OR THEIR SUPPLIERS<br>
    + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN<br>
    + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN<br>
    + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE<br>
    + * SOFTWARE.<br>
    + */<br>
    +<br>
    +/*<br>
    + * Test glGetTexImage for luminance formats.<br>
    + * Brian Paul<br>
    + * 8 Mar 2012<br>
    + */<br>
    +<br>
    +#include &quot;piglit-util.h&quot;<br>
    +<br>
    +int piglit_width = 100, piglit_height = 100;<br>
    +int piglit_window_mode = GLUT_RGBA | GLUT_DOUBLE;<br>
    +static const char *TestName = &quot;getteximage-luminance&quot;;<br>
    +static float tolerance = 2.0 / 255.0;<br>
    +<br>
    +<br>
    +static bool<br>
    +rgba_equal(const float *c1, const float *c2)<br>
    +{<br>
    +       return ((fabs(c1[0] - c2[0]) &lt; tolerance) &amp;&amp;<br>
    +               (fabs(c1[1] - c2[1]) &lt; tolerance) &amp;&amp;<br>
    +               (fabs(c1[2] - c2[2]) &lt; tolerance) &amp;&amp;<br>
    +               (fabs(c1[3] - c2[3]) &lt; tolerance));<br>
    +}<br>
    +<br>
    +<br>
    +static bool<br>
    +lum_equal(const float *l1, const float *l2)<br>
    +{<br>
    +       return fabs(*l1 - *l2) &lt; tolerance;<br>
    +}<br>
    +<br>
    +<br>
    +/*<br>
    + * Test reading back a luminance texture as luminance and RGBA.<br>
    + */<br>
    +static bool<br>
    +test_luminance(void)<br>
    +{<br>
    +       static const GLfloat lumImage[2*2] = { 0.25, 0.25, 0.25,<br>
    0.25 };<br>
    +       static const GLfloat rgbaImage[4] = { 0.25, 0.0, 0.0, 1.0 };<br>
    +       GLuint tex;<br>
    +       GLfloat test[2*2*4];<br>
    +<br>
    +       /* create 2x2 GL_LUMINANCE texture */<br>
    +       glGenTextures(1, &amp;tex);<br>
    +       glBindTexture(GL_TEXTURE_2D, tex);<br>
    +       glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 2, 2, 0,<br>
    +                    GL_LUMINANCE, GL_FLOAT, lumImage);<br>
    +<br>
    +       /* Get and check luminance image */<br>
    +       glGetTexImage(GL_TEXTURE_2D, 0, GL_LUMINANCE, GL_FLOAT, test);<br>
    +       if (!lum_equal(lumImage, test)) {<br>
    +               printf(&quot;%s: glGetTexImage(GL_LUMINANCE as&quot;<br>
    + &quot; GL_LUMINANCE) failed\n&quot;, TestName);<br>
    +               printf(&quot;  Expected %g  Found %g\n&quot;, lumImage[0],<br>
    test[0]);<br>
    +               return false;<br>
    +       }<br>
    +<br>
    +       /* Get and check rgba image */<br>
    +       glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_FLOAT, &amp;test);<br>
    +       if (!rgba_equal(rgbaImage, test)) {<br>
    +               printf(&quot;%s: glGetTexImage(GL_LUMINANCE as GL_RGBA)<br>
    failed\n&quot;,<br>
    +                      TestName);<br>
    +               printf(&quot;  Expected %g, %g, %g, %g  Found %g, %g,<br>
    %g, %g\n&quot;,<br>
    +                      rgbaImage[0], rgbaImage[1], rgbaImage[2],<br>
    rgbaImage[3],<br>
    +                      test[0], test[1], test[2], test[3]);<br>
    +               return false;<br>
    +       }<br>
    +<br>
    +       return true;<br>
    +}<br>
    +<br>
    +<br>
    +/*<br>
    + * Test reading back an RGBA texture as luminance.<br>
    + */<br>
    +static bool<br>
    +test_rgba(void)<br>
    +{<br>
    +       static const GLfloat rgbaImage[4] = { 0.5, 0.25, 0.125, 1.0 };<br>
    +       static const GLfloat lumImage[1] = { 0.5 };<br>
<br>
I think expected value should be: l = 0.5 + 0.25 + 0.125<br>
</div></div></blockquote>
<br>
No, per the GL spec and testing with NVIDIA&#39;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&#39;s a test for that also, below.</blockquote>

<div>Thanks for explaining Brian. Test below is FBO + glReadPixels(GL_LUMINANCE as GL_RGBA).</div><div>We can also add a case of FBO + glReadPixels(GL_RGBA as GL_LUMINANCE) if it is not tested in any other piglit test.</div>

<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I&#39;m getting this failure on Sandybridge:<br>
  getteximage-luminance: glGetTexImage(GL_RGBA as GL_LUMINANCE) failed<br>
  Expected 0.5  Found 0.878431<br>
<br>
There is another failure for which i&#39;ll send out a patch:<br>
getteximage-luminance: glReadPixels(GL_LUMINANCE as GL_RGBA) failed<br>
   Expected 0.25, 0, 0, 1  Found 0.25098, 0.25098, 0.25098, 1<br>
</blockquote>
<br></div>
As I wrote in the bug report, I have patches that fix these issues and I&#39;ll post them later.</blockquote><div>I noticed you pushed the changes.</div><div><br></div><div>- Anuj </div></div><br>