summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Paul <brian.paul@tungstengraphics.com>2008-11-10 11:42:42 -0700
committerBrian Paul <brianp@vmware.com>2009-01-06 08:38:29 -0700
commitde445478915af41e1e078cbb8c2cbcce340f83b6 (patch)
treeb1df08e658cb3651c6703ff8c1e20f38e593a7e7
parentc478a1baca0d97b03f391361dfeb953939f245d4 (diff)
mesa: initial support for uniform variable initializers.
This lets one specify initial values for uniforms in the code, avoiding the need to call glUniform() in some cases. (cherry picked from commit 379ff8c9567940ebff44870cf7b0202882445fa6)
-rw-r--r--src/mesa/shader/slang/slang_codegen.c27
1 files changed, 22 insertions, 5 deletions
diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c
index d83e3b01e6..a76b6da32b 100644
--- a/src/mesa/shader/slang/slang_codegen.c
+++ b/src/mesa/shader/slang/slang_codegen.c
@@ -3705,11 +3705,6 @@ _slang_codegen_global_variable(slang_assemble_ctx *A, slang_variable *var,
const GLint totalSize = array_size(size, var->array_len);
const GLuint swizzle = _slang_var_swizzle(totalSize, 0);
- if (var->initializer) {
- slang_info_log_error(A->log, "illegal initializer for uniform '%s'", varName);
- return GL_FALSE;
- }
-
if (prog) {
/* user-defined uniform */
if (datatype == GL_NONE) {
@@ -3734,6 +3729,12 @@ _slang_codegen_global_variable(slang_assemble_ctx *A, slang_variable *var,
* "f.a" (GL_FLOAT_VEC3)
* "f.b" (GL_FLOAT_VEC4)
*/
+
+ if (var->initializer) {
+ slang_info_log_error(A->log,
+ "unsupported initializer for uniform '%s'", varName);
+ return GL_FALSE;
+ }
}
else {
slang_info_log_error(A->log,
@@ -3747,6 +3748,22 @@ _slang_codegen_global_variable(slang_assemble_ctx *A, slang_variable *var,
totalSize, datatype);
store = _slang_new_ir_storage_swz(PROGRAM_UNIFORM, uniformLoc,
totalSize, swizzle);
+ if (var->initializer) {
+ _slang_simplify(var->initializer, &A->space, A->atoms);
+ if (var->initializer->type == SLANG_OPER_LITERAL_FLOAT ||
+ var->initializer->type == SLANG_OPER_LITERAL_INT) {
+ /* simple float/vector initializer */
+ GLfloat *uniformValue =
+ prog->Parameters->ParameterValues[uniformLoc];
+ COPY_4V(uniformValue, var->initializer->literal);
+ }
+ else {
+ /* complex initializer */
+ slang_info_log_error(A->log,
+ "unsupported initializer for uniform '%s'", varName);
+ return GL_FALSE;
+ }
+ }
}
}
else {