From 6147cafce137c6d3e5d7bbb6c8d5e6b5a62c3d8f Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Sun, 27 Apr 2008 00:44:18 -0400 Subject: [PATCH] Implemented uniform array setting in OpenGL glue code. --HG-- branch : trunk --- mojoshader_opengl.c | 64 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 50 insertions(+), 14 deletions(-) diff --git a/mojoshader_opengl.c b/mojoshader_opengl.c index 3cb0376b..c98ed5d8 100644 --- a/mojoshader_opengl.c +++ b/mojoshader_opengl.c @@ -280,49 +280,85 @@ void MOJOSHADER_glBindProgram(MOJOSHADER_glProgram *program) } // MOJOSHADER_glBindProgram +static inline uint maxuint(const uint a, const uint b) +{ + return ((a > b) ? a : b); +} // maxuint + + void MOJOSHADER_glSetVertexShaderUniformF(unsigned int idx, const float *data, - unsigned int vec4count) + unsigned int vec4n) { + const uint maxregs = STATICARRAYLEN(vs_register_file_f) / 4; + if (idx < maxregs) + { + const uint cpy = maxuint(maxregs - idx, vec4n) * sizeof (*data)) * 4; + memcpy(vs_register_file_f + (idx * 4), data, cpy); + } // if } // MOJOSHADER_glSetVertexShaderUniformF void MOJOSHADER_glSetVertexShaderUniformI(unsigned int idx, const int *data, - unsigned int ivec4count) + unsigned int ivec4n) { + const uint maxregs = STATICARRAYLEN(vs_register_file_i) / 4; + if (idx < maxregs) + { + const uint cpy = maxuint(maxregs - idx, ivec4n) * sizeof (*data)) * 4; + memcpy(vs_register_file_i + (idx * 4), data, cpy); + } // if } // MOJOSHADER_glSetVertexShaderUniformI void MOJOSHADER_glSetVertexShaderUniformB(unsigned int idx, const int *data, unsigned int bcount) { - // !!! FIXME: check for overflow! - uint8 *wptr = vs_register_file_b + idx; - uint8 *endptr = wptr + bcount; - while (wptr != endptr) - *(wptr++) = *(data++) ? 1 : 0; + const uint maxregs = STATICARRAYLEN(vs_register_file_f) / 4; + if (idx < maxregs) + { + uint8 *wptr = vs_register_file_b + idx; + uint8 *endptr = wptr + maxuint(maxregs - idx, bcount); + while (wptr != endptr) + *(wptr++) = *(data++) ? 1 : 0; + } // if } // MOJOSHADER_glSetVertexShaderUniformB void MOJOSHADER_glSetPixelShaderUniformF(unsigned int idx, const float *data, - unsigned int vec4count) + unsigned int vec4n) { + const uint maxregs = STATICARRAYLEN(ps_register_file_f) / 4; + if (idx < maxregs) + { + const uint cpy = maxuint(maxregs - idx, vec4n) * sizeof (*data)) * 4; + memcpy(ps_register_file_f + (idx * 4), data, cpy); + } // if } // MOJOSHADER_glSetPixelShaderUniformF void MOJOSHADER_glSetPixelShaderUniformI(unsigned int idx, const int *data, - unsigned int ivec4count) + unsigned int ivec4n) { + const uint maxregs = STATICARRAYLEN(ps_register_file_i) / 4; + if (idx < maxregs) + { + const uint cpy = maxuint(maxregs - idx, ivec4n) * sizeof (*data)) * 4; + memcpy(ps_register_file_i + (idx * 4), data, cpy); + } // if } // MOJOSHADER_glSetPixelShaderUniformI void MOJOSHADER_glSetPixelShaderUniformB(unsigned int idx, const int *data, unsigned int bcount) { - // !!! FIXME: check for overflow! - uint8 *wptr = ps_register_file_b + idx; - uint8 *endptr = wptr + bcount; - while (wptr != endptr) - *(wptr++) = *(data++) ? 1 : 0; + const uint maxregs = STATICARRAYLEN(ps_register_file_f) / 4; + if (idx < maxregs) + { + uint8 *wptr = ps_register_file_b + idx; + uint8 *endptr = wptr + maxuint(maxregs - idx, bcount); + while (wptr != endptr) + *(wptr++) = *(data++) ? 1 : 0; + } // if } // MOJOSHADER_glSetPixelShaderUniformB