Implemented foundation for reporting uniforms to calling app. trunk
authorRyan C. Gordon <icculus@icculus.org>
Fri, 04 Apr 2008 09:45:04 -0400
branchtrunk
changeset 92 bc1bb138e855
parent 91 3ae89caee681
child 93 fb4f31787e6f
Implemented foundation for reporting uniforms to calling app. Generation of uniforms not implemented, yet.
mojoshader.c
mojoshader.h
testparse.c
--- a/mojoshader.c	Fri Apr 04 08:53:43 2008 -0400
+++ b/mojoshader.c	Fri Apr 04 09:45:04 2008 -0400
@@ -3534,6 +3534,17 @@
     if (data->output != NULL)  // check for NULL in case of dumb free() impl.
         f((void *) data->output);
 
+    if (data->uniforms != NULL)
+    {
+        int i;
+        for (i = 0; i < data->uniform_count; i++)
+        {
+            if (data->uniforms[i].name != NULL)
+                f((void *) data->uniforms[i].name);
+        } // for
+        f((void *) data->uniforms);
+    } // if
+
     if ((data->error != NULL) && (data->error != out_of_mem_str))
         f((void *) data->error);
 
--- a/mojoshader.h	Fri Apr 04 08:53:43 2008 -0400
+++ b/mojoshader.h	Fri Apr 04 09:45:04 2008 -0400
@@ -46,6 +46,20 @@
     MOJOSHADER_TYPE_ANY = 0xFFFFFFFF   /* used for bitmasks */
 } MOJOSHADER_shaderType;
 
+typedef enum
+{
+    MOJOSHADER_UNIFORM_FLOAT,
+    MOJOSHADER_UNIFORM_INT,
+    MOJOSHADER_UNIFORM_BOOL
+} MOJOSHADER_uniform_type;
+
+typedef struct
+{
+    int index;
+    const char *name;
+    MOJOSHADER_uniform_type type;
+} MOJOSHADER_uniform;
+
 
 /*
  * Structure used to return data from parsing of a shader...
@@ -99,6 +113,18 @@
     int minor_ver;
 
     /*
+     * The number of elements pointed to by (uniforms).
+     */
+    int uniform_count;
+
+    /*
+     * (uniform_count) elements of data on how to access uniforms to be
+     *  set by this shader. "Uniforms" are what Direct3D calls "Constants" ...
+     *  IDirect3DDevice::SetVertexShaderConstantF() would need this data.
+     */
+    MOJOSHADER_uniform *uniforms;
+
+    /*
      * This is the malloc implementation you passed to MOJOSHADER_parse().
      */
     MOJOSHADER_malloc malloc;
--- a/testparse.c	Fri Apr 04 08:53:43 2008 -0400
+++ b/testparse.c	Fri Apr 04 09:45:04 2008 -0400
@@ -55,6 +55,23 @@
         printf("SHADER TYPE: %s\n", shader_type(pd->shader_type));
         printf("VERSION: %d.%d\n", pd->major_ver, pd->minor_ver);
         printf("INSTRUCTION COUNT: %d\n", (int) pd->instruction_count);
+        printf("UNIFORMS:");
+        if (pd->uniform_count == 0)
+            printf(" (none.)\n");
+        else
+        {
+            static const char *typenames[] = { "float", "int", "bool" };
+            int i;
+            printf("\n");
+            for (i = 0; i < pd->uniform_count; i++)
+            {
+                const MOJOSHADER_uniform *u = &pd->uniforms[i];
+                const char *name = u->name ? u->name : "";
+                const char *typestr = typenames[(int) u->type];
+                printf("    * %d: %s %s\n", u->index, typestr, name);
+            } // for
+        } // else
+
         if (pd->output != NULL)
             printf("OUTPUT:\n%s\n", pd->output);
     } // else