[Piglit] [PATCH 2/2] Add integer-attributes test.

christoph at bumiller.com christoph at bumiller.com
Mon Dec 19 07:52:42 PST 2011


From: Christoph Bumiller <e0425955 at student.tuwien.ac.at>

---
 tests/all.tests                    |    1 +
 tests/shaders/CMakeLists.gl.txt    |    1 +
 tests/shaders/integer-attributes.c |  187 ++++++++++++++++++++++++++++++++++++
 3 files changed, 189 insertions(+), 0 deletions(-)
 create mode 100644 tests/shaders/integer-attributes.c

diff --git a/tests/all.tests b/tests/all.tests
index b713de0..699c9e4 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -485,6 +485,7 @@ add_plain_test(shaders, 'glsl-max-vertex-attrib')
 add_plain_test(shaders, 'glsl-kwin-blur-1')
 add_plain_test(shaders, 'glsl-kwin-blur-2')
 add_plain_test(shaders, 'gpu_shader4_attribs')
+add_plain_test(shaders, 'integer-attributes')
 add_plain_test(shaders, 'link-mismatch-layout-01')
 add_plain_test(shaders, 'link-mismatch-layout-02')
 add_plain_test(shaders, 'link-mismatch-layout-03')
diff --git a/tests/shaders/CMakeLists.gl.txt b/tests/shaders/CMakeLists.gl.txt
index 9d72260..b16ce16 100644
--- a/tests/shaders/CMakeLists.gl.txt
+++ b/tests/shaders/CMakeLists.gl.txt
@@ -157,6 +157,7 @@ IF (UNIX)
 ENDIF (UNIX)
 add_executable (glsl-kwin-blur-1 glsl-kwin-blur-1.c)
 add_executable (glsl-kwin-blur-2 glsl-kwin-blur-2.c)
+add_executable (integer-attributes integer-attributes.c)
 add_executable (link-mismatch-layout-01 link-mismatch-layout-01.c)
 add_executable (link-mismatch-layout-02 link-mismatch-layout-02.c)
 add_executable (link-mismatch-layout-03 link-mismatch-layout-03.c)
