<div dir="ltr">On 26 August 2013 11:51, Jacob Penner <span dir="ltr"><<a href="mailto:jkpenner91@gmail.com" target="_blank">jkpenner91@gmail.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">---<br>
 tests/spec/gl-3.2/layered-rendering/readpixels.c | 223 +++++++++++++++++++++++<br>
 1 file changed, 223 insertions(+)<br>
 create mode 100644 tests/spec/gl-3.2/layered-rendering/readpixels.c<br>
<br>
diff --git a/tests/spec/gl-3.2/layered-rendering/readpixels.c b/tests/spec/gl-3.2/layered-rendering/readpixels.c<br>
new file mode 100644<br>
index 0000000..494bd95<br>
--- /dev/null<br>
+++ b/tests/spec/gl-3.2/layered-rendering/readpixels.c<br>
@@ -0,0 +1,223 @@<br>
+/*<br>
+ * Copyright © 2013 Intel Corporation<br>
+ *<br>
+ * Permission is hereby granted, free of charge, to any person obtaining a<br>
+ * copy of this software and associated documentation files (the "Software"),<br>
+ * to deal in the Software without restriction, including without limitation<br>
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,<br>
+ * and/or sell copies of the Software, and to permit persons to whom the<br>
+ * 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 "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br>
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL<br>
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br>
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING<br>
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS<br>
+ * IN THE SOFTWARE.<br>
+ */<br>
+<br>
+<br>
+/** @file readpixel.c<br>
+ *<br>
+ * Section 4.4.7(Framebuffer Objects) From GL spec 3.2 core:<br>
+ *<br>
+ * When commands such as ReadPixels read from a layered framebuffer, the<br>
+ * image at layer zero of the selected attachment is always used to obtain<br>
+ * pixel values.<br>
+ *<br>
+ * Test Layout<br>
+ *<br>
+ *       tex1     tex2<br>
+ *    *--------*--------*      texture 1 will start with different colors in<br>
+ *    | layer2 | layer2 |     each layer.<br>
+ *    *--------*--------*<br>
+ *    | layer1 | layer1 |      texture 2 will start with all layers set to<br>
+ *    *--------*--------*     black.<br>
+ *<br>
+ * Final Result<br>
+ *    After using glReadPixels() to retrieve data from tex1 and assigning<br>
+ *   the data to tex2, the tex2 color for layer1 will be the same as the color<br>
+ *   for tex1's layer1 and tex2's color in layer 2 should still be black.<br>
+ */ <br></blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+<br>
+#include "piglit-util-gl-common.h"<br>
+<br>
+PIGLIT_GL_TEST_CONFIG_BEGIN<br>
+<br>
+       config.supports_gl_compat_version = 31;<br>
+       config.supports_gl_core_version = 31;<br>
+<br>
+       config.window_width  = 128;<br>
+       config.window_height = 128;<br>
+       config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;<br>
+<br>
+PIGLIT_GL_TEST_CONFIG_END<br>
+<br>
+static GLuint fbo;<br>
+static GLuint texture[2];<br>
+<br>
+static const float colors[3][3] = {<br>
+       {0.0, 1.0, 0.0},<br>
+       {0.0, 0.0, 1.0},<br>
+       {0.0, 0.0, 0.0}<br>
+};<br>
+<br>
+bool<br>
+display_layered_texture(int x, int y, int w, int h, int texWidth, int texHeight,<br>
+                       GLenum textureType, GLuint texture, int layers) {<br>
+       GLuint tempFBO;<br>
+       unsigned int i;<br>
+       int dx1, dy1, dx2, dy2;<br>
+<br>
+       dx1 = x;<br>
+       dx2 = x+w;<br>
+<br>
+       /* Gen temp fbo */<br>
+       glGenFramebuffers(1, &tempFBO);<br>
+<br>
+       /* loop through each layer, attaching the individual layer to the<br>
+        * temp fbo, then blit fbo to the correct location on screen<br>
+        */<br>
+       for(i = 0; i < layers; i++) {<br>
+               GLenum framebufferStatus;<br>
+<br>
+               dy1 = y + (i)  *(h/layers);<br>
+               dy2 = y + (i+1)*(h/layers);<br>
+<br>
+               glBindFramebuffer(GL_FRAMEBUFFER, tempFBO);<br>
+               glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,<br>
+                                         texture, 0, i);<br>
+<br>
+               framebufferStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER);<br>
+               if(framebufferStatus != GL_FRAMEBUFFER_COMPLETE) {<br>
+                       printf("Framebuffer Status: %s\n",<br>
+                              piglit_get_gl_enum_name(framebufferStatus));<br>
+                       return false;<br>
+               }<br>
+<br>
+               glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);<br>
+               glBindFramebuffer(GL_READ_FRAMEBUFFER, tempFBO);<br>
+               glBlitFramebuffer(0, 0, texWidth, texHeight,<br>
+                                 dx1, dy1, dx2, dy2, GL_COLOR_BUFFER_BIT,<br>
+                                 GL_NEAREST);<br>
+       }<br>
+<br>
+       /* Cleanup temp fbo */<br>
+       glBindFramebuffer(GL_FRAMEBUFFER, 0);<br>
+       glDeleteFramebuffers(1, &tempFBO);<br>
+<br>
+       return piglit_check_gl_error(GL_NO_ERROR);<br>
+}<br>
+<br>
+GLuint<br>
+CreateTextureLayered(int w, int h, int d, GLenum dataType, void *data)<br>
+{<br>
+       GLuint tex;<br>
+<br>
+       glGenTextures(1, &tex);<br>
+       glBindTexture(GL_TEXTURE_3D, tex);<br>
+       glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);<br>
+       glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);<br>
+       glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_REPEAT);<br>
+       glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_REPEAT);<br>
+       glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_REPEAT);<br>
+       glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB, w, h, d, 0, GL_RGB,<br>
+                    dataType, data);<br>
+       glBindTexture(GL_TEXTURE_3D, 0);<br>
+<br>
+       if(!piglit_check_gl_error(GL_NO_ERROR)) {<br>
+               return 0;<br>
+       }<br>
+       else {<br>
+               return tex;<br>
+       }<br>
+}<br>
+<br>
+void<br>
+piglit_init(int argc, char **argv)<br>
+{<br>
+       int i, j;<br>
+       float colorData[2][piglit_width*piglit_height*3];<br>
+       float *resultData = malloc(2*3*piglit_width*piglit_height*sizeof(float));<br>
+<br>
+       /* fill in colorData */<br>
+       for(j = 0; j < 2; j++)<br>
+       for(i = 0; i < piglit_width*piglit_height; i++) {<br>
+               colorData[j][i*3+0] = colors[j][0];<br>
+               colorData[j][i*3+1] = colors[j][1];<br>
+               colorData[j][i*3+2] = colors[j][2];<br>
+       }<br>
+<br>
+       /* clear resultData to a color */<br>
+       for(i = 0; i < 2*piglit_width*piglit_height; i++) {<br>
+               resultData[i*3+0] = colors[j][0];<br>
+               resultData[i*3+1] = colors[j][1];<br>
+               resultData[i*3+2] = colors[j][2];<br>
+       }<br>
+<br>
+       glGenFramebuffers(1, &fbo);<br>
+       glBindFramebuffer(GL_FRAMEBUFFER, fbo);<br>
+<br>
+       /* Create the Source framebuffer object */<br>
+       texture[0] = CreateTextureLayered(piglit_width, piglit_height, 2,<br>
+                                         GL_FLOAT, colorData);<br>
+<br>
+       /* Check if texture was generated */<br>
+       if(texture[0] == 0) {<br>
+               piglit_report_result(PIGLIT_FAIL);<br>
+       }<br>
+<br>
+       glBindTexture(GL_TEXTURE_3D, texture[0]);<br>
+       glFramebufferTexture3D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,<br>
+                              GL_TEXTURE_3D, texture[0], 0, 0);<br></blockquote><div><br></div><div>Once we get here, all we should need to do is call piglit_probe_rect_rgb() (which internally calls ReadPixels()), and then report a piglit result.  There's no need to copy the images to the screen.<br>
<br>That should make it possible to simplify the test significantly--we now only need one texture, piglit_display() can be empty, and we don't need the display_layered_texture() function at all anymore.<br></div><div>
 </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+<br>
