From 733de81496dda6a99842dcf7e37f175f73d60ca6 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Mon, 18 Aug 2008 11:16:05 -0400 Subject: [PATCH] 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. --HG-- branch : trunk --- mojoshader.c | 32 ++++++-------------------------- mojoshader_opengl.c | 37 +++++++++++++++---------------------- 2 files changed, 21 insertions(+), 48 deletions(-) diff --git a/mojoshader.c b/mojoshader.c index 67c4eb36..699fdf10 100644 --- a/mojoshader.c +++ b/mojoshader.c @@ -4110,9 +4110,7 @@ static void emit_ARB1_attribute(Context *ctx, RegisterType regtype, int regnum, 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 @@ static void process_definitions(Context *ctx) (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 diff --git a/mojoshader_opengl.c b/mojoshader_opengl.c index 6a6c1fb5..cb730a95 100644 --- a/mojoshader_opengl.c +++ b/mojoshader_opengl.c @@ -1496,34 +1496,27 @@ void MOJOSHADER_glSetVertexAttribute(MOJOSHADER_usage usage, 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; + int i; - // 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. - - 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; + 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. + // !!! 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)) - { - 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.