2 * Copyright 2011 VMware, Inc.
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
25 * Asst. gl[Get]Uniformfv tests.
26 * Brian Paul, 27 May 2011
29 #include "piglit-util-gl.h"
31 PIGLIT_GL_TEST_CONFIG_BEGIN
33 config
.supports_gl_compat_version
= 10;
35 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
| PIGLIT_GL_VISUAL_DOUBLE
;
37 PIGLIT_GL_TEST_CONFIG_END
39 static char *TestName
= "getuniform-02";
41 static const char vs_text
[] =
43 " float a, b, c, d; \n"
45 "uniform float f1; \n"
46 "uniform vec4 v[3]; \n"
48 "uniform float f2; \n"
52 " gl_Position = vec4(0.0, 0.0, 0.0, 1.0);\n"
53 " vec4 t = vec4(s.a, s.b, s.c, s.d) * f1 + f2;\n"
54 " t += v[0] + v[1] + v[2]; \n"
55 " gl_FrontColor = t; \n"
67 piglit_init(int argc
, char **argv
)
71 GLint expectedNum
= 7;
72 GLint loc_f1
, loc_f2
, loc_sa
, loc_sd
, loc_v1
;
74 static const GLfloat vVals
[4] = {30.0, 31.0, 32.0, 33.0};
76 piglit_require_vertex_shader();
77 piglit_require_fragment_shader();
79 vs
= piglit_compile_shader_text(GL_VERTEX_SHADER
, vs_text
);
80 prog
= piglit_link_simple_program(vs
, 0);
84 glGetProgramiv(prog
, GL_ACTIVE_UNIFORMS
, &numUniforms
);
85 if (numUniforms
!= expectedNum
) {
86 printf("%s: incorrect number of uniforms (found %d, expected %d)\n",
87 TestName
, numUniforms
, expectedNum
);
88 piglit_report_result(PIGLIT_FAIL
);
91 /* check types, sizes */
92 for (i
= 0; i
< numUniforms
; i
++) {
95 GLint size
, expectedSize
;
96 GLenum type
, expectedType
;
99 glGetActiveUniform(prog
,
100 i
, sizeof(name
), &len
, &size
, &type
, name
);
101 loc
= glGetUniformLocation(prog
, name
);
104 printf("%s: bad uniform location for %s: %d\n", TestName
, name
, loc
);
105 piglit_report_result(PIGLIT_FAIL
);
108 if (!piglit_automatic
) {
109 printf("%d: %s loc=%d size=%d type=0x%x\n", i
, name
, loc
, size
, type
);
112 /* OpenGL ES 3.0 and OpenGL 4.2 require that the "[0]" be appended to
113 * the name. Earlier versions of the spec are ambiguous. Accept either
116 if (strcmp(name
, "v") == 0 || strcmp(name
, "v[0]") == 0) {
117 expectedType
= GL_FLOAT_VEC4_ARB
;
121 expectedType
= GL_FLOAT
;
125 if (type
!= expectedType
) {
126 printf("%s: wrong type for 'v' (found 0x%x, expected 0x%x)\n",
127 TestName
, type
, expectedType
);
128 piglit_report_result(PIGLIT_FAIL
);
131 if (size
!= expectedSize
) {
132 printf("%s: wrong size for 'v' (found %d, expected %d)\n",
133 TestName
, size
, expectedSize
);
134 piglit_report_result(PIGLIT_FAIL
);
138 /* Check setting/getting values */
140 loc_f1
= glGetUniformLocation(prog
, "f1");
141 loc_f2
= glGetUniformLocation(prog
, "f2");
142 loc_sa
= glGetUniformLocation(prog
, "s.a");
143 loc_sd
= glGetUniformLocation(prog
, "s.d");
144 loc_v1
= glGetUniformLocation(prog
, "v[1]");
146 glUniform1f(loc_f1
, 5.0);
147 glUniform1f(loc_f2
, 10.0);
148 glUniform1f(loc_sa
, 15.0);
149 glUniform1f(loc_sd
, 20.0);
150 glUniform4fv(loc_v1
, 1, vVals
);
152 glGetUniformfv(prog
, loc_f1
, v
);
154 printf("%s: wrong value for f1 (found %f, expected %f)\n",
155 TestName
, v
[0], 5.0);
156 piglit_report_result(PIGLIT_FAIL
);
159 glGetUniformfv(prog
, loc_f2
, v
);
161 printf("%s: wrong value for f2 (found %f, expected %f)\n",
162 TestName
, v
[0], 10.0);
163 piglit_report_result(PIGLIT_FAIL
);
166 glGetUniformfv(prog
, loc_sa
, v
);
168 printf("%s: wrong value for s.a (found %f, expected %f)\n",
169 TestName
, v
[0], 15.0);
170 piglit_report_result(PIGLIT_FAIL
);
173 glGetUniformfv(prog
, loc_sd
, v
);
175 printf("%s: wrong value for s.d (found %f, expected %f)\n",
176 TestName
, v
[0], 20.0);
177 piglit_report_result(PIGLIT_FAIL
);
180 glGetUniformfv(prog
, loc_v1
, v
);
185 printf("%s: wrong value for v[1] (found %g,%g,%g,%g, expected %g,%g,%g,%g)\n",
186 TestName
, v
[0], v
[1], v
[2], v
[3], 30.0, 31.0, 32.0, 33.0);
187 piglit_report_result(PIGLIT_FAIL
);
190 piglit_report_result(PIGLIT_PASS
);