diff --git a/tests/shaders/integer-attributes.c b/tests/shaders/integer-attributes.c
new file mode 100644
index 0000000..48c0bd3
--- /dev/null
+++ b/tests/shaders/integer-attributes.c
@@ -0,0 +1,187 @@
+/*
+ * Copyright © 2011 Christoph Bumiller
+ *
+ * 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 integer-attributes.c
+ *
+ * Test that integer attributes via VertexAttribIPointer work properly.
+ *
+ * It uses one vertex attribute for each possible integer type and
+ * combines them in the shader.
+ */
+
+#include "piglit-util.h"
+
+int piglit_width = 100, piglit_height = 100;
+int piglit_window_mode = GLUT_RGB | GLUT_ALPHA | GLUT_DOUBLE;
+
+static GLuint vbo;
+static GLuint fbo;
+static GLuint rboSigned, rboUnsigned;
+static GLint rboWidth = 4, rboHeight = 4;
+
+
+struct Vertex
+{
+	GLfloat vtx[2];
+	GLuint u4[2];
+	GLushort u2[2];
+	GLubyte u1[4];
+	GLint s4[2];
+	GLshort s2[2];
+	GLbyte s1[4];
+};
+
+static struct Vertex VertexData =
+{
+	{ -1.0f, -1.0f },
+	{ 0xdead0000, 0x00bb0000 },
+	{ 0xca00, 0xee00 },
+	{ 0xfe, 0x33, 0x00, 0x01 },
+	{ 1000000, -500000 },
+	{ 25000, -10000 },
+	{ -1, -2, 0, 1 },
+};
+
+static const char *VertShaderText =
+	"#version 130\n"
+	"in ivec4 a4s, a2s, a1s;\n"
+	"in uvec4 a4u, a2u, a1u;\n"
+	"in vec4 vtx;\n"
+	"flat out ivec4 v0;\n"
+	"flat out uvec4 v1;\n"
+	"void main()\n"
+	"{\n"
+	"   v0 = a4s + a2s * a1s;\n"
+	"   v1 = a4u | a2u | a1u;\n"
+	"   gl_Position = vtx;\n"
+	"}\n";
+
+static const char *FragShaderText =
+	"#version 130\n"
+	"flat in ivec4 v0;\n"
+	"flat in uvec4 v1;\n"
+	"out ivec4 c0;\n"
+	"out uvec4 c1;\n"
+	"void main()\n"
+	"{\n"
+	"   c0 = v0;\n"
+	"   c1 = v1;\n"
+	"}\n";
+
+static GLuint VertShader, FragShader, Program;
+
+enum piglit_result
+piglit_display(void)
+{
+	int i, pass;
+	const GLuint stride = sizeof(struct Vertex);
+
+	GLenum buffers[2] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1 };
+
+	const GLint sExpect[4] = { 975000, -480000, 0, 2 };
+	const GLuint uExpect[4] = { 0xdeadcafe, 0x00bbee33, 0, 1 };
+
+	for (i = 0; i < 7; ++i)
+		glEnableVertexAttribArray(i);
+
+	glBindBuffer(GL_ARRAY_BUFFER, vbo);
+	assert(stride == 40);
+	glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, stride, (void *)0);
+	glVertexAttribIPointer(1, 2, GL_UNSIGNED_INT, stride, (void *)8);
+	glVertexAttribIPointer(2, 2, GL_UNSIGNED_SHORT, stride, (void *)16);
+	glVertexAttribIPointer(3, 2, GL_UNSIGNED_BYTE, stride, (void *)20);
+	glVertexAttribIPointer(4, 2, GL_INT, stride, (void *)24);
+	glVertexAttribIPointer(5, 2, GL_SHORT, stride, (void *)32);
+	glVertexAttribIPointer(6, 2, GL_BYTE, stride, (void *)36);
+
+	glBindFramebuffer(GL_FRAMEBUFFER, fbo);
+	glDrawBuffers(2, buffers);
+
+	glDrawArrays(GL_QUADS, 0, 4);
+
+	glReadBuffer(GL_COLOR_ATTACHMENT0);
+	pass = piglit_probe_pixel_rgba_sint(0, 0, sExpect);
+	glReadBuffer(GL_COLOR_ATTACHMENT1);
+	pass = piglit_probe_pixel_rgba_uint(0, 0, uExpect) && pass;
+
+	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+	struct Vertex vData[4];
+	int i;
+
+	piglit_require_extension("GL_EXT_texture_integer");
+	piglit_require_GLSL_version(130);
+
+
+	VertShader = piglit_compile_shader_text(GL_VERTEX_SHADER,
+						VertShaderText);
+	FragShader = piglit_compile_shader_text(GL_FRAGMENT_SHADER,
+						FragShaderText);
+	Program = piglit_link_simple_program(VertShader, FragShader);
+
+	glBindAttribLocation(Program, 0, "vtx");
+	glBindAttribLocation(Program, 1, "a4u");
+	glBindAttribLocation(Program, 2, "a2u");
+	glBindAttribLocation(Program, 3, "a1u");
+	glBindAttribLocation(Program, 4, "a4s");
+	glBindAttribLocation(Program, 5, "a2s");
+	glBindAttribLocation(Program, 6, "a1s");
+	glBindFragDataLocation(Program, 0, "c0");
+	glBindFragDataLocation(Program, 1, "c1");
+	glLinkProgram(Program);
+
+	glUseProgram(Program);
+
+
+	glGenRenderbuffers(1, &rboSigned);
+	glGenRenderbuffers(1, &rboUnsigned);
+
+	glBindRenderbuffer(GL_RENDERBUFFER, rboSigned);
+	glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA32I, rboWidth, rboHeight);
+	glBindRenderbuffer(GL_RENDERBUFFER, rboUnsigned);
+	glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA32UI, rboWidth, rboHeight);
+
+	glGenFramebuffers(1, &fbo);
+	glBindFramebuffer(GL_FRAMEBUFFER, fbo);
+	glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
+				  GL_RENDERBUFFER, rboSigned);
+	glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1,
+				  GL_RENDERBUFFER, rboUnsigned);
+
+
+	for (i = 0; i < 4; ++i)
+		memcpy(&vData[i], &VertexData, sizeof(vData[i]));
+	vData[1].vtx[1] = 1.0f;
+	vData[2].vtx[0] = 1.0f;
+	vData[2].vtx[1] = 1.0f;
+	vData[3].vtx[0] = 1.0f;
+
+	glGenBuffers(1, &vbo);
+	glBindBuffer(GL_ARRAY_BUFFER, vbo);
+	glBufferData(GL_ARRAY_BUFFER,
+		     4 * sizeof(struct Vertex), vData, GL_STATIC_DRAW);
+}
-- 
1.7.3.4



More information about the Piglit mailing list