cmake: move defaults into the per-platform section
[piglit.git] / tests / shaders / glsl-getattriblocation.c
blob6a781a2f68cf2bde6c1f65eeadec86d9ba95b052
1 /*
2 * Copyright © 2009 Intel Corporation
3 * Copyright © 2010 VMware, Inc.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
25 /**
26 * \file glsl-getattriblocation.c
28 * Check glGetAttribLocation().
30 * We'd typically expect that the first user-defined vertex attribute
31 * to wind up in location 0, but that's not guaranteed. Check that
32 * rendering works when there's only one user-defined vertex attribute.
33 * If the GLSL compiler chooses a location other than zero, this might
34 * cause a failure.
36 * This test is based on the glsl-dlist-getattriblocation.c test written
37 * by Ian.
39 * \author Ian Romanick <ian.d.romanick@intel.com>
40 * \author Brian Paul
43 #include "piglit-util-gl.h"
45 PIGLIT_GL_TEST_CONFIG_BEGIN
47 config.supports_gl_compat_version = 10;
49 config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
51 PIGLIT_GL_TEST_CONFIG_END
53 static const GLchar *vertShaderText =
54 "attribute vec4 attrib;\n"
55 "void main()\n"
56 "{\n"
57 " gl_Position = gl_ModelViewProjectionMatrix * attrib;\n"
58 " gl_FrontColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
59 "} \n";
62 static const GLfloat Vcoords[4][2] = { {-1, -1}, {1, -1}, {1, 1}, {-1, 1}};
65 enum piglit_result
66 piglit_display(void)
68 static const GLfloat expColor[4] = {0, 1, 0, 1};
69 GLint vs;
70 GLint prog;
71 GLint stat;
72 GLint attrib_loc;
73 enum piglit_result result;
75 vs = glCreateShader(GL_VERTEX_SHADER);
76 glShaderSource(vs, 1, &vertShaderText, NULL);
78 glCompileShader(vs);
79 glGetShaderiv(vs, GL_COMPILE_STATUS, &stat);
80 if (!stat) {
81 fprintf(stderr, "glsl-getattriblocation: error compiling vertex shader!\n");
82 exit(1);
85 prog = glCreateProgram();
86 glAttachShader(prog, vs);
87 glLinkProgram(prog);
89 attrib_loc = glGetAttribLocation(prog, "attrib");
90 if (!piglit_automatic)
91 printf("attrib_loc = %d\n", attrib_loc);
93 glUseProgram(prog);
95 glMatrixMode(GL_PROJECTION);
96 glLoadIdentity();
97 glOrtho(-1.1, 1.1, -1.1, 1.1, -1, 1);
99 glClear(GL_COLOR_BUFFER_BIT);
101 glVertexAttribPointer(attrib_loc, 2, GL_FLOAT, GL_FALSE, 0, Vcoords);
102 glEnableVertexAttribArray(attrib_loc);
104 glDrawArrays(GL_POLYGON, 0, 4);
106 result = piglit_probe_pixel_rgba(20, 20, expColor)
107 ? PIGLIT_PASS : PIGLIT_FAIL;
109 glDisableVertexAttribArray(attrib_loc);
111 piglit_present_results();
113 return result;
117 void
118 piglit_init(int argc, char **argv)
120 piglit_require_gl_version(20);