<br>On Thu, Mar 8, 2012 at 7:22 AM, 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">

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/show_bug.cgi?id=46679</a><br>
---<br>
 tests/all.tests                         |    1 +<br>
 tests/texturing/CMakeLists.gl.txt       |    1 +<br>
 tests/texturing/getteximage-luminance.c |  198 +++++++++++++++++++++++++++++++<br>
 3 files changed, 200 insertions(+), 0 deletions(-)<br>
 create mode 100644 tests/texturing/getteximage-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-fixed&#39;] = concurrent_test(&#39;incomplete-texture -auto fixed&#39;)<br>
 texturing[&#39;incomplete-texture-arb_fp&#39;] = concurrent_test(&#39;incomplete-texture -auto arb_fp&#39;)<br>
diff --git a/tests/texturing/CMakeLists.gl.txt b/tests/texturing/CMakeLists.gl.txt<br>
index 6e12cc0..b60503d 100644<br>
--- a/tests/texturing/CMakeLists.gl.txt<br>
+++ b/tests/texturing/CMakeLists.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 fragment-and-vertex-texturing.c)<br>
 add_executable (levelclamp levelclamp.c)<br>
diff --git a/tests/texturing/getteximage-luminance.c b/tests/texturing/getteximage-luminance.c<br>
new file mode 100644<br>
index 0000000..3da5549<br>
--- /dev/null<br>
+++ b/tests/texturing/getteximage-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 obtaining a<br>
+ * copy of this software and associated documentation files (the &quot;Software&quot;),<br>
+ * to deal in the Software without restriction, including without limitation<br>
+ * on the rights to use, copy, modify, merge, publish, distribute, sub<br>
+ * license, and/or sell copies of the Software, and to permit persons to whom<br>
+ * the Software is furnished to do so, subject to the following conditions:<br>
+ *<br>
+ * The above copyright notice and this permission notice (including the next<br>
+ * paragraph) shall be included in all copies or substantial 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, 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], 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) failed\n&quot;,<br>
+                      TestName);<br>
+               printf(&quot;  Expected %g, %g, %g, %g  Found %g, %g, %g, %g\n&quot;,<br>
+                      rgbaImage[0], rgbaImage[1], rgbaImage[2], 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></blockquote><div>I think expected value should be: l = 0.5 + 0.25 + 0.125</div><div>I&#39;m getting this failure on Sandybridge:</div><div> getteximage-luminance: glGetTexImage(GL_RGBA as GL_LUMINANCE) failed</div>

<div> Expected 0.5  Found 0.878431</div><div><br></div><div>There is another failure for which i&#39;ll send out a patch:</div><div><div>getteximage-luminance: glReadPixels(GL_LUMINANCE as GL_RGBA) failed</div><div>  Expected 0.25, 0, 0, 1  Found 0.25098, 0.25098, 0.25098, 1</div>

</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+       GLuint tex;<br>
+       GLfloat test[2*2*4];<br>
+<br>
+       /* create 1x1 GL_RGBA texture */<br>
+       glGenTextures(1, &amp;tex);<br>
+       glBindTexture(GL_TEXTURE_2D, tex);<br>
+       glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0,<br>
+                    GL_RGBA, GL_FLOAT, rgbaImage);<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_RGBA as GL_LUMINANCE) failed\n&quot;,<br>
+                      TestName);<br>
+               printf(&quot;  Expected %g  Found %g\n&quot;, lumImage[0], test[0]);<br>
+               return false;<br>
+       }<br>
+<br>
+       return true;<br>
+}<br>
+<br>
+<br>
+/*<br>
+ * Test reading back a luminance texture via FBO + glReadPixels.<br>
+ */<br>
+static bool<br>
+test_fbo_readpixels(void)<br>
+{<br>
+       static const GLfloat lumImage[2*2] = { 0.25, 0.25, 0.25, 0.25 };<br>
+       static const GLfloat rgbaImage[4] = { 0.25, 0.0, 0.0, 1.0 };<br>
+       GLuint tex, fbo;<br>
+       GLfloat test[2*2*4];<br>
+       GLenum status;<br>
+<br>
+       if (!piglit_is_extension_supported(&quot;GL_ARB_framebuffer_object&quot;))<br>
+               return true;<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>
+       /* create an FBO to wrap the texture so we can read it back<br>
+        * with glReadPixels<br>
+        */<br>
+       glGenFramebuffers(1, &amp;fbo);<br>
+       glBindFramebuffer(GL_FRAMEBUFFER, fbo);<br>
+       glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0_EXT,<br>
+                              GL_TEXTURE_2D, tex, 0);<br>
+<br>
+       status = glCheckFramebufferStatus(GL_FRAMEBUFFER_EXT);<br>
+       if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {<br>
+               /* can&#39;t test glReadPixels from a luminance fbo/texture */<br>
+               if (!piglit_automatic) {<br>
+                       printf(&quot;Skipping FBO ReadPixels test\n&quot;);<br>
+               }<br>
+               return true;<br>
+       }<br>
+<br>
+       /* get rgba image */<br>
+       glReadPixels(0, 0, 1, 1, GL_RGBA, GL_FLOAT, test);<br>
+       if (!rgba_equal(rgbaImage, test)) {<br>
+               printf(&quot;%s: glReadPixels(GL_LUMINANCE as GL_RGBA) failed\n&quot;,<br>
+                      TestName);<br>
+               printf(&quot;  Expected %g, %g, %g, %g  Found %g, %g, %g, %g\n&quot;,<br>
+                      rgbaImage[0], rgbaImage[1], rgbaImage[2], rgbaImage[3],<br>
+                      test[0], test[1], test[2], test[3]);<br>
+               return false;<br>
+       }<br>
+<br>
+       return true;<br>
+}<br>
+<br>
+<br>
+<br>
+enum piglit_result<br>
+piglit_display(void)<br>
+{<br>
+       bool pass = true;<br>
+<br>
+       pass = test_luminance() &amp;&amp; pass;<br>
+       pass = test_rgba() &amp;&amp; pass;<br>
+       pass = test_fbo_readpixels() &amp;&amp; pass;<br>
+<br>
+       return pass ? PIGLIT_PASS : PIGLIT_FAIL;<br>
+}<br>
+<br>
+<br>
+void<br>
+piglit_init(int argc, char **argv)<br>
+{<br>
+       glewInit();<br>
+}<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.7.3.4<br>
<br>
_______________________________________________<br>
Piglit mailing list<br>
<a href="mailto:Piglit@lists.freedesktop.org">Piglit@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/piglit" target="_blank">http://lists.freedesktop.org/mailman/listinfo/piglit</a><br>
</font></span></blockquote></div><br>