mesa: glGetProgramResourceLocationIndex
authorTapani Pälli <tapani.palli@intel.com>
Thu, 12 Mar 2015 12:08:38 +0000 (14:08 +0200)
committerTapani Pälli <tapani.palli@intel.com>
Thu, 16 Apr 2015 04:55:56 +0000 (07:55 +0300)
Patch adds required helper functions to shaderapi.h and
the actual implementation.

The added functionality can be tested by tests for following
functions that are refactored by later patches:

   GetFragDataIndex

v2: return -1 if output not referenced by fragment stage
    (Ilia Mirkin)

Signed-off-by: Tapani Pälli <tapani.palli@intel.com>
Reviewed-by: Martin Peres <martin.peres@linux.intel.com>
src/mesa/main/program_resource.c
src/mesa/main/shader_query.cpp
src/mesa/main/shaderapi.h

index ee39f3125cf0591028bf70a914354393f4079557..9eb4e2ffd0c28a47b8b8991c459f202b386e9dd9 100644 (file)
@@ -364,9 +364,32 @@ _mesa_GetProgramResourceLocation(GLuint program, GLenum programInterface,
    return _mesa_program_resource_location(shProg, programInterface, name);
 }
 
+/**
+ * Returns output index for dual source blending.
+ */
 GLint GLAPIENTRY
 _mesa_GetProgramResourceLocationIndex(GLuint program, GLenum programInterface,
                                       const GLchar *name)
 {
-   return -1;
+   GET_CURRENT_CONTEXT(ctx);
+   struct gl_shader_program *shProg =
+      lookup_linked_program(program, "glGetProgramResourceLocationIndex");
+
+   if (!shProg || !name || invalid_array_element_syntax(name))
+      return -1;
+
+   /* From the GL_ARB_program_interface_query spec:
+    *
+    * "For GetProgramResourceLocationIndex, <programInterface> must be
+    * PROGRAM_OUTPUT."
+    */
+   if (programInterface != GL_PROGRAM_OUTPUT) {
+      _mesa_error(ctx, GL_INVALID_ENUM,
+                  "glGetProgramResourceLocationIndex(%s)",
+                  _mesa_lookup_enum_by_nr(programInterface));
+      return -1;
+   }
+
+   return _mesa_program_resource_location_index(shProg, GL_PROGRAM_OUTPUT,
+                                                name);
 }
index f50ceb6a56b7c098bd144e062a4b1a977e470935..8b2281ddd5c564c415a8eb25d042b2682e90dd9c 100644 (file)
@@ -821,3 +821,21 @@ _mesa_program_resource_location(struct gl_shader_program *shProg,
 
    return program_resource_location(shProg, res, name);
 }
+
+/**
+ * Function implements following index queries:
+ *    glGetFragDataIndex
+ */
+GLint
+_mesa_program_resource_location_index(struct gl_shader_program *shProg,
+                                      GLenum interface, const char *name)
+{
+   struct gl_program_resource *res =
+      _mesa_program_resource_find_name(shProg, interface, name);
+
+   /* Non-existent variable or resource is not referenced by fragment stage. */
+   if (!res || !(res->StageReferences & (1 << MESA_SHADER_FRAGMENT)))
+      return -1;
+
+   return RESOURCE_VAR(res)->data.index;
+}
index 73ebf601107e67a84be46fc1e917c1c58ab06457..50460185c33dc3dce0d5e555302eca69e19d64b1 100644 (file)
@@ -248,6 +248,10 @@ extern GLint
 _mesa_program_resource_location(struct gl_shader_program *shProg,
                                 GLenum interface, const char *name);
 
+extern GLint
+_mesa_program_resource_location_index(struct gl_shader_program *shProg,
+                                      GLenum interface, const char *name);
+
 #ifdef __cplusplus
 }
 #endif