First shot at attributes reporting API. trunk
authorRyan C. Gordon <icculus@icculus.org>
Sat, 05 Apr 2008 08:21:53 -0400
branchtrunk
changeset 100 2b88649b6f98
parent 99 20d0bb294e9e
child 101 0834e95e5e76
First shot at attributes reporting API.
mojoshader.h
testparse.c
--- a/mojoshader.h	Fri Apr 04 14:46:51 2008 -0400
+++ b/mojoshader.h	Sat Apr 05 08:21:53 2008 -0400
@@ -54,9 +54,9 @@
  */
 typedef enum
 {
-    MOJOSHADER_UNIFORM_FLOAT,
-    MOJOSHADER_UNIFORM_INT,
-    MOJOSHADER_UNIFORM_BOOL
+    MOJOSHADER_UNIFORM_FLOAT = 0,
+    MOJOSHADER_UNIFORM_INT = 1,
+    MOJOSHADER_UNIFORM_BOOL = 2,
 } MOJOSHADER_uniformType;
 
 /*
@@ -69,10 +69,45 @@
  */
 typedef struct
 {
+    MOJOSHADER_uniformType type;
     int index;
-    MOJOSHADER_uniformType type;
 } MOJOSHADER_uniform;
 
+/*
+ * Data types for attributes. See MOJOSHADER_attribute for more information.
+ */
+typedef enum
+{
+    MOJOSHADER_USAGE_POSITION = 0,
+    MOJOSHADER_USAGE_BLENDWEIGHT = 1,
+    MOJOSHADER_USAGE_BLENDINDICES = 2,
+    MOJOSHADER_USAGE_NORMAL = 3,
+    MOJOSHADER_USAGE_PSIZE = 4,
+    MOJOSHADER_USAGE_TEXCOORD = 5,
+    MOJOSHADER_USAGE_TANGENT = 6,
+    MOJOSHADER_USAGE_BINORMAL = 7,
+    MOJOSHADER_USAGE_TESSFACTOR = 8,
+    MOJOSHADER_USAGE_POSITIONT = 9,
+    MOJOSHADER_USAGE_COLOR = 10,
+    MOJOSHADER_USAGE_FOG = 11,
+    MOJOSHADER_USAGE_DEPTH = 12,
+    MOJOSHADER_USAGE_SAMPLE = 13,
+} MOJOSHADER_usage;
+
+/*
+ * These are the attributes to be set for a shader. "Attributes" are what
+ *  Direct3D calls "Vertex Declarations Usages" ...
+ *  IDirect3DDevice::CreateVertexDeclaration() would need this data, for
+ *  example. Each attribute is associated with an array of data that uses one
+ *  element per-vertex. So if usage==MOJOSHADER_USAGE_COLOR and index==1, that
+ *  means we'd expect a secondary color array to be bound to this shader
+ *  before drawing.
+ */
+typedef struct
+{
+    MOJOSHADER_usage usage;
+    int index;
+} MOJOSHADER_attribute;
 
 /*
  * Structure used to return data from parsing of a shader...
@@ -136,6 +171,18 @@
      */
     MOJOSHADER_uniform *uniforms;
 
+
+    /*
+     * The number of elements pointed to by (attributes).
+     */
+    int attribute_count;
+
+    /*
+     * (attribute_count) elements of data that specify Attributes to be set
+     *  for this shader. See discussion on MOJOSHADER_attribute for details.
+     */
+    MOJOSHADER_attribute *attributes;
+
     /*
      * This is the malloc implementation you passed to MOJOSHADER_parse().
      */
--- a/testparse.c	Fri Apr 04 14:46:51 2008 -0400
+++ b/testparse.c	Sat Apr 05 08:21:53 2008 -0400
@@ -55,6 +55,29 @@
         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("ATTRIBUTES:");
+        if (pd->attribute_count == 0)
+            printf(" (none.)\n");
+        else
+        {
+            int i;
+            printf("\n");
+            for (i = 0; i < pd->attribute_count; i++)
+            {
+                static const char *usagenames[] = {
+                    "position", "blendweight", "blendindices", "normal",
+                    "psize", "texcoord", "tangent", "binormal", "tessfactor",
+                    "positiont", "color", "fog", "depth", "sample"
+                };
+                const MOJOSHADER_attribute *a = &pd->attributes[i];
+                char numstr[16] = { 0 };
+                if (a->index != 0)
+                    snprintf(numstr, sizeof (numstr), "%d", a->index);
+                printf("    * %s%s\n", usagenames[(int) a->usage], numstr);
+            } // for
+        } // else
+
         printf("UNIFORMS:");
         if (pd->uniform_count == 0)
             printf(" (none.)\n");