Minor tweaks to help out at a driver level.
[mesa.git] / src / mesa / main / nvprogram.c
index 61dca5001acb45c4f3301cd48264ed2d81601227..d32cb7f2b51608fb898010612e6431b0de45a1ce 100644 (file)
@@ -1,8 +1,8 @@
 /*
  * Mesa 3-D graphics library
- * Version:  5.1
+ * Version:  6.0
  *
- * Copyright (C) 1999-2003  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2004  Brian Paul   All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
  * \author Brian Paul
  */
 
+/*
+ * Regarding GL_NV_fragment/vertex_program, GL_NV_vertex_program1_1, etc:
+ *
+ * Portions of this software may use or implement intellectual
+ * property owned and licensed by NVIDIA Corporation. NVIDIA disclaims
+ * any and all warranties with respect to such intellectual property,
+ * including any use thereof or modifications thereto.
+ */
 
 #include "glheader.h"
 #include "context.h"
 #include "nvvertparse.h"
 #include "nvvertprog.h"
 #include "nvprogram.h"
+#include "program.h"
 
 
-/**
- * Set the vertex/fragment program error state (position and error string).
- * This is generally called from within the parsers.
- */
-void
-_mesa_set_program_error(GLcontext *ctx, GLint pos, const char *string)
-{
-   ctx->Program.ErrorPos = pos;
-   _mesa_free((void *) ctx->Program.ErrorString);
-   if (!string)
-      string = "";
-   ctx->Program.ErrorString = _mesa_strdup(string);
-}
-
-
-/**
- * Find the line number and column for 'pos' within 'string'.
- * Return a copy of the line which contains 'pos'.  Free the line with
- * _mesa_free().
- * \param string  the program string
- * \param pos     the position within the string
- * \param line    returns the line number corresponding to 'pos'.
- * \param col     returns the column number corresponding to 'pos'.
- * \return copy of the line containing 'pos'.
- */
-const GLubyte *
-_mesa_find_line_column(const GLubyte *string, const GLubyte *pos,
-                       GLint *line, GLint *col)
-{
-   const GLubyte *lineStart = string;
-   const GLubyte *p = string;
-   GLubyte *s;
-   int len;
-
-   *line = 1;
-
-   while (p != pos) {
-      if (*p == (GLubyte) '\n') {
-         (*line)++;
-         lineStart = p + 1;
-      }
-      p++;
-   }
-
-   *col = (pos - lineStart) + 1;
-
-   /* return copy of this line */
-   while (*p != 0 && *p != '\n')
-      p++;
-   len = p - lineStart;
-   s = (GLubyte *) _mesa_malloc(len + 1);
-   _mesa_memcpy(s, lineStart, len);
-   s[len] = 0;
-
-   return s;
-}
-
-
-
-/**
- * Allocate and initialize a new fragment/vertex program object
- * \param ctx  context
- * \param id   program id/number
- * \param target  program target/type
- * \return  pointer to new program object
- */
-struct program *
-_mesa_alloc_program(GLcontext *ctx, GLenum target, GLuint id)
-{
-   struct program *prog;
-
-   if (target == GL_VERTEX_PROGRAM_NV
-       || target == GL_VERTEX_PROGRAM_ARB) {
-      struct vertex_program *vprog = CALLOC_STRUCT(vertex_program);
-      if (!vprog) {
-         return NULL;
-      }
-      prog = &(vprog->Base);
-   }
-   else if (target == GL_FRAGMENT_PROGRAM_NV
-            || target == GL_FRAGMENT_PROGRAM_ARB) {
-      struct fragment_program *fprog = CALLOC_STRUCT(fragment_program);
-      if (!fprog) {
-         return NULL;
-      }
-      prog = &(fprog->Base);
-   }
-   else {
-      _mesa_problem(ctx, "bad target in _mesa_alloc_program");
-      return NULL;
-   }
-   prog->Id = id;
-   prog->Target = target;
-   prog->Resident = GL_TRUE;
-   prog->RefCount = 1;
-   return prog;
-}
-
-
-/**
- * Delete a program and remove it from the hash table, ignoring the
- * reference count.
- * \note Called from the GL API dispatcher.
- */
-void
-_mesa_delete_program(GLcontext *ctx, struct program *prog)
-{
-   ASSERT(prog);
-
-   if (prog->String)
-      _mesa_free(prog->String);
-   if (prog->Target == GL_VERTEX_PROGRAM_NV ||
-       prog->Target == GL_VERTEX_STATE_PROGRAM_NV) {
-      struct vertex_program *vprog = (struct vertex_program *) prog;
-      if (vprog->Instructions)
-         _mesa_free(vprog->Instructions);
-   }
-   else if (prog->Target == GL_FRAGMENT_PROGRAM_NV) {
-      struct fragment_program *fprog = (struct fragment_program *) prog;
-      if (fprog->Instructions)
-         _mesa_free(fprog->Instructions);
-      if (fprog->Parameters) {
-         GLuint i;
-         for (i = 0; i < fprog->NumParameters; i++) {
-            _mesa_free((void *) fprog->Parameters[i].Name);
-         }
-         _mesa_free(fprog->Parameters);
-      }
-   }
-   _mesa_free(prog);
-}
-
-
-/**
- * Bind a program (make it current)
- * \note Called from the GL API dispatcher by both glBindProgramNV
- * and glBindProgramARB.
- */
-void
-_mesa_BindProgramNV(GLenum target, GLuint id)
-{
-   struct program *prog;
-   GET_CURRENT_CONTEXT(ctx);
-   ASSERT_OUTSIDE_BEGIN_END(ctx);
-
-   if ((target == GL_VERTEX_PROGRAM_NV
-        && ctx->Extensions.NV_vertex_program) ||
-       (target == GL_VERTEX_PROGRAM_ARB
-        && ctx->Extensions.ARB_vertex_program)) {
-      if (ctx->VertexProgram.Current &&
-          ctx->VertexProgram.Current->Base.Id == id)
-         return;
-      /* decrement refcount on previously bound vertex program */
-      if (ctx->VertexProgram.Current) {
-         ctx->VertexProgram.Current->Base.RefCount--;
-         /* and delete if refcount goes below one */
-         if (ctx->VertexProgram.Current->Base.RefCount <= 0) {
-            _mesa_delete_program(ctx, &(ctx->VertexProgram.Current->Base));
-            _mesa_HashRemove(ctx->Shared->Programs, id);
-         }
-      }
-   }
-   else if ((target == GL_FRAGMENT_PROGRAM_NV
-             && ctx->Extensions.NV_fragment_program) ||
-            (target == GL_FRAGMENT_PROGRAM_ARB
-             && ctx->Extensions.ARB_fragment_program)) {
-      if (ctx->FragmentProgram.Current &&
-          ctx->FragmentProgram.Current->Base.Id == id)
-         return;
-      /* decrement refcount on previously bound fragment program */
-      if (ctx->FragmentProgram.Current) {
-         ctx->FragmentProgram.Current->Base.RefCount--;
-         /* and delete if refcount goes below one */
-         if (ctx->FragmentProgram.Current->Base.RefCount <= 0) {
-            _mesa_delete_program(ctx, &(ctx->FragmentProgram.Current->Base));
-            _mesa_HashRemove(ctx->Shared->Programs, id);
-         }
-      }
-   }
-   else {
-      _mesa_error(ctx, GL_INVALID_ENUM, "glBindProgramNV/ARB(target)");
-      return;
-   }
-
-   /* NOTE: binding to a non-existant program is not an error.
-    * That's supposed to be caught in glBegin.
-    */
-   if (id == 0) {
-      /* default program */
-      prog = NULL;
-      if (target == GL_VERTEX_PROGRAM_NV || target == GL_VERTEX_PROGRAM_ARB)
-         prog = ctx->Shared->DefaultVertexProgram;
-      else
-         prog = ctx->Shared->DefaultFragmentProgram;
-   }
-   else {
-      prog = (struct program *) _mesa_HashLookup(ctx->Shared->Programs, id);
-      if (prog) {
-         if (prog->Target == 0) {
-            /* prog was allocated with glGenProgramsNV */
-            prog->Target = target;
-         }
-         else if (prog->Target != target) {
-            _mesa_error(ctx, GL_INVALID_OPERATION,
-                        "glBindProgramNV/ARB(target mismatch)");
-            return;
-         }
-      }
-      else {
-         /* allocate a new program now */
-         prog = _mesa_alloc_program(ctx, target, id);
-         if (!prog) {
-            _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindProgramNV/ARB");
-            return;
-         }
-         prog->Id = id;
-         prog->Target = target;
-         prog->Resident = GL_TRUE;
-         prog->RefCount = 1;
-         _mesa_HashInsert(ctx->Shared->Programs, id, prog);
-      }
-   }
-
-   /* bind now */
-   if (target == GL_VERTEX_PROGRAM_NV || target == GL_VERTEX_PROGRAM_ARB) {
-      ctx->VertexProgram.Current = (struct vertex_program *) prog;
-   }
-   else if (target == GL_FRAGMENT_PROGRAM_NV || target == GL_FRAGMENT_PROGRAM_ARB) {
-      ctx->FragmentProgram.Current = (struct fragment_program *) prog;
-   }
-
-   if (prog)
-      prog->RefCount++;
-}
-
-
-/**
- * Delete a list of programs.
- * \note Not compiled into display lists.
- * \note Called by both glDeleteProgramsNV and glDeleteProgramsARB.
- */
-void
-_mesa_DeleteProgramsNV(GLsizei n, const GLuint *ids)
-{
-   GLint i;
-   GET_CURRENT_CONTEXT(ctx);
-   ASSERT_OUTSIDE_BEGIN_END(ctx);
-
-   if (n < 0) {
-      _mesa_error( ctx, GL_INVALID_VALUE, "glDeleteProgramsNV" );
-      return;
-   }
-
-   for (i = 0; i < n; i++) {
-      if (ids[i] != 0) {
-         struct program *prog = (struct program *)
-            _mesa_HashLookup(ctx->Shared->Programs, ids[i]);
-         if (prog) {
-            if (prog->Target == GL_VERTEX_PROGRAM_NV ||
-                prog->Target == GL_VERTEX_STATE_PROGRAM_NV) {
-               if (ctx->VertexProgram.Current &&
-                   ctx->VertexProgram.Current->Base.Id == ids[i]) {
-                  /* unbind this currently bound program */
-                  _mesa_BindProgramNV(prog->Target, 0);
-               }
-            }
-            else if (prog->Target == GL_FRAGMENT_PROGRAM_NV) {
-               if (ctx->FragmentProgram.Current &&
-                   ctx->FragmentProgram.Current->Base.Id == ids[i]) {
-                  /* unbind this currently bound program */
-                  _mesa_BindProgramNV(prog->Target, 0);
-               }
-            }
-            else {
-               _mesa_problem(ctx, "bad target in glDeleteProgramsNV");
-               return;
-            }
-            prog->RefCount--;
-            if (prog->RefCount <= 0) {
-               _mesa_delete_program(ctx, prog);
-            }
-         }
-      }
-   }
-}
-
 
 /**
  * Execute a vertex state program.
  * \note Called from the GL API dispatcher.
  */
