[Piglit] [PATCH 5/9] GL 3.2: Test layered framebuffer status

Jacob Penner jkpenner91 at gmail.com
Mon Aug 26 11:49:28 PDT 2013


---
 .../layered-rendering/framebuffer-layer-complete.c | 168 +++++++++++++++++++++
 1 file changed, 168 insertions(+)
 create mode 100644 tests/spec/gl-3.2/layered-rendering/framebuffer-layer-complete.c

diff --git a/tests/spec/gl-3.2/layered-rendering/framebuffer-layer-complete.c b/tests/spec/gl-3.2/layered-rendering/framebuffer-layer-complete.c
new file mode 100644
index 0000000..fa36f42
--- /dev/null
+++ b/tests/spec/gl-3.2/layered-rendering/framebuffer-layer-complete.c
@@ -0,0 +1,168 @@
+/*
+ * 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 framebuffer-layer-complete.c
+ *
+ * Section 4.4.4(FRAMEBUFFER OBJECTS) From GL spec 3.2 core:
+ * If any framebuffer attachment is layered, all populated attachments must be
+ * layered. Additionally, all populated color attachments must be from textures
+ * of the same target.
+ */
+
+#include "piglit-util-gl-common.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+	config.supports_gl_compat_version = 32;
+	config.supports_gl_core_version = 32;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+const int texWidth = 30;
+const int texHeight = 30;
+const int texDepth = 2;
+
+void
+create_bind_texture(GLenum textureType, GLuint *texture) {
+	glGenTextures(1, texture);
+	glBindTexture(textureType, *texture);
+
+	switch(textureType) {
+	case GL_TEXTURE_2D:
+		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);
+		glTexImage2D(textureType, 0, GL_RGB, texWidth, texHeight,
+			     0, GL_RGB, GL_FLOAT, NULL);
+		break;
+	case GL_TEXTURE_3D:
+		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);
+		glTexImage3D(textureType, 0, GL_RGB, texWidth, texHeight,
+			     texDepth, 0, GL_RGB, GL_FLOAT, NULL);
+		break;
+	default:
+		glDeleteTextures(1, texture);
+		*texture = 0;
+		break;
+	}
+}
+
+void
+attach_texture(GLenum framebuffer, GLenum attachment, GLenum textureType,
+	       GLuint texture)
+{
+	switch(textureType) {
+		case GL_TEXTURE_2D:
+			glFramebufferTexture2D(framebuffer, attachment,
+					       textureType, texture, 0);
+			break;
+		case GL_TEXTURE_3D:
+			glFramebufferTexture(framebuffer, attachment,
+					     texture, 0);
+			break;
+	}
+}
+
+bool
+CheckFramebufferStatus(GLenum expected) {
+	GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
+	if(status != expected) {
+		printf("Expected Framebuffer status '%s', got '%s'\n",
+		       piglit_get_gl_enum_name(expected), 
+		       piglit_get_gl_enum_name(status));
+		return false;
+	}
+	return true;
+}
+
+bool
+test_fb_incomplete_layer_targets(GLenum texOneType, GLenum texTwoType,
+				 GLenum expectedFbStatus)
+{
+	bool pass = true;
+	GLuint fbo, texture[2];
+
+	glGenTextures(2, texture);
+
+	glGenFramebuffers(1, &fbo);
+	glBindFramebuffer(GL_FRAMEBUFFER, fbo);
+
+	/* Setup texture one */
+	create_bind_texture(texOneType, &texture[0]);
+	attach_texture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
+		       texOneType, texture[0]);
+
+	/* Setup texture two */
+	create_bind_texture(texTwoType, &texture[1]);
+	attach_texture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1,
+		       texTwoType, texture[1]);
+
+	pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
+
+	/* Check for expected fb status */
+	pass = CheckFramebufferStatus(expectedFbStatus) && pass;
+
+	/* Clean up */
+	glBindFramebuffer(GL_FRAMEBUFFER, 0);
+	glDeleteFramebuffers(1, &fbo);
+	glDeleteTextures(2, texture);
+
+	return pass;
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+	bool pass = true;
+
+	pass = test_fb_incomplete_layer_targets(GL_TEXTURE_2D, GL_TEXTURE_2D,
+			GL_FRAMEBUFFER_COMPLETE)
+			&& pass;
+
+	pass = test_fb_incomplete_layer_targets(GL_TEXTURE_3D, GL_TEXTURE_2D,
+			GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS)
+			&& pass;
+
+	pass = test_fb_incomplete_layer_targets(GL_TEXTURE_2D,  GL_TEXTURE_3D,
+			GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS)
+			&& pass;
+
+	pass = test_fb_incomplete_layer_targets(GL_TEXTURE_3D,  GL_TEXTURE_3D,
+			GL_FRAMEBUFFER_COMPLETE)
+			&& pass;
+
+	piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
+}
+
+enum piglit_result
+piglit_display(void)
+{
+	/* Unreachable */
+	return PIGLIT_FAIL;
+}
-- 
1.8.3.1



More information about the Piglit mailing list