mesa: Support EXT_framebuffer_blit targets in ES 3.0 as well.
[mesa.git] / src / mesa / main / shader_query.cpp
index e532a29e1cf96d811ed991965211e7433157ad9c..27b1b8f568848b092b2c97d86fd342b08a113645 100644 (file)
@@ -40,15 +40,11 @@ extern "C" {
 }
 
 void GLAPIENTRY
-_mesa_BindAttribLocationARB(GLhandleARB program, GLuint index,
+_mesa_BindAttribLocation(GLhandleARB program, GLuint index,
                             const GLcharARB *name)
 {
    GET_CURRENT_CONTEXT(ctx);
 
-   const GLint size = -1; /* unknown size */
-   GLint i;
-   GLenum datatype = GL_FLOAT_VEC4;
-
    struct gl_shader_program *const shProg =
       _mesa_lookup_shader_program_err(ctx, program, "glBindAttribLocation");
    if (!shProg)
@@ -81,7 +77,7 @@ _mesa_BindAttribLocationARB(GLhandleARB program, GLuint index,
 }
 
 void GLAPIENTRY
-_mesa_GetActiveAttribARB(GLhandleARB program, GLuint desired_index,
+_mesa_GetActiveAttrib(GLhandleARB program, GLuint desired_index,
                          GLsizei maxLength, GLsizei * length, GLint * size,
                          GLenum * type, GLcharARB * name)
 {
@@ -111,8 +107,7 @@ _mesa_GetActiveAttribARB(GLhandleARB program, GLuint desired_index,
 
       if (var == NULL
          || var->mode != ir_var_in
-         || var->location == -1
-         || var->location < VERT_ATTRIB_GENERIC0)
+         || var->location == -1)
         continue;
 
       if (current_index == desired_index) {
@@ -137,7 +132,7 @@ _mesa_GetActiveAttribARB(GLhandleARB program, GLuint desired_index,
 }
 
 GLint GLAPIENTRY
-_mesa_GetAttribLocationARB(GLhandleARB program, const GLcharARB * name)
+_mesa_GetAttribLocation(GLhandleARB program, const GLcharARB * name)
 {
    GET_CURRENT_CONTEXT(ctx);
    struct gl_shader_program *const shProg =
@@ -203,8 +198,7 @@ _mesa_count_active_attribs(struct gl_shader_program *shProg)
 
       if (var == NULL
          || var->mode != ir_var_in
-         || var->location == -1
-         || var->location < VERT_ATTRIB_GENERIC0)
+         || var->location == -1)
         continue;
 
       i++;
@@ -230,8 +224,7 @@ _mesa_longest_attribute_name_length(struct gl_shader_program *shProg)
 
       if (var == NULL
          || var->mode != ir_var_in
-         || var->location == -1
-         || var->location < VERT_ATTRIB_GENERIC0)
+         || var->location == -1)
         continue;
 
       const size_t len = strlen(var->name);
@@ -241,3 +234,169 @@ _mesa_longest_attribute_name_length(struct gl_shader_program *shProg)
 
    return longest;
 }
+
+void GLAPIENTRY
+_mesa_BindFragDataLocation(GLuint program, GLuint colorNumber,
+                          const GLchar *name)
+{
+   _mesa_BindFragDataLocationIndexed(program, colorNumber, 0, name);
+}
+
+void GLAPIENTRY
+_mesa_BindFragDataLocationIndexed(GLuint program, GLuint colorNumber,
+                                  GLuint index, const GLchar *name)
+{
+   GET_CURRENT_CONTEXT(ctx);
+
+   struct gl_shader_program *const shProg =
+      _mesa_lookup_shader_program_err(ctx, program, "glBindFragDataLocationIndexed");
+   if (!shProg)
+      return;
+
+   if (!name)
+      return;
+
+   if (strncmp(name, "gl_", 3) == 0) {
+      _mesa_error(ctx, GL_INVALID_OPERATION, "glBindFragDataLocationIndexed(illegal name)");
+      return;
+   }
+
+   if (index > 1) {
+      _mesa_error(ctx, GL_INVALID_VALUE, "glBindFragDataLocationIndexed(index)");
+      return;
+   }
+
+   if (index == 0 && colorNumber >= ctx->Const.MaxDrawBuffers) {
+      _mesa_error(ctx, GL_INVALID_VALUE, "glBindFragDataLocationIndexed(colorNumber)");
+      return;
+   }
+
+   if (index == 1 && colorNumber >= ctx->Const.MaxDualSourceDrawBuffers) {
+      _mesa_error(ctx, GL_INVALID_VALUE, "glBindFragDataLocationIndexed(colorNumber)");
+      return;
+   }
+
+   /* Replace the current value if it's already in the list.  Add
+    * FRAG_RESULT_DATA0 because that's how the linker differentiates
+    * between built-in attributes and user-defined attributes.
+    */
+   shProg->FragDataBindings->put(colorNumber + FRAG_RESULT_DATA0, name);
+   shProg->FragDataIndexBindings->put(index, name);
+   /*
+    * Note that this binding won't go into effect until
+    * glLinkProgram is called again.
+    */
+
+}
+
+GLint GLAPIENTRY
+_mesa_GetFragDataIndex(GLuint program, const GLchar *name)
+{
+   GET_CURRENT_CONTEXT(ctx);
+   struct gl_shader_program *const shProg =
+      _mesa_lookup_shader_program_err(ctx, program, "glGetFragDataIndex");
+
+   if (!shProg) {
+      return -1;
+   }
+
+   if (!shProg->LinkStatus) {
+      _mesa_error(ctx, GL_INVALID_OPERATION,
+                  "glGetFragDataIndex(program not linked)");
+      return -1;
+   }
+
+   if (!name)
+      return -1;
+
+   if (strncmp(name, "gl_", 3) == 0) {
+      _mesa_error(ctx, GL_INVALID_OPERATION,
+                  "glGetFragDataIndex(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->index;
+   }
+
+   return -1;
+}
+
+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;
+}