-void
+void GLAPIENTRY
 _mesa_ExecuteProgramNV(GLenum target, GLuint id, const GLfloat *params)
 {
    struct vertex_program *vprog;
@@ -346,6 +69,8 @@ _mesa_ExecuteProgramNV(GLenum target, GLuint id, const GLfloat *params)
       return;
    }
 
+   FLUSH_VERTICES(ctx, _NEW_PROGRAM);
+
    vprog = (struct vertex_program *)
       _mesa_HashLookup(ctx->Shared->Programs, id);
 
@@ -361,55 +86,12 @@ _mesa_ExecuteProgramNV(GLenum target, GLuint id, const GLfloat *params)
 }
 
 
-/**
- * Generate a list of new program identifiers.
- * \note Not compiled into display lists.
- * \note Called by both glGenProgramsNV and glGenProgramsARB.
- */
-void
-_mesa_GenProgramsNV(GLsizei n, GLuint *ids)
-{
-   GLuint first;
-   GLuint i;
-   GET_CURRENT_CONTEXT(ctx);
-   ASSERT_OUTSIDE_BEGIN_END(ctx);
-
-   if (n < 0) {
-      _mesa_error(ctx, GL_INVALID_VALUE, "glGenPrograms");
-      return;
-   }
-
-   if (!ids)
-      return;
-
-   first = _mesa_HashFindFreeKeyBlock(ctx->Shared->Programs, n);
-
-   for (i = 0; i < (GLuint) n; i++) {
-      const int bytes = MAX2(sizeof(struct vertex_program),
-                             sizeof(struct fragment_program));
-      struct program *prog = (struct program *) _mesa_calloc(bytes);
-      if (!prog) {
-         _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGenPrograms");
-         return;
-      }
-      prog->RefCount = 1;
-      prog->Id = first + i;
-      _mesa_HashInsert(ctx->Shared->Programs, first + i, prog);
-   }
-
-   /* Return the program names */
-   for (i = 0; i < (GLuint) n; i++) {
-      ids[i] = first + i;
-   }
-}
-
-
 /**
  * Determine if a set of programs is resident in hardware.
  * \note Not compiled into display lists.
  * \note Called from the GL API dispatcher.
  */
