[Piglit] [PATCH 7/9] GL 3.2: Test ReadPixels() works properly with layered framebuffers.
Paul Berry
stereotype441 at gmail.com
Tue Aug 27 13:45:10 PDT 2013
On 26 August 2013 11:51, Jacob Penner <jkpenner91 at gmail.com> wrote:
> ---
> tests/spec/gl-3.2/layered-rendering/readpixels.c | 223
> +++++++++++++++++++++++
> 1 file changed, 223 insertions(+)
> create mode 100644 tests/spec/gl-3.2/layered-rendering/readpixels.c
>
> diff --git a/tests/spec/gl-3.2/layered-rendering/readpixels.c
> b/tests/spec/gl-3.2/layered-rendering/readpixels.c
> new file mode 100644
> index 0000000..494bd95
> --- /dev/null
> +++ b/tests/spec/gl-3.2/layered-rendering/readpixels.c
> @@ -0,0 +1,223 @@
> +/*
> + * Copyright © 2013 Intel Corporation
> + *
> + * 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
> + * the rights to use, copy, modify, merge, publish, distribute,
> sublicense,
> + * 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 NONINFRINGEMENT. IN NO EVENT
> SHALL
> + * THE AUTHORS OR COPYRIGHT HOLDERS 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.
> + */
> +
> +
> +/** @file readpixel.c
> + *
> + * Section 4.4.7(Framebuffer Objects) From GL spec 3.2 core:
> + *
> + * When commands such as ReadPixels read from a layered framebuffer, the
> + * image at layer zero of the selected attachment is always used to obtain
> + * pixel values.
> + *
> + * Test Layout
> + *
> + * tex1 tex2
> + * *--------*--------* texture 1 will start with different colors
> in
> + * | layer2 | layer2 | each layer.
> + * *--------*--------*
> + * | layer1 | layer1 | texture 2 will start with all layers set to
> + * *--------*--------* black.
> + *
> + * Final Result
> + * After using glReadPixels() to retrieve data from tex1 and assigning
> + * the data to tex2, the tex2 color for layer1 will be the same as the
> color
> + * for tex1's layer1 and tex2's color in layer 2 should still be black.
> + */
>
+
> +#include "piglit-util-gl-common.h"
> +
> +PIGLIT_GL_TEST_CONFIG_BEGIN
> +
> + config.supports_gl_compat_version = 31;
> + config.supports_gl_core_version = 31;
> +
> + config.window_width = 128;
> + config.window_height = 128;
> + config.window_visual = PIGLIT_GL_VISUAL_RGB |
> PIGLIT_GL_VISUAL_DOUBLE;
> +
> +PIGLIT_GL_TEST_CONFIG_END
> +
> +static GLuint fbo;
> +static GLuint texture[2];
> +
> +static const float colors[3][3] = {
> + {0.0, 1.0, 0.0},
> + {0.0, 0.0, 1.0},
> + {0.0, 0.0, 0.0}
> +};
> +
> +bool
> +display_layered_texture(int x, int y, int w, int h, int texWidth, int
> texHeight,
> + GLenum textureType, GLuint texture, int layers) {
> + GLuint tempFBO;
> + unsigned int i;
> + int dx1, dy1, dx2, dy2;
> +
> + dx1 = x;
> + dx2 = x+w;
> +
> + /* Gen temp fbo */
> + glGenFramebuffers(1, &tempFBO);
> +
> + /* loop through each layer, attaching the individual layer to the
> + * temp fbo, then blit fbo to the correct location on screen
> + */
> + for(i = 0; i < layers; i++) {
> + GLenum framebufferStatus;
> +
> + dy1 = y + (i) *(h/layers);
> + dy2 = y + (i+1)*(h/layers);
> +
> + glBindFramebuffer(GL_FRAMEBUFFER, tempFBO);
> + glFramebufferTextureLayer(GL_FRAMEBUFFER,
> GL_COLOR_ATTACHMENT0,
> + texture, 0, i);
> +
> + framebufferStatus =
> glCheckFramebufferStatus(GL_FRAMEBUFFER);
> + if(framebufferStatus != GL_FRAMEBUFFER_COMPLETE) {
> + printf("Framebuffer Status: %s\n",
> + piglit_get_gl_enum_name(framebufferStatus));
> + return false;
> + }
> +
> + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
> + glBindFramebuffer(GL_READ_FRAMEBUFFER, tempFBO);
> + glBlitFramebuffer(0, 0, texWidth, texHeight,
> + dx1, dy1, dx2, dy2, GL_COLOR_BUFFER_BIT,
> + GL_NEAREST);
> + }
> +
> + /* Cleanup temp fbo */
> + glBindFramebuffer(GL_FRAMEBUFFER, 0);
> + glDeleteFramebuffers(1, &tempFBO);
> +
> + return piglit_check_gl_error(GL_NO_ERROR);
> +}
> +
> +GLuint
> +CreateTextureLayered(int w, int h, int d, GLenum dataType, void *data)
> +{
> + GLuint tex;
> +
> + glGenTextures(1, &tex);
> + glBindTexture(GL_TEXTURE_3D, tex);
> + glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
> + glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
> + glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_REPEAT);
> + glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_REPEAT);
> + glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_REPEAT);
> + glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB, w, h, d, 0, GL_RGB,
> + dataType, data);
> + glBindTexture(GL_TEXTURE_3D, 0);
> +
> + if(!piglit_check_gl_error(GL_NO_ERROR)) {
> + return 0;
> + }
> + else {
> + return tex;
> + }
> +}
> +
> +void
> +piglit_init(int argc, char **argv)
> +{
> + int i, j;
> + float colorData[2][piglit_width*piglit_height*3];
> + float *resultData =
> malloc(2*3*piglit_width*piglit_height*sizeof(float));
> +
> + /* fill in colorData */
> + for(j = 0; j < 2; j++)
> + for(i = 0; i < piglit_width*piglit_height; i++) {
> + colorData[j][i*3+0] = colors[j][0];
> + colorData[j][i*3+1] = colors[j][1];
> + colorData[j][i*3+2] = colors[j][2];
> + }
> +
> + /* clear resultData to a color */
> + for(i = 0; i < 2*piglit_width*piglit_height; i++) {
> + resultData[i*3+0] = colors[j][0];
> + resultData[i*3+1] = colors[j][1];
> + resultData[i*3+2] = colors[j][2];
> + }
> +
> + glGenFramebuffers(1, &fbo);
> + glBindFramebuffer(GL_FRAMEBUFFER, fbo);
> +
> + /* Create the Source framebuffer object */
> + texture[0] = CreateTextureLayered(piglit_width, piglit_height, 2,
> + GL_FLOAT, colorData);
> +
> + /* Check if texture was generated */
> + if(texture[0] == 0) {
> + piglit_report_result(PIGLIT_FAIL);
> + }
> +
> + glBindTexture(GL_TEXTURE_3D, texture[0]);
> + glFramebufferTexture3D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
> + GL_TEXTURE_3D, texture[0], 0, 0);
>
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.
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.
> +
> + /* Get Pixel Data */
> + glReadPixels(0, 0, piglit_width, piglit_height,
> + GL_RGB, GL_FLOAT, resultData);
> +
> + /* Create new texture with the retrieved pixel data */
> + texture[1] = CreateTextureLayered(piglit_width, piglit_height, 2,
> + GL_FLOAT, resultData);
> +
> + if(!piglit_check_gl_error(GL_NO_ERROR)) {
> + piglit_report_result(PIGLIT_FAIL);
> + }
> +}
> +
> +enum piglit_result
> +piglit_display(void)
> +{
> + bool pass = true;
> +
> + /* Display Source Texture */
> + display_layered_texture(0, 0, piglit_width/2, piglit_height,
> + piglit_width, piglit_height, GL_TEXTURE_3D,
> + texture[0], 2);
> +
> + /* Display Dest Texture */
> + display_layered_texture(piglit_width/2, 0, piglit_width/2,
> + piglit_height, piglit_width, piglit_height,
> + GL_TEXTURE_3D, texture[1], 2);
> +
> + pass = piglit_probe_rect_rgb(0, 0, piglit_width, piglit_height/2,
> + colors[0]) && pass;
> +
> + pass = piglit_probe_rect_rgb(0, piglit_height/2, piglit_width/2,
> + piglit_height/2, colors[1]) && pass;
> +
> + pass = piglit_probe_rect_rgb(piglit_width/2, piglit_height/2,
> + piglit_width/2, piglit_height/2,
> + colors[2]) && pass;
> +
> + if(!piglit_check_gl_error(GL_NO_ERROR)) {
> + pass = false;
> + }
> +
> + piglit_present_results();
> + return pass ? PIGLIT_PASS : PIGLIT_FAIL;
> +}
> --
> 1.8.3.1
>
> _______________________________________________
> 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/20130827/3e6a1f95/attachment.html>
More information about the Piglit
mailing list