mojoshader.h
changeset 450 6a9faf398c1d
parent 438 73492129c1af
child 454 70c9818840eb
--- a/mojoshader.h	Sat Aug 23 20:33:03 2008 -0400
+++ b/mojoshader.h	Tue Aug 26 05:54:49 2008 -0400
@@ -201,6 +201,20 @@
 } MOJOSHADER_attribute;
 
 /*
+ * Use this if you want to specify newly-parsed code to swizzle incoming
+ *  data. This can be useful if you know, at parse time, that a shader
+ *  will be processing data on COLOR0 that should be RGBA, but you'll
+ *  be passing it a vertex array full of ARGB instead.
+ */
+typedef struct
+{
+    MOJOSHADER_usage usage;
+    unsigned int index;
+    unsigned char swizzles[4];  /* {0,1,2,3} == .xyzw, {2,2,2,2} == .zzzz */
+} MOJOSHADER_swizzle;
+
+
+/*
  * Structure used to return data from parsing of a shader...
  */
 typedef struct
@@ -311,6 +325,19 @@
     MOJOSHADER_attribute *attributes;
 
     /*
+     * The number of elements pointed to by (swizzles).
+     */
+    int swizzle_count;
+
+    /*
+     * (swizzle_count) elements of data that specify swizzles the shader will
+     *  apply to incoming attributes. This is a copy of what was passed to
+     *  MOJOSHADER_parseData().
+     * This can be NULL on error or if (swizzle_count) is zero.
+     */
+    MOJOSHADER_swizzle *swizzles;
+
+    /*
      * This is the malloc implementation you passed to MOJOSHADER_parse().
      */
     MOJOSHADER_malloc malloc;
@@ -396,6 +423,12 @@
  *  MOJOSHADER_parseData object, which is still safe to pass to
  *  MOJOSHADER_freeParseData()).
  *
+ * You can tell the generated program to swizzle certain inputs. If you know
+ *  that COLOR0 should be RGBA but you're passing in ARGB, you can specify
+ *  a swizzle of { MOJOSHADER_USAGE_COLOR, 0, {1,2,3,0} } to (swiz). If the
+ *  input register in the code would produce reg.ywzx, that swizzle would
+ *  change it to reg.wzxy ... (swiz) can be NULL.
+ *
  * This function is thread safe, so long as (m) and (f) are too, and that
  *  (tokenbuf) remains intact for the duration of the call. This allows you
  *  to parse several shaders on separate CPU cores at the same time.
@@ -403,6 +436,8 @@
 const MOJOSHADER_parseData *MOJOSHADER_parse(const char *profile,
                                              const unsigned char *tokenbuf,
                                              const unsigned int bufsize,
+                                             const MOJOSHADER_swizzle *swiz,
+                                             const unsigned int swizcount,
                                              MOJOSHADER_malloc m,
                                              MOJOSHADER_free f,
                                              void *d);
@@ -594,6 +629,7 @@
  *
  *   (tokenbuf) is a buffer of Direct3D shader bytecode.
  *   (bufsize) is the size, in bytes, of the bytecode buffer.
+ *   (swiz) and (swizcount) are passed to MOJOSHADER_parse() unmolested.
  *
  * Returns NULL on error, or a shader handle on success.
  *
@@ -607,7 +643,9 @@
  * Compiled shaders from this function may not be shared between contexts.
  */
 MOJOSHADER_glShader *MOJOSHADER_glCompileShader(const unsigned char *tokenbuf,
-                                                const unsigned int bufsize);
+                                                const unsigned int bufsize,
+                                                const MOJOSHADER_swizzle *swiz,
+                                                const unsigned int swizcount);
 
 
 /*