mesa: initial support for uniform variable initializers.
authorBrian Paul <brian.paul@tungstengraphics.com>
Mon, 10 Nov 2008 18:42:42 +0000 (11:42 -0700)
committerBrian Paul <brian.paul@tungstengraphics.com>
Mon, 10 Nov 2008 19:39:36 +0000 (12:39 -0700)
This lets one specify initial values for uniforms in the code, avoiding
the need to call glUniform() in some cases.

src/mesa/shader/slang/slang_codegen.c

index ea35d67969465781094c77854c115a00fad05c8f..8ab1fa8f2a6d169118e009239dcf999e304d1322 100644 (file)
@@ -3708,11 +3708,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) {
@@ -3737,6 +3732,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,
@@ -3750,6 +3751,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 {