summaryrefslogtreecommitdiffstats
path: root/src/mesa/main/shader_query.cpp
diff options
context:
space:
mode:
authorIan Romanick <[email protected]>2011-11-04 16:32:02 -0700
committerIan Romanick <[email protected]>2011-11-08 11:10:11 -0800
commit59012c31337f104aedfe69ca6d3cf784581df544 (patch)
tree220f2b9939da8be3bc29498308ca38891a4279b6 /src/mesa/main/shader_query.cpp
parentb12b5d9ab5c0153c93ca5ad9cd93cb36e41be4eb (diff)
mesa: Implement glGetFragDataLocation
Fixes piglit's getfragdatalocation test. Signed-off-by: Ian Romanick <[email protected]> Reviewed-by: Paul Berry <[email protected]> Reviewed-by: Eric Anholt <[email protected]>
Diffstat (limited to 'src/mesa/main/shader_query.cpp')
-rw-r--r--src/mesa/main/shader_query.cpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/mesa/main/shader_query.cpp b/src/mesa/main/shader_query.cpp
index 23667a13328..38bacdb747b 100644
--- a/src/mesa/main/shader_query.cpp
+++ b/src/mesa/main/shader_query.cpp
@@ -274,3 +274,59 @@ _mesa_BindFragDataLocation(GLuint program, GLuint colorNumber,
* glLinkProgram is called again.
*/
}
+
+GLint GLAPIENTRY
+_mesa_GetFragDataLocation(GLuint program, const GLchar *name)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ struct gl_shader_program *const shProg =
+ _mesa_lookup_shader_program_err(ctx, program, "glGetFragDataLocation");
+
+ if (!shProg) {
+ return -1;
+ }
+
+ if (!shProg->LinkStatus) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glGetFragDataLocation(program not linked)");
+ return -1;
+ }
+
+ if (!name)
+ return -1;
+
+ if (strncmp(name, "gl_", 3) == 0) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glGetFragDataLocation(illegal name)");
+ return -1;
+ }
+
+ /* Not having a fragment shader is not an error.
+ */
+ if (shProg->_LinkedShaders[MESA_SHADER_FRAGMENT] == NULL)
+ return -1;
+
+ exec_list *ir = shProg->_LinkedShaders[MESA_SHADER_FRAGMENT]->ir;
+ foreach_list(node, ir) {
+ const ir_variable *const var = ((ir_instruction *) node)->as_variable();
+
+ /* The extra check against FRAG_RESULT_DATA0 is because
+ * glGetFragDataLocation 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_out
+ || var->location == -1
+ || var->location < FRAG_RESULT_DATA0)
+ continue;
+
+ if (strcmp(var->name, name) == 0)
+ return var->location - FRAG_RESULT_DATA0;
+ }
+
+ return -1;
+}