summaryrefslogtreecommitdiffstats
path: root/src/mesa/main/shader_query.cpp
diff options
context:
space:
mode:
authorTapani Pälli <[email protected]>2015-03-12 13:45:22 +0200
committerTapani Pälli <[email protected]>2015-04-16 07:55:56 +0300
commite0e4d77f0120865b3ca0a4055358fc87d38d1cfe (patch)
tree38e663dd90d25ef851687b3b2920d5061d976953 /src/mesa/main/shader_query.cpp
parent2a5a0d19d67b2ccd7eee33a6f3bead66cc2d78ff (diff)
mesa: glGetProgramResourceLocation
Patch adds required helper functions to shaderapi.h and the actual implementation. corresponding Piglit test: arb_program_interface_query-resource-location The added functionality can be tested by tests for following functions that are refactored by later patches: GetAttribLocation GetUniformLocation GetFragDataLocation v2: code cleanup, changes to array element syntax checking (Ilia Mirkin) Signed-off-by: Tapani Pälli <[email protected]> Reviewed-by: Martin Peres <[email protected]>
Diffstat (limited to 'src/mesa/main/shader_query.cpp')
-rw-r--r--src/mesa/main/shader_query.cpp67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/mesa/main/shader_query.cpp b/src/mesa/main/shader_query.cpp
index ab61be97a09..f50ceb6a56b 100644
--- a/src/mesa/main/shader_query.cpp
+++ b/src/mesa/main/shader_query.cpp
@@ -754,3 +754,70 @@ _mesa_get_program_resource_name(struct gl_shader_program *shProg,
}
return true;
}
+
+static GLint
+program_resource_location(struct gl_shader_program *shProg,
+ struct gl_program_resource *res, const char *name)
+{
+ unsigned index, offset;
+ int array_index = -1;
+
+ if (res->Type == GL_PROGRAM_INPUT || res->Type == GL_PROGRAM_OUTPUT) {
+ array_index = array_index_of_resource(res, name);
+ if (array_index < 0)
+ return -1;
+ }
+
+ /* VERT_ATTRIB_GENERIC0 and FRAG_RESULT_DATA0 are decremented as these
+ * offsets are used internally to differentiate between built-in attributes
+ * and user-defined attributes.
+ */
+ switch (res->Type) {
+ case GL_PROGRAM_INPUT:
+ return RESOURCE_VAR(res)->data.location + array_index - VERT_ATTRIB_GENERIC0;
+ case GL_PROGRAM_OUTPUT:
+ return RESOURCE_VAR(res)->data.location + array_index - FRAG_RESULT_DATA0;
+ case GL_UNIFORM:
+ index = _mesa_get_uniform_location(shProg, name, &offset);
+
+ if (index == GL_INVALID_INDEX)
+ return -1;
+
+ /* From the GL_ARB_uniform_buffer_object spec:
+ *
+ * "The value -1 will be returned if <name> does not correspond to an
+ * active uniform variable name in <program>, if <name> is associated
+ * with a named uniform block, or if <name> starts with the reserved
+ * prefix "gl_"."
+ */
+ if (RESOURCE_UNI(res)->block_index != -1 ||
+ RESOURCE_UNI(res)->atomic_buffer_index != -1)
+ return -1;
+
+ /* location in remap table + array element offset */
+ return RESOURCE_UNI(res)->remap_location + offset;
+
+ default:
+ return -1;
+ }
+}
+
+/**
+ * Function implements following location queries:
+ * glGetAttribLocation
+ * glGetFragDataLocation
+ * glGetUniformLocation
+ */
+GLint
+_mesa_program_resource_location(struct gl_shader_program *shProg,
+ GLenum interface, const char *name)
+{
+ struct gl_program_resource *res =
+ _mesa_program_resource_find_name(shProg, interface, name);
+
+ /* Resource not found. */
+ if (!res)
+ return -1;
+
+ return program_resource_location(shProg, res, name);
+}