+       /* Get Pixel Data */<br>
+       glReadPixels(0, 0, piglit_width, piglit_height,<br>
+                    GL_RGB, GL_FLOAT, resultData);<br>
+<br>
+       /* Create new texture with the retrieved pixel data */<br>
+       texture[1] = CreateTextureLayered(piglit_width, piglit_height, 2,<br>
+                                         GL_FLOAT, resultData);<br>
+<br>
+       if(!piglit_check_gl_error(GL_NO_ERROR)) {<br>
+               piglit_report_result(PIGLIT_FAIL);<br>
+       }<br>
+}<br>
+<br>
+enum piglit_result<br>
+piglit_display(void)<br>
+{<br>
+       bool pass = true;<br>
+<br>
+       /* Display Source Texture */<br>
+       display_layered_texture(0, 0, piglit_width/2, piglit_height,<br>
+                               piglit_width, piglit_height, GL_TEXTURE_3D,<br>
+                               texture[0], 2);<br>
+<br>
+       /* Display Dest Texture */<br>
+       display_layered_texture(piglit_width/2, 0, piglit_width/2,<br>
+                               piglit_height, piglit_width, piglit_height,<br>
+                               GL_TEXTURE_3D, texture[1], 2);<br>
+<br>
+       pass = piglit_probe_rect_rgb(0, 0, piglit_width, piglit_height/2,<br>
+                                    colors[0]) && pass;<br>
+<br>
+       pass = piglit_probe_rect_rgb(0, piglit_height/2, piglit_width/2,<br>
+                                    piglit_height/2, colors[1]) && pass;<br>
+<br>
+       pass = piglit_probe_rect_rgb(piglit_width/2, piglit_height/2,<br>
+                                    piglit_width/2, piglit_height/2,<br>
+                                    colors[2]) && pass;<br>
+<br>
+       if(!piglit_check_gl_error(GL_NO_ERROR)) {<br>
+               pass = false;<br>
+       }<br>
+<br>
+       piglit_present_results();<br>
+       return pass ? PIGLIT_PASS : PIGLIT_FAIL;<br>
+}<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.8.3.1<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></div></div>