mojoshader_opengl.c
branchtrunk
changeset 206 7027d889acdd
parent 205 8583f89985df
child 207 d9cee469e080
equal deleted inserted replaced
205:8583f89985df 206:7027d889acdd
    84     uint32 refcount;
    84     uint32 refcount;
    85 };
    85 };
    86 
    86 
    87 typedef struct
    87 typedef struct
    88 {
    88 {
       
    89     MOJOSHADER_shaderType shader_type;
    89     MOJOSHADER_uniform *uniform;
    90     MOJOSHADER_uniform *uniform;
    90     GLint location;
    91     GLint location;
    91 } UniformMap;
    92 } UniformMap;
    92 
    93 
    93 struct MOJOSHADER_glProgram
    94 struct MOJOSHADER_glProgram
   257                             MOJOSHADER_glShader *shader)
   258                             MOJOSHADER_glShader *shader)
   258 {
   259 {
   259     int i;
   260     int i;
   260     const MOJOSHADER_parseData *pd = shader->parseData;
   261     const MOJOSHADER_parseData *pd = shader->parseData;
   261     const MOJOSHADER_uniforms *u = pd->uniforms;
   262     const MOJOSHADER_uniforms *u = pd->uniforms;
       
   263     const MOJOSHADER_shaderType shader_type = pd->shader_type;
   262 
   264 
   263     for (i = 0; i < pd->uniform_count; i++)
   265     for (i = 0; i < pd->uniform_count; i++)
   264     {
   266     {
   265         const GLint loc = pglGetUniformLocationARB(program->handle, u[i].name);
   267         const GLint loc = pglGetUniformLocationARB(program->handle, u[i].name);
   266         if (loc != -1)  // maybe the Uniform was optimized out?
   268         if (loc != -1)  // maybe the Uniform was optimized out?
   267         {
   269         {
   268             UniformMap *map = &program->uniforms[program->uniform_count];
   270             UniformMap *map = &program->uniforms[program->uniform_count];
       
   271             map->shader_type = shader_type;
   269             map->uniform = &u[i];
   272             map->uniform = &u[i];
   270             map->location = loc;
   273             map->location = loc;
   271             program->uniform_count++;
   274             program->uniform_count++;
   272         } // if
   275         } // if
   273     } // for
   276     } // for
   436 } // MOJOSHADER_glSetVertexAttribute
   439 } // MOJOSHADER_glSetVertexAttribute
   437 
   440 
   438 
   441 
   439 void MOJOSHADER_glProgramReady(void)
   442 void MOJOSHADER_glProgramReady(void)
   440 {
   443 {
       
   444     int i;
       
   445 
       
   446     if (bound_program == NULL)
       
   447         return;  // nothing to do.
       
   448 
       
   449     // !!! FIXME: don't push Uniforms if we know they haven't changed.
       
   450 
       
   451     // push Uniforms to the program from our register files...
       
   452     for (i = 0; i < bound_program->uniform_count; i++)
       
   453     {
       
   454         const UniformMap *map = &bound_program->uniforms[i];
       
   455         const MOJOSHADER_uniform *u = map->uniform;
       
   456         const MOJOSHADER_uniformType type = u->type;
       
   457         const MOJOSHADER_shaderType shader_type = map->shader_type;
       
   458         const int index = u->index;
       
   459         const GLint location = map->location;
       
   460 
       
   461         if (shader_type == MOJOSHADER_TYPE_VERTEX)
       
   462         {
       
   463             if (type == MOJOSHADER_UNIFORM_FLOAT)
       
   464                 pglUniform4fvARB(location, 1, &vs_register_file_f[index * 4]);
       
   465             else if (type == MOJOSHADER_UNIFORM_INT)
       
   466                 pglUniform4ivARB(location, 1, &vs_register_file_i[index * 4]);
       
   467             else if (type == MOJOSHADER_UNIFORM_BOOL)
       
   468                 pglUniform1iARB(location, vs_register_file_b[index]);
       
   469         } // if
       
   470 
       
   471         else if (shader_type == MOJOSHADER_TYPE_PIXEL)
       
   472         {
       
   473             if (type == MOJOSHADER_UNIFORM_FLOAT)
       
   474                 pglUniform4fvARB(location, 1, &ps_register_file_f[index * 4]);
       
   475             else if (type == MOJOSHADER_UNIFORM_INT)
       
   476                 pglUniform4ivARB(location, 1, &ps_register_file_i[index * 4]);
       
   477             else if (type == MOJOSHADER_UNIFORM_BOOL)
       
   478                 pglUniform1iARB(location, ps_register_file_b[index]);
       
   479         } // else if
       
   480     } // for
   441 } // MOJOSHADER_glProgramReady
   481 } // MOJOSHADER_glProgramReady
   442 
   482 
   443 
   483 
   444 void MOJOSHADER_glDeleteProgram(const MOJOSHADER_glProgram *program)
   484 void MOJOSHADER_glDeleteProgram(const MOJOSHADER_glProgram *program)
   445 {
   485 {