diff options
author | Ian Romanick <[email protected]> | 2011-10-18 14:29:43 -0700 |
---|---|---|
committer | Ian Romanick <[email protected]> | 2011-11-07 13:33:16 -0800 |
commit | 9516182e80d5a21ab402c9b2cbe9e6c46e5bb1d8 (patch) | |
tree | 6384710a940594a5ce54f47383c68ff0c29688a7 /src/mesa/main/uniform_query.cpp | |
parent | 07731ed1692eb5d72110b3c5b693f37e581e3809 (diff) |
mesa: Add _mesa_propagate_uniforms_to_driver_storage
This function propagates the values from the backing storage of a
gl_uniform_storage structure to the driver supplied data locations.
Signed-off-by: Ian Romanick <[email protected]>
Tested-by: Tom Stellard <[email protected]>
Diffstat (limited to 'src/mesa/main/uniform_query.cpp')
-rw-r--r-- | src/mesa/main/uniform_query.cpp | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/src/mesa/main/uniform_query.cpp b/src/mesa/main/uniform_query.cpp index c680cd4920e..120317cc2fc 100644 --- a/src/mesa/main/uniform_query.cpp +++ b/src/mesa/main/uniform_query.cpp @@ -26,6 +26,7 @@ #include "main/context.h" #include "ir.h" #include "../glsl/program.h" +#include "../glsl/ir_uniform.h" extern "C" { #include "main/image.h" @@ -738,6 +739,122 @@ set_program_uniform(struct gl_context *ctx, struct gl_program *program, } /** + * Propagate some values from uniform backing storage to driver storage + * + * Values propagated from uniform backing storage to driver storage + * have all format / type conversions previously requested by the + * driver applied. This function is most often called by the + * implementations of \c glUniform1f, etc. and \c glUniformMatrix2f, + * etc. + * + * \param uni Uniform whose data is to be propagated to driver storage + * \param array_index If \c uni is an array, this is the element of + * the array to be propagated. + * \param count Number of array elements to propagate. + */ +extern "C" void +_mesa_propagate_uniforms_to_driver_storage(struct gl_uniform_storage *uni, + unsigned array_index, + unsigned count) +{ + unsigned i; + + /* vector_elements and matrix_columns can be 0 for samplers. + */ + const unsigned components = MAX2(1, uni->type->vector_elements); + const unsigned vectors = MAX2(1, uni->type->matrix_columns); + + /* Store the data in the driver's requested type in the driver's storage + * areas. + */ + unsigned src_vector_byte_stride = components * 4; + + for (i = 0; i < uni->num_driver_storage; i++) { + struct gl_uniform_driver_storage *const store = &uni->driver_storage[i]; + uint8_t *dst = (uint8_t *) store->data; + const unsigned extra_stride = + store->element_stride - (vectors * store->vector_stride); + const uint8_t *src = + (uint8_t *) (&uni->storage[array_index * (components * vectors)].i); + +#if 0 + printf("%s: %p[%d] components=%u vectors=%u count=%u vector_stride=%u " + "extra_stride=%u\n", + __func__, dst, array_index, components, + vectors, count, store->vector_stride, extra_stride); +#endif + + dst += array_index * store->element_stride; + + switch (store->format) { + case uniform_native: + case uniform_bool_int_0_1: { + unsigned j; + unsigned v; + + for (j = 0; j < count; j++) { + for (v = 0; v < vectors; v++) { + memcpy(dst, src, src_vector_byte_stride); + src += src_vector_byte_stride; + dst += store->vector_stride; + } + + dst += extra_stride; + } + break; + } + + case uniform_int_float: + case uniform_bool_float: { + const int *isrc = (const int *) src; + unsigned j; + unsigned v; + unsigned c; + + for (j = 0; j < count; j++) { + for (v = 0; v < vectors; v++) { + for (c = 0; c < components; c++) { + ((float *) dst)[c] = (float) *isrc; + isrc++; + } + + dst += store->vector_stride; + } + + dst += extra_stride; + } + break; + } + + case uniform_bool_int_0_not0: { + const int *isrc = (const int *) src; + unsigned j; + unsigned v; + unsigned c; + + for (j = 0; j < count; j++) { + for (v = 0; v < vectors; v++) { + for (c = 0; c < components; c++) { + ((int *) dst)[c] = *isrc == 0 ? 0 : ~0; + isrc++; + } + + dst += store->vector_stride; + } + + dst += extra_stride; + } + break; + } + + default: + assert(!"Should not get here."); + break; + } + } +} + +/** * Called via glUniform*() functions. */ extern "C" void |