Skip to content

Commit

Permalink
First shot at attributes reporting API.
Browse files Browse the repository at this point in the history
--HG--
branch : trunk
  • Loading branch information
icculus committed Apr 5, 2008
1 parent f2fef35 commit 8643f77
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 4 deletions.
55 changes: 51 additions & 4 deletions mojoshader.h
Expand Up @@ -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;

/*
Expand All @@ -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...
Expand Down Expand Up @@ -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().
*/
Expand Down
23 changes: 23 additions & 0 deletions testparse.c
Expand Up @@ -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");
Expand Down

0 comments on commit 8643f77

Please sign in to comment.