Reimplement the post-increment/decrement functions.
[mesa.git] / src / mesa / shader / nvprogram.c
index 758d62c1378b6eacbfdc86c0e469965acf60cc4e..531a41083cbb0adb53174427781d817de3dff9b1 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Mesa 3-D graphics library
- * Version:  6.5.1
+ * Version:  6.5.2
  *
  * Copyright (C) 1999-2006  Brian Paul   All Rights Reserved.
  *
@@ -42,9 +42,9 @@
 #include "hash.h"
 #include "imports.h"
 #include "macros.h"
-#include "mtypes.h"
+#include "prog_parameter.h"
+#include "prog_instruction.h"
 #include "nvfragparse.h"
-#include "program_instruction.h"
 #include "nvvertexec.h"
 #include "nvvertparse.h"
 #include "nvprogram.h"
@@ -59,7 +59,7 @@
 void GLAPIENTRY
 _mesa_ExecuteProgramNV(GLenum target, GLuint id, const GLfloat *params)
 {
-   struct vertex_program *vprog;
+   struct gl_vertex_program *vprog;
    GET_CURRENT_CONTEXT(ctx);
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
@@ -70,18 +70,14 @@ _mesa_ExecuteProgramNV(GLenum target, GLuint id, const GLfloat *params)
 
    FLUSH_VERTICES(ctx, _NEW_PROGRAM);
 
-   vprog = (struct vertex_program *)
-      _mesa_HashLookup(ctx->Shared->Programs, id);
+   vprog = (struct gl_vertex_program *) _mesa_lookup_program(ctx, id);
 
    if (!vprog || vprog->Base.Target != GL_VERTEX_STATE_PROGRAM_NV) {
       _mesa_error(ctx, GL_INVALID_OPERATION, "glExecuteProgramNV");
       return;
    }
    
-   _mesa_init_vp_per_vertex_registers(ctx);
-   _mesa_init_vp_per_primitive_registers(ctx);
-   COPY_4V(ctx->VertexProgram.Inputs[VERT_ATTRIB_POS], params);
-   _mesa_exec_vertex_program(ctx, vprog);
+   _mesa_exec_vertex_state_program(ctx, vprog, params);
 }
 
 
@@ -90,8 +86,9 @@ _mesa_ExecuteProgramNV(GLenum target, GLuint id, const GLfloat *params)
  * \note Not compiled into display lists.
  * \note Called from the GL API dispatcher.
  */
