Removed all the unnecessary POSITION0 tapdancing. trunk
authorRyan C. Gordon <icculus@icculus.org>
Mon, 18 Aug 2008 11:16:05 -0400
branchtrunk
changeset 446 217be2ec9419
parent 445 4bd3d8435e4d
child 447 67bd7577ed1f
child 819 7c157b0d5026
Removed all the unnecessary POSITION0 tapdancing. Technically, this fixes the glsl profile on Mac OS X, but really, it's fixing it everywhere; we were just getting lucky on other platforms.
mojoshader.c
mojoshader_opengl.c
--- a/mojoshader.c	Mon Aug 18 11:14:44 2008 -0400
+++ b/mojoshader.c	Mon Aug 18 11:16:05 2008 -0400
@@ -4110,9 +4110,7 @@
 
         if (regtype == REG_TYPE_INPUT)
         {
-            int attr = 0;  // POSITION0 _must_ be vertex.attrib[0]!
-            if ((usage != MOJOSHADER_USAGE_POSITION) || (index != 0))
-                attr = ++ctx->assigned_vertex_attributes;
+            const int attr = ctx->assigned_vertex_attributes++;
             push_output(ctx, &ctx->globals);
             output_line(ctx, "ATTRIB %s = vertex.attrib[%d];", varname, attr);
             pop_output(ctx);
@@ -7505,31 +7503,13 @@
                                       (TextureType) item->index);
     } // for
 
-    // ...and attributes... (find input POSITION0 here, so it's always first).
+    // ...and attributes...
     for (item = ctx->attributes.next; item != NULL; item = item->next)
     {
-        if ( (item->regtype == REG_TYPE_INPUT) &&
-             (item->usage == MOJOSHADER_USAGE_POSITION) && (item->index == 0) )
-        {
-            ctx->attribute_count++;
-            ctx->profile->attribute_emitter(ctx, item->regtype, item->regnum,
-                                            MOJOSHADER_USAGE_POSITION, 0,
-                                            item->writemask, item->misc);
-            break;
-        } // if
-    } // for
-
-    // ...and attributes... (everything but input POSITION0).
-    for (item = ctx->attributes.next; item != NULL; item = item->next)
-    {
-        if ( (item->regtype != REG_TYPE_INPUT) ||
-             (item->usage != MOJOSHADER_USAGE_POSITION) || (item->index != 0) )
-        {
-            ctx->attribute_count++;
-            ctx->profile->attribute_emitter(ctx, item->regtype, item->regnum,
-                                            item->usage, item->index,
-                                            item->writemask, item->misc);
-        } // if
+        ctx->attribute_count++;
+        ctx->profile->attribute_emitter(ctx, item->regtype, item->regnum,
+                                        item->usage, item->index,
+                                        item->writemask, item->misc);
     } // for
 } // process_definitions
 
--- a/mojoshader_opengl.c	Mon Aug 18 11:14:44 2008 -0400
+++ b/mojoshader_opengl.c	Mon Aug 18 11:16:05 2008 -0400
@@ -1496,34 +1496,27 @@
 
     const GLenum gl_type = opengl_attr_type(type);
     const GLboolean norm = (normalized) ? GL_TRUE : GL_FALSE;
+    const int count = ctx->bound_program->attribute_count;
     GLuint gl_index = 0;
-
-    // We have to map POSITION0 to generic vertex attribute 0; the
-    //  GL_ARB_vertex_shader spec says this is equivalent to using
-    //  glVertexPointer(), but without the limitations of that entry point.
+    int i;
 
-    if ((usage != MOJOSHADER_USAGE_POSITION) || (index != 0))
+    for (i = 0; i < count; i++)
     {
-        int i;
-        const int count = ctx->bound_program->attribute_count;
-        for (i = 0; i < count; i++)
+        const AttributeMap *map = &ctx->bound_program->attributes[i];
+        const MOJOSHADER_attribute *a = map->attribute;
+
+        // !!! FIXME: is this array guaranteed to be sorted by usage?
+        // !!! FIXME:  if so, we can break if a->usage > usage.
+
+        if ((a->usage == usage) && (a->index == index))
         {
-            const AttributeMap *map = &ctx->bound_program->attributes[i];
-            const MOJOSHADER_attribute *a = map->attribute;
-
-            // !!! FIXME: is this array guaranteed to be sorted by usage?
-            // !!! FIXME:  if so, we can break if a->usage > usage.
+            gl_index = map->location;
+            break;
+        } // if
+    } // for
 
-            if ((a->usage == usage) && (a->index == index))
-            {
-                gl_index = map->location;
-                break;
-            } // if
-        } // for
-
-        if (gl_index == 0)
-            return;  // nothing to do, this shader doesn't use this stream.
-    } // if
+    if (i == count)
+        return;  // nothing to do, this shader doesn't use this stream.
 
     // these happen to work in both ARB1 and GLSL, but if something alien
     //  shows up, we'll have to split these into profile*() functions.