checkpoint: more infrastructure for GL_ARB_vertex/fragment_program.
authorBrian Paul <brian.paul@tungstengraphics.com>
Thu, 17 Apr 2003 01:48:19 +0000 (01:48 +0000)
committerBrian Paul <brian.paul@tungstengraphics.com>
Thu, 17 Apr 2003 01:48:19 +0000 (01:48 +0000)
src/mesa/main/arbprogram.c
src/mesa/main/config.h
src/mesa/main/context.c
src/mesa/main/mtypes.h
src/mesa/main/nvprogram.c
src/mesa/main/nvprogram.h
src/mesa/main/nvvertexec.c
src/mesa/main/nvvertexec.h
src/mesa/main/nvvertparse.c
src/mesa/main/nvvertparse.h

index 54df8183b5c1a675d6f3d8d39f927bab1070bc78..f78f257aa6383246d002bddf5a7f04e9d4d4bd15 100644 (file)
 #include "imports.h"
 #include "macros.h"
 #include "mtypes.h"
+#include "nvprogram.h"
 #include "arbprogram.h"
 
 
+/* XXX temporary */
+extern void _mesa_parse_arb_vertex_program(GLcontext *ctx, GLenum target,
+                                           const GLubyte *string, GLsizei len,
+                                           struct vertex_program *prog);
+
+extern void _mesa_parse_arb_fragment_program(GLcontext *ctx, GLenum target,
+                                           const GLubyte *string, GLsizei len,
+                                           struct fragment_program *prog);
+
 
 void
 _mesa_VertexAttrib1sARB(GLuint index, GLshort x)
@@ -231,36 +241,131 @@ _mesa_VertexAttribPointerARB(GLuint index, GLint size, GLenum type,
 void
 _mesa_EnableVertexAttribArrayARB(GLuint index)
 {
+   GET_CURRENT_CONTEXT(ctx);
+   ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+   if (index >= ctx->Const.MaxVertexProgramAttribs) {
+      _mesa_error(ctx, GL_INVALID_VALUE,
+                  "glEnableVertexAttribArrayARB(index)");
+      return;
+   }
+
+   ctx->Array.VertexAttrib[index].Enabled = GL_TRUE;
+   ctx->Array._Enabled |= _NEW_ARRAY_ATTRIB(index);
+   ctx->Array.NewState |= _NEW_ARRAY_ATTRIB(index);
 }
 
 
 void
 _mesa_DisableVertexAttribArrayARB(GLuint index)
 {
+   GET_CURRENT_CONTEXT(ctx);
+   ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+   if (index >= ctx->Const.MaxVertexProgramAttribs) {
+      _mesa_error(ctx, GL_INVALID_VALUE,
+                  "glEnableVertexAttribArrayARB(index)");
+      return;
+   }
+
+   ctx->Array.VertexAttrib[index].Enabled = GL_FALSE;
+   ctx->Array._Enabled &= ~_NEW_ARRAY_ATTRIB(index);
+   ctx->Array.NewState &= ~_NEW_ARRAY_ATTRIB(index);
 }
 
 
 void
 _mesa_GetVertexAttribdvARB(GLuint index, GLenum pname, GLdouble *params)
 {
+   GLfloat fparams[4];
+   GET_CURRENT_CONTEXT(ctx);
+   ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+   _mesa_GetVertexAttribfvARB(index, pname, fparams);
+   if (ctx->ErrorValue == GL_NO_ERROR) {
+      if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
+         COPY_4V(params, fparams);
+      }
+      else {
+         params[0] = fparams[0];
+      }
+   }
 }
 
 
 void
 _mesa_GetVertexAttribfvARB(GLuint index, GLenum pname, GLfloat *params)
 {
+   GET_CURRENT_CONTEXT(ctx);
+   ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+   if (index == 0 || index >= VERT_ATTRIB_MAX) {
+      _mesa_error(ctx, GL_INVALID_VALUE, "glGetVertexAttribfvARB(index)");
+      return;
+   }
+
+   switch (pname) {
+      case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB:
+         params[0] = ctx->Array.VertexAttrib[index].Enabled;
+         break;
+      case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB:
+         params[0] = ctx->Array.VertexAttrib[index].Size;
+         break;
+      case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB:
+         params[0] = ctx->Array.VertexAttrib[index].Stride;
+         break;
+      case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB:
+         params[0] = ctx->Array.VertexAttrib[index].Type;
+         break;
+      case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB:
+         params[0] = ctx->Array.VertexAttrib[index].Normalized;
+         break;
+      case GL_CURRENT_VERTEX_ATTRIB_ARB:
+         COPY_4V(params, ctx->Current.Attrib[index]);
+         break;
+      default:
+         _mesa_error(ctx, GL_INVALID_ENUM, "glGetVertexAttribfvARB(pname)");
+         return;
+   }
 }
 
 
 void
 _mesa_GetVertexAttribivARB(GLuint index, GLenum pname, GLint *params)
 {
+   GLfloat fparams[4];
+   GET_CURRENT_CONTEXT(ctx);
+   ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+   _mesa_GetVertexAttribfvARB(index, pname, fparams);
+   if (ctx->ErrorValue == GL_NO_ERROR) {
+      if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
+         COPY_4V(params, fparams);  /* float to int */
+      }
+      else {
+         params[0] = fparams[0];
+      }
+   }
 }
 
 
 void
 _mesa_GetVertexAttribPointervARB(GLuint index, GLenum pname, GLvoid **pointer)
 {
+   GET_CURRENT_CONTEXT(ctx);
+   ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+   if (index >= ctx->Const.MaxVertexProgramAttribs) {
+      _mesa_error(ctx, GL_INVALID_VALUE, "glGetVertexAttribPointerARB(index)");
+      return;
+   }
+
+   if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB) {
+      _mesa_error(ctx, GL_INVALID_ENUM, "glGetVertexAttribPointerARB(pname)");
+      return;
+   }
+
+   *pointer = ctx->Array.VertexAttrib[index].Ptr;;
 }
 
 