-GLboolean _mesa_AreProgramsResidentNV(GLsizei n, const GLuint *ids,
+GLboolean GLAPIENTRY _mesa_AreProgramsResidentNV(GLsizei n, const GLuint *ids,
                                       GLboolean *residences)
 {
    GLint i, j;
@@ -456,7 +138,7 @@ GLboolean _mesa_AreProgramsResidentNV(GLsizei n, const GLuint *ids,
  * Request that a set of programs be resident in hardware.
  * \note Called from the GL API dispatcher.
  */
-void
+void GLAPIENTRY
 _mesa_RequestResidentProgramsNV(GLsizei n, const GLuint *ids)
 {
    GLint i;
@@ -494,7 +176,7 @@ _mesa_RequestResidentProgramsNV(GLsizei n, const GLuint *ids)
  * \note Not compiled into display lists.
  * \note Called from the GL API dispatcher.
  */
-void
+void GLAPIENTRY
 _mesa_GetProgramParameterfvNV(GLenum target, GLuint index,
                               GLenum pname, GLfloat *params)
 {
@@ -529,7 +211,7 @@ _mesa_GetProgramParameterfvNV(GLenum target, GLuint index,
  * \note Not compiled into display lists.
  * \note Called from the GL API dispatcher.
  */
-void
+void GLAPIENTRY
 _mesa_GetProgramParameterdvNV(GLenum target, GLuint index,
                               GLenum pname, GLdouble *params)
 {
@@ -564,7 +246,7 @@ _mesa_GetProgramParameterdvNV(GLenum target, GLuint index,
  * \note Not compiled into display lists.
  * \note Called from the GL API dispatcher.
  */
-void
+void GLAPIENTRY
 _mesa_GetProgramivNV(GLuint id, GLenum pname, GLint *params)
 {
    struct program *prog;
@@ -601,7 +283,7 @@ _mesa_GetProgramivNV(GLuint id, GLenum pname, GLint *params)
  * \note Not compiled into display lists.
  * \note Called from the GL API dispatcher.
  */
-void
+void GLAPIENTRY
 _mesa_GetProgramStringNV(GLuint id, GLenum pname, GLubyte *program)
 {
    struct program *prog;
@@ -635,7 +317,7 @@ _mesa_GetProgramStringNV(GLuint id, GLenum pname, GLubyte *program)
  * \note Not compiled into display lists.
  * \note Called from the GL API dispatcher.
  */
-void
+void GLAPIENTRY
 _mesa_GetTrackMatrixivNV(GLenum target, GLuint address,
                          GLenum pname, GLint *params)
 {
@@ -677,7 +359,7 @@ _mesa_GetTrackMatrixivNV(GLenum target, GLuint address,
  * \note Not compiled into display lists.
  * \note Called from the GL API dispatcher.
  */
-void
+void GLAPIENTRY
 _mesa_GetVertexAttribdvNV(GLuint index, GLenum pname, GLdouble *params)
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -713,7 +395,7 @@ _mesa_GetVertexAttribdvNV(GLuint index, GLenum pname, GLdouble *params)
  * \note Not compiled into display lists.
  * \note Called from the GL API dispatcher.
  */
-void
+void GLAPIENTRY
 _mesa_GetVertexAttribfvNV(GLuint index, GLenum pname, GLfloat *params)
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -749,7 +431,7 @@ _mesa_GetVertexAttribfvNV(GLuint index, GLenum pname, GLfloat *params)
  * \note Not compiled into display lists.
  * \note Called from the GL API dispatcher.
  */
-void
+void GLAPIENTRY
 _mesa_GetVertexAttribivNV(GLuint index, GLenum pname, GLint *params)
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -782,7 +464,7 @@ _mesa_GetVertexAttribivNV(GLuint index, GLenum pname, GLint *params)
             _mesa_error(ctx, GL_INVALID_ENUM, "glGetVertexAttribdvNV");
             return;
          }
-         params[0] = ctx->Array.VertexAttribArrayBufferBinding[index];
+         params[0] = ctx->Array.VertexAttrib[index].BufferObj->Name;
          break;
       default:
          _mesa_error(ctx, GL_INVALID_ENUM, "glGetVertexAttribdvNV");
@@ -796,7 +478,7 @@ _mesa_GetVertexAttribivNV(GLuint index, GLenum pname, GLint *params)
  * \note Not compiled into display lists.
  * \note Called from the GL API dispatcher.
  */
-void
+void GLAPIENTRY
 _mesa_GetVertexAttribPointervNV(GLuint index, GLenum pname, GLvoid **pointer)
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -812,40 +494,16 @@ _mesa_GetVertexAttribPointervNV(GLuint index, GLenum pname, GLvoid **pointer)
       return;
    }
 
-   *pointer = ctx->Array.VertexAttrib[index].Ptr;;
+   *pointer = (GLvoid *) ctx->Array.VertexAttrib[index].Ptr;;
 }
 
 
-/**
- * Determine if id names a program.
- * \note Not compiled into display lists.
- * \note Called from both glIsProgramNV and glIsProgramARB.
- * \param id is the program identifier
- * \return GL_TRUE if id is a program, else GL_FALSE.
- */
-GLboolean
-_mesa_IsProgramNV(GLuint id)
-{
-   struct program *prog;
-   GET_CURRENT_CONTEXT(ctx);
-   ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
-
-   if (id == 0)
-      return GL_FALSE;
-
-   prog = (struct program *) _mesa_HashLookup(ctx->Shared->Programs, id);
-   if (prog && prog->Target)
-      return GL_TRUE;
-   else
-      return GL_FALSE;
-}
-
 
 /**
  * Load/parse/compile a program.
  * \note Called from the GL API dispatcher.
  */
-void
+void GLAPIENTRY
 _mesa_LoadProgramNV(GLenum target, GLuint id, GLsizei len,
                     const GLubyte *program)
 {
@@ -858,6 +516,8 @@ _mesa_LoadProgramNV(GLenum target, GLuint id, GLsizei len,
       return;
    }
 
+   FLUSH_VERTICES(ctx, _NEW_PROGRAM);
+
    prog = (struct program *) _mesa_HashLookup(ctx->Shared->Programs, id);
 
    if (prog && prog->Target != 0 && prog->Target != target) {
@@ -907,7 +567,7 @@ _mesa_LoadProgramNV(GLenum target, GLuint id, GLsizei len,
  * Set a program parameter register.
  * \note Called from the GL API dispatcher.
  */
-void
+void GLAPIENTRY
 _mesa_ProgramParameter4dNV(GLenum target, GLuint index,
                            GLdouble x, GLdouble y, GLdouble z, GLdouble w)
 {
@@ -920,7 +580,7 @@ _mesa_ProgramParameter4dNV(GLenum target, GLuint index,
  * Set a program parameter register.
  * \note Called from the GL API dispatcher.
  */
-void
+void GLAPIENTRY
 _mesa_ProgramParameter4dvNV(GLenum target, GLuint index,
                             const GLdouble *params)
 {
@@ -934,7 +594,7 @@ _mesa_ProgramParameter4dvNV(GLenum target, GLuint index,
  * Set a program parameter register.
  * \note Called from the GL API dispatcher.
  */
-void
+void GLAPIENTRY
 _mesa_ProgramParameter4fNV(GLenum target, GLuint index,
                            GLfloat x, GLfloat y, GLfloat z, GLfloat w)
 {
@@ -943,6 +603,7 @@ _mesa_ProgramParameter4fNV(GLenum target, GLuint index,
 
    if (target == GL_VERTEX_PROGRAM_NV && ctx->Extensions.NV_vertex_program) {
       if (index < MAX_NV_VERTEX_PROGRAM_PARAMS) {
+         FLUSH_VERTICES(ctx, _NEW_PROGRAM);
          ASSIGN_4V(ctx->VertexProgram.Parameters[index], x, y, z, w);
       }
       else {
@@ -961,7 +622,7 @@ _mesa_ProgramParameter4fNV(GLenum target, GLuint index,
  * Set a program parameter register.
  * \note Called from the GL API dispatcher.
  */
-void
+void GLAPIENTRY
 _mesa_ProgramParameter4fvNV(GLenum target, GLuint index,
                             const GLfloat *params)
 {
@@ -975,7 +636,7 @@ _mesa_ProgramParameter4fvNV(GLenum target, GLuint index,
  * Set a sequence of program parameter registers.
  * \note Called from the GL API dispatcher.
  */
-void
+void GLAPIENTRY
 _mesa_ProgramParameters4dvNV(GLenum target, GLuint index,
                              GLuint num, const GLdouble *params)
 {
@@ -1007,7 +668,7 @@ _mesa_ProgramParameters4dvNV(GLenum target, GLuint index,
  * Set a sequence of program parameter registers.
  * \note Called from the GL API dispatcher.
  */
-void
+void GLAPIENTRY
 _mesa_ProgramParameters4fvNV(GLenum target, GLuint index,
                              GLuint num, const GLfloat *params)
 {
@@ -1037,13 +698,15 @@ _mesa_ProgramParameters4fvNV(GLenum target, GLuint index,
  * Setup tracking of matrices into program parameter registers.
  * \note Called from the GL API dispatcher.
  */
-void
+void GLAPIENTRY
 _mesa_TrackMatrixNV(GLenum target, GLuint address,
                     GLenum matrix, GLenum transform)
 {
    GET_CURRENT_CONTEXT(ctx);
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
+   FLUSH_VERTICES(ctx, _NEW_PROGRAM);
+
    if (target == GL_VERTEX_PROGRAM_NV && ctx->Extensions.NV_vertex_program) {
       if (address & 0x3) {
          /* addr must be multiple of four */
@@ -1095,16 +758,19 @@ _mesa_TrackMatrixNV(GLenum target, GLuint address,
 }
 
 
-void
+void GLAPIENTRY
 _mesa_ProgramNamedParameter4fNV(GLuint id, GLsizei len, const GLubyte *name,
                                 GLfloat x, GLfloat y, GLfloat z, GLfloat w)
 {
    struct program *prog;
    struct fragment_program *fragProg;
-   GLuint i;
+   GLfloat *v;
+
    GET_CURRENT_CONTEXT(ctx);
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
+   FLUSH_VERTICES(ctx, _NEW_PROGRAM);
+
    prog = (struct program *) _mesa_HashLookup(ctx->Shared->Programs, id);
    if (!prog || prog->Target != GL_FRAGMENT_PROGRAM_NV) {
       _mesa_error(ctx, GL_INVALID_OPERATION, "glProgramNamedParameterNV");
@@ -1117,24 +783,20 @@ _mesa_ProgramNamedParameter4fNV(GLuint id, GLsizei len, const GLubyte *name,
    }
 
    fragProg = (struct fragment_program *) prog;
-   for (i = 0; i < fragProg->NumParameters; i++) {
-      if (!_mesa_strncmp(fragProg->Parameters[i].Name,
-                         (const char *) name, len) &&
-          fragProg->Parameters[i].Name[len] == 0) {
-         ASSERT(!fragProg->Parameters[i].Constant);
-         fragProg->Parameters[i].Values[0] = x;
-         fragProg->Parameters[i].Values[1] = y;
-         fragProg->Parameters[i].Values[2] = z;
-         fragProg->Parameters[i].Values[3] = w;
-         return;
-      }
+   v = _mesa_lookup_parameter_value(fragProg->Parameters, len, (char *) name);
+   if (v) {
+      v[0] = x;
+      v[1] = y;
+      v[2] = z;
+      v[3] = w;
+      return;
    }
 
    _mesa_error(ctx, GL_INVALID_VALUE, "glProgramNamedParameterNV");
 }
 
 
-void
+void GLAPIENTRY
 _mesa_ProgramNamedParameter4fvNV(GLuint id, GLsizei len, const GLubyte *name,
                                  const float v[])
 {
@@ -1142,7 +804,7 @@ _mesa_ProgramNamedParameter4fvNV(GLuint id, GLsizei len, const GLubyte *name,
 }
 
 
-void
+void GLAPIENTRY
 _mesa_ProgramNamedParameter4dNV(GLuint id, GLsizei len, const GLubyte *name,
                                 GLdouble x, GLdouble y, GLdouble z, GLdouble w)
 {
@@ -1151,7 +813,7 @@ _mesa_ProgramNamedParameter4dNV(GLuint id, GLsizei len, const GLubyte *name,
 }
 
 
-void
+void GLAPIENTRY
 _mesa_ProgramNamedParameter4dvNV(GLuint id, GLsizei len, const GLubyte *name,
                                  const double v[])
 {
@@ -1161,13 +823,14 @@ _mesa_ProgramNamedParameter4dvNV(GLuint id, GLsizei len, const GLubyte *name,
 }
 
 
-void
+void GLAPIENTRY
 _mesa_GetProgramNamedParameterfvNV(GLuint id, GLsizei len, const GLubyte *name,
                                    GLfloat *params)
 {
    struct program *prog;
    struct fragment_program *fragProg;
-   GLuint i;
+   const GLfloat *v;
+
    GET_CURRENT_CONTEXT(ctx);
 
    if (!ctx->_CurrentProgram)
@@ -1185,24 +848,20 @@ _mesa_GetProgramNamedParameterfvNV(GLuint id, GLsizei len, const GLubyte *name,
    }
 
    fragProg = (struct fragment_program *) prog;
-   for (i = 0; i < fragProg->NumParameters; i++) {
-      if (!_mesa_strncmp(fragProg->Parameters[i].Name,
-                         (const char *) name, len) &&
-          fragProg->Parameters[i].Name[len] == 0) {
-         ASSERT(!fragProg->Parameters[i].Constant);
-         params[0] = fragProg->Parameters[i].Values[0];
-         params[1] = fragProg->Parameters[i].Values[1];
-         params[2] = fragProg->Parameters[i].Values[2];
-         params[3] = fragProg->Parameters[i].Values[3];
-         return;
-      }
+   v = _mesa_lookup_parameter_value(fragProg->Parameters, len, (char *) name);
+   if (v) {
+      params[0] = v[0];
+      params[1] = v[1];
+      params[2] = v[2];
+      params[3] = v[3];
+      return;
    }
 
    _mesa_error(ctx, GL_INVALID_VALUE, "glGetProgramNamedParameterNV");
 }
 
 
-void
+void GLAPIENTRY
 _mesa_GetProgramNamedParameterdvNV(GLuint id, GLsizei len, const GLubyte *name,
                                    GLdouble *params)
 {