[Piglit] [PATCH] new test : glsl-max-vertex-attrib.c

Tapani Pälli tapani.palli at intel.com
Wed May 25 04:56:19 PDT 2011


Queries the value for GL_MAX_VERTEX_ATTRIBS and uses that as index
to set a value with various functions. GL specification states that
GL_INVALID_VALUE should occur if index >= GL_MAX_VERTEX_ATTRIBS.

added more functions and a shader (needed for some functions) and
fixed shaders to actually work, phh.
---
 tests/all.tests                        |    1 +
 tests/shaders/CMakeLists.gl.txt        |    1 +
 tests/shaders/glsl-max-vertex-attrib.c |  160 ++++++++++++++++++++++++++++++++
 3 files changed, 162 insertions(+), 0 deletions(-)
 create mode 100644 tests/shaders/glsl-max-vertex-attrib.c

diff --git a/tests/all.tests b/tests/all.tests
index 561fc42..7b9ff87 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -407,6 +407,7 @@ add_plain_test(shaders, 'glsl-link-initializer-05')
 add_plain_test(shaders, 'glsl-link-initializer-06')
 add_plain_test(shaders, 'glsl-link-invariant-01')
 add_plain_test(shaders, 'glsl-link-centroid-01')
+add_plain_test(shaders, 'glsl-max-vertex-attrib')
 add_plain_test(shaders, 'glsl-link-struct-array')
 add_plain_test(shaders, 'glsl-kwin-blur-1')
 add_plain_test(shaders, 'glsl-kwin-blur-2')
diff --git a/tests/shaders/CMakeLists.gl.txt b/tests/shaders/CMakeLists.gl.txt
index cf9e3e9..3fcd4ca 100644
--- a/tests/shaders/CMakeLists.gl.txt
+++ b/tests/shaders/CMakeLists.gl.txt
@@ -14,6 +14,7 @@ link_libraries (
 	${GLUT_glut_LIBRARY}
 )
 
+add_executable (glsl-max-vertex-attrib glsl-max-vertex-attrib.c)
 add_executable (activeprogram-bad-program activeprogram-bad-program.c)
 add_executable (activeprogram-get activeprogram-get.c)
 add_executable (ati-fs-bad-delete ati-fs-bad-delete.c)
