[Piglit] [PATCH 3/9] GL 3.2: Test layered framebuffers blit properly.

Jacob Penner jkpenner91 at gmail.com
Mon Aug 26 11:44:25 PDT 2013


---
 tests/spec/gl-3.2/layered-rendering/blit.c | 352 +++++++++++++++++++++++++++++
 1 file changed, 352 insertions(+)
 create mode 100644 tests/spec/gl-3.2/layered-rendering/blit.c

diff --git a/tests/spec/gl-3.2/layered-rendering/blit.c b/tests/spec/gl-3.2/layered-rendering/blit.c
new file mode 100644
index 0000000..d897840
--- /dev/null
+++ b/tests/spec/gl-3.2/layered-rendering/blit.c
@@ -0,0 +1,352 @@
+/*
+ * 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 blit.c
+ *
+ * Section 4.3.2(Reading and Copying Pixels) From GL spec 3.2 core:
+ *   If the read framebuffer is layered (see section 4.4.7), pixel values are
+ * read from layer zero. If the draw framebuffer is layered, pixel values are
+ * written to layer zero. If both read and draw framebuffers are layered, the
+ * blit operation is still performed only on layer zero.
+ *
+ * Test Layout
+ * *-------*-------*    test1:
+ * |       |       |      Source tex is layered, Dest tex is layered
+ * | test3 | test4 |    test2:
+ * |       |       |      Source tex is layered, Dest tex is not layered
+ * *-------*-------*    test3:
+ * |       |       |      Source tex is not layered, Dest tex is layered
+ * | test1 | test2 |    test4:
+ * |       |       |      Source tex is not layered, Dest tex is not layered
+ * *-------*-------*
+ *
+ *    src dest           Each Test
+ *   *---*---*             Display source tex layers on left
+ *   |   |   | layer 1     Blit source tex to dest tex
+ *   *---*---*             Display resulting layers
+ *   |   |   | layer 2
+ *   *---*---*
+ */
+
+#include "piglit-util-gl-common.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+	config.supports_gl_compat_version = 32;
+	config.supports_gl_core_version = 32;
+
+	config.window_width  = 128;
+	config.window_height = 128;
+	config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+/* Values Set in piglit init */
+const int texWidth  = 32;
+const int texHeight = 32;
+const int texDepth  = 2;
+const int texelsPerLayer = 32 * 32;
+const int floatPerLayer  = 32 * 32 * 3;
+
+static const float srcColors[2][3] = {
+	{1, 0, 0}, {0, 1, 0}
+};
+
+static const float desColors[2][3] = {
+	{0, 0, 1}, {0, 1, 1}
+};
+
+/*
+ * Blit the passed texture to the screen. If texture is layered,
+ * loops through each layer and blit it to the screen.
+ */
+bool
+display_texture(int x, int y, int w, int h,
+		     GLuint tex, int layers)
+{
+	GLuint tempFBO;
+	int i, dx1, dy1, dx2, dy2;
+	GLenum fbStatus;
+
+	dx1 = x;
+	dx2 = x+w;
+
+	/* Gen temp fbo to work with */
+	glGenFramebuffers(1, &tempFBO);
+
+	if(layers == 1) {
+		dy1 = y;
+		dy2 = y+h;
+
+		glBindFramebuffer(GL_FRAMEBUFFER, tempFBO);
+		glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
+				       GL_TEXTURE_2D, tex, 0);
+
+		/* Blit layer to screen */
+		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);
+	}
+	else {
+		/* loop through each layer */
+		for( i = 0; i < layers; i++) {
+			dy1 = y + i*(h/layers);
+			dy2 = y + (i+1)*(h/layers);
+
+			/* Bind new layer to display */
+			glBindFramebuffer(GL_FRAMEBUFFER, tempFBO);
+			glFramebufferTextureLayer(GL_FRAMEBUFFER,
+						  GL_COLOR_ATTACHMENT0,
+						  tex, 0, i);
+
+			fbStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER);
+			if(fbStatus != GL_FRAMEBUFFER_COMPLETE) {
+				printf("Framebuffer Status: %s\n",
+				       piglit_get_gl_enum_name(fbStatus));
+				return false;
+			}
+
+			/* Blit layer to screen */
+			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);
+}
+
+void
+gen_color_data(float *colorData, int texelsPerLayer, int layers, bool useSrcTex)
+{
+	int i, j;
+	for(j = 0; j < layers; j++)
+	for(i = 0; i < texelsPerLayer; i++) {
+		int offset = j * texelsPerLayer * 3 + i * 3;
+		if(useSrcTex) {
+			colorData[offset + 0] = srcColors[j][0];
+			colorData[offset + 1] = srcColors[j][1];
+			colorData[offset + 2] = srcColors[j][2];
+		}
+		else {
+			colorData[offset + 0] = desColors[j][0];
+			colorData[offset + 1] = desColors[j][1];
+			colorData[offset + 2] = desColors[j][2];
+		}
+	}
+}
+
+void
+create_bind_texture(GLenum textureType, GLuint *texture, bool useSrcTex)
+{
+	piglit_check_gl_error(GL_NO_ERROR);
+
+	glGenTextures(1, texture);
+	glBindTexture(textureType, *texture);
+
+	glTexParameteri(textureType, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+	glTexParameteri(textureType, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+	glTexParameteri(textureType, GL_TEXTURE_WRAP_S, GL_REPEAT);
+	glTexParameteri(textureType, GL_TEXTURE_WRAP_T, GL_REPEAT);
+	glTexParameteri(textureType, GL_TEXTURE_WRAP_R, GL_REPEAT);
+
+	if(textureType == GL_TEXTURE_2D) {
+		float colorData[floatPerLayer];
+		gen_color_data(colorData, texelsPerLayer, 1, useSrcTex);
+		glTexImage2D(textureType, 0, GL_RGB, texWidth, texHeight, 0,
+			     GL_RGB, GL_FLOAT, colorData);
+	}
+	else if(textureType == GL_TEXTURE_3D) {
+		float colorData[texDepth * floatPerLayer];
+		gen_color_data(colorData, texelsPerLayer, texDepth, useSrcTex);
+		glTexImage3D(textureType, 0, GL_RGB, texWidth, texHeight,
+			     texDepth, 0, GL_RGB, GL_FLOAT, colorData);
+	}
+
+	if(!piglit_check_gl_error(GL_NO_ERROR)) {
+		glDeleteTextures(1, texture);
+		*texture = 0;
+	}
+}
+
+bool
+testFramebufferBlitLayered(int x, int y, int w, int h,
+			   bool sLayered, bool dLayered)
+{
+	bool pass = true;
+	GLuint srcFBO, desFBO;
+	GLuint srcTex, desTex;
+	GLenum fbStatus;
+	int srclayers = (sLayered) ? (texDepth) : (1);
+	int deslayers = (dLayered) ? (texDepth) : (1);
+
+	/* Set up source fbo */
+	glGenFramebuffers(1, &srcFBO);
+	glBindFramebuffer(GL_FRAMEBUFFER, srcFBO);
+
+	piglit_check_gl_error(GL_NO_ERROR);
+	if(sLayered) {
+		create_bind_texture(GL_TEXTURE_3D, &srcTex, true);
+		glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
+				     srcTex, 0);
+	}
+	else {
+		create_bind_texture(GL_TEXTURE_2D, &srcTex, true);
+		glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
+				     GL_TEXTURE_2D, srcTex, 0);
+	}
+
+	/* Check source framebuffer status */
+	fbStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER);
+	if(fbStatus != GL_FRAMEBUFFER_COMPLETE) {
+		printf("FtestFramebufferBlitLayered srcFBO Status: %s\n",
+		       piglit_get_gl_enum_name(fbStatus));
+		return false;
+	}
+
+	/* Set up dest fbo */
+	glGenFramebuffers(1, &desFBO);
+	glBindFramebuffer(GL_FRAMEBUFFER, desFBO);
+
+	if(dLayered) {
+		create_bind_texture(GL_TEXTURE_3D, &desTex, false);
+		glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
+				     desTex, 0);
+	}
+	else {
+		create_bind_texture(GL_TEXTURE_2D, &desTex, false);
+		glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
+				       GL_TEXTURE_2D, desTex, 0);
+	}
+
+	/* Check dest framebuffer status */
+	fbStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER);
+	if(fbStatus != GL_FRAMEBUFFER_COMPLETE) {
+		printf("testFramebufferBlitLayered desFBO Status: %s\n",
+		       piglit_get_gl_enum_name(fbStatus));
+		return false;
+	}
+
+	/* Check for if any errors have occured */
+	if(!piglit_check_gl_error(GL_NO_ERROR)) {
+		printf("Error setting up framebuffers for test.\n");
+		return false;
+	}
+
+	/* Blit from source to dest framebuffers */
+	glBindFramebuffer(GL_READ_FRAMEBUFFER, srcFBO);
+	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, desFBO);
+	glBlitFramebuffer(0, 0, texWidth, texHeight,
+			  0, 0, texWidth, texHeight,
+			  GL_COLOR_BUFFER_BIT, GL_LINEAR);
+
+	/* Display the results */
+	display_texture(x, y, w/2, h, srcTex, srclayers);
+	display_texture(x+w/2, y, w/2, h, desTex, deslayers);
+
+	/* Check for pass condition */
+	if(sLayered) {
+		pass = piglit_probe_rect_rgb(x, y, w/2, h/2, srcColors[0])
+		       && pass;
+		pass = piglit_probe_rect_rgb(x, y+h/2, w/2, h/2, srcColors[1])
+		       && pass;
+	}
+	else {
+		pass = piglit_probe_rect_rgb(x, y, w/2, h, srcColors[0])
+		       && pass;
+	}
+
+	if(dLayered) {
+		pass = piglit_probe_rect_rgb(x+w/2, y, w/2, h/2, srcColors[0])
+		       && pass;
+		pass = piglit_probe_rect_rgb(x+w/2, y+h/2, w/2, h/2,
+					     desColors[1])
+		       && pass;
+	}
+	else {
+		pass = piglit_probe_rect_rgb(x+w/2, y, w/2, h, srcColors[0])
+		       && pass;
+	}
+
+
+	/* Clean up */
+	glBindFramebuffer(GL_FRAMEBUFFER, 0);
+	glDeleteFramebuffers(1, &srcFBO);
+	glDeleteFramebuffers(1, &desFBO);
+	glDeleteTextures(1, &srcTex);
+	glDeleteTextures(1, &desTex);
+
+	/* Check for if any errors have occured */
+	if(!piglit_check_gl_error(GL_NO_ERROR)) {
+		printf("Error setting up framebuffers for test.\n");
+		return false;
+	}
+
+	return pass;
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+
+}
+
+enum piglit_result
+piglit_display(void)
+{
+	bool pass = true;
+	int hw = piglit_width/2;
+	int hh = piglit_height/2;
+
+	glBindFramebuffer(GL_FRAMEBUFFER, 0);
+	glClearColor(1,1,1,1);
+	glClear(GL_COLOR_BUFFER_BIT);
+
+	/* Source is layered, Dest is layered */
+	pass = testFramebufferBlitLayered( 0,  0, hw, hh, true,  true)  && pass;
+
+	/* Source is layered, Dest is not layered */
+	pass = testFramebufferBlitLayered(hw,  0, hw, hh, true,  false) && pass;
+
+	/* Source not is layered, Dest is layered */
+	pass = testFramebufferBlitLayered( 0, hh, hw, hh, false, true)  && pass;
+
+	/* Source not is layered, Dest is not layered */
+	pass = testFramebufferBlitLayered(hw, hh, hw, hh, false, false) && pass;
+
+	/* Check for if any errors have occured */
+	pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
+
+	piglit_present_results();
+
+	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
-- 
1.8.3.1



More information about the Piglit mailing list