mesa: Move _mesa_all_buffers_are_unmapped to arrayobj.c.
[mesa.git] / src / mesa / main / arbprogram.c
index fe8cd6bbce0221d831281f3d7424c88e199f1f28..911b6fa3960472148311efd18daca655d6459e34 100644 (file)
 #include "main/macros.h"
 #include "main/mtypes.h"
 #include "main/arbprogram.h"
+#include "main/shaderapi.h"
 #include "program/arbprogparse.h"
 #include "program/program.h"
 #include "program/prog_print.h"
 
+#ifdef _MSC_VER
+#include <stdlib.h>
+#define PATH_MAX _MAX_PATH
+#endif
 
 /**
  * Bind a program (make it current)
@@ -118,8 +123,8 @@ _mesa_BindProgramARB(GLenum target, GLuint id)
    }
 
    /* Never null pointers */
-   ASSERT(ctx->VertexProgram.Current);
-   ASSERT(ctx->FragmentProgram.Current);
+   assert(ctx->VertexProgram.Current);
+   assert(ctx->FragmentProgram.Current);
 
    if (ctx->Driver.BindProgram)
       ctx->Driver.BindProgram(ctx, target, newProg);
@@ -200,13 +205,18 @@ _mesa_GenProgramsARB(GLsizei n, GLuint *ids)
    if (!ids)
       return;
 
+   _mesa_HashLockMutex(ctx->Shared->Programs);
+
    first = _mesa_HashFindFreeKeyBlock(ctx->Shared->Programs, n);
 
    /* Insert pointer to dummy program as placeholder */
    for (i = 0; i < (GLuint) n; i++) {
-      _mesa_HashInsert(ctx->Shared->Programs, first + i, &_mesa_DummyProgram);
+      _mesa_HashInsertLocked(ctx->Shared->Programs, first + i,
+                             &_mesa_DummyProgram);
    }
 
+   _mesa_HashUnlockMutex(ctx->Shared->Programs);
+
    /* Return the program names */
    for (i = 0; i < (GLuint) n; i++) {
       ids[i] = first + i;
@@ -373,6 +383,27 @@ _mesa_ProgramStringARB(GLenum target, GLenum format, GLsizei len,
       }
       fflush(stderr);
    }
+
+   /* Capture vp-*.shader_test/fp-*.shader_test files. */
+   const char *capture_path = _mesa_get_shader_capture_path();
+   if (capture_path != NULL) {
+      FILE *file;
+      char filename[PATH_MAX];
+      const char *shader_type =
+         target == GL_FRAGMENT_PROGRAM_ARB ? "fragment" : "vertex";
+
+      _mesa_snprintf(filename, sizeof(filename), "%s/%cp-%u.shader_test",
+                     capture_path, shader_type[0], base->Id);
+      file = fopen(filename, "w");
+      if (file) {
+         fprintf(file,
+                 "[require]\nGL_ARB_%s_program\n\n[%s program]\n%s\n",
+                 shader_type, shader_type, (const char *) string);
+         fclose(file);
+      } else {
+         _mesa_warning(ctx, "Failed to open %s", filename);
+      }
+   }
 }
 
 
@@ -524,7 +555,7 @@ _mesa_ProgramLocalParameter4fARB(GLenum target, GLuint index,
 
    if (get_local_param_pointer(ctx, "glProgramLocalParameterARB",
                               target, index, &param)) {
-      ASSERT(index < MAX_PROGRAM_LOCAL_PARAMS);
+      assert(index < MAX_PROGRAM_LOCAL_PARAMS);
       ASSIGN_4V(param, x, y, z, w);
    }
 }
@@ -639,8 +670,8 @@ _mesa_GetProgramivARB(GLenum target, GLenum pname, GLint *params)
       return;
    }
 
-   ASSERT(prog);
-   ASSERT(limits);
+   assert(prog);
+   assert(limits);
 
    /* Queries supported for both vertex and fragment programs */
    switch (pname) {
@@ -817,7 +848,7 @@ _mesa_GetProgramStringARB(GLenum target, GLenum pname, GLvoid *string)
       return;
    }
 
-   ASSERT(prog);
+   assert(prog);
 
    if (pname != GL_PROGRAM_STRING_ARB) {
       _mesa_error(ctx, GL_INVALID_ENUM, "glGetProgramStringARB(pname)");