diff --git a/tests/shaders/glsl-max-vertex-attrib.c b/tests/shaders/glsl-max-vertex-attrib.c
new file mode 100644
index 0000000..8e83366
--- /dev/null
+++ b/tests/shaders/glsl-max-vertex-attrib.c
@@ -0,0 +1,160 @@
+/*
+ * Copyright © 2010 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 glsl-max-vertex-attrib.c
+ * Test setting vertex attrib value of GL_MAX_VERTEX_ATTRIBS attrib
+ *
+ * Queries the value for GL_MAX_VERTEX_ATTRIBS and uses that as index
+ * to set a value. GL specification states that GL_INVALID_VALUE should
+ * occur if index >= GL_MAX_VERTEX_ATTRIBS.
+ *
+ * \author Sun Yi <yi.sun at intel.com>
+ * \author Tapani Pälli <tapani.palli at intel.com>
+ */
+
+#include "piglit-util.h"
+#include "piglit-framework.h"
+
+int piglit_window_mode = GLUT_RGB;
+int piglit_width = 250, piglit_height = 250;
+
+static int test = 0;
+
+#define CHECK_GL_INVALID_VALUE \
+	if (glGetError() != GL_INVALID_VALUE) return PIGLIT_FAIL; \
+	else printf("glsl-max-vertex-attrib test %d passed\n", ++test);
+
+static const char *vShaderString =
+	"attribute float pos;\n"
+	"void main()\n"
+	"{\n"
+	"	gl_Position = pos;\n"
+	"}\n";
+
+static const char *fShaderString =
+	"void main()\n"
+	"{\n"
+	"	gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
+	"}\n";
+
+enum piglit_result piglit_display(void)
+{
+	GLvoid *datap;
+	GLint intv[] = { 1, 1, 1, 1 };
+	GLfloat floatv[] = { 1.0, 1.0, 1.0, 1.0 };
+	GLfloat quad[] = { -1.0, 1.0, 1.0, 1.0, -1.0, -1.0, 1.0, -1.0 };
+
+	GLsizei length;
+	GLint size;
+	GLenum type;
+	GLchar buffer[64];
+
+	GLuint program, vShader, fShader;
+	int maxAttribCount;
+
+	/* --- valid program needed for some of the functions --- */
+
+	fShader = glCreateShader(GL_FRAGMENT_SHADER);
+	vShader = glCreateShader(GL_VERTEX_SHADER);
+
+	glShaderSource(fShader, 1, &fShaderString, NULL);
+	glShaderSource(vShader, 1, &vShaderString, NULL);
+
+	glCompileShader(vShader);
+	glCompileShader(fShader);
+
+	program = glCreateProgram();
+
+	glAttachShader(program, vShader);
+	glAttachShader(program, fShader);
+
+	glLinkProgram(program);
+
+	glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &maxAttribCount);
+
+	/* --- tests begin here --- */
+
+	glVertexAttrib1f(maxAttribCount, floatv[0]);
+	CHECK_GL_INVALID_VALUE;
+
+	glVertexAttrib2f(maxAttribCount, floatv[0], floatv[1]);
+	CHECK_GL_INVALID_VALUE;
+
+	glVertexAttrib3f(maxAttribCount, floatv[0], floatv[1], floatv[2]);
+	CHECK_GL_INVALID_VALUE;
+
+	glVertexAttrib4f(maxAttribCount, floatv[0], floatv[1], floatv[2],
+			 floatv[3]);
+	CHECK_GL_INVALID_VALUE;
+
+	glVertexAttrib1fv(maxAttribCount, floatv);
+	CHECK_GL_INVALID_VALUE;
+
+	glVertexAttrib2fv(maxAttribCount, floatv);
+	CHECK_GL_INVALID_VALUE;
+
+	glVertexAttrib3fv(maxAttribCount, floatv);
+	CHECK_GL_INVALID_VALUE;
+
+	glVertexAttrib4fv(maxAttribCount, floatv);
+	CHECK_GL_INVALID_VALUE;
+
+	glVertexAttribPointer(maxAttribCount, 2, GL_FLOAT, GL_FALSE, 0, quad);
+	CHECK_GL_INVALID_VALUE;
+
+	glBindAttribLocation(program, maxAttribCount, "pos");
+	CHECK_GL_INVALID_VALUE;
+
+	glEnableVertexAttribArray(maxAttribCount);
+	CHECK_GL_INVALID_VALUE;
+
+	glDisableVertexAttribArray(maxAttribCount);
+	CHECK_GL_INVALID_VALUE;
+
+	glGetVertexAttribfv(maxAttribCount, GL_CURRENT_VERTEX_ATTRIB, floatv);
+	CHECK_GL_INVALID_VALUE;
+
+	glGetVertexAttribiv(maxAttribCount, GL_CURRENT_VERTEX_ATTRIB, intv);
+	CHECK_GL_INVALID_VALUE;
+
+	glGetVertexAttribPointerv(maxAttribCount,
+				  GL_VERTEX_ATTRIB_ARRAY_POINTER, &datap);
+	CHECK_GL_INVALID_VALUE;
+
+	glGetActiveAttrib(program, maxAttribCount, 64, &length, &size, &type,
+			  buffer);
+	CHECK_GL_INVALID_VALUE;
+
+	return PIGLIT_PASS;
+}
+
+void piglit_init(int argc, char **argv)
+{
+	if (!GLEW_VERSION_2_0) {
+		printf("Requires OpenGL 2.0\n");
+		piglit_report_result(PIGLIT_SKIP);
+		exit(1);
+	}
+}
-- 
1.7.5.2

---------------------------------------------------------------------
Intel Finland Oy
Registered Address: PL 281, 00181 Helsinki 
Business Identity Code: 0357606 - 4 
Domiciled in Helsinki 

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.


More information about the Piglit mailing list