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 shader_query.cpp
26 * C-to-C++ bridge functions to query GLSL shader data
28 * \author Ian Romanick <ian.d.romanick@intel.com>
31 #include "main/core.h"
32 #include "glsl_symbol_table.h"
34 #include "shaderobj.h"
37 #include "shaderapi.h"
41 _mesa_GetAttribLocationARB(GLhandleARB program
, const GLcharARB
* name
)
43 GET_CURRENT_CONTEXT(ctx
);
44 struct gl_shader_program
*const shProg
=
45 _mesa_lookup_shader_program_err(ctx
, program
, "glGetAttribLocation");
51 if (!shProg
->LinkStatus
) {
52 _mesa_error(ctx
, GL_INVALID_OPERATION
,
53 "glGetAttribLocation(program not linked)");
60 /* Not having a vertex shader is not an error.
62 if (shProg
->_LinkedShaders
[MESA_SHADER_VERTEX
] == NULL
)
65 exec_list
*ir
= shProg
->_LinkedShaders
[MESA_SHADER_VERTEX
]->ir
;
66 foreach_list(node
, ir
) {
67 const ir_variable
*const var
= ((ir_instruction
*) node
)->as_variable();
69 /* The extra check against VERT_ATTRIB_GENERIC0 is because
70 * glGetAttribLocation cannot be used on "conventional" attributes.
72 * From page 95 of the OpenGL 3.0 spec:
74 * "If name is not an active attribute, if name is a conventional
75 * attribute, or if an error occurs, -1 will be returned."
78 || var
->mode
!= ir_var_in
79 || var
->location
== -1
80 || var
->location
< VERT_ATTRIB_GENERIC0
)
83 if (strcmp(var
->name
, name
) == 0)
84 return var
->location
- VERT_ATTRIB_GENERIC0
;