[Piglit] [PATCH] gl-2.0/vertexattribpointer: new test for glVertexAttribPointer
Brian Paul
brianp at vmware.com
Sun Jun 1 13:33:02 PDT 2014
Tests all the type/size/normalize combinations for glVertexAttribPointer.
Note- a similar test should be written for GL 3.0's glVertexAttribIPointer.
---
tests/all.py | 1 +
tests/spec/gl-2.0/CMakeLists.gl.txt | 1 +
tests/spec/gl-2.0/vertexattribpointer.c | 256 +++++++++++++++++++++++++++++++
3 files changed, 258 insertions(+)
create mode 100644 tests/spec/gl-2.0/vertexattribpointer.c
diff --git a/tests/all.py b/tests/all.py
index d449e47..a42e79e 100644
--- a/tests/all.py
+++ b/tests/all.py
@@ -865,6 +865,7 @@ spec['!OpenGL 2.0'] = gl20
add_concurrent_test(gl20, 'attribs')
add_concurrent_test(gl20, 'gl-2.0-edgeflag')
add_concurrent_test(gl20, 'gl-2.0-edgeflag-immediate')
+add_concurrent_test(gl20, 'gl-2.0-vertexattribpointer')
add_plain_test(gl20, 'attrib-assignments')
add_plain_test(gl20, 'getattriblocation-conventional')
add_plain_test(gl20, 'clip-flag-behavior')
diff --git a/tests/spec/gl-2.0/CMakeLists.gl.txt b/tests/spec/gl-2.0/CMakeLists.gl.txt
index b930eef..3ac0d68 100644
--- a/tests/spec/gl-2.0/CMakeLists.gl.txt
+++ b/tests/spec/gl-2.0/CMakeLists.gl.txt
@@ -13,3 +13,4 @@ link_libraries (
piglit_add_executable (vertex-program-two-side vertex-program-two-side.c)
piglit_add_executable (gl-2.0-edgeflag edgeflag.c)
piglit_add_executable (gl-2.0-edgeflag-immediate edgeflag-immediate.c)
+piglit_add_executable (gl-2.0-vertexattribpointer vertexattribpointer.c)
diff --git a/tests/spec/gl-2.0/vertexattribpointer.c b/tests/spec/gl-2.0/vertexattribpointer.c
new file mode 100644
index 0000000..b232c99
--- /dev/null
+++ b/tests/spec/gl-2.0/vertexattribpointer.c
@@ -0,0 +1,256 @@
+/*
+ * Copyright 2014 VMware, Inc.
+ *
+ * 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.
+ */
+
+/**
+ * Test glVertexAttribPointer with all combinations of types, sizes and
+ * normalized/unnormalized.
+ */
+
+#include "piglit-util-gl-common.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+ config.supports_gl_compat_version = 20;
+ config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DOUBLE;
+PIGLIT_GL_TEST_CONFIG_END
+
+
+static const char *vertShaderText =
+ "uniform float scale, bias; \n"
+ "attribute vec4 attr; \n"
+ "varying vec4 color; \n"
+ " \n"
+ "void main() \n"
+ "{ \n"
+ " gl_Position = gl_Vertex; \n"
+ " color = attr * scale + bias; \n"
+ "} \n";
+
+static const char *fragShaderText =
+ "varying vec4 color;\n"
+ "void main()\n"
+ "{ \n"
+ " gl_FragColor = color; \n"
+ "} \n";
+
+
+static const GLfloat float4_data[] = { 0.5, 0.0, 0.75, 1.0 };
+static const GLubyte ubyte4_data[] = { 100, 0, 200, 255 };
+static const GLbyte byte4_data[] = { 50, 0, -25, -50 };
+static const GLushort ushort4_data[] = { 16000, 0, 32000, 65535 };
+static const GLshort short4_data[] = { 2000, 0, -4000, -8000 };
+static const GLuint uint4_data[] = { 10000000, 0, 20000000, 80000000 };
+static const GLint int4_data[] = { 10000000, 0, -20000000, -40000000 };
+
+static GLuint Prog;
+static GLint ScaleUniform, BiasUniform, AttrAttrib;
+
+
+/*
+ * Test glVertexAttribArray(type, size, normalized)
+ */
+static bool
+test_array(GLenum type, GLuint size, GLboolean normalized)
+{
+ static const GLfloat verts[4][2] = {
+ { -1.0, -1.0 },
+ { 1.0, -1.0 },
+ { 1.0, 1.0 },
+ { -1.0, 1.0 }
+ };
+ GLubyte attr_buffer[100];
+ float scale, bias;
+ int typeSize;
+ const void *data;
+ float expected[4];
+ int i, p;
+
+ switch (type) {
+ case GL_BYTE:
+ scale = 1.0 / 127.0;
+ bias = 0.5;
+ typeSize = sizeof(GLbyte);
+ data = byte4_data;
+ for (i = 0; i < 4; i++)
+ expected[i] = byte4_data[i] * scale + bias;
+ break;
+ case GL_UNSIGNED_BYTE:
+ scale = 1.0 / 255.0;
+ bias = 0.0;
+ typeSize = sizeof(GLubyte);
+ data = ubyte4_data;
+ for (i = 0; i < 4; i++)
+ expected[i] = ubyte4_data[i] * scale + bias;
+ break;
+ case GL_SHORT:
+ scale = 1.0 / 32767.0;
+ bias = 0.5;
+ typeSize = sizeof(GLshort);
+ data = short4_data;
+ for (i = 0; i < 4; i++)
+ expected[i] = short4_data[i] * scale + bias;
+ break;
+ case GL_UNSIGNED_SHORT:
+ scale = 1.0 / 65535.0;
+ bias = 0.0;
+ typeSize = sizeof(GLushort);
+ data = ushort4_data;
+ for (i = 0; i < 4; i++)
+ expected[i] = ushort4_data[i] * scale + bias;
+ break;
+ case GL_INT:
+ scale = 1.0 / (float) 0x7fffffff;
+ bias = 0.5;
+ typeSize = sizeof(GLint);
+ data = int4_data;
+ for (i = 0; i < 4; i++)
+ expected[i] = int4_data[i] * scale + bias;
+ break;
+ case GL_UNSIGNED_INT:
+ scale = 1.0 / (float) 0xffffffff;
+ bias = 0.0;
+ typeSize = sizeof(GLuint);
+ data = uint4_data;
+ for (i = 0; i < 4; i++)
+ expected[i] = uint4_data[i] * scale + bias;
+ break;
+ case GL_FLOAT:
+ scale = 1.0;
+ bias = 0.0;
+ typeSize = sizeof(GLfloat);
+ data = float4_data;
+ for (i = 0; i < 4; i++)
+ expected[i] = float4_data[i] * scale + bias;
+ break;
+ default:
+ assert(0);
+ scale = 1.0;
+ bias = 0.0;
+ typeSize = sizeof(GLfloat);
+ }
+
+ if (normalized) {
+ scale = 1.0;
+ }
+
+ /* set unused components to defaults */
+ switch (size) {
+ case 1:
+ expected[1] = 0.0 * scale + bias;
+ case 2:
+ expected[2] = 0.0 * scale + bias;
+ case 3:
+ expected[3] = 1.0 * scale + bias;
+ }
+
+ /* clamp to [0, 1] */
+ for (i = 0; i < 4; i++)
+ expected[i] = CLAMP(expected[i], 0.0, 1.0);
+
+ /* Setup the attribute buffer by making four copies of the
+ * test's array data (for the four vertices).
+ */
+ {
+ int i, sz = typeSize * size;
+ for (i = 0; i < 4; i++) {
+ memcpy(attr_buffer + i * sz, data, sz);
+ }
+ }
+
+ glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, verts);
+ glEnableVertexAttribArray(0);
+ glVertexAttribPointer(AttrAttrib, size, type,
+ normalized, 0, attr_buffer);
+ glEnableVertexAttribArray(AttrAttrib);
+
+ glViewport(0, 0, piglit_width, piglit_height);
+ glClearColor(1,0,0,0);
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ glUniform1f(ScaleUniform, scale);
+ glUniform1f(BiasUniform, bias);
+ glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
+
+ glDisableVertexAttribArray(0);
+ glDisableVertexAttribArray(AttrAttrib);
+
+ p = piglit_probe_pixel_rgba(piglit_width / 2, piglit_height / 2,
+ expected);
+ if (!p) {
+ printf("Test %s[%d] %s failed\n",
+ piglit_get_gl_enum_name(type),
+ size,
+ (normalized ? "Normalized" : "Unnormalized"));
+ fflush(stdout);
+ }
+
+ piglit_present_results();
+
+ return p;
+}
+
+
+enum piglit_result
+piglit_display(void)
+{
+ static const GLenum types[] = {
+ GL_BYTE,
+ GL_UNSIGNED_BYTE,
+ GL_SHORT,
+ GL_UNSIGNED_SHORT,
+ GL_INT,
+ GL_UNSIGNED_INT,
+ GL_FLOAT
+ };
+ bool pass = true;
+ int t, size, normalized;
+
+ for (t = 0; t < ARRAY_SIZE(types); t++) {
+ for (size = 1; size <= 4; size++) {
+ for (normalized = 0; normalized < 2; normalized++) {
+ pass = test_array(types[t], size, normalized)
+ && pass;
+ }
+ }
+ }
+
+ return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
+
+
+void
+piglit_init(int argc, char **argv)
+{
+ piglit_require_gl_version(20);
+
+ Prog = piglit_build_simple_program(vertShaderText, fragShaderText);
+ if (!Prog) {
+ printf("Failed to compile/link program\n");
+ piglit_report_result(PIGLIT_FAIL);
+ }
+
+ glUseProgram(Prog);
+
+ ScaleUniform = glGetUniformLocation(Prog, "scale");
+ BiasUniform = glGetUniformLocation(Prog, "bias");
+ AttrAttrib = glGetAttribLocation(Prog, "attr");
+}
--
1.7.10.4
More information about the Piglit
mailing list