mojoshader_opengl.c
branchtrunk
changeset 255 796394130035
parent 254 13184ff204b9
child 262 0f1531ac2578
equal deleted inserted replaced
254:13184ff204b9 255:796394130035
   607     program_unref(ctx->bound_program);
   607     program_unref(ctx->bound_program);
   608     ctx->bound_program = program;
   608     ctx->bound_program = program;
   609 } // MOJOSHADER_glBindProgram
   609 } // MOJOSHADER_glBindProgram
   610 
   610 
   611 
   611 
   612 static inline uint maxuint(const uint a, const uint b)
   612 static inline uint minuint(const uint a, const uint b)
   613 {
   613 {
   614     return ((a > b) ? a : b);
   614     return ((a < b) ? a : b);
   615 } // maxuint
   615 } // minuint
   616 
   616 
   617 
   617 
   618 void MOJOSHADER_glSetVertexShaderUniformF(unsigned int idx, const float *data,
   618 void MOJOSHADER_glSetVertexShaderUniformF(unsigned int idx, const float *data,
   619                                           unsigned int vec4n)
   619                                           unsigned int vec4n)
   620 {
   620 {
   621     const uint maxregs = STATICARRAYLEN(ctx->vs_reg_file_f) / 4;
   621     const uint maxregs = STATICARRAYLEN(ctx->vs_reg_file_f) / 4;
   622     if (idx < maxregs)
   622     if (idx < maxregs)
   623     {
   623     {
   624         assert(sizeof (GLfloat) == sizeof (float));
   624         assert(sizeof (GLfloat) == sizeof (float));
   625         const uint cpy = (maxuint(maxregs - idx, vec4n) * sizeof (*data)) * 4;
   625         const uint cpy = (minuint(maxregs - idx, vec4n) * sizeof (*data)) * 4;
   626         memcpy(ctx->vs_reg_file_f + (idx * 4), data, cpy);
   626         memcpy(ctx->vs_reg_file_f + (idx * 4), data, cpy);
   627     } // if
   627     } // if
   628 } // MOJOSHADER_glSetVertexShaderUniformF
   628 } // MOJOSHADER_glSetVertexShaderUniformF
   629 
   629 
   630 
   630 
   633 {
   633 {
   634     const uint maxregs = STATICARRAYLEN(ctx->vs_reg_file_i) / 4;
   634     const uint maxregs = STATICARRAYLEN(ctx->vs_reg_file_i) / 4;
   635     if (idx < maxregs)
   635     if (idx < maxregs)
   636     {
   636     {
   637         assert(sizeof (GLint) == sizeof (int));
   637         assert(sizeof (GLint) == sizeof (int));
   638         const uint cpy = (maxuint(maxregs - idx, ivec4n) * sizeof (*data)) * 4;
   638         const uint cpy = (minuint(maxregs - idx, ivec4n) * sizeof (*data)) * 4;
   639         memcpy(ctx->vs_reg_file_i + (idx * 4), data, cpy);
   639         memcpy(ctx->vs_reg_file_i + (idx * 4), data, cpy);
   640     } // if
   640     } // if
   641 } // MOJOSHADER_glSetVertexShaderUniformI
   641 } // MOJOSHADER_glSetVertexShaderUniformI
   642 
   642 
   643 
   643 
   646 {
   646 {
   647     const uint maxregs = STATICARRAYLEN(ctx->vs_reg_file_f) / 4;
   647     const uint maxregs = STATICARRAYLEN(ctx->vs_reg_file_f) / 4;
   648     if (idx < maxregs)
   648     if (idx < maxregs)
   649     {
   649     {
   650         GLint *wptr = ctx->vs_reg_file_b + idx;
   650         GLint *wptr = ctx->vs_reg_file_b + idx;
   651         GLint *endptr = wptr + maxuint(maxregs - idx, bcount);
   651         GLint *endptr = wptr + minuint(maxregs - idx, bcount);
   652         while (wptr != endptr)
   652         while (wptr != endptr)
   653             *(wptr++) = *(data++) ? 1 : 0;
   653             *(wptr++) = *(data++) ? 1 : 0;
   654     } // if
   654     } // if
   655 } // MOJOSHADER_glSetVertexShaderUniformB
   655 } // MOJOSHADER_glSetVertexShaderUniformB
   656 
   656 
   660 {
   660 {
   661     const uint maxregs = STATICARRAYLEN(ctx->ps_reg_file_f) / 4;
   661     const uint maxregs = STATICARRAYLEN(ctx->ps_reg_file_f) / 4;
   662     if (idx < maxregs)
   662     if (idx < maxregs)
   663     {
   663     {
   664         assert(sizeof (GLfloat) == sizeof (float));
   664         assert(sizeof (GLfloat) == sizeof (float));
   665         const uint cpy = (maxuint(maxregs - idx, vec4n) * sizeof (*data)) * 4;
   665         const uint cpy = (minuint(maxregs - idx, vec4n) * sizeof (*data)) * 4;
   666         memcpy(ctx->ps_reg_file_f + (idx * 4), data, cpy);
   666         memcpy(ctx->ps_reg_file_f + (idx * 4), data, cpy);
   667     } // if
   667     } // if
   668 } // MOJOSHADER_glSetPixelShaderUniformF
   668 } // MOJOSHADER_glSetPixelShaderUniformF
   669 
   669 
   670 
   670 
   673 {
   673 {
   674     const uint maxregs = STATICARRAYLEN(ctx->ps_reg_file_i) / 4;
   674     const uint maxregs = STATICARRAYLEN(ctx->ps_reg_file_i) / 4;
   675     if (idx < maxregs)
   675     if (idx < maxregs)
   676     {
   676     {
   677         assert(sizeof (GLint) == sizeof (int));
   677         assert(sizeof (GLint) == sizeof (int));
   678         const uint cpy = (maxuint(maxregs - idx, ivec4n) * sizeof (*data)) * 4;
   678         const uint cpy = (minuint(maxregs - idx, ivec4n) * sizeof (*data)) * 4;
   679         memcpy(ctx->ps_reg_file_i + (idx * 4), data, cpy);
   679         memcpy(ctx->ps_reg_file_i + (idx * 4), data, cpy);
   680     } // if
   680     } // if
   681 } // MOJOSHADER_glSetPixelShaderUniformI
   681 } // MOJOSHADER_glSetPixelShaderUniformI
   682 
   682 
   683 
   683 
   686 {
   686 {
   687     const uint maxregs = STATICARRAYLEN(ctx->ps_reg_file_f) / 4;
   687     const uint maxregs = STATICARRAYLEN(ctx->ps_reg_file_f) / 4;
   688     if (idx < maxregs)
   688     if (idx < maxregs)
   689     {
   689     {
   690         GLint *wptr = ctx->ps_reg_file_b + idx;
   690         GLint *wptr = ctx->ps_reg_file_b + idx;
   691         GLint *endptr = wptr + maxuint(maxregs - idx, bcount);
   691         GLint *endptr = wptr + minuint(maxregs - idx, bcount);
   692         while (wptr != endptr)
   692         while (wptr != endptr)
   693             *(wptr++) = *(data++) ? 1 : 0;
   693             *(wptr++) = *(data++) ? 1 : 0;
   694     } // if
   694     } // if
   695 } // MOJOSHADER_glSetPixelShaderUniformB
   695 } // MOJOSHADER_glSetPixelShaderUniformB
   696 
   696