mojoshader.c
changeset 1055 3295380ce6fc
parent 1054 63dd1a46ce13
child 1058 dcbe39bffedc
--- a/mojoshader.c	Mon Jun 20 15:26:34 2011 -0400
+++ b/mojoshader.c	Mon Jun 20 15:47:16 2011 -0400
@@ -7966,6 +7966,61 @@
     return retval;
 } // build_attributes
 
+static MOJOSHADER_attribute *build_outputs(Context *ctx, int *_count)
+{
+    int count = 0;
+
+    if (ctx->attribute_count == 0)
+    {
+        *_count = 0;
+        return NULL;  // nothing to do.
+    } // if
+
+    const size_t len = sizeof (MOJOSHADER_attribute) * ctx->attribute_count;
+    MOJOSHADER_attribute *retval = (MOJOSHADER_attribute *) Malloc(ctx, len);
+
+    if (retval != NULL)
+    {
+        RegisterList *item = ctx->attributes.next;
+        MOJOSHADER_attribute *wptr = retval;
+        int i;
+
+        memset(retval, '\0', len);
+
+        for (i = 0; i < ctx->attribute_count; i++)
+        {
+            if (item == NULL)
+            {
+                fail(ctx, "BUG: mismatched attribute list and count");
+                break;
+            } // if
+
+            switch (item->regtype)
+            {
+                case REG_TYPE_RASTOUT:
+                case REG_TYPE_ATTROUT:
+                case REG_TYPE_TEXCRDOUT:
+                case REG_TYPE_COLOROUT:
+                case REG_TYPE_DEPTHOUT:
+                    wptr->usage = item->usage;
+                    wptr->index = item->index;
+                    wptr->name = alloc_varname(ctx, item);
+                    wptr++;
+                    count++;
+                    break;
+                default:
+                    break;
+            } // switch
+
+
+            item = item->next;
+        } // for
+    } // if
+
+    *_count = count;
+    return retval;
+} // build_outputs
+
 
 static MOJOSHADER_parseData *build_parsedata(Context *ctx)
 {
@@ -7973,12 +8028,14 @@
     MOJOSHADER_constant *constants = NULL;
     MOJOSHADER_uniform *uniforms = NULL;
     MOJOSHADER_attribute *attributes = NULL;
+    MOJOSHADER_attribute *outputs = NULL;
     MOJOSHADER_sampler *samplers = NULL;
     MOJOSHADER_swizzle *swizzles = NULL;
     MOJOSHADER_error *errors = NULL;
     MOJOSHADER_parseData *retval = NULL;
     size_t output_len = 0;
     int attribute_count = 0;
+    int output_count = 0;
 
     if (ctx->out_of_memory)
         return &MOJOSHADER_out_of_mem_data;
@@ -8002,6 +8059,9 @@
         attributes = build_attributes(ctx, &attribute_count);
 
     if (!isfail(ctx))
+        outputs = build_outputs(ctx, &output_count);
+
+    if (!isfail(ctx))
         samplers = build_samplers(ctx);
 
     const int error_count = errorlist_count(ctx->errors);
@@ -8041,6 +8101,13 @@
             Free(ctx, attributes);
         } // if
 
+        if (outputs != NULL)
+        {
+            for (i = 0; i < output_count; i++)
+                Free(ctx, (void *) outputs[i].name);
+            Free(ctx, outputs);
+        } // if
+
         if (samplers != NULL)
         {
             for (i = 0; i < ctx->sampler_count; i++)
@@ -8077,6 +8144,8 @@
         retval->samplers = samplers;
         retval->attribute_count = attribute_count;
         retval->attributes = attributes;
+        retval->output_count = output_count;
+        retval->outputs = outputs;
         retval->swizzle_count = ctx->swizzles_count;
         retval->swizzles = swizzles;
         retval->symbol_count = ctx->ctab.symbol_count;
@@ -8386,6 +8455,10 @@
         f((void *) data->attributes[i].name, d);
     f((void *) data->attributes, d);
 
+    for (i = 0; i < data->output_count; i++)
+        f((void *) data->outputs[i].name, d);
+    f((void *) data->outputs, d);
+
     for (i = 0; i < data->sampler_count; i++)
         f((void *) data->samplers[i].name, d);
     f((void *) data->samplers, d);