@@ -268,24 +373,134 @@ void
 _mesa_ProgramStringARB(GLenum target, GLenum format, GLsizei len,
                        const GLvoid *string)
 {
+   GET_CURRENT_CONTEXT(ctx);
+   ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+   if (target == GL_VERTEX_PROGRAM_ARB
+       && ctx->Extensions.ARB_vertex_program) {
+      struct vertex_program *prog = ctx->VertexProgram.Current;
+      if (format != GL_PROGRAM_FORMAT_ASCII_ARB) {
+         _mesa_error(ctx, GL_INVALID_ENUM, "glProgramStringARB(format)");
+         return;
+      }
+      _mesa_parse_arb_vertex_program(ctx, target, string, len, prog);
+   }
+   else if (target == GL_FRAGMENT_PROGRAM_ARB
+            && ctx->Extensions.ARB_fragment_program) {
+      struct fragment_program *prog = ctx->FragmentProgram.Current;
+      if (format != GL_PROGRAM_FORMAT_ASCII_ARB) {
+         _mesa_error(ctx, GL_INVALID_ENUM, "glProgramStringARB(format)");
+         return;
+      }
+      _mesa_parse_arb_fragment_program(ctx, target, string, len, prog);
+   }
+   else {
+      _mesa_error(ctx, GL_INVALID_ENUM, "glProgramStringARB(target)");
+   }
 }
 
 
 void
 _mesa_BindProgramARB(GLenum target, GLuint program)
 {
+   struct program *prog;
+   GET_CURRENT_CONTEXT(ctx);
+   ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+   if (target == GL_VERTEX_PROGRAM_ARB
+       && ctx->Extensions.ARB_vertex_program) {
+      if (ctx->VertexProgram.Current &&
+          ctx->VertexProgram.Current->Base.Id == program)
+         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, program);
+         }
+      }
+   }
+   else if (target == GL_FRAGMENT_PROGRAM_ARB
+            && ctx->Extensions.ARB_fragment_program) {
+      if (ctx->FragmentProgram.Current &&
+          ctx->FragmentProgram.Current->Base.Id == program)
+         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, program);
+         }
+      }
+   }
+   else {
+      _mesa_error(ctx, GL_INVALID_ENUM, "glBindProgramARB(target)");
+      return;
+   }
+
+   /* NOTE: binding to a non-existant program is not an error.
+    * That's supposed to be caught in glBegin.
+    * NOTE: program number 0 is legal here.
+    */
+   if (program == 0) {
+      /* default program */
+      if (target == GL_VERTEX_PROGRAM_NV)
+         prog = ctx->Shared->DefaultVertexProgram;
+      else
+         prog = ctx->Shared->DefaultFragmentProgram;
+   }
+   else {
+      prog = (struct program *) _mesa_HashLookup(ctx->Shared->Programs, program);
+   }
+   if (!prog && program > 0){
+      /* allocate new program */
+      prog = _mesa_alloc_program(ctx, target, program);
+      if (!prog) {
+         _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindProgramARB");
+         return;
+      }
+      prog->Id = program;
+      prog->Target = target;
+      prog->Resident = GL_TRUE;
+      prog->RefCount = 1;
+      _mesa_HashInsert(ctx->Shared->Programs, program, prog);
+   }
+
+   /* bind now */
+   if (target == GL_VERTEX_PROGRAM_NV) {
+      ctx->VertexProgram.Current = (struct vertex_program *) prog;
+   }
+   else if (target == GL_FRAGMENT_PROGRAM_NV) {
+      ctx->FragmentProgram.Current = (struct fragment_program *) prog;
+   }
+
+   if (prog)
+      prog->RefCount++;
 }
 
 
 void
 _mesa_DeleteProgramsARB(GLsizei n, const GLuint *programs)
 {
+   _mesa_DeleteProgramsNV(n, programs);
 }
 
 
 void
 _mesa_GenProgramsARB(GLsizei n, GLuint *programs)
 {
+   _mesa_GenProgramsNV(n, programs);
+}
+
+
+GLboolean
+_mesa_IsProgramARB(GLuint program)
+{
+   return _mesa_IsProgramNV(program);
 }
 
 
@@ -293,13 +508,16 @@ void
 _mesa_ProgramEnvParameter4dARB(GLenum target, GLuint index,
                                GLdouble x, GLdouble y, GLdouble z, GLdouble w)
 {
+   _mesa_ProgramEnvParameter4fARB(target, index, x, y, z, w);
 }
 
 
 void
 _mesa_ProgramEnvParameter4dvARB(GLenum target, GLuint index,
-                                   const GLdouble *params)
+                                const GLdouble *params)
 {
+   _mesa_ProgramEnvParameter4fARB(target, index, params[0], params[1],
+                                  params[2], params[3]);
 }
 
 
@@ -307,6 +525,31 @@ void
 _mesa_ProgramEnvParameter4fARB(GLenum target, GLuint index,
                                GLfloat x, GLfloat y, GLfloat z, GLfloat w)
 {
+   GET_CURRENT_CONTEXT(ctx);
+   ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+   if (target == GL_FRAGMENT_PROGRAM_NV
+       && ctx->Extensions.ARB_fragment_program) {
+      if (index >= ctx->Const.MaxFragmentProgramEnvParams) {
+         _mesa_error(ctx, GL_INVALID_VALUE, "glProgramEnvParameter(index)");
+         return;
+      }
+      index += MAX_NV_FRAGMENT_PROGRAM_TEMPS;  /* XXX fix */
+      ASSIGN_4V(ctx->FragmentProgram.Machine.Registers[index], x, y, z, w);
+   }
+   if (target == GL_VERTEX_PROGRAM_NV
+       && ctx->Extensions.ARB_vertex_program) {
+      if (index >= ctx->Const.MaxVertexProgramEnvParams) {
+         _mesa_error(ctx, GL_INVALID_VALUE, "glProgramEnvParameter(index)");
+         return;
+      }
+      index += MAX_NV_VERTEX_PROGRAM_TEMPS;  /* XXX fix */
+      ASSIGN_4V(ctx->VertexProgram.Machine.Registers[index], x, y, z, w);
+   }
+   else {
+      _mesa_error(ctx, GL_INVALID_ENUM, "glProgramEnvParameter(target)");
+      return;
+   }
 }
 
 
