Skip to content

Commit

Permalink
Removed all the unnecessary POSITION0 tapdancing.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
icculus committed Aug 18, 2008
1 parent 381a258 commit 733de81
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 48 deletions.
32 changes: 6 additions & 26 deletions mojoshader.c
Expand Up @@ -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);
Expand Down Expand Up @@ -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

Expand Down
37 changes: 15 additions & 22 deletions mojoshader_opengl.c
Expand Up @@ -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.
Expand Down

0 comments on commit 733de81

Please sign in to comment.