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
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.
26 * \file glsl-bindattriblocation.c
28 * Check glBindAttribLocation().
30 * We create a simple vertex shader with a single user-defined vertex
31 * attribute bound to location 3 (or anything non-zero). Then try to
32 * draw a polygon. Mesa has (had) a draw-time validation check which
33 * no-op'd the draw if vertex array #0 was not enabled.
35 * This test is based on the glsl-dlist-getattriblocation.c test written
38 * \author Ian Romanick <ian.d.romanick@intel.com>
42 #include "piglit-util-gl.h"
44 PIGLIT_GL_TEST_CONFIG_BEGIN
46 config
.supports_gl_compat_version
= 10;
48 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
| PIGLIT_GL_VISUAL_DOUBLE
;
50 PIGLIT_GL_TEST_CONFIG_END
52 static const GLchar
*vertShaderText
=
53 "attribute vec4 attrib;\n"
56 " gl_Position = gl_ModelViewProjectionMatrix * attrib;\n"
57 " gl_FrontColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
61 static const GLfloat Vcoords
[4][2] = { {-1, -1}, {1, -1}, {1, 1}, {-1, 1}};
67 static const GLfloat expColor
[4] = {0, 1, 0, 1};
70 GLint orig_attrib_loc
, attrib_loc
;
71 enum piglit_result result
;
73 vs
= piglit_compile_shader_text(GL_VERTEX_SHADER
, vertShaderText
);
78 prog
= piglit_link_simple_program(vs
, 0);
83 orig_attrib_loc
= glGetAttribLocation(prog
, "attrib");
84 if (!piglit_automatic
)
85 printf("original attrib_loc = %d\n", orig_attrib_loc
);
87 /* Bind "attrib" to location 3 and re-link */
88 glBindAttribLocation(prog
, 3, "attrib");
91 /* check that the bind worked */
92 attrib_loc
= glGetAttribLocation(prog
, "attrib");
93 if (!piglit_automatic
)
94 printf("new attrib_loc = %d\n", attrib_loc
);
95 if (attrib_loc
!= 3) {
96 fprintf(stderr
, "glsl-bindattriblocation: glBindAttribLocation failed\n");
97 fprintf(stderr
, " expectec location 3, found location %d\n",
102 /* now draw something and check that it works */
105 glMatrixMode(GL_PROJECTION
);
107 glOrtho(-1.1, 1.1, -1.1, 1.1, -1, 1);
109 glClear(GL_COLOR_BUFFER_BIT
);
111 glVertexAttribPointer(attrib_loc
, 2, GL_FLOAT
, GL_FALSE
, 0, Vcoords
);
112 glEnableVertexAttribArray(attrib_loc
);
114 glDrawArrays(GL_POLYGON
, 0, 4);
116 result
= piglit_probe_pixel_rgba(20, 20, expColor
)
117 ? PIGLIT_PASS
: PIGLIT_FAIL
;
119 glDisableVertexAttribArray(attrib_loc
);
121 piglit_present_results();
128 piglit_init(int argc
, char **argv
)
130 piglit_require_vertex_shader();
132 piglit_require_gl_version(20);