From 8643f77a4b641b06477c82f8b0e804efd92e001c Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Sat, 5 Apr 2008 08:21:53 -0400 Subject: [PATCH] First shot at attributes reporting API. --HG-- branch : trunk --- mojoshader.h | 55 ++++++++++++++++++++++++++++++++++++++++++++++++---- testparse.c | 23 ++++++++++++++++++++++ 2 files changed, 74 insertions(+), 4 deletions(-) diff --git a/mojoshader.h b/mojoshader.h index 4c9cd432..c16894d1 100644 --- a/mojoshader.h +++ b/mojoshader.h @@ -54,9 +54,9 @@ typedef enum */ 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 enum */ typedef struct { - int index; MOJOSHADER_uniformType type; + int index; } 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 @@ typedef struct */ 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(). */ diff --git a/testparse.c b/testparse.c index da8e3e7c..d3a0864b 100644 --- a/testparse.c +++ b/testparse.c @@ -55,6 +55,29 @@ static void do_parse(const unsigned char *buf, const int len, const char *prof) 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");