Skip to content
Permalink
Browse files
Implemented foundation for reporting uniforms to calling app.
Generation of uniforms not implemented, yet.

--HG--
branch : trunk
  • Loading branch information
icculus committed Apr 4, 2008
1 parent ce1cc9a commit 97e1f97562a7f50a1989588e8bbc3870478135d5
Showing with 54 additions and 0 deletions.
  1. +11 −0 mojoshader.c
  2. +26 −0 mojoshader.h
  3. +17 −0 testparse.c
@@ -3534,6 +3534,17 @@ void MOJOSHADER_freeParseData(const MOJOSHADER_parseData *_data)
if (data->output != NULL) // check for NULL in case of dumb free() impl.
f((void *) data->output);

if (data->uniforms != NULL)
{
int i;
for (i = 0; i < data->uniform_count; i++)
{
if (data->uniforms[i].name != NULL)
f((void *) data->uniforms[i].name);
} // for
f((void *) data->uniforms);
} // if

if ((data->error != NULL) && (data->error != out_of_mem_str))
f((void *) data->error);

@@ -46,6 +46,20 @@ typedef enum
MOJOSHADER_TYPE_ANY = 0xFFFFFFFF /* used for bitmasks */
} MOJOSHADER_shaderType;

typedef enum
{
MOJOSHADER_UNIFORM_FLOAT,
MOJOSHADER_UNIFORM_INT,
MOJOSHADER_UNIFORM_BOOL
} MOJOSHADER_uniform_type;

typedef struct
{
int index;
const char *name;
MOJOSHADER_uniform_type type;
} MOJOSHADER_uniform;


/*
* Structure used to return data from parsing of a shader...
@@ -98,6 +112,18 @@ typedef struct
*/
int minor_ver;

/*
* The number of elements pointed to by (uniforms).
*/
int uniform_count;

/*
* (uniform_count) elements of data on how to access uniforms to be
* set by this shader. "Uniforms" are what Direct3D calls "Constants" ...
* IDirect3DDevice::SetVertexShaderConstantF() would need this data.
*/
MOJOSHADER_uniform *uniforms;

/*
* This is the malloc implementation you passed to MOJOSHADER_parse().
*/
@@ -55,6 +55,23 @@ 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("UNIFORMS:");
if (pd->uniform_count == 0)
printf(" (none.)\n");
else
{
static const char *typenames[] = { "float", "int", "bool" };
int i;
printf("\n");
for (i = 0; i < pd->uniform_count; i++)
{
const MOJOSHADER_uniform *u = &pd->uniforms[i];
const char *name = u->name ? u->name : "";
const char *typestr = typenames[(int) u->type];
printf(" * %d: %s %s\n", u->index, typestr, name);
} // for
} // else

if (pd->output != NULL)
printf("OUTPUT:\n%s\n", pd->output);
} // else

0 comments on commit 97e1f97

Please sign in to comment.