Skip to content
Permalink
Browse files
First shot at attributes reporting API.
--HG--
branch : trunk
  • Loading branch information
icculus committed Apr 5, 2008
1 parent f2fef35 commit 8643f77a4b641b06477c82f8b0e804efd92e001c
Showing with 74 additions and 4 deletions.
  1. +51 −4 mojoshader.h
  2. +23 −0 testparse.c
@@ -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().
*/
@@ -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");

0 comments on commit 8643f77

Please sign in to comment.