summaryrefslogtreecommitdiffstats
path: root/src/mesa/main/shader_query.cpp
diff options
context:
space:
mode:
authorIan Romanick <[email protected]>2011-08-16 12:51:25 -0700
committerIan Romanick <[email protected]>2011-10-04 12:33:28 -0700
commitb7fa0d0727a3a9e1f64d3cfc7a0f157b35dec09e (patch)
tree84d4cf73928dd54023863471f1a72e4be1b7e877 /src/mesa/main/shader_query.cpp
parent7bbcc0b832b02f9da6365ec6a86a0167cf75d8a8 (diff)
mesa: Move _mesa_GetAttribLocationARB to shader_query.cpp
This allows querying the linked shader itself rather than the Mesa IR. This is the first step towards removing gl_program::Attributes. Signed-off-by: Ian Romanick <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
Diffstat (limited to 'src/mesa/main/shader_query.cpp')
-rw-r--r--src/mesa/main/shader_query.cpp88
1 files changed, 88 insertions, 0 deletions
diff --git a/src/mesa/main/shader_query.cpp b/src/mesa/main/shader_query.cpp
new file mode 100644
index 00000000000..d5c1546967e
--- /dev/null
+++ b/src/mesa/main/shader_query.cpp
@@ -0,0 +1,88 @@
+/*
+ * Copyright © 2011 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * \file shader_query.cpp
+ * C-to-C++ bridge functions to query GLSL shader data
+ *
+ * \author Ian Romanick <[email protected]>
+ */
+
+#include "main/core.h"
+#include "glsl_symbol_table.h"
+#include "ir.h"
+#include "shaderobj.h"
+
+extern "C" {
+#include "shaderapi.h"
+}
+
+GLint GLAPIENTRY
+_mesa_GetAttribLocationARB(GLhandleARB program, const GLcharARB * name)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ struct gl_shader_program *const shProg =
+ _mesa_lookup_shader_program_err(ctx, program, "glGetAttribLocation");
+
+ if (!shProg) {
+ return -1;
+ }
+
+ if (!shProg->LinkStatus) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glGetAttribLocation(program not linked)");
+ return -1;
+ }
+
+ if (!name)
+ return -1;
+
+ /* Not having a vertex shader is not an error.
+ */
+ if (shProg->_LinkedShaders[MESA_SHADER_VERTEX] == NULL)
+ return -1;
+
+ exec_list *ir = shProg->_LinkedShaders[MESA_SHADER_VERTEX]->ir;
+ foreach_list(node, ir) {
+ const ir_variable *const var = ((ir_instruction *) node)->as_variable();
+
+ /* The extra check against VERT_ATTRIB_GENERIC0 is because
+ * glGetAttribLocation cannot be used on "conventional" attributes.
+ *
+ * From page 95 of the OpenGL 3.0 spec:
+ *
+ * "If name is not an active attribute, if name is a conventional
+ * attribute, or if an error occurs, -1 will be returned."
+ */
+ if (var == NULL
+ || var->mode != ir_var_in
+ || var->location == -1
+ || var->location < VERT_ATTRIB_GENERIC0)
+ continue;
+
+ if (strcmp(var->name, name) == 0)
+ return var->location - VERT_ATTRIB_GENERIC0;
+ }
+
+ return -1;
+}