-GLboolean GLAPIENTRY _mesa_AreProgramsResidentNV(GLsizei n, const GLuint *ids,
-                                      GLboolean *residences)
+GLboolean GLAPIENTRY
+_mesa_AreProgramsResidentNV(GLsizei n, const GLuint *ids,
+                            GLboolean *residences)
 {
    GLint i, j;
    GLboolean allResident = GL_TRUE;
@@ -104,13 +101,12 @@ GLboolean GLAPIENTRY _mesa_AreProgramsResidentNV(GLsizei n, const GLuint *ids,
    }
 
    for (i = 0; i < n; i++) {
-      const struct program *prog;
+      const struct gl_program *prog;
       if (ids[i] == 0) {
          _mesa_error(ctx, GL_INVALID_VALUE, "glAreProgramsResidentNV");
          return GL_FALSE;
       }
-      prog = (const struct program *)
-         _mesa_HashLookup(ctx->Shared->Programs, ids[i]);
+      prog = _mesa_lookup_program(ctx, ids[i]);
       if (!prog) {
          _mesa_error(ctx, GL_INVALID_VALUE, "glAreProgramsResidentNV");
          return GL_FALSE;
@@ -151,14 +147,14 @@ _mesa_RequestResidentProgramsNV(GLsizei n, const GLuint *ids)
 
    /* just error checking for now */
    for (i = 0; i < n; i++) {
-      struct program *prog;
+      struct gl_program *prog;
 
       if (ids[i] == 0) {
          _mesa_error(ctx, GL_INVALID_VALUE, "glRequestResidentProgramsNV(id)");
          return;
       }
 
-      prog = (struct program *) _mesa_HashLookup(ctx->Shared->Programs, ids[i]);
+      prog = _mesa_lookup_program(ctx, ids[i]);
       if (!prog) {
          _mesa_error(ctx, GL_INVALID_VALUE, "glRequestResidentProgramsNV(id)");
          return;
@@ -248,13 +244,13 @@ _mesa_GetProgramParameterdvNV(GLenum target, GLuint index,
 void GLAPIENTRY
 _mesa_GetProgramivNV(GLuint id, GLenum pname, GLint *params)
 {
-   struct program *prog;
+   struct gl_program *prog;
    GET_CURRENT_CONTEXT(ctx);
 
    if (!ctx->_CurrentProgram)
       ASSERT_OUTSIDE_BEGIN_END(ctx);
 
-   prog = (struct program *) _mesa_HashLookup(ctx->Shared->Programs, id);
+   prog = _mesa_lookup_program(ctx, id);
    if (!prog) {
       _mesa_error(ctx, GL_INVALID_OPERATION, "glGetProgramivNV");
       return;
@@ -285,7 +281,7 @@ _mesa_GetProgramivNV(GLuint id, GLenum pname, GLint *params)
 void GLAPIENTRY
 _mesa_GetProgramStringNV(GLuint id, GLenum pname, GLubyte *program)
 {
-   struct program *prog;
+   struct gl_program *prog;
    GET_CURRENT_CONTEXT(ctx);
 
    if (!ctx->_CurrentProgram)
@@ -296,7 +292,7 @@ _mesa_GetProgramStringNV(GLuint id, GLenum pname, GLubyte *program)
       return;
    }
 
-   prog = (struct program *) _mesa_HashLookup(ctx->Shared->Programs, id);
+   prog = _mesa_lookup_program(ctx, id);
    if (!prog) {
       _mesa_error(ctx, GL_INVALID_OPERATION, "glGetProgramStringNV");
       return;
@@ -364,7 +360,7 @@ _mesa_GetVertexAttribdvNV(GLuint index, GLenum pname, GLdouble *params)
    GET_CURRENT_CONTEXT(ctx);
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
-   if (index == 0 || index >= MAX_NV_VERTEX_PROGRAM_INPUTS) {
+   if (index >= MAX_NV_VERTEX_PROGRAM_INPUTS) {
       _mesa_error(ctx, GL_INVALID_VALUE, "glGetVertexAttribdvNV(index)");
       return;
    }
@@ -380,6 +376,11 @@ _mesa_GetVertexAttribdvNV(GLuint index, GLenum pname, GLdouble *params)
          params[0] = ctx->Array.ArrayObj->VertexAttrib[index].Type;
          break;
       case GL_CURRENT_ATTRIB_NV:
+         if (index == 0) {
+            _mesa_error(ctx, GL_INVALID_OPERATION,
+                        "glGetVertexAttribdvNV(index == 0)");
+            return;
+         }
         FLUSH_CURRENT(ctx, 0);
          COPY_4V(params, ctx->Current.Attrib[index]);
          break;
@@ -400,7 +401,7 @@ _mesa_GetVertexAttribfvNV(GLuint index, GLenum pname, GLfloat *params)
    GET_CURRENT_CONTEXT(ctx);
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
-   if (index == 0 || index >= MAX_NV_VERTEX_PROGRAM_INPUTS) {
+   if (index >= MAX_NV_VERTEX_PROGRAM_INPUTS) {
       _mesa_error(ctx, GL_INVALID_VALUE, "glGetVertexAttribdvNV(index)");
       return;
    }
@@ -416,6 +417,11 @@ _mesa_GetVertexAttribfvNV(GLuint index, GLenum pname, GLfloat *params)
          params[0] = (GLfloat) ctx->Array.ArrayObj->VertexAttrib[index].Type;
          break;
       case GL_CURRENT_ATTRIB_NV:
+         if (index == 0) {
+            _mesa_error(ctx, GL_INVALID_OPERATION,
+                        "glGetVertexAttribfvNV(index == 0)");
+            return;
+         }
         FLUSH_CURRENT(ctx, 0);
          COPY_4V(params, ctx->Current.Attrib[index]);
          break;
@@ -436,7 +442,7 @@ _mesa_GetVertexAttribivNV(GLuint index, GLenum pname, GLint *params)
    GET_CURRENT_CONTEXT(ctx);
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
-   if (index == 0 || index >= MAX_NV_VERTEX_PROGRAM_INPUTS) {
+   if (index >= MAX_NV_VERTEX_PROGRAM_INPUTS) {
       _mesa_error(ctx, GL_INVALID_VALUE, "glGetVertexAttribdvNV(index)");
       return;
    }
@@ -452,6 +458,11 @@ _mesa_GetVertexAttribivNV(GLuint index, GLenum pname, GLint *params)
          params[0] = ctx->Array.ArrayObj->VertexAttrib[index].Type;
          break;
       case GL_CURRENT_ATTRIB_NV:
+         if (index == 0) {
+            _mesa_error(ctx, GL_INVALID_OPERATION,
+                        "glGetVertexAttribivNV(index == 0)");
+            return;
+         }
         FLUSH_CURRENT(ctx, 0);
          params[0] = (GLint) ctx->Current.Attrib[index][0];
          params[1] = (GLint) ctx->Current.Attrib[index][1];
@@ -506,7 +517,7 @@ void GLAPIENTRY
 _mesa_LoadProgramNV(GLenum target, GLuint id, GLsizei len,
                     const GLubyte *program)
 {
-   struct program *prog;
+   struct gl_program *prog;
    GET_CURRENT_CONTEXT(ctx);
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
@@ -522,7 +533,7 @@ _mesa_LoadProgramNV(GLenum target, GLuint id, GLsizei len,
 
    FLUSH_VERTICES(ctx, _NEW_PROGRAM);
 
-   prog = (struct program *) _mesa_HashLookup(ctx->Shared->Programs, id);
+   prog = _mesa_lookup_program(ctx, id);
 
    if (prog && prog->Target != 0 && prog->Target != target) {
       _mesa_error(ctx, GL_INVALID_OPERATION, "glLoadProgramNV(target)");
@@ -532,9 +543,9 @@ _mesa_LoadProgramNV(GLenum target, GLuint id, GLsizei len,
    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;
+      struct gl_vertex_program *vprog = (struct gl_vertex_program *) prog;
       if (!vprog || prog == &_mesa_DummyProgram) {
-         vprog = (struct vertex_program *)
+         vprog = (struct gl_vertex_program *)
             ctx->Driver.NewProgram(ctx, target, id);
          if (!vprog) {
             _mesa_error(ctx, GL_OUT_OF_MEMORY, "glLoadProgramNV");
@@ -546,9 +557,9 @@ _mesa_LoadProgramNV(GLenum target, GLuint id, GLsizei len,
    }
    else if (target == GL_FRAGMENT_PROGRAM_NV
             && ctx->Extensions.NV_fragment_program) {
-      struct fragment_program *fprog = (struct fragment_program *) prog;
+      struct gl_fragment_program *fprog = (struct gl_fragment_program *) prog;
       if (!fprog || prog == &_mesa_DummyProgram) {
-         fprog = (struct fragment_program *)
+         fprog = (struct gl_fragment_program *)
             ctx->Driver.NewProgram(ctx, target, id);
          if (!fprog) {
             _mesa_error(ctx, GL_OUT_OF_MEMORY, "glLoadProgramNV");
@@ -686,7 +697,7 @@ _mesa_ProgramParameters4fvNV(GLenum target, GLuint index,
       for (i = 0; i < num; i++) {
          COPY_4V(ctx->VertexProgram.Parameters[index + i], params);
          params += 4;
-      };
+      }
    }
    else {
       _mesa_error(ctx, GL_INVALID_ENUM, "glProgramParameters4fvNV");
@@ -764,8 +775,8 @@ 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;
+   struct gl_program *prog;
+   struct gl_fragment_program *fragProg;
    GLfloat *v;
 
    GET_CURRENT_CONTEXT(ctx);
@@ -773,7 +784,7 @@ _mesa_ProgramNamedParameter4fNV(GLuint id, GLsizei len, const GLubyte *name,
 
    FLUSH_VERTICES(ctx, _NEW_PROGRAM);
 
-   prog = (struct program *) _mesa_HashLookup(ctx->Shared->Programs, id);
+   prog = _mesa_lookup_program(ctx, id);
    if (!prog || prog->Target != GL_FRAGMENT_PROGRAM_NV) {
       _mesa_error(ctx, GL_INVALID_OPERATION, "glProgramNamedParameterNV");
       return;
@@ -784,7 +795,7 @@ _mesa_ProgramNamedParameter4fNV(GLuint id, GLsizei len, const GLubyte *name,
       return;
    }
 
-   fragProg = (struct fragment_program *) prog;
+   fragProg = (struct gl_fragment_program *) prog;
    v = _mesa_lookup_parameter_value(fragProg->Base.Parameters, len,
                                     (char *) name);
    if (v) {
@@ -830,8 +841,8 @@ void GLAPIENTRY
 _mesa_GetProgramNamedParameterfvNV(GLuint id, GLsizei len, const GLubyte *name,
                                    GLfloat *params)
 {
-   struct program *prog;
-   struct fragment_program *fragProg;
+   struct gl_program *prog;
+   struct gl_fragment_program *fragProg;
    const GLfloat *v;
 
    GET_CURRENT_CONTEXT(ctx);
@@ -839,7 +850,7 @@ _mesa_GetProgramNamedParameterfvNV(GLuint id, GLsizei len, const GLubyte *name,
    if (!ctx->_CurrentProgram)
       ASSERT_OUTSIDE_BEGIN_END(ctx);
 
-   prog = (struct program *) _mesa_HashLookup(ctx->Shared->Programs, id);
+   prog = _mesa_lookup_program(ctx, id);
    if (!prog || prog->Target != GL_FRAGMENT_PROGRAM_NV) {
       _mesa_error(ctx, GL_INVALID_OPERATION, "glGetProgramNamedParameterNV");
       return;
@@ -850,7 +861,7 @@ _mesa_GetProgramNamedParameterfvNV(GLuint id, GLsizei len, const GLubyte *name,
       return;
    }
 
-   fragProg = (struct fragment_program *) prog;
+   fragProg = (struct gl_fragment_program *) prog;
    v = _mesa_lookup_parameter_value(fragProg->Base.Parameters,
                                     len, (char *) name);
    if (v) {