cmake: move defaults into the per-platform section
[piglit.git] / tests / shaders / getuniform-02.c
blobb0bd86a31461d3a21f59c9db9e2acf76b208ad2a
1 /*
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
13 * Software.
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
21 * IN THE SOFTWARE.
24 /**
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[] =
42 "struct s1 { \n"
43 " float a, b, c, d; \n"
44 "}; \n"
45 "uniform float f1; \n"
46 "uniform vec4 v[3]; \n"
47 "uniform s1 s;\n"
48 "uniform float f2; \n"
49 "\n"
50 "void main()\n"
51 "{\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"
56 "}\n";
58 enum piglit_result
59 piglit_display(void)
61 /* never called */
62 return PIGLIT_FAIL;
66 void
67 piglit_init(int argc, char **argv)
69 GLuint vs, prog;
70 GLint numUniforms, i;
71 GLint expectedNum = 7;
72 GLint loc_f1, loc_f2, loc_sa, loc_sd, loc_v1;
73 GLfloat v[4];
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);
82 glUseProgram(prog);
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++) {
93 GLcharARB name[100];
94 GLsizei len;
95 GLint size, expectedSize;
96 GLenum type, expectedType;
97 GLint loc;
99 glGetActiveUniform(prog,
100 i, sizeof(name), &len, &size, &type, name);
101 loc = glGetUniformLocation(prog, name);
103 if (loc < 0) {
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
114 * name.
116 if (strcmp(name, "v") == 0 || strcmp(name, "v[0]") == 0) {
117 expectedType = GL_FLOAT_VEC4_ARB;
118 expectedSize = 3;
120 else {
121 expectedType = GL_FLOAT;
122 expectedSize = 1;
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);
153 if (v[0] != 5.0) {
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);
160 if (v[0] != 10.0) {
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);
167 if (v[0] != 15.0) {
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);
174 if (v[0] != 20.0) {
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);
181 if (v[0] != 30.0 ||
182 v[1] != 31.0 ||
183 v[2] != 32.0 ||
184 v[3] != 33.0) {
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);