2 * Copyright © 2011 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
21 * DEALINGS IN THE SOFTWARE.
25 * \file bindattriblocation-scratch-name.c
26 * Verify that glBindAttribLocation doesn't keep the applications name pointer.
28 * This reproduces Mesa bugzilla #41499 (bugzilla #41508 is a dup of the same
31 * \author Ian Romanick <ian.d.romanick@intel.com>
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 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
44 PIGLIT_GL_TEST_CONFIG_END
46 static const GLchar
*vertShaderText
=
47 "attribute vec4 attrib;\n"
48 "void main() { gl_Position = attrib; }\n";
57 piglit_init(int argc
, char **argv
)
59 static const char name
[] = "attrib";
60 char alt_name
[sizeof(name
)];
65 piglit_require_vertex_shader();
67 vs
= piglit_compile_shader_text(GL_VERTEX_SHADER
, vertShaderText
);
69 piglit_report_result(PIGLIT_FAIL
);
72 prog
= glCreateProgram();
73 glAttachShader(prog
, vs
);
75 /* Bind "attrib" to location 3. Once the attribute is bound, smash
76 * the string containing the name. After smashing the name, link the
77 * shader. If the implementation kept our name pointer, there will be
80 memcpy(alt_name
, name
, sizeof(name
));
81 glBindAttribLocation(prog
, 3, alt_name
);
82 memset(alt_name
, 0, sizeof(alt_name
));
85 if (!piglit_link_check_status(prog
))
86 piglit_report_result(PIGLIT_FAIL
);
88 attrib_loc
= glGetAttribLocation(prog
, "attrib");
89 if (attrib_loc
!= 3) {
90 fprintf(stderr
, "Expected location 3, got location %d\n",
92 piglit_report_result(PIGLIT_FAIL
);
95 piglit_report_result(PIGLIT_PASS
);