@@ -314,10 +557,61 @@ void
 _mesa_ProgramEnvParameter4fvARB(GLenum target, GLuint index,
                                    const GLfloat *params)
 {
+   _mesa_ProgramEnvParameter4fARB(target, index, params[0], params[1],
+                                  params[2], params[3]);
+}
+
+
+void
+_mesa_GetProgramEnvParameterdvARB(GLenum target, GLuint index,
+                                  GLdouble *params)
+{
+   GET_CURRENT_CONTEXT(ctx);
+   GLfloat fparams[4];
+
+   _mesa_GetProgramEnvParameterfvARB(target, index, fparams);
+   if (ctx->ErrorValue == GL_NO_ERROR) {
+      params[0] = fparams[0];
+      params[1] = fparams[1];
+      params[2] = fparams[2];
+      params[3] = fparams[3];
+   }
+}
+
+
+void
+_mesa_GetProgramEnvParameterfvARB(GLenum target, GLuint index, 
+                                  GLfloat *params)
+{
+   GET_CURRENT_CONTEXT(ctx);
+   ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+   if (target == GL_FRAGMENT_PROGRAM_NV
+       && ctx->Extensions.ARB_fragment_program) {
+      if (index >= ctx->Const.MaxFragmentProgramEnvParams) {
+         _mesa_error(ctx, GL_INVALID_VALUE, "glGetProgramEnvParameter(index)");
+         return;
+      }
+      index += MAX_NV_FRAGMENT_PROGRAM_TEMPS;  /* XXX fix */
+      COPY_4V(params, ctx->FragmentProgram.Machine.Registers[index]);
+   }
+   if (target == GL_VERTEX_PROGRAM_NV
+       && ctx->Extensions.ARB_vertex_program) {
+      if (index >= ctx->Const.MaxVertexProgramEnvParams) {
+         _mesa_error(ctx, GL_INVALID_VALUE, "glGetProgramEnvParameter(index)");
+         return;
+      }
+      index += MAX_NV_VERTEX_PROGRAM_TEMPS;  /* XXX fix */
+      COPY_4V(params, ctx->VertexProgram.Machine.Registers[index]);
+   }
+   else {
+      _mesa_error(ctx, GL_INVALID_ENUM, "glGetProgramEnvParameter(target)");
+      return;
+   }
 }
 
 
