move GL_MESA_program_debug code into program.c
authorBrian Paul <brian.paul@tungstengraphics.com>
Fri, 5 Sep 2003 19:27:25 +0000 (19:27 +0000)
committerBrian Paul <brian.paul@tungstengraphics.com>
Fri, 5 Sep 2003 19:27:25 +0000 (19:27 +0000)
src/mesa/main/arbprogram.c
src/mesa/main/arbprogram.h
src/mesa/main/program.c
src/mesa/main/program.h

index 4e40d278343bbe380d9bb6bb8378b9630cf5ab8d..6803f4d4d6d0f98b6609ca9a5c26dcc1e049636c 100644 (file)
@@ -692,210 +692,3 @@ _mesa_GetProgramStringARB(GLenum target, GLenum pname, GLvoid *string)
    MEMCPY(string, prog->String, _mesa_strlen((char *) prog->String));
 }
 
-
-
-/* XXX temporary */
-void
-glProgramCallbackMESA(GLenum target, GLprogramcallbackMESA callback,
-                      GLvoid *data)
-{
-   _mesa_ProgramCallbackMESA(target, callback, data);
-}
-
-
-void
-_mesa_ProgramCallbackMESA(GLenum target, GLprogramcallbackMESA callback,
-                          GLvoid *data)
-{
-   GET_CURRENT_CONTEXT(ctx);
-
-   switch (target) {
-      case GL_FRAGMENT_PROGRAM_ARB:
-         if (!ctx->Extensions.ARB_fragment_program) {
-            _mesa_error(ctx, GL_INVALID_ENUM, "glProgramCallbackMESA(target)");
-            return;
-         }
-         ctx->FragmentProgram.Callback = callback;
-         ctx->FragmentProgram.CallbackData = data;
-         break;
-      case GL_FRAGMENT_PROGRAM_NV:
-         if (!ctx->Extensions.NV_fragment_program) {
-            _mesa_error(ctx, GL_INVALID_ENUM, "glProgramCallbackMESA(target)");
-            return;
-         }
-         ctx->FragmentProgram.Callback = callback;
-         ctx->FragmentProgram.CallbackData = data;
-         break;
-      case GL_VERTEX_PROGRAM_ARB: /* == GL_VERTEX_PROGRAM_NV */
-         if (!ctx->Extensions.ARB_vertex_program &&
-             !ctx->Extensions.NV_vertex_program) {
-            _mesa_error(ctx, GL_INVALID_ENUM, "glProgramCallbackMESA(target)");
-            return;
-         }
-         ctx->VertexProgram.Callback = callback;
-         ctx->VertexProgram.CallbackData = data;
-         break;
-      default:
-         _mesa_error(ctx, GL_INVALID_ENUM, "glProgramCallbackMESA(target)");
-         return;
-   }
-}
-
-
-/* XXX temporary */
-void
-glGetProgramRegisterfvMESA(GLenum target,
-                           GLsizei len, const GLubyte *registerName,
-                           GLfloat *v)
-{
-   _mesa_GetProgramRegisterfvMESA(target, len, registerName, v);
-}
-
-
-void
-_mesa_GetProgramRegisterfvMESA(GLenum target,
-                               GLsizei len, const GLubyte *registerName,
-                               GLfloat *v)
-{
-   char reg[1000];
-   GET_CURRENT_CONTEXT(ctx);
-
-   /* We _should_ be inside glBegin/glEnd */
-#if 0
-   if (ctx->Driver.CurrentExecPrimitive == PRIM_OUTSIDE_BEGIN_END) {
-      _mesa_error(ctx, GL_INVALID_OPERATION, "glGetProgramRegisterfvMESA");
-      return;
-   }
-#endif
-
-   /* make null-terminated copy of registerName */
-   _mesa_memcpy(reg, registerName, len);
-   reg[len] = 0;
-
-   switch (target) {
-      case GL_VERTEX_PROGRAM_NV:
-         if (!ctx->Extensions.ARB_vertex_program &&
-             !ctx->Extensions.NV_vertex_program) {
-            _mesa_error(ctx, GL_INVALID_ENUM,
-                        "glGetProgramRegisterfvMESA(target)");
-            return;
-         }
-         if (!ctx->VertexProgram.Enabled) {
-            _mesa_error(ctx, GL_INVALID_OPERATION,
-                        "glGetProgramRegisterfvMESA");
-            return;
-         }
-         /* GL_NV_vertex_program */
-         if (reg[0] == 'R') {
-            /* Temp register */
-            GLint i = _mesa_atoi(reg + 1);
-            if (i >= (GLint)ctx->Const.MaxVertexProgramTemps) {
-               _mesa_error(ctx, GL_INVALID_VALUE,
-                           "glGetProgramRegisterfvMESA(registerName)");
-               return;
-            }
-            COPY_4V(v, ctx->VertexProgram.Temporaries[i]);
-         }
-         else if (reg[0] == 'v' && reg[1] == '[') {
-            /* Vertex Input attribute */
-            GLuint i;
-            for (i = 0; i < ctx->Const.MaxVertexProgramAttribs; i++) {
-               const char *name = _mesa_nv_vertex_input_register_name(i);
-               char number[10];
-               sprintf(number, "%d", i);
-               if (_mesa_strncmp(reg + 2, name, 4) == 0 ||
-                   _mesa_strncmp(reg + 2, number, _mesa_strlen(number)) == 0) {
-                  COPY_4V(v, ctx->VertexProgram.Inputs[i]);
-                  return;
-               }
-            }
-            _mesa_error(ctx, GL_INVALID_VALUE,
-                        "glGetProgramRegisterfvMESA(registerName)");
-            return;
-         }
-         else if (reg[0] == 'o' && reg[1] == '[') {
-            /* Vertex output attribute */
-         }
-         /* GL_ARB_vertex_program */
-         else if (_mesa_strncmp(reg, "vertex.", 7) == 0) {
-
-         }
-         else {
-            _mesa_error(ctx, GL_INVALID_VALUE,
-                        "glGetProgramRegisterfvMESA(registerName)");
-            return;
-         }
-         break;
-      case GL_FRAGMENT_PROGRAM_ARB:
-         if (!ctx->Extensions.ARB_fragment_program) {
-            _mesa_error(ctx, GL_INVALID_ENUM,
-                        "glGetProgramRegisterfvMESA(target)");
-            return;
-         }
-         if (!ctx->FragmentProgram.Enabled) {
-            _mesa_error(ctx, GL_INVALID_OPERATION,
-                        "glGetProgramRegisterfvMESA");
-            return;
-         }
-         /* XXX to do */
-         break;
-      case GL_FRAGMENT_PROGRAM_NV:
-         if (!ctx->Extensions.NV_fragment_program) {
-            _mesa_error(ctx, GL_INVALID_ENUM,
-                        "glGetProgramRegisterfvMESA(target)");
-            return;
-         }
-         if (!ctx->FragmentProgram.Enabled) {
-            _mesa_error(ctx, GL_INVALID_OPERATION,
-                        "glGetProgramRegisterfvMESA");
-            return;
-         }
-         if (reg[0] == 'R') {
-            /* Temp register */
-            GLint i = _mesa_atoi(reg + 1);
-            if (i >= (GLint)ctx->Const.MaxFragmentProgramTemps) {
-               _mesa_error(ctx, GL_INVALID_VALUE,
-                           "glGetProgramRegisterfvMESA(registerName)");
-               return;
-            }
-            COPY_4V(v, ctx->FragmentProgram.Machine.Temporaries[i]);
-         }
-         else if (reg[0] == 'f' && reg[1] == '[') {
-            /* Fragment input attribute */
-            GLuint i;
-            for (i = 0; i < ctx->Const.MaxFragmentProgramAttribs; i++) {
-               const char *name = _mesa_nv_fragment_input_register_name(i);
-               if (_mesa_strncmp(reg + 2, name, 4) == 0) {
-                  COPY_4V(v, ctx->FragmentProgram.Machine.Inputs[i]);
-                  return;
-               }
-            }
-            _mesa_error(ctx, GL_INVALID_VALUE,
-                        "glGetProgramRegisterfvMESA(registerName)");
-            return;
-         }
-         else if (_mesa_strcmp(reg, "o[COLR]") == 0) {
-            /* Fragment output color */
-            COPY_4V(v, ctx->FragmentProgram.Machine.Outputs[FRAG_OUTPUT_COLR]);
-         }
-         else if (_mesa_strcmp(reg, "o[COLH]") == 0) {
-            /* Fragment output color */
-            COPY_4V(v, ctx->FragmentProgram.Machine.Outputs[FRAG_OUTPUT_COLH]);
-         }
-         else if (_mesa_strcmp(reg, "o[DEPR]") == 0) {
-            /* Fragment output depth */
-            COPY_4V(v, ctx->FragmentProgram.Machine.Outputs[FRAG_OUTPUT_DEPR]);
-         }
-         else {
-            _mesa_error(ctx, GL_INVALID_VALUE,
-                        "glGetProgramRegisterfvMESA(registerName)");
-            return;
-         }
-         break;
-      default:
-         _mesa_error(ctx, GL_INVALID_ENUM,
-                     "glGetProgramRegisterfvMESA(target)");
-         return;
-   }
-
-}
index bc5a6626ed585c2c88c163fe3c622b0d317be637..8bfb180bac10f2b456c209378cc51906651debb2 100644 (file)
@@ -125,12 +125,4 @@ extern void
 _mesa_GetProgramStringARB(GLenum target, GLenum pname, GLvoid *string);
 
 
