[Piglit] [PATCH] arb_direct_state_access: Add a FramebufferTextureLayer cube-map test
Fredrik Höglund
fredrik at kde.org
Wed Apr 29 10:41:41 PDT 2015
This test verifies that faces of a cube-map texture can be attached
to a framebuffer object using glNamedFramebufferTextureLayer and
glFramebufferTextureLayer.
---
tests/all.py | 4 +
.../spec/arb_direct_state_access/CMakeLists.gl.txt | 1 +
.../fbo-texturelayer-cubemap.c | 322 +++++++++++++++++++++
3 files changed, 327 insertions(+)
create mode 100644 tests/spec/arb_direct_state_access/fbo-texturelayer-cubemap.c
diff --git a/tests/all.py b/tests/all.py
index 6197c18..e80c2cd 100755
--- a/tests/all.py
+++ b/tests/all.py
@@ -4305,6 +4305,10 @@ with profile.group_manager(
g(['arb_direct_state_access-create-programpipelines'],
'create-programpipelines')
g(['arb_direct_state_access-create-queries'], 'create-queries')
+ g(['arb_direct_state_access-fbo-texturelayer-cubemap glNamedFramebufferTextureLayer'],
+ 'fbo-texturelayer-cubemap glNamedFramebufferTextureLayer')
+ g(['arb_direct_state_access-fbo-texturelayer-cubemap glFramebufferTextureLayer'],
+ 'fbo-texturelayer-cubemap glFramebufferTextureLayer')
with profile.group_manager(
PiglitGLTest,
diff --git a/tests/spec/arb_direct_state_access/CMakeLists.gl.txt b/tests/spec/arb_direct_state_access/CMakeLists.gl.txt
index a5ae423..1b837f9 100644
--- a/tests/spec/arb_direct_state_access/CMakeLists.gl.txt
+++ b/tests/spec/arb_direct_state_access/CMakeLists.gl.txt
@@ -36,4 +36,5 @@ piglit_add_executable (arb_direct_state_access-texture-buffer texture-buffer.c)
piglit_add_executable (arb_direct_state_access-create-samplers create-samplers.c)
piglit_add_executable (arb_direct_state_access-create-programpipelines create-programpipelines.c)
piglit_add_executable (arb_direct_state_access-create-queries create-queries.c)
+piglit_add_executable (arb_direct_state_access-fbo-texturelayer-cubemap fbo-texturelayer-cubemap.c)
# vim: ft=cmake:
diff --git a/tests/spec/arb_direct_state_access/fbo-texturelayer-cubemap.c b/tests/spec/arb_direct_state_access/fbo-texturelayer-cubemap.c
new file mode 100644
index 0000000..c158cce
--- /dev/null
+++ b/tests/spec/arb_direct_state_access/fbo-texturelayer-cubemap.c
@@ -0,0 +1,322 @@
+/*
+ * Copyright (C) 2015 Fredrik Höglund
+ *
+ * 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
+ * on the rights to use, copy, modify, merge, publish, distribute, sub
+ * license, 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 NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS AND/OR THEIR SUPPLIERS 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 fbo-texturelayer-cubemap.c
+ *
+ * Verifies that faces of a cube-map texture can be attached to a
+ * framebuffer object using NamedFramebufferTextureLayer and
+ * FramebufferTextureLayer.
+ */
+
+#include "piglit-util-gl.h"
+
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+ config.supports_gl_core_version = 31;
+
+ config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+
+const char *vs =
+ "#version 140\n"
+ "#extension GL_ARB_draw_instanced : require\n"
+ "in vec4 piglit_vertex;\n"
+ "in vec3 piglit_texcoord;\n"
+ "out vec3 texcoord;\n"
+ "void main(void)\n{\n"
+ " gl_Position = piglit_vertex;\n"
+ " gl_Position.xy +=\n"
+ " vec2(gl_InstanceID) * vec2(1.0 / 3.0, -1.0 / 3.0);\n"
+ " texcoord = piglit_texcoord;\n"
+ "}";
+
+const char *fs =
+ "#version 140\n"
+ "in vec3 texcoord;\n"
+ "out vec4 fragColor;\n"
+ "uniform samplerCube sampler;\n"
+ "void main(void)\n{\n"
+ " fragColor = texture(sampler, texcoord);\n"
+ "}";
+
+static bool test_named_fbo = false;
+
+
+static bool
+check_attachment_parameter(GLuint fbo, GLenum attachment,
+ GLenum pname, GLint expected, int line)
+{
+ GLint value;
+ glGetNamedFramebufferAttachmentParameteriv(fbo, attachment,
+ pname, &value);
+
+ if (value != expected) {
+ if (pname == GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE) {
+ fprintf(stderr, "%s was %s, expected %s (%s:%d)\n",
+ piglit_get_gl_enum_name(pname),
+ value == GL_NONE ? "GL_NONE" :
+ piglit_get_gl_enum_name(value),
+ piglit_get_gl_enum_name(expected),
+ __FILE__, line);
+ } else {
+ fprintf(stderr, "%s was %d, expected %d (%s:%d)\n",
+ piglit_get_gl_enum_name(pname),
+ value, expected, __FILE__, line);
+ }
+ return false;
+ }
+
+ return true;
+}
+
+
+static bool
+check_attachment_parameters_(GLuint fbo, GLuint texture, GLenum face, int line)
+{
+ bool pass = true;
+
+ pass = check_attachment_parameter(fbo, GL_COLOR_ATTACHMENT0,
+ GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, texture, line) && pass;
+
+ pass = check_attachment_parameter(fbo, GL_COLOR_ATTACHMENT0,
+ GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL, 0, line) && pass;
+
+ pass = check_attachment_parameter(fbo, GL_COLOR_ATTACHMENT0,
+ GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE, face, line)
+ && pass;
+
+ pass = check_attachment_parameter(fbo, GL_COLOR_ATTACHMENT0,
+ GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER, 0, line) && pass;
+
+ return pass;
+}
+
+
+#define check_attachment_parameters(fbo, texture, face) \
+ check_attachment_parameters_(fbo, texture, face, __LINE__)
+
+
+static bool
+check_framebuffer_complete_(GLuint fbo, int line)
+{
+ GLenum status = glCheckNamedFramebufferStatus(fbo, GL_FRAMEBUFFER);
+
+ if (status != GL_FRAMEBUFFER_COMPLETE) {
+ fprintf(stderr, "Status of FBO %u was %s, "
+ "expected GL_FRAMEBUFFER_COMPLETE (%s:%d)\n",
+ fbo, piglit_get_gl_enum_name(status), __FILE__, line);
+ return false;
+ }
+
+ return true;
+}
+
+
+#define check_framebuffer_complete(fbo) \
+ check_framebuffer_complete_(fbo, __LINE__)
+
+
+enum piglit_result
+piglit_display(void)
+{
+ GLuint vao, fbo, texture, vbos[2];
+ const float size = 2.0 / 6.0;
+
+ /* The vertex positions for the triangle strip */
+ const float vertices[] = {
+ -1.0, 1.0 - size, /* Bottom-left */
+ -1.0, 1.0, /* Top-left */
+ -1.0 + size, 1.0 - size, /* Bottom-right */
+ -1.0 + size, 1.0, /* Top-right */
+ };
+
+ /* The color for each cube map face */
+ static const float colors[6][4] = {
+ { 1.0, 0.0, 0.0, 1.0 }, /* Red */
+ { 0.0, 1.0, 0.0, 1.0 }, /* Green */
+ { 0.0, 0.0, 1.0, 1.0 }, /* Blue */
+ { 0.0, 1.0, 1.0, 1.0 }, /* Cyan */
+ { 1.0, 0.0, 1.0, 1.0 }, /* Magenta */
+ { 1.0, 1.0, 0.0, 1.0 }, /* Yellow */
+ };
+
+ /* The texture coordinates for each instance of the triangle strip */
+ static const float coords[6][3] = {
+ { +1.0, 0.0, 0.0 }, /* GL_TEXTURE_CUBE_MAP_POSITIVE_X */
+ { -1.0, 0.0, 0.0 }, /* GL_TEXTURE_CUBE_MAP_NEGATIVE_X */
+ { 0.0, +1.0, 0.0 }, /* GL_TEXTURE_CUBE_MAP_POSITIVE_Y */
+ { 0.0, -1.0, 0.0 }, /* GL_TEXTURE_CUBE_MAP_NEGATIVE_Y */
+ { 0.0, 0.0, +1.0 }, /* GL_TEXTURE_CUBE_MAP_POSITIVE_Z */
+ { 0.0, 0.0, -1.0 }, /* GL_TEXTURE_CUBE_MAP_NEGATIVE_Z */
+ };
+
+ bool pass = true;
+ int i;
+
+ /* Create a cube map texture */
+ glCreateTextures(GL_TEXTURE_CUBE_MAP, 1, &texture);
+ glTextureStorage2D(texture, 1, GL_RGBA8, 16, 16);
+
+ /* Attach each face in turn to a framebuffer object and clear it */
+ glCreateFramebuffers(1, &fbo);
+
+ if (test_named_fbo) {
+ for (i = 0; i < 6; i++) {
+ const GLenum face = GL_TEXTURE_CUBE_MAP_POSITIVE_X + i;
+ glNamedFramebufferTextureLayer(fbo,
+ GL_COLOR_ATTACHMENT0,
+ texture, 0, i);
+
+ pass = check_attachment_parameters(fbo, texture,
+ face) && pass;
+
+ pass = check_framebuffer_complete(fbo) && pass;
+
+ glClearNamedFramebufferfv(fbo, GL_COLOR, 0, colors[i]);
+ }
+ } else {
+ glBindFramebuffer(GL_FRAMEBUFFER, fbo);
+
+ for (i = 0; i < 6; i++) {
+ const GLenum face = GL_TEXTURE_CUBE_MAP_POSITIVE_X + i;
+ glFramebufferTextureLayer(GL_FRAMEBUFFER,
+ GL_COLOR_ATTACHMENT0,
+ texture, 0, i);
+
+ pass = check_attachment_parameters(fbo, texture,
+ face) && pass;
+
+ pass = check_framebuffer_complete(fbo) && pass;
+
+ glClearBufferfv(GL_COLOR, 0, colors[i]);
+ }
+
+ glBindFramebuffer(GL_FRAMEBUFFER, piglit_winsys_fbo);
+ }
+
+ pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
+
+ glDeleteFramebuffers(1, &fbo);
+
+ /* Create and configure a vertex array object */
+ glCreateVertexArrays(1, &vao);
+
+ glVertexArrayAttribFormat(vao, PIGLIT_ATTRIB_POS,
+ 2, GL_FLOAT, GL_FALSE, 0);
+ glVertexArrayAttribBinding(vao, PIGLIT_ATTRIB_POS, 0);
+ glEnableVertexArrayAttrib(vao, PIGLIT_ATTRIB_POS);
+
+ glVertexArrayAttribFormat(vao, PIGLIT_ATTRIB_TEX,
+ 3, GL_FLOAT, GL_FALSE, 0);
+ glVertexArrayAttribBinding(vao, PIGLIT_ATTRIB_TEX, 1);
+ glEnableVertexArrayAttrib(vao, PIGLIT_ATTRIB_TEX);
+
+ /* Create the vertex buffers and upload data */
+ glCreateBuffers(2, vbos);
+ glNamedBufferStorage(vbos[0], sizeof(vertices), vertices, 0);
+ glNamedBufferStorage(vbos[1], sizeof(coords), coords, 0);
+
+ /* Bind the vertex buffers and set the instance divisor for
+ * the second VBO slot to 1.
+ */
+ {
+ static const GLintptr offsets[] = { 0, 0 };
+ static const GLsizei strides[] = {
+ 2 * sizeof(float),
+ 3 * sizeof(float)
+ };
+
+ glVertexArrayVertexBuffers(vao, 0, 2, vbos, offsets, strides);
+ glVertexArrayBindingDivisor(vao, 1, 1);
+ }
+
+ /* Clear the color buffer to gray */
+ glClearColor(0.5, 0.5, 0.5, 1.0);
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ /* Bind the vertex array object and the cube map texture,
+ * and draw the cube faces.
+ */
+ glBindVertexArray(vao);
+ glBindTextureUnit(0, texture);
+ glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, 6);
+
+ /* Clean up */
+ glDeleteTextures(1, &texture);
+ glDeleteVertexArrays(1, &vao);
+ glDeleteBuffers(2, vbos);
+
+ pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
+
+ for (i = 0; i < 6; i++) {
+ int x = i * piglit_width / 6.0 + piglit_width / 12.0;
+ int y = i * piglit_height / 6.0 + piglit_height / 12.0;
+ pass = piglit_probe_pixel_rgba(x, piglit_height - y,
+ colors[i]) && pass;
+ }
+
+ piglit_present_results();
+
+ return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
+
+
+static void
+usage(int argc, char *argv[])
+{
+ fprintf(stderr, "Usage: %s <glFramebufferTextureLayer|"
+ "glNamedFramebufferTextureLayer>\n", argv[0]);
+ exit(1);
+}
+
+
+void
+piglit_init(int argc, char *argv[])
+{
+ GLuint program;
+
+ piglit_require_extension("GL_ARB_direct_state_access");
+ piglit_require_extension("GL_ARB_draw_instanced");
+ piglit_require_extension("GL_ARB_instanced_arrays");
+ piglit_require_extension("GL_ARB_multi_bind");
+ piglit_require_extension("GL_ARB_vertex_array_object");
+ piglit_require_extension("GL_ARB_vertex_attrib_binding");
+
+ if (argc != 2)
+ usage(argc, argv);
+
+ if (strcmp("glNamedFramebufferTextureLayer", argv[1]) == 0)
+ test_named_fbo = true;
+ else if (strcmp("glFramebufferTextureLayer", argv[1]) == 0)
+ test_named_fbo = false;
+ else
+ usage(argc, argv);
+
+ program = piglit_build_simple_program(vs, fs);
+
+ glUseProgram(program);
+}
--
2.1.4
More information about the Piglit
mailing list