-#if 111
+#if 111 /* from nvprogram.c */
 
 void
 _mesa_ProgramLocalParameter4fARB(GLenum target, GLuint index,
@@ -326,13 +620,16 @@ _mesa_ProgramLocalParameter4fARB(GLenum target, GLuint index,
    GET_CURRENT_CONTEXT(ctx);
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
-   if (target == GL_FRAGMENT_PROGRAM_NV) {
+   if ((target == GL_FRAGMENT_PROGRAM_NV
+        && ctx->Extensions.NV_fragment_program) ||
+       (target == GL_FRAGMENT_PROGRAM_ARB
+        && ctx->Extensions.ARB_fragment_program)) {
       struct fragment_program *fprog = ctx->FragmentProgram.Current;
       if (!fprog) {
          _mesa_error(ctx, GL_INVALID_ENUM, "glProgramLocalParameterARB");
          return;
       }
-      if (index >= MAX_NV_FRAGMENT_PROGRAM_PARAMS) {
+      if (index >= ctx->Const.MaxFragmentProgramLocalParams) {
          _mesa_error(ctx, GL_INVALID_VALUE, "glProgramLocalParameterARB");
          return;
       }
@@ -341,6 +638,22 @@ _mesa_ProgramLocalParameter4fARB(GLenum target, GLuint index,
       fprog->Base.LocalParams[index][2] = z;
       fprog->Base.LocalParams[index][3] = w;
    }
+   else if (target == GL_VERTEX_PROGRAM_ARB
+            && ctx->Extensions.ARB_vertex_program) {
+      struct vertex_program *vprog = ctx->VertexProgram.Current;
+      if (!vprog) {
+         _mesa_error(ctx, GL_INVALID_ENUM, "glProgramLocalParameterARB");
+         return;
+      }
+      if (index >= ctx->Const.MaxVertexProgramLocalParams) {
+         _mesa_error(ctx, GL_INVALID_VALUE, "glProgramLocalParameterARB");
+         return;
+      }
+      vprog->Base.LocalParams[index][0] = x;
+      vprog->Base.LocalParams[index][1] = y;
+      vprog->Base.LocalParams[index][2] = z;
+      vprog->Base.LocalParams[index][3] = w;
+   }
    else {
       _mesa_error(ctx, GL_INVALID_ENUM, "glProgramLocalParameterARB");
       return;
@@ -352,8 +665,8 @@ void
 _mesa_ProgramLocalParameter4fvARB(GLenum target, GLuint index,
                                   const GLfloat *params)
 {
-   glProgramLocalParameter4fARB(target, index, params[0], params[1],
-                                params[2], params[3]);
+   _mesa_ProgramLocalParameter4fARB(target, index, params[0], params[1],
+                                    params[2], params[3]);
 }
 
 
@@ -362,8 +675,8 @@ _mesa_ProgramLocalParameter4dARB(GLenum target, GLuint index,
                                  GLdouble x, GLdouble y,
                                  GLdouble z, GLdouble w)
 {
-   glProgramLocalParameter4fARB(target, index, (GLfloat)x, (GLfloat)y, 
-                                              (GLfloat)z, (GLfloat)w);
+   _mesa_ProgramLocalParameter4fARB(target, index, (GLfloat) x, (GLfloat) y, 
+                                    (GLfloat) z, (GLfloat) w);
 }
 
 
@@ -371,9 +684,9 @@ void
 _mesa_ProgramLocalParameter4dvARB(GLenum target, GLuint index,
                                   const GLdouble *params)
 {
-   glProgramLocalParameter4fARB(target, index, (GLfloat)params[0], 
-                               (GLfloat)params[1], (GLfloat)params[2],
-                               (GLfloat)params[3]);
+   _mesa_ProgramLocalParameter4fARB(target, index,
+                                    (GLfloat) params[0], (GLfloat) params[1],
+                                    (GLfloat) params[2], (GLfloat) params[3]);
 }
 
 
@@ -381,7 +694,7 @@ void
 _mesa_GetProgramLocalParameterfvARB(GLenum target, GLuint index,
                                     GLfloat *params)
 {
-   struct program *prog;
+   const struct program *prog;
    GLuint maxParams;
    GET_CURRENT_CONTEXT(ctx);
    ASSERT_OUTSIDE_BEGIN_END(ctx);
@@ -389,14 +702,14 @@ _mesa_GetProgramLocalParameterfvARB(GLenum target, GLuint index,
    if (target == GL_VERTEX_PROGRAM_ARB
        && ctx->Extensions.ARB_vertex_program) {
       prog = &(ctx->VertexProgram.Current->Base);
-      maxParams = ctx->Const.MaxVertexProgramParams;
+      maxParams = ctx->Const.MaxVertexProgramLocalParams;
    }
    else if ((target == GL_FRAGMENT_PROGRAM_ARB
              && ctx->Extensions.ARB_fragment_program) ||
             (target == GL_FRAGMENT_PROGRAM_NV
              && ctx->Extensions.NV_fragment_program)) {
       prog = &(ctx->FragmentProgram.Current->Base);
-      maxParams = ctx->Const.MaxFragmentProgramParams;
+      maxParams = ctx->Const.MaxFragmentProgramLocalParams;
    }
    else {
       _mesa_error(ctx, GL_INVALID_ENUM,
@@ -411,10 +724,7 @@ _mesa_GetProgramLocalParameterfvARB(GLenum target, GLuint index,
    }
 
    ASSERT(prog);
-   params[0] = prog->LocalParams[index][0];
-   params[1] = prog->LocalParams[index][1];
-   params[2] = prog->LocalParams[index][2];
-   params[3] = prog->LocalParams[index][3];
+   COPY_4V(params, prog->LocalParams[index]);
 }
 
 
@@ -423,12 +733,11 @@ _mesa_GetProgramLocalParameterdvARB(GLenum target, GLuint index,
                                     GLdouble *params)
 {
    GLfloat floatParams[4];
-   glGetProgramLocalParameterfvARB(target, index, floatParams);
+   _mesa_GetProgramLocalParameterfvARB(target, index, floatParams);
    COPY_4V(params, floatParams);
 }
 
-#else
-
+#else /* stubs */
 
 void
 _mesa_ProgramLocalParameter4dARB(GLenum target, GLuint index,
@@ -458,23 +767,6 @@ _mesa_ProgramLocalParameter4fvARB(GLenum target, GLuint index,
 {
 }
 
-#endif
-
-void
-_mesa_GetProgramEnvParameterdvARB(GLenum target, GLuint index,
-                                  GLdouble *params)
-{
-}
-
-
-void
-_mesa_GetProgramEnvParameterfvARB(GLenum target, GLuint index, 
-                                  GLfloat *params)
-{
-}
-
-
-#if 000
 void
 _mesa_GetProgramLocalParameterdvARB(GLenum target, GLuint index,
                                     GLdouble *params)
@@ -487,8 +779,8 @@ _mesa_GetProgramLocalParameterfvARB(GLenum target, GLuint index,
                                     GLfloat *params)
 {
 }
-#endif
 
+#endif /* stubs */
 
 
 void
@@ -498,10 +790,12 @@ _mesa_GetProgramivARB(GLenum target, GLenum pname, GLint *params)
    GET_CURRENT_CONTEXT(ctx);
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
-   if (target == GL_VERTEX_PROGRAM_ARB) {
+   if (target == GL_VERTEX_PROGRAM_ARB
+       && ctx->Extensions.ARB_vertex_program) {
       prog = &(ctx->VertexProgram.Current->Base);
    }
-   else if (target == GL_FRAGMENT_PROGRAM_ARB) {
+   else if (target == GL_FRAGMENT_PROGRAM_ARB
+            && ctx->Extensions.ARB_vertex_program) {
       prog = &(ctx->FragmentProgram.Current->Base);
    }
    else {
@@ -525,27 +819,167 @@ _mesa_GetProgramivARB(GLenum target, GLenum pname, GLint *params)
          *params = prog->NumInstructions;
          break;
       case GL_MAX_PROGRAM_INSTRUCTIONS_ARB:
+         if (target == GL_VERTEX_PROGRAM_ARB)
+            *params = ctx->Const.MaxVertexProgramInstructions;
+         else
+            *params = ctx->Const.MaxFragmentProgramInstructions;
+         break;
       case GL_PROGRAM_NATIVE_INSTRUCTIONS_ARB:
+         *params = prog->NumInstructions;
+         break;
       case GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB:
+         if (target == GL_VERTEX_PROGRAM_ARB)
+            *params = ctx->Const.MaxVertexProgramInstructions;
+         else
+            *params = ctx->Const.MaxFragmentProgramInstructions;
+         break;
       case GL_PROGRAM_TEMPORARIES_ARB:
+         *params = prog->NumTemporaries;
+         break;
       case GL_MAX_PROGRAM_TEMPORARIES_ARB:
+         if (target == GL_VERTEX_PROGRAM_ARB)
+            *params = ctx->Const.MaxVertexProgramTemps;
+         else
+            *params = ctx->Const.MaxFragmentProgramTemps;
+         break;
       case GL_PROGRAM_NATIVE_TEMPORARIES_ARB:
+         /* XXX same as GL_PROGRAM_TEMPORARIES_ARB? */
+         *params = prog->NumTemporaries;
+         break;
       case GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB:
+         /* XXX same as GL_MAX_PROGRAM_TEMPORARIES_ARB? */
+         if (target == GL_VERTEX_PROGRAM_ARB)
+            *params = ctx->Const.MaxVertexProgramTemps;
+         else
+            *params = ctx->Const.MaxFragmentProgramTemps;
+         break;
       case GL_PROGRAM_PARAMETERS_ARB:
+         *params = prog->NumParameters;
+         break;
       case GL_MAX_PROGRAM_PARAMETERS_ARB:
+         if (target == GL_VERTEX_PROGRAM_ARB)
+            *params = ctx->Const.MaxVertexProgramLocalParams;
+         else
+            *params = ctx->Const.MaxFragmentProgramLocalParams;
+         break;
       case GL_PROGRAM_NATIVE_PARAMETERS_ARB:
+         /* XXX same as GL_MAX_PROGRAM_PARAMETERS_ARB? */
+         *params = prog->NumParameters;
+         break;
       case GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB:
+         /* XXX same as GL_MAX_PROGRAM_PARAMETERS_ARB? */
+         if (target == GL_VERTEX_PROGRAM_ARB)
+            *params = ctx->Const.MaxVertexProgramLocalParams;
+         else
+            *params = ctx->Const.MaxFragmentProgramLocalParams;
+         break;
       case GL_PROGRAM_ATTRIBS_ARB:
+         *params = prog->NumAttributes;
+         break;
       case GL_MAX_PROGRAM_ATTRIBS_ARB:
+         if (target == GL_VERTEX_PROGRAM_ARB)
+            *params = ctx->Const.MaxVertexProgramAttribs;
+         else
+            *params = ctx->Const.MaxFragmentProgramAttribs;
+         break;
       case GL_PROGRAM_NATIVE_ATTRIBS_ARB:
+         /* XXX same as GL_PROGRAM_ATTRIBS_ARB? */
+         *params = prog->NumAttributes;
+         break;
       case GL_MAX_PROGRAM_NATIVE_ATTRIBS_ARB:
+         /* XXX same as GL_MAX_PROGRAM_ATTRIBS_ARB? */
+         if (target == GL_VERTEX_PROGRAM_ARB)
+            *params = ctx->Const.MaxVertexProgramAttribs;
+         else
+            *params = ctx->Const.MaxFragmentProgramAttribs;
+         break;
       case GL_PROGRAM_ADDRESS_REGISTERS_ARB:
+         *params = prog->NumAddressRegs;
+         break;
       case GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB:
+         if (target == GL_VERTEX_PROGRAM_ARB)
+            *params = ctx->Const.MaxVertexProgramAddressRegs;
+         else
+            *params = ctx->Const.MaxFragmentProgramAddressRegs;
+         break;
       case GL_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB:
+         /* XXX same as GL_PROGRAM_ADDRESS_REGISTERS_ARB? */
+         *params = prog->NumAddressRegs;
+         break;
       case GL_MAX_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB:
+         /* XXX same as GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB? */
+         if (target == GL_VERTEX_PROGRAM_ARB)
+            *params = ctx->Const.MaxVertexProgramAddressRegs;
+         else
+            *params = ctx->Const.MaxFragmentProgramAddressRegs;
+         break;
       case GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB:
+         if (target == GL_VERTEX_PROGRAM_ARB)
+            *params = ctx->Const.MaxVertexProgramLocalParams;
+         else
+            *params = ctx->Const.MaxFragmentProgramLocalParams;
+         break;
       case GL_MAX_PROGRAM_ENV_PARAMETERS_ARB:
+         if (target == GL_VERTEX_PROGRAM_ARB)
+            *params = ctx->Const.MaxVertexProgramEnvParams;
+         else
+            *params = ctx->Const.MaxFragmentProgramEnvParams;
+         break;
       case GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB:
+         /* XXX ok? */
+         *params = GL_TRUE;
+         break;
+
+      /*
+       * The following apply to fragment programs only.
+       */
+      case GL_PROGRAM_ALU_INSTRUCTIONS_ARB:
+      case GL_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB:
+         if (target != GL_FRAGMENT_PROGRAM_ARB) {
+            _mesa_error(ctx, GL_INVALID_ENUM, "glGetProgramivARB(target)");
+            return;
+         }
+         *params = ctx->FragmentProgram.Current->NumAluInstructions;
+         break;
+      case GL_PROGRAM_TEX_INSTRUCTIONS_ARB:
+      case GL_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB:
+         if (target != GL_FRAGMENT_PROGRAM_ARB) {
+            _mesa_error(ctx, GL_INVALID_ENUM, "glGetProgramivARB(target)");
+            return;
+         }
+         *params = ctx->FragmentProgram.Current->NumTexInstructions;
+         break;
+      case GL_PROGRAM_TEX_INDIRECTIONS_ARB:
+      case GL_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB:
+         if (target != GL_FRAGMENT_PROGRAM_ARB) {
+            _mesa_error(ctx, GL_INVALID_ENUM, "glGetProgramivARB(target)");
+            return;
+         }
+         *params = ctx->FragmentProgram.Current->NumTexIndirections;
+         break;
+      case GL_MAX_PROGRAM_ALU_INSTRUCTIONS_ARB:
+      case GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB:
+         if (target != GL_FRAGMENT_PROGRAM_ARB) {
+            _mesa_error(ctx, GL_INVALID_ENUM, "glGetProgramivARB(target)");
+            return;
+         }
+         *params = ctx->Const.MaxFragmentProgramAluInstructions;
+         break;
+      case GL_MAX_PROGRAM_TEX_INSTRUCTIONS_ARB:
+      case GL_MAX_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB:
+         if (target != GL_FRAGMENT_PROGRAM_ARB) {
+            _mesa_error(ctx, GL_INVALID_ENUM, "glGetProgramivARB(target)");
+            return;
+         }
+         *params = ctx->Const.MaxFragmentProgramTexInstructions;
+         break;
+      case GL_MAX_PROGRAM_TEX_INDIRECTIONS_ARB:
+      case GL_MAX_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB:
+         if (target != GL_FRAGMENT_PROGRAM_ARB) {
+            _mesa_error(ctx, GL_INVALID_ENUM, "glGetProgramivARB(target)");
+            return;
+         }
+         *params = ctx->Const.MaxFragmentProgramTexIndirections;
          break;
       default:
          _mesa_error(ctx, GL_INVALID_ENUM, "glGetProgramivARB(pname)");
@@ -581,21 +1015,3 @@ _mesa_GetProgramStringARB(GLenum target, GLenum pname, GLvoid *string)
 
    MEMCPY(string, prog->String, _mesa_strlen((char *) prog->String));
 }
-
-
-GLboolean
-_mesa_IsProgramARB(GLuint program)
-{
-   struct program *prog;
-   GET_CURRENT_CONTEXT(ctx);
-   ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
-
-   if (program == 0)
-      return GL_FALSE;
-
-   prog = (struct program *) _mesa_HashLookup(ctx->Shared->Programs, program);
-   if (prog && prog->Target)
-      return GL_TRUE;
-   else
-      return GL_FALSE;
-}
index f1f621c6b82a6c5a11059acd5f90241c03cc34d7..f537a539e6db1a3b9bdf93d76197f83270acd789 100644 (file)
 #define MAX_NV_FRAGMENT_PROGRAM_OUTPUTS        3
 #define MAX_NV_FRAGMENT_PROGRAM_WRITE_ONLYS    2
 
+/* GL_ARB_vertex_program */
+#define MAX_VERTEX_PROGRAM_ADDRESS_REGS 1
+
+/* GL_ARB_fragment_program */
+#define MAX_FRAGMENT_PROGRAM_ADDRESS_REGS 1
+#define MAX_FRAGMENT_PROGRAM_ALU_INSTRUCTIONS 48
+#define MAX_FRAGMENT_PROGRAM_TEX_INSTRUCTIONS 24
+#define MAX_FRAGMENT_PROGRAM_TEX_INDIRECTIONS  4
 
 
 /*
index 6c816ebd8ba7f43512a5fe085e30387572eea2bd..88dea9e1db5fa188abb16c3a7b1a52ad1015af58 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: context.c,v 1.198 2003/04/11 01:20:08 brianp Exp $ */
+/* $Id: context.c,v 1.199 2003/04/17 01:48:20 brianp Exp $ */
 
 /*
  * Mesa 3-D graphics library
@@ -650,10 +650,21 @@ alloc_shared_state( GLcontext *ctx )
 
    ss->DisplayList = _mesa_NewHashTable();
    ss->TexObjects = _mesa_NewHashTable();
-#if FEATURE_NV_vertex_program
+#if FEATURE_NV_vertex_program || FEATURE_NV_fragment_program
    ss->Programs = _mesa_NewHashTable();
 #endif
 
+#if FEATURE_ARB_vertex_program
+   ss->DefaultVertexProgram = _mesa_alloc_program(ctx, GL_VERTEX_PROGRAM_ARB, 0);
+   if (!ss->DefaultVertexProgram)
+      goto cleanup;
+#endif
+#if FEATURE_ARB_fragment_program
+   ss->DefaultFragmentProgram = _mesa_alloc_program(ctx, GL_FRAGMENT_PROGRAM_ARB, 0);
+   if (!ss->DefaultFragmentProgram)
+      goto cleanup;
+#endif
+
    ss->Default1D = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_1D);
    if (!ss->Default1D)
       goto cleanup;
@@ -700,6 +711,14 @@ alloc_shared_state( GLcontext *ctx )
 #if FEATURE_NV_vertex_program
    if (ss->Programs)
       _mesa_DeleteHashTable(ss->Programs);
+#endif
+#if FEATURE_ARB_vertex_program
+   if (ss->DefaultVertexProgram)
+      _mesa_delete_program(ctx, ss->DefaultVertexProgram);
+#endif
+#if FEATURE_ARB_fragment_program
+   if (ss->DefaultFragmentProgram)
+      _mesa_delete_program(ctx, ss->DefaultFragmentProgram);
 #endif
    if (ss->Default1D)
       (*ctx->Driver.DeleteTexture)(ctx, ss->Default1D);
@@ -757,7 +776,11 @@ free_shared_state( GLcontext *ctx, struct gl_shared_state *ss )
    while (1) {
       GLuint prog = _mesa_HashFirstEntry(ss->Programs);
       if (prog) {
-         _mesa_delete_program(ctx, prog);
+         struct program *p = (struct program *) _mesa_HashLookup(ss->Programs,
+                                                                 prog);
+         ASSERT(p);
+         _mesa_delete_program(ctx, p);
+         _mesa_HashRemove(ss->Programs, prog);
       }
       else {
          break;
@@ -966,12 +989,23 @@ init_attrib_groups( GLcontext *ctx )
    ctx->Const.MaxClipPlanes = MAX_CLIP_PLANES;
    ctx->Const.MaxLights = MAX_LIGHTS;
 #if FEATURE_ARB_vertex_program
-   ctx->Const.MaxVertexProgramParams = MAX_NV_VERTEX_PROGRAM_PARAMS;
    ctx->Const.MaxVertexProgramInstructions = MAX_NV_VERTEX_PROGRAM_INSTRUCTIONS;
+   ctx->Const.MaxVertexProgramAttribs = MAX_NV_VERTEX_PROGRAM_INPUTS;
+   ctx->Const.MaxVertexProgramTemps = MAX_NV_VERTEX_PROGRAM_TEMPS;
+   ctx->Const.MaxVertexProgramLocalParams = MAX_NV_VERTEX_PROGRAM_PARAMS;
+   ctx->Const.MaxVertexProgramEnvParams = MAX_NV_VERTEX_PROGRAM_PARAMS;/*XXX*/
+   ctx->Const.MaxVertexProgramAddressRegs = MAX_VERTEX_PROGRAM_ADDRESS_REGS;
 #endif
 #if FEATURE_ARB_fragment_program
-   ctx->Const.MaxFragmentProgramParams = MAX_NV_FRAGMENT_PROGRAM_PARAMS;
    ctx->Const.MaxFragmentProgramInstructions = MAX_NV_FRAGMENT_PROGRAM_INSTRUCTIONS;
+   ctx->Const.MaxFragmentProgramAttribs = MAX_NV_FRAGMENT_PROGRAM_INPUTS;
+   ctx->Const.MaxFragmentProgramTemps = MAX_NV_FRAGMENT_PROGRAM_TEMPS;
+   ctx->Const.MaxFragmentProgramLocalParams = MAX_NV_FRAGMENT_PROGRAM_PARAMS;
+   ctx->Const.MaxFragmentProgramEnvParams = MAX_NV_FRAGMENT_PROGRAM_PARAMS;/*XXX*/
+   ctx->Const.MaxFragmentProgramAddressRegs = MAX_FRAGMENT_PROGRAM_ADDRESS_REGS;
+   ctx->Const.MaxFragmentProgramAluInstructions = MAX_FRAGMENT_PROGRAM_ALU_INSTRUCTIONS;
+   ctx->Const.MaxFragmentProgramTexInstructions = MAX_FRAGMENT_PROGRAM_TEX_INSTRUCTIONS;
+   ctx->Const.MaxFragmentProgramTexIndirections = MAX_FRAGMENT_PROGRAM_TEX_INDIRECTIONS;
 #endif
 
 
@@ -1940,14 +1974,14 @@ _mesa_free_context_data( GLcontext *ctx )
    if (ctx->VertexProgram.Current) {
       ctx->VertexProgram.Current->Base.RefCount--;
       if (ctx->VertexProgram.Current->Base.RefCount <= 0)
-         _mesa_delete_program(ctx, ctx->VertexProgram.Current->Base.Id);
+         _mesa_delete_program(ctx, &(ctx->VertexProgram.Current->Base));
    }
 #endif
 #if FEATURE_NV_fragment_program
    if (ctx->FragmentProgram.Current) {
       ctx->FragmentProgram.Current->Base.RefCount--;
       if (ctx->FragmentProgram.Current->Base.RefCount <= 0)
-         _mesa_delete_program(ctx, ctx->FragmentProgram.Current->Base.Id);
+         _mesa_delete_program(ctx, &(ctx->FragmentProgram.Current->Base));
    }
 #endif
 
index e2569f05e2e004bd82eb3ddda18856497649ad10..e931f49de88ee0f7fa7ee2a0ae23d2b9a858f995 100644 (file)
@@ -1081,6 +1081,7 @@ struct gl_client_array {
    void *Ptr;
    GLuint Flags;
    GLuint Enabled;             /* one of the _NEW_ARRAY_ bits */
+   GLboolean Normalized;        /* GL_ARB_vertex_program */
 };
 
 
@@ -1267,8 +1268,11 @@ struct fragment_program
    GLuint InputsRead;     /* Bitmask of which input regs are read */
    GLuint OutputsWritten; /* Bitmask of which output regs are written to */
    GLuint TexturesUsed[MAX_TEXTURE_IMAGE_UNITS];  /* TEXTURE_x_INDEX bitmask */
-   GLuint NumParameters;
+   GLuint NumAluInstructions; /* GL_ARB_fragment_program */
+   GLuint NumTexInstructions;
+   GLuint NumTexIndirections;
    struct program_parameter *Parameters; /* array [NumParameters] */
+   GLuint NumParameters;
 };
 
 
@@ -1282,7 +1286,7 @@ struct program_state {
 
 
 /*
- * State for GL_NV_vertex_program
+ * State for GL_ARB/NV_vertex_program
  */
 struct vertex_program_state
 {
@@ -1298,7 +1302,7 @@ struct vertex_program_state
 
 
 /*
- * State for GL_NV_fragment_program
+ * State for GL_ARB/NV_fragment_program
  */
 struct fragment_program_state
 {
@@ -1327,6 +1331,12 @@ struct gl_shared_state {
 
    /* GL_NV_vertex/_program */
    struct _mesa_HashTable *Programs;
+#if FEATURE_ARB_vertex_program
+   struct program *DefaultVertexProgram;
+#endif
+#if FEATURE_ARB_fragment_program
+   struct program *DefaultFragmentProgram;
+#endif
 
    void *DriverData;  /* Device driver shared state */
 };
@@ -1398,11 +1408,22 @@ struct gl_constants {
    GLuint MaxClipPlanes;
    GLuint MaxLights;
    /* GL_ARB_vertex_program */
-   GLuint MaxVertexProgramParams;
    GLuint MaxVertexProgramInstructions;
+   GLuint MaxVertexProgramAttribs;
+   GLuint MaxVertexProgramTemps;
+   GLuint MaxVertexProgramLocalParams;
+   GLuint MaxVertexProgramEnvParams;
+   GLuint MaxVertexProgramAddressRegs;
    /* GL_ARB_fragment_program */
-   GLuint MaxFragmentProgramParams;
    GLuint MaxFragmentProgramInstructions;
+   GLuint MaxFragmentProgramAttribs;
+   GLuint MaxFragmentProgramTemps;
+   GLuint MaxFragmentProgramLocalParams;
+   GLuint MaxFragmentProgramEnvParams;
+   GLuint MaxFragmentProgramAddressRegs;
+   GLuint MaxFragmentProgramAluInstructions;
+   GLuint MaxFragmentProgramTexInstructions;
+   GLuint MaxFragmentProgramTexIndirections;
 };
 
 
index 9e1b2ed828b5d63b60c25a91078ca41727d6b5af..b91bf21e586b451fb3c0749b2b5c6c3f2d18cf96 100644 (file)
@@ -102,6 +102,45 @@ _mesa_find_line_column(const GLubyte *string, const GLubyte *pos,
 
 
 
+/**
+ * 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
@@ -109,35 +148,31 @@ _mesa_find_line_column(const GLubyte *string, const GLubyte *pos,
  * \note Called from the GL API dispatcher.
  */
 void
-_mesa_delete_program(GLcontext *ctx, GLuint id)
+_mesa_delete_program(GLcontext *ctx, struct program *prog)
 {
-   struct program *prog = (struct program *)
-      _mesa_HashLookup(ctx->Shared->Programs, id);
+   ASSERT(prog);
 
-   if (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);
+   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_HashRemove(ctx->Shared->Programs, id);
-      _mesa_free(prog);
    }
+   _mesa_free(prog);
 }
 
 
@@ -152,7 +187,8 @@ _mesa_BindProgramNV(GLenum target, GLuint id)
    GET_CURRENT_CONTEXT(ctx);
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
-   if (target == GL_VERTEX_PROGRAM_NV) {
+   if (target == GL_VERTEX_PROGRAM_NV
+       && ctx->Extensions.NV_vertex_program) {
       if (ctx->VertexProgram.Current &&
           ctx->VertexProgram.Current->Base.Id == id)
          return;
@@ -160,11 +196,14 @@ _mesa_BindProgramNV(GLenum target, GLuint id)
       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.Id);
+         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) {
+   else if (target == GL_FRAGMENT_PROGRAM_NV
+       && ctx->Extensions.NV_fragment_program) {
       if (ctx->FragmentProgram.Current &&
           ctx->FragmentProgram.Current->Base.Id == id)
          return;
@@ -172,12 +211,14 @@ _mesa_BindProgramNV(GLenum target, GLuint id)
       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.Id);
+         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");
+      _mesa_error(ctx, GL_INVALID_ENUM, "glBindProgramNV(target)");
       return;
    }
 
@@ -190,27 +231,11 @@ _mesa_BindProgramNV(GLenum target, GLuint id)
    }
    else {
       prog = (struct program *) _mesa_HashLookup(ctx->Shared->Programs, id);
-
       if (!prog && id > 0){
          /* allocate new program */
-         if (target == GL_VERTEX_PROGRAM_NV) {
-            struct vertex_program *vprog = CALLOC_STRUCT(vertex_program);
-            if (!vprog) {
-               _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindProgramNV");
-               return;
-            }
-            prog = &(vprog->Base);
-         }
-         else if (target == GL_FRAGMENT_PROGRAM_NV) {
-            struct fragment_program *fprog = CALLOC_STRUCT(fragment_program);
-            if (!fprog) {
-               _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindProgramNV");
-               return;
-            }
-            prog = &(fprog->Base);
-         }
-         else {
-            _mesa_error(ctx, GL_INVALID_ENUM, "glBindProgramNV(target)");
+         prog = _mesa_alloc_program(ctx, target, id);
+         if (!prog) {
+            _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindProgramNV");
             return;
          }
          prog->Id = id;
@@ -277,7 +302,7 @@ _mesa_DeleteProgramsNV(GLsizei n, const GLuint *ids)
             }
             prog->RefCount--;
             if (prog->RefCount <= 0) {
-               _mesa_delete_program(ctx, ids[i]);
+               _mesa_delete_program(ctx, prog);
             }
          }
       }
@@ -330,7 +355,7 @@ _mesa_GenProgramsNV(GLsizei n, GLuint *ids)
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
    if (n < 0) {
-      _mesa_error(ctx, GL_INVALID_VALUE, "glGenProgramsNV");
+      _mesa_error(ctx, GL_INVALID_VALUE, "glGenPrograms");
       return;
    }
 
@@ -344,7 +369,7 @@ _mesa_GenProgramsNV(GLsizei n, GLuint *ids)
                              sizeof(struct fragment_program));
       struct program *prog = (struct program *) _mesa_calloc(bytes);
       if (!prog) {
-         _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGenProgramsNV");
+         _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGenPrograms");
          return;
       }
       prog->RefCount = 1;
@@ -595,7 +620,8 @@ _mesa_GetTrackMatrixivNV(GLenum target, GLuint address,
    GET_CURRENT_CONTEXT(ctx);
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
-   if (target == GL_VERTEX_PROGRAM_NV) {
+   if (target == GL_VERTEX_PROGRAM_NV
+       && ctx->Extensions.NV_vertex_program) {
       GLuint i;
 
       if ((address & 0x3) || address >= MAX_NV_VERTEX_PROGRAM_PARAMS) {
@@ -769,7 +795,8 @@ _mesa_GetVertexAttribPointervNV(GLuint index, GLenum pname, GLvoid **pointer)
  * \param id is the program identifier
  * \return GL_TRUE if id is a program, else GL_FALSE.
  */
-GLboolean _mesa_IsProgramNV(GLuint id)
+GLboolean
+_mesa_IsProgramNV(GLuint id)
 {
    struct program *prog;
    GET_CURRENT_CONTEXT(ctx);
@@ -787,7 +814,7 @@ GLboolean _mesa_IsProgramNV(GLuint id)
 
 
 /**
- * Load a program.
+ * Load/parse/compile a program.
  * \note Called from the GL API dispatcher.
  */
 void
@@ -810,11 +837,9 @@ _mesa_LoadProgramNV(GLenum target, GLuint id, GLsizei len,
       return;
    }
 
-   /* Reset error pos and string */
-   _mesa_set_program_error(ctx, -1, NULL);
-
-   if (target == GL_VERTEX_PROGRAM_NV ||
-       target == GL_VERTEX_STATE_PROGRAM_NV) {
+   if ((target == GL_VERTEX_PROGRAM_NV ||
+        target == GL_VERTEX_STATE_PROGRAM_NV)
+       && ctx->Extensions.NV_vertex_program) {
       struct vertex_program *vprog = (struct vertex_program *) prog;
       if (!vprog) {
          vprog = CALLOC_STRUCT(vertex_program);
@@ -828,7 +853,8 @@ _mesa_LoadProgramNV(GLenum target, GLuint id, GLsizei len,
       }
       _mesa_parse_nv_vertex_program(ctx, target, program, len, vprog);
    }
-   else if (target == GL_FRAGMENT_PROGRAM_NV) {
+   else if (target == GL_FRAGMENT_PROGRAM_NV
+            && ctx->Extensions.NV_fragment_program) {
       struct fragment_program *fprog = (struct fragment_program *) prog;
       if (!fprog) {
          fprog = CALLOC_STRUCT(fragment_program);
@@ -843,7 +869,7 @@ _mesa_LoadProgramNV(GLenum target, GLuint id, GLsizei len,
       _mesa_parse_nv_fragment_program(ctx, target, program, len, fprog);
    }
    else {
-      _mesa_error(ctx, GL_INVALID_ENUM, "LoadProgramNV(target)");
+      _mesa_error(ctx, GL_INVALID_ENUM, "glLoadProgramNV(target)");
    }
 }
 
@@ -887,7 +913,7 @@ _mesa_ProgramParameter4fNV(GLenum target, GLuint index,
    GET_CURRENT_CONTEXT(ctx);
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
-   if (target == GL_VERTEX_PROGRAM_NV) {
+   if (target == GL_VERTEX_PROGRAM_NV && ctx->Extensions.NV_vertex_program) {
       if (index < MAX_NV_VERTEX_PROGRAM_PARAMS) {
          index += VP_PROG_REG_START;
          ASSIGN_4V(ctx->VertexProgram.Machine.Registers[index], x, y, z, w);
@@ -929,7 +955,7 @@ _mesa_ProgramParameters4dvNV(GLenum target, GLuint index,
    GET_CURRENT_CONTEXT(ctx);
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
-   if (target == GL_VERTEX_PROGRAM_NV) {
+   if (target == GL_VERTEX_PROGRAM_NV && ctx->Extensions.NV_vertex_program) {
       GLuint i;
       if (index + num > MAX_NV_VERTEX_PROGRAM_PARAMS) {
          _mesa_error(ctx, GL_INVALID_VALUE, "glProgramParameters4dvNV");
@@ -960,7 +986,7 @@ _mesa_ProgramParameters4fvNV(GLenum target, GLuint index,
    GET_CURRENT_CONTEXT(ctx);
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
-   if (target == GL_VERTEX_PROGRAM_NV) {
+   if (target == GL_VERTEX_PROGRAM_NV && ctx->Extensions.NV_vertex_program) {
       GLuint i;
       if (index + num > MAX_NV_VERTEX_PROGRAM_PARAMS) {
          _mesa_error(ctx, GL_INVALID_VALUE, "glProgramParameters4fvNV");
@@ -991,7 +1017,7 @@ _mesa_TrackMatrixNV(GLenum target, GLuint address,
    GET_CURRENT_CONTEXT(ctx);
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
-   if (target == GL_VERTEX_PROGRAM_NV) {
+   if (target == GL_VERTEX_PROGRAM_NV && ctx->Extensions.NV_vertex_program) {
       if (address & 0x3) {
          /* addr must be multiple of four */
          _mesa_error(ctx, GL_INVALID_VALUE, "glTrackMatrixNV(address)");
index 7293804500a561a22a7831e7c586e22c154f4c0b..bc5118dbc2b1fc66afc0e92d54a95924681f34e9 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: nvprogram.h,v 1.6 2003/03/29 16:37:08 brianp Exp $ */
+/* $Id: nvprogram.h,v 1.7 2003/04/17 01:48:20 brianp Exp $ */
 
 /*
  * Mesa 3-D graphics library
@@ -40,8 +40,11 @@ extern const GLubyte *
 _mesa_find_line_column(const GLubyte *string, const GLubyte *pos,
                        GLint *line, GLint *col);
 
+extern struct program *
+_mesa_alloc_program(GLcontext *ctx, GLenum target, GLuint id);
+
 extern void
-_mesa_delete_program(GLcontext *ctx, GLuint id);
+_mesa_delete_program(GLcontext *ctx, struct program *prog);
 
 
 
index dcf385d0e396eff05f4fa1077797883b7c110dda..94507aba8808cdbe8f63032f20817c140ccff6f8 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id: nvvertexec.c,v 1.5 2003/03/29 16:04:31 brianp Exp $ */
-
 /*
  * Mesa 3-D graphics library
  * Version:  5.1
index 76b2b66f0abf909984dab21008ef66752d574fa0..0242d0ed7ca1d1ec82115fa114b512f0ecd188e0 100644 (file)
@@ -1,10 +1,8 @@
-/* $Id: nvvertexec.h,v 1.1 2003/01/14 04:55:46 brianp Exp $ */
-
 /*
  * Mesa 3-D graphics library
  * Version:  5.1
  *
- * Copyright (C) 1999-2001  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2003  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"),
index f8e1168ded3ca03b82ed7909d669cfee6fc814e3..a06f02060e43a8db18849b75fb603cb1f53674ed 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id: nvvertparse.c,v 1.6 2003/04/11 01:20:12 brianp Exp $ */
-
 /*
  * Mesa 3-D graphics library
  * Version:  5.1
index b46fa35bf0cd348a3511bacf7b9f06e42ac78b9d..5949b9228b60bbfcd8bcca8bf37d2d1375e3f885 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id: nvvertparse.h,v 1.2 2003/03/29 16:38:08 brianp Exp $ */
-
 /*
  * Mesa 3-D graphics library
  * Version:  5.1