-extern void
-_mesa_ProgramCallbackMESA(GLenum target, GLprogramcallbackMESA callback,
-                          GLvoid *data);
-
-extern void
-_mesa_GetProgramRegisterfvMESA(GLenum target, GLsizei len,
-                               const GLubyte *registerName, GLfloat *v);
-
 #endif
index fe816e344b7e6856bb6097476b963acd8fdd10de..e7a3ed9f595b3e0a609497735a4ea8212b1dcaf9 100644 (file)
@@ -36,6 +36,9 @@
 #include "macros.h"
 #include "mtypes.h"
 #include "program.h"
+#include "nvfragparse.h"
+#include "nvfragprog.h"
+#include "nvvertparse.h"
 
 
 /**********************************************************************/
@@ -925,3 +928,225 @@ _mesa_IsProgram(GLuint id)
    else
       return GL_FALSE;
 }
+
+
+
+/**********************************************************************/
+/* GL_MESA_program_debug extension                                    */
+/**********************************************************************/
+
+
+/* XXX temporary */
+void
+glProgramCallbackMESA(GLenum target, GLprogramcallbackMESA callback,
+                      GLvoid *data)
+{
+   _mesa_ProgramCallbackMESA(target, callback, data);
+}
+
+
+void
+_mesa_ProgramCallbackMESA(GLenum target, GLprogramcallbackMESA callback,
+                          GLvoid *data)
+{
+   GET_CURRENT_CONTEXT(ctx);
+
+   switch (target) {
+      case GL_FRAGMENT_PROGRAM_ARB:
+         if (!ctx->Extensions.ARB_fragment_program) {
+            _mesa_error(ctx, GL_INVALID_ENUM, "glProgramCallbackMESA(target)");
+            return;
+         }
+         ctx->FragmentProgram.Callback = callback;
+         ctx->FragmentProgram.CallbackData = data;
+         break;
+      case GL_FRAGMENT_PROGRAM_NV:
+         if (!ctx->Extensions.NV_fragment_program) {
+            _mesa_error(ctx, GL_INVALID_ENUM, "glProgramCallbackMESA(target)");
+            return;
+         }
+         ctx->FragmentProgram.Callback = callback;
+         ctx->FragmentProgram.CallbackData = data;
+         break;
+      case GL_VERTEX_PROGRAM_ARB: /* == GL_VERTEX_PROGRAM_NV */
+         if (!ctx->Extensions.ARB_vertex_program &&
+             !ctx->Extensions.NV_vertex_program) {
+            _mesa_error(ctx, GL_INVALID_ENUM, "glProgramCallbackMESA(target)");
+            return;
+         }
+         ctx->VertexProgram.Callback = callback;
+         ctx->VertexProgram.CallbackData = data;
+         break;
+      default:
+         _mesa_error(ctx, GL_INVALID_ENUM, "glProgramCallbackMESA(target)");
+         return;
+   }
+}
+
+
+/* XXX temporary */
+void
+glGetProgramRegisterfvMESA(GLenum target,
+                           GLsizei len, const GLubyte *registerName,
+                           GLfloat *v)
+{
+   _mesa_GetProgramRegisterfvMESA(target, len, registerName, v);
+}
+
+
+void
+_mesa_GetProgramRegisterfvMESA(GLenum target,
+                               GLsizei len, const GLubyte *registerName,
+                               GLfloat *v)
+{
+   char reg[1000];
+   GET_CURRENT_CONTEXT(ctx);
+
+   /* We _should_ be inside glBegin/glEnd */
+#if 0
+   if (ctx->Driver.CurrentExecPrimitive == PRIM_OUTSIDE_BEGIN_END) {
+      _mesa_error(ctx, GL_INVALID_OPERATION, "glGetProgramRegisterfvMESA");
+      return;
+   }
+#endif
+
+   /* make null-terminated copy of registerName */
+   len = MIN2(len, sizeof(reg) - 1);
+   _mesa_memcpy(reg, registerName, len);
+   reg[len] = 0;
+
+   switch (target) {
+      case GL_VERTEX_PROGRAM_NV:
+         if (!ctx->Extensions.ARB_vertex_program &&
+             !ctx->Extensions.NV_vertex_program) {
+            _mesa_error(ctx, GL_INVALID_ENUM,
+                        "glGetProgramRegisterfvMESA(target)");
+            return;
+         }
+         if (!ctx->VertexProgram.Enabled) {
+            _mesa_error(ctx, GL_INVALID_OPERATION,
+                        "glGetProgramRegisterfvMESA");
+            return;
+         }
+         /* GL_NV_vertex_program */
+         if (reg[0] == 'R') {
+            /* Temp register */
+            GLint i = _mesa_atoi(reg + 1);
+            if (i >= (GLint)ctx->Const.MaxVertexProgramTemps) {
+               _mesa_error(ctx, GL_INVALID_VALUE,
+                           "glGetProgramRegisterfvMESA(registerName)");
+               return;
+            }
+            COPY_4V(v, ctx->VertexProgram.Temporaries[i]);
+         }
+         else if (reg[0] == 'v' && reg[1] == '[') {
+            /* Vertex Input attribute */
+            GLuint i;
+            for (i = 0; i < ctx->Const.MaxVertexProgramAttribs; i++) {
+               const char *name = _mesa_nv_vertex_input_register_name(i);
+               char number[10];
+               sprintf(number, "%d", i);
+               if (_mesa_strncmp(reg + 2, name, 4) == 0 ||
+                   _mesa_strncmp(reg + 2, number, _mesa_strlen(number)) == 0) {
+                  COPY_4V(v, ctx->VertexProgram.Inputs[i]);
+                  return;
+               }
+            }
+            _mesa_error(ctx, GL_INVALID_VALUE,
+                        "glGetProgramRegisterfvMESA(registerName)");
+            return;
+         }
+         else if (reg[0] == 'o' && reg[1] == '[') {
+            /* Vertex output attribute */
+         }
+         /* GL_ARB_vertex_program */
+         else if (_mesa_strncmp(reg, "vertex.", 7) == 0) {
+
+         }
+         else {
+            _mesa_error(ctx, GL_INVALID_VALUE,
+                        "glGetProgramRegisterfvMESA(registerName)");
+            return;
+         }
+         break;
+      case GL_FRAGMENT_PROGRAM_ARB:
+         if (!ctx->Extensions.ARB_fragment_program) {
+            _mesa_error(ctx, GL_INVALID_ENUM,
+                        "glGetProgramRegisterfvMESA(target)");
+            return;
+         }
+         if (!ctx->FragmentProgram.Enabled) {
+            _mesa_error(ctx, GL_INVALID_OPERATION,
+                        "glGetProgramRegisterfvMESA");
+            return;
+         }
+         /* XXX to do */
+         break;
+      case GL_FRAGMENT_PROGRAM_NV:
+         if (!ctx->Extensions.NV_fragment_program) {
+            _mesa_error(ctx, GL_INVALID_ENUM,
+                        "glGetProgramRegisterfvMESA(target)");
+            return;
+         }
+         if (!ctx->FragmentProgram.Enabled) {
+            _mesa_error(ctx, GL_INVALID_OPERATION,
+                        "glGetProgramRegisterfvMESA");
+            return;
+         }
+         if (reg[0] == 'R') {
+            /* Temp register */
+            GLint i = _mesa_atoi(reg + 1);
+            if (i >= (GLint)ctx->Const.MaxFragmentProgramTemps) {
+               _mesa_error(ctx, GL_INVALID_VALUE,
+                           "glGetProgramRegisterfvMESA(registerName)");
+               return;
+            }
+            COPY_4V(v, ctx->FragmentProgram.Machine.Temporaries[i]);
+         }
+         else if (reg[0] == 'f' && reg[1] == '[') {
+            /* Fragment input attribute */
+            GLuint i;
+            for (i = 0; i < ctx->Const.MaxFragmentProgramAttribs; i++) {
+               const char *name = _mesa_nv_fragment_input_register_name(i);
+               if (_mesa_strncmp(reg + 2, name, 4) == 0) {
+                  COPY_4V(v, ctx->FragmentProgram.Machine.Inputs[i]);
+                  return;
+               }
+            }
+            _mesa_error(ctx, GL_INVALID_VALUE,
+                        "glGetProgramRegisterfvMESA(registerName)");
+            return;
+         }
+         else if (_mesa_strcmp(reg, "o[COLR]") == 0) {
+            /* Fragment output color */
+            COPY_4V(v, ctx->FragmentProgram.Machine.Outputs[FRAG_OUTPUT_COLR]);
+         }
+         else if (_mesa_strcmp(reg, "o[COLH]") == 0) {
+            /* Fragment output color */
+            COPY_4V(v, ctx->FragmentProgram.Machine.Outputs[FRAG_OUTPUT_COLH]);
+         }
+         else if (_mesa_strcmp(reg, "o[DEPR]") == 0) {
+            /* Fragment output depth */
+            COPY_4V(v, ctx->FragmentProgram.Machine.Outputs[FRAG_OUTPUT_DEPR]);
+         }
+         else {
+            /* try user-defined identifiers */
+            const GLfloat *value = _mesa_lookup_parameter_value(
+                       ctx->FragmentProgram.Current->Parameters, -1, reg);
+            if (reg) {
+               COPY_4V(v, value);
+            }
+            else {
+               _mesa_error(ctx, GL_INVALID_VALUE,
+                           "glGetProgramRegisterfvMESA(registerName)");
+               return;
+            }
+         }
+         break;
+      default:
+         _mesa_error(ctx, GL_INVALID_ENUM,
+                     "glGetProgramRegisterfvMESA(target)");
+         return;
+   }
+
+}
index 2445fcc9a44d849e6bd29843e0589a9c105c342f..70982c53404ac15f49fedfa070ebc42ec580e58e 100644 (file)
@@ -208,4 +208,18 @@ extern GLboolean
 _mesa_IsProgram(GLuint id);
 
 
+
+/*
+ * GL_MESA_program_debug
+ */
+
+extern void
+_mesa_ProgramCallbackMESA(GLenum target, GLprogramcallbackMESA callback,
+                          GLvoid *data);
+
+extern void
+_mesa_GetProgramRegisterfvMESA(GLenum target, GLsizei len,
+                               const GLubyte *registerName, GLfloat *v);
+
+
 #endif /* PROGRAM_H */