Skip to content

Commit

Permalink
Implemented MOJOSHADER_glProgramReady().
Browse files Browse the repository at this point in the history
--HG--
branch : trunk
  • Loading branch information
icculus committed Apr 27, 2008
1 parent fb8819d commit c893b78
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions mojoshader_opengl.c
Expand Up @@ -86,6 +86,7 @@ struct MOJOSHADER_glShader

typedef struct
{
MOJOSHADER_shaderType shader_type;
MOJOSHADER_uniform *uniform;
GLint location;
} UniformMap;
Expand Down Expand Up @@ -259,13 +260,15 @@ static void lookup_uniforms(MOJOSHADER_glProgram *program,
int i;
const MOJOSHADER_parseData *pd = shader->parseData;
const MOJOSHADER_uniforms *u = pd->uniforms;
const MOJOSHADER_shaderType shader_type = pd->shader_type;

for (i = 0; i < pd->uniform_count; i++)
{
const GLint loc = pglGetUniformLocationARB(program->handle, u[i].name);
if (loc != -1) // maybe the Uniform was optimized out?
{
UniformMap *map = &program->uniforms[program->uniform_count];
map->shader_type = shader_type;
map->uniform = &u[i];
map->location = loc;
program->uniform_count++;
Expand Down Expand Up @@ -438,6 +441,43 @@ void MOJOSHADER_glSetVertexAttribute(MOJOSHADER_usage usage,

void MOJOSHADER_glProgramReady(void)
{
int i;

if (bound_program == NULL)
return; // nothing to do.

// !!! FIXME: don't push Uniforms if we know they haven't changed.

// push Uniforms to the program from our register files...
for (i = 0; i < bound_program->uniform_count; i++)
{
const UniformMap *map = &bound_program->uniforms[i];
const MOJOSHADER_uniform *u = map->uniform;
const MOJOSHADER_uniformType type = u->type;
const MOJOSHADER_shaderType shader_type = map->shader_type;
const int index = u->index;
const GLint location = map->location;

if (shader_type == MOJOSHADER_TYPE_VERTEX)
{
if (type == MOJOSHADER_UNIFORM_FLOAT)
pglUniform4fvARB(location, 1, &vs_register_file_f[index * 4]);
else if (type == MOJOSHADER_UNIFORM_INT)
pglUniform4ivARB(location, 1, &vs_register_file_i[index * 4]);
else if (type == MOJOSHADER_UNIFORM_BOOL)
pglUniform1iARB(location, vs_register_file_b[index]);
} // if

else if (shader_type == MOJOSHADER_TYPE_PIXEL)
{
if (type == MOJOSHADER_UNIFORM_FLOAT)
pglUniform4fvARB(location, 1, &ps_register_file_f[index * 4]);
else if (type == MOJOSHADER_UNIFORM_INT)
pglUniform4ivARB(location, 1, &ps_register_file_i[index * 4]);
else if (type == MOJOSHADER_UNIFORM_BOOL)
pglUniform1iARB(location, ps_register_file_b[index]);
} // else if
} // for
} // MOJOSHADER_glProgramReady


Expand Down

0 comments on commit c893b78

Please sign in to comment.