<div dir="ltr">On 19 July 2013 13:09, Jacob Penner <span dir="ltr"><<a href="mailto:jkpenner91@gmail.com" target="_blank">jkpenner91@gmail.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Test that the size value returned from glGetActiveAttrib is correct<br>
for arrays of various sizes.<br></blockquote><div><br></div><div>I'd recommend changing the commit subject to "Add glGetActiveAttrib test for arrays", just so people aren't confused (we already have a more general test for glGetActiveAttrib).<br>
</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
---<br>
 tests/spec/CMakeLists.txt                          |   1 +<br>
 tests/spec/glsl-1.50/CMakeLists.txt                |   1 +<br>
 tests/spec/glsl-1.50/execution/CMakeLists.gl.txt   |  13 ++<br>
 tests/spec/glsl-1.50/execution/CMakeLists.txt      |   1 +<br>
 .../glsl-1.50/execution/get-active-attrib-array.c  | 141 +++++++++++++++++++++<br>
 5 files changed, 157 insertions(+)<br>
 create mode 100644 tests/spec/glsl-1.50/CMakeLists.txt<br>
 create mode 100644 tests/spec/glsl-1.50/execution/CMakeLists.gl.txt<br>
 create mode 100644 tests/spec/glsl-1.50/execution/CMakeLists.txt<br>
 create mode 100644 tests/spec/glsl-1.50/execution/get-active-attrib-array.c<br>
<br>
diff --git a/tests/spec/CMakeLists.txt b/tests/spec/CMakeLists.txt<br>
index 4ca366b..b380e17 100644<br>
--- a/tests/spec/CMakeLists.txt<br>
+++ b/tests/spec/CMakeLists.txt<br>
@@ -54,6 +54,7 @@ add_subdirectory (glsl-1.10)<br>
 add_subdirectory (glsl-1.20)<br>
 add_subdirectory (glsl-1.30)<br>
 add_subdirectory (glsl-1.40)<br>
+add_subdirectory (glsl-1.50)<br>
 add_subdirectory (glsl-es-3.00)<br>
 add_subdirectory (gl-1.0)<br>
 add_subdirectory (gl-2.0)<br>
diff --git a/tests/spec/glsl-1.50/CMakeLists.txt b/tests/spec/glsl-1.50/CMakeLists.txt<br>
new file mode 100644<br>
index 0000000..bb76f08<br>
--- /dev/null<br>
+++ b/tests/spec/glsl-1.50/CMakeLists.txt<br>
@@ -0,0 +1 @@<br>
+add_subdirectory (execution)<br>
diff --git a/tests/spec/glsl-1.50/execution/CMakeLists.gl.txt b/tests/spec/glsl-1.50/execution/CMakeLists.gl.txt<br>
new file mode 100644<br>
index 0000000..c15eece<br>
--- /dev/null<br>
+++ b/tests/spec/glsl-1.50/execution/CMakeLists.gl.txt<br>
@@ -0,0 +1,13 @@<br>
+include_directories(<br>
+       ${GLEXT_INCLUDE_DIR}<br>
+       ${OPENGL_INCLUDE_PATH}<br>
+       ${piglit_SOURCE_DIR}/tests/util<br>
+)<br>
+<br>
+link_libraries (<br>
+       piglitutil_${piglit_target_api}<br>
+       ${OPENGL_gl_LIBRARY}<br>
+       ${OPENGL_glu_LIBRARY}<br>
+)<br>
+<br>
+piglit_add_executable (glsl-1.50-get-active-attrib-array get-active-attrib-array.c)<br>
diff --git a/tests/spec/glsl-1.50/execution/CMakeLists.txt b/tests/spec/glsl-1.50/execution/CMakeLists.txt<br>
new file mode 100644<br>
index 0000000..144a306<br>
--- /dev/null<br>
+++ b/tests/spec/glsl-1.50/execution/CMakeLists.txt<br>
@@ -0,0 +1 @@<br>
+piglit_include_target_api()<br>
diff --git a/tests/spec/glsl-1.50/execution/get-active-attrib-array.c b/tests/spec/glsl-1.50/execution/get-active-attrib-array.c<br>
new file mode 100644<br>
index 0000000..9f93c65<br>
--- /dev/null<br>
+++ b/tests/spec/glsl-1.50/execution/get-active-attrib-array.c<br>
@@ -0,0 +1,141 @@<br>
+/*<br>
+ * Copyright © 2012 Intel Corporation<br>
+ *<br>
+ * Permission is hereby granted, free of charge, to any person obtaining a<br>
+ * copy of this software and associated documentation files (the "Software"),<br>
+ * to deal in the Software without restriction, including without limitation<br>
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,<br>
+ * and/or sell copies of the Software, and to permit persons to whom the<br>
+ * Software is furnished to do so, subject to the following conditions:<br>
+ *<br>
+ * The above copyright notice and this permission notice (including the next<br>
+ * paragraph) shall be included in all copies or substantial portions of the<br>
+ * Software.<br>
+ *<br>
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br>
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL<br>
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br>
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING<br>
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS<br>
+ * IN THE SOFTWARE.<br>
+ */<br>
+<br>
+/*<br>
+ * Check that glGetActiveAttrib returns the correct size values,<br>
+ * for arrays of various sizes.<br>
+ */<br>
+<br>
+#include "piglit-util-gl-common.h"<br>
+<br>
+PIGLIT_GL_TEST_CONFIG_BEGIN<br>
+//config.supports_gl_core_version = 32;<br>
+<br>
+       config.supports_gl_compat_version = 10;<br></blockquote><div><br></div><div>Array support for vertex attributes only appears in GL 3.2, so this should be:<br><br></div><div>config.supports_gl_core_version = 32;<br>
</div><div>config.supports_gl_compat_version = 32;<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+<br>
+PIGLIT_GL_TEST_CONFIG_END<br>
+<br>
+static const char *vs_source =<br>
+       "#version 150\n"<br>
+       "in int a[1];\n"<br>
+       "in int b[2];\n"<br>
+       "in int c[3];\n"<br>
+       "in int d[4];\n"<br>
+       "in int e[5];\n"<br>
+       "\n"<br>
+       "out vec4 color;\n"<br>
+       "void main()\n"<br>
+       "{\n"<br>
+       "       color = vec4(a[0] + b[0] + b[1],\n"<br>
+       "                    c[0] + c[1] + c[2],\n"<br>
+       "                    d[0] + d[1] + d[2] + d[3],\n"<br>
+       "                    e[0] + e[1] + e[2] + e[3] + e[4]);\n"<br>
+       "}\n";<br>
+<br>
+static const char *fs_source =<br>
+       "#version 150\n"<br>
+       "in vec4 color;\n"<br>
+       "void main()\n"<br>
+       "{\n"<br>
+       "       gl_FragColor = color;\n"<br>
+       "}\n";<br>
+<br>
+enum piglit_result<br>
+piglit_display(void)<br>
+{<br>
+       /* UNREACHED */<br>
+       return PIGLIT_FAIL;<br>
+}<br>
+<br>
+/*<br>
+ * Find the given attribute size then, check if the passed expected size<br>
+ * is equal to the actual size.<br>
+ */<br>
+bool<br>
+getAttribLocTest(GLint program, int active_attribs, int max_name_length,<br>
+               char *attrib_name, int expected_size)<br>
+{<br>
+       bool pass = true;<br>
+       int size = -1;<br>
+       GLenum type = GL_NONE;<br>
+       char *name = malloc(max_name_length-1);<br>
+<br>
+       int i;<br>
+       for(i = 0; i < active_attribs; i++)<br>
+       {<br></blockquote><div><br></div><div>The formatting convention we use in Piglit is for the opening brace to go on the same line as a "for" or "if" statement.  So this should be:<br><br>for (i = 0; i < active_attribs; i++) {<br>
</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+               glGetActiveAttrib(program, i, max_name_length,<br>
+                       NULL, &size, &type, name);<br>
+<br>
+<br>
+               if(strcmp(attrib_name, name) == 0)<br>
+               {<br>
+                       // exit out of for loop<br>
+                       i = active_attribs;<br>
+               }<br></blockquote><div><br></div><div>The conventional way to do this is:<br><br>if(strcmp(attrib_name, name) == 0)<br></div><div>    break;<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

+       }<br></blockquote><div><br></div><div>If we get through the loop without finding an attribute matching attrib_name, we ought to report an error at this point.  I'd recommend adding something like the following:<br>
<br></div><div>if (i != active_attribs) {<br></div><div>    printf("Attribute '%s' not found\n", attrib_name);<br></div><div>    pass = false;<br>}<br><br></div><div>(This assumes you take my advice about using "break")<br>
</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+<br>
+       if(!pass)<br>
+       {<br>
+               printf("Attribute '%s': size %d; expected %d\n",<br>
+                       name, size, expected_size);<br>
+       }<br>
+<br>
+       pass = (size == expected_size)?(true):(false);<br></blockquote><div><br></div>You're checking "pass" before setting it, so the printf will never happen.<br><div><br></div><div>I'd recommend changing this to:<br>
<br></div><div>if (size != expected_size) {<br></div><div>    printf(...);<br></div><div>    pass = false;<br>}<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

+<br>
+       return pass;<br>
+}<br>
+<br>
+void<br>
+piglit_init(int argc, char **argv)<br>
+{<br>
+       bool pass = true;<br>
+<br>
+       GLint prog = 0;<br>
+<br>
+       GLint active_attribs = 0;<br>
+       GLint max_length = 0;<br>
+<br>
+       piglit_require_GLSL_version(150);<br>
+<br>
+       prog = piglit_build_simple_program(vs_source, fs_source);<br>
+<br>
+       glLinkProgram(prog);<br></blockquote><div><br></div><div>piglit_build_simple_program() automatically calls glLinkProgram() so this is unnecessary.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

+       glUseProgram(prog);<br>
+<br>
+       glGetProgramiv(prog, GL_ACTIVE_ATTRIBUTES, &active_attribs);<br>
+       glGetProgramiv(prog, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &max_length);<br>
+<br>
+       /*<br>
+        * Check the size of the given attribute with the<br>
+        * corresponding expected array size.<br>
+        */<br>
+       pass = getAttribLocTest(prog, active_attribs, max_length, "a", 1) && pass;<br>
+       pass = getAttribLocTest(prog, active_attribs, max_length, "b", 2) && pass;<br>
+       pass = getAttribLocTest(prog, active_attribs, max_length, "c", 3) && pass;<br>
+       pass = getAttribLocTest(prog, active_attribs, max_length, "d", 4) && pass;<br>
+       pass = getAttribLocTest(prog, active_attribs, max_length, "e", 5) && pass;<br>
+<br>
+       glDeleteProgram(prog);<br>
+<br>
+       piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);<br>
+}<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.8.3.1<br>
<br>
_______________________________________________<br>
Piglit mailing list<br>
<a href="mailto:Piglit@lists.freedesktop.org">Piglit@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/piglit" target="_blank">http://lists.freedesktop.org/mailman/listinfo/piglit</a><br>
</font></span></blockquote></div><br></div></div>