init secondary color to (0,0,0,1). remove some redundant initializations.
[mesa.git] / src / mesa / main / program.c
index 546c0540032ae1510d054bae9a45087ee0e44b60..e32e8a3b1aced79aa8b0717ebb664d0147e7946d 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"),
@@ -140,14 +140,17 @@ _mesa_find_line_column(const GLubyte *string, const GLubyte *pos,
 
 
 /**
- * Allocate and initialize a new fragment/vertex program object
+ * Allocate and initialize a new fragment/vertex program object but don't
+ * put it into the program hash table.
+ * Called via ctx->Driver.NewProgram.  May be wrapped (OO deriviation)
+ * by a device driver function.
  * \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)
+_mesa_new_program(GLcontext *ctx, GLenum target, GLuint id)
 {
    struct program *prog;
 
@@ -168,7 +171,7 @@ _mesa_alloc_program(GLcontext *ctx, GLenum target, GLuint id)
       prog = &(fprog->Base);
    }
    else {
-      _mesa_problem(ctx, "bad target in _mesa_alloc_program");
+      _mesa_problem(ctx, "bad target in _mesa_new_program");
       return NULL;
    }
    prog->Id = id;
@@ -182,7 +185,8 @@ _mesa_alloc_program(GLcontext *ctx, GLenum target, GLuint id)
 /**
  * Delete a program and remove it from the hash table, ignoring the
  * reference count.
- * \note Called from the GL API dispatcher.
+ * Called via ctx->Driver.DeleteProgram.  May be wrapped (OO deriviation)
+ * by a device driver function.
  */
 void
 _mesa_delete_program(GLcontext *ctx, struct program *prog)
@@ -197,7 +201,8 @@ _mesa_delete_program(GLcontext *ctx, struct program *prog)
       if (vprog->Instructions)
          _mesa_free(vprog->Instructions);
    }
-   else if (prog->Target == GL_FRAGMENT_PROGRAM_NV) {
+   else if (prog->Target == GL_FRAGMENT_PROGRAM_NV ||
+            prog->Target == GL_FRAGMENT_PROGRAM_ARB) {
       struct fragment_program *fprog = (struct fragment_program *) prog;
       if (fprog->Instructions)
          _mesa_free(fprog->Instructions);
@@ -345,7 +350,7 @@ _mesa_add_state_reference(struct program_parameter_list *paramList,
    idx = add_parameter(paramList, "Some State", NULL, STATE);
        
    for (a=0; a<6; a++)
-      paramList->Parameters[idx].StateIndexes[a] = stateTokens[a];
+      paramList->Parameters[idx].StateIndexes[a] = (enum state_index) stateTokens[a];
 
    return idx;
 }
@@ -798,6 +803,8 @@ _mesa_BindProgram(GLenum target, GLuint id)
    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) ||
        (target == GL_VERTEX_PROGRAM_ARB
@@ -810,7 +817,7 @@ _mesa_BindProgram(GLenum target, GLuint id)
          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));
+            ctx->Driver.DeleteProgram(ctx, &(ctx->VertexProgram.Current->Base));
             _mesa_HashRemove(ctx->Shared->Programs, id);
          }
       }
@@ -827,7 +834,7 @@ _mesa_BindProgram(GLenum target, GLuint id)
          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));
+            ctx->Driver.DeleteProgram(ctx, &(ctx->FragmentProgram.Current->Base));
             _mesa_HashRemove(ctx->Shared->Programs, id);
          }
       }
@@ -863,7 +870,7 @@ _mesa_BindProgram(GLenum target, GLuint id)
       }
       else {
          /* allocate a new program now */
-         prog = _mesa_alloc_program(ctx, target, id);
+         prog = ctx->Driver.NewProgram(ctx, target, id);
          if (!prog) {
             _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindProgramNV/ARB");
             return;
@@ -886,6 +893,9 @@ _mesa_BindProgram(GLenum target, GLuint id)
 
    if (prog)
       prog->RefCount++;
+
+   if (ctx->Driver.BindProgram)
+      ctx->Driver.BindProgram(ctx, target, prog);
 }
 
 
@@ -899,7 +909,7 @@ _mesa_DeletePrograms(GLsizei n, const GLuint *ids)
 {
    GLint i;
    GET_CURRENT_CONTEXT(ctx);
-   ASSERT_OUTSIDE_BEGIN_END(ctx);
+   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
 
    if (n < 0) {
       _mesa_error( ctx, GL_INVALID_VALUE, "glDeleteProgramsNV" );
@@ -919,7 +929,8 @@ _mesa_DeletePrograms(GLsizei n, const GLuint *ids)
                   _mesa_BindProgram(prog->Target, 0);
                }
             }
-            else if (prog->Target == GL_FRAGMENT_PROGRAM_NV) {
+            else if (prog->Target == GL_FRAGMENT_PROGRAM_NV ||
+                     prog->Target == GL_FRAGMENT_PROGRAM_ARB) {
                if (ctx->FragmentProgram.Current &&
                    ctx->FragmentProgram.Current->Base.Id == ids[i]) {
                   /* unbind this currently bound program */
@@ -932,7 +943,7 @@ _mesa_DeletePrograms(GLsizei n, const GLuint *ids)
             }
             prog->RefCount--;
             if (prog->RefCount <= 0) {
-               _mesa_delete_program(ctx, prog);
+               ctx->Driver.DeleteProgram(ctx, prog);
             }
          }
       }