2 * Copyright © 2009 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 * Eric Anholt <eric@anholt.net>
28 /** @file glsl-getactiveuniform-count.c
30 * Tests that glGetActiveUniform() has the uniform's string length correctly
31 * reflected in GL_ACTIVE_UNIFORM_MAX_LENGTH and the *length outvalue.
34 #include "piglit-util-gl.h"
36 PIGLIT_GL_TEST_CONFIG_BEGIN
38 config
.supports_gl_compat_version
= 10;
40 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
| PIGLIT_GL_VISUAL_DOUBLE
;
42 PIGLIT_GL_TEST_CONFIG_END
54 piglit_init(int argc
, char **argv
)
56 GLboolean pass
= GL_TRUE
;
57 GLint vs
, fs
, len
, ret_len
;
62 /* OpenGL ES 3.0 and OpenGL 4.2 require that the "[0]" be appended to
63 * the name. Earlier versions of the spec are ambiguous. Accept
66 const size_t scalar_length
= strlen("color");
67 const size_t array_length
= strlen("color[0]");
69 piglit_require_gl_version(20);
71 vs
= piglit_compile_shader(GL_VERTEX_SHADER
,
72 "shaders/glsl-getactiveuniform-length.vert");
73 fs
= piglit_compile_shader(GL_FRAGMENT_SHADER
,
74 "shaders/glsl-color.frag");
76 prog
= piglit_link_simple_program(vs
, fs
);
78 /* From page 261 (page 275 of the PDF) of the OpenGL 2.1 specification:
80 * If pname is ACTIVE UNIFORM MAX LENGTH, the length of
81 * the longest active uniform name, including a null
82 * terminator, is returned.
85 glGetProgramiv(prog
, GL_ACTIVE_UNIFORM_MAX_LENGTH
, &len
);
86 if (len
!= (scalar_length
+ 1) && len
!= (array_length
+ 1)) {
87 printf("Unexpected max active uniform length "
88 "(saw %d, expected %lu or %lu)\n", len
,
89 (unsigned long) scalar_length
,
90 (unsigned long) array_length
);
94 /* From page 80 (page 88 of the PDF) of the OpenGL 2.1 specification:
96 * The actual number of characters written into name,
97 * excluding the null terminator, is returned in length.
100 glGetActiveUniform(prog
, 0, len
+ 20, &ret_len
, &size
, &type
, name
);
102 if (ret_len
!= scalar_length
&& ret_len
!= array_length
) {
103 printf("Unexpected active uniform length "
104 "(saw %d, expected %lu or %lu) for \"%s\"\n",
106 (unsigned long) scalar_length
,
107 (unsigned long) array_length
,
114 piglit_report_result(PIGLIT_PASS
);
116 piglit_report_result(PIGLIT_FAIL
);