mesa: Initialize NV_vertex_program fields for the parameter lists and such.
authorEric Anholt <eric@anholt.net>
Wed, 23 Sep 2009 23:49:52 +0000 (16:49 -0700)
committerEric Anholt <eric@anholt.net>
Thu, 24 Sep 2009 20:34:06 +0000 (13:34 -0700)
This helps let drivers treat NV_vp like ARB_vp.

src/mesa/shader/nvprogram.c
src/mesa/shader/nvprogram.h
src/mesa/shader/nvvertparse.c

index d6469b17bea7074228a4061219acbd4c26b527eb..fdb2f4210addf3734facc85d9446b66989b9f71a 100644 (file)
@@ -511,6 +511,34 @@ _mesa_GetVertexAttribPointervNV(GLuint index, GLenum pname, GLvoid **pointer)
 
 
 
+void
+_mesa_setup_nv_temporary_count(GLcontext *ctx, struct gl_program *program)
+{
+   int i;
+
+   program->NumTemporaries = 0;
+   for (i = 0; i < program->NumInstructions; i++) {
+      struct prog_instruction *inst = &program->Instructions[i];
+
+      if (inst->DstReg.File == PROGRAM_TEMPORARY) {
+        program->NumTemporaries = MAX2(program->NumTemporaries,
+                                       inst->DstReg.Index + 1);
+      }
+      if (inst->SrcReg[0].File == PROGRAM_TEMPORARY) {
+        program->NumTemporaries = MAX2(program->NumTemporaries,
+                                       inst->SrcReg[0].Index + 1);
+      }
+      if (inst->SrcReg[1].File == PROGRAM_TEMPORARY) {
+        program->NumTemporaries = MAX2(program->NumTemporaries,
+                                       inst->SrcReg[1].Index + 1);
+      }
+      if (inst->SrcReg[2].File == PROGRAM_TEMPORARY) {
+        program->NumTemporaries = MAX2(program->NumTemporaries,
+                                       inst->SrcReg[2].Index + 1);
+      }
+   }
+}
+
 /**
  * Load/parse/compile a program.
  * \note Called from the GL API dispatcher.
index bfac165b5ed29a836aa7bd16054a9b55e87699eb..0ed143d52f726cc0f81571c55b89043b1b991526 100644 (file)
@@ -103,5 +103,7 @@ extern void GLAPIENTRY
 _mesa_GetProgramNamedParameterdvNV(GLuint id, GLsizei len, const GLubyte *name,
                                    GLdouble *params);
 
+extern void
+_mesa_setup_nv_temporary_count(GLcontext *ctx, struct gl_program *program);
 
 #endif
index f5e2df267081dbe2cc41cbe4e2c22c1142b9298b..a94e6b8b80353aa57b7b89806ce40a2295c986a3 100644 (file)
@@ -44,6 +44,7 @@
 #include "nvprogram.h"
 #include "nvvertparse.h"
 #include "prog_instruction.h"
+#include "prog_parameter.h"
 #include "prog_print.h"
 #include "program.h"
 
@@ -1345,6 +1346,9 @@ _mesa_parse_nv_vertex_program(GLcontext *ctx, GLenum dstTarget,
 
 
    if (Parse_Program(&parseState, instBuffer)) {
+      gl_state_index state_tokens[STATE_LENGTH] = {0, 0, 0, 0, 0};
+      int i;
+
       /* successful parse! */
 
       if (parseState.isStateProgram) {
@@ -1398,6 +1402,27 @@ _mesa_parse_nv_vertex_program(GLcontext *ctx, GLenum dstTarget,
       _mesa_fprint_program_opt(stdout, &program->Base, PROG_PRINT_NV, 0);
       _mesa_printf("------------------------------\n");
 #endif
+
+      if (program->Base.Parameters)
+        _mesa_free_parameter_list(program->Base.Parameters);
+
+      program->Base.Parameters = _mesa_new_parameter_list ();
+      program->Base.NumParameters = 0;
+
+      state_tokens[0] = STATE_VERTEX_PROGRAM;
+      state_tokens[1] = STATE_ENV;
+      /* Add refs to all of the potential params, in order.  If we want to not
+       * upload everything, _mesa_layout_parameters is the answer.
+       */
+      for (i = 0; i < MAX_NV_VERTEX_PROGRAM_PARAMS; i++) {
+        state_tokens[2] = i;
+        int index = _mesa_add_state_reference(program->Base.Parameters,
+                                              state_tokens);
+        assert(index == i);
+      }
+      program->Base.NumParameters = program->Base.Parameters->NumParameters;
+
+      _mesa_setup_nv_temporary_count(ctx, &program->Base);
    }
    else {
       /* Error! */