Navigation Menu

Skip to content

Commit

Permalink
Implemented foundation for reporting uniforms to calling app.
Browse files Browse the repository at this point in the history
Generation of uniforms not implemented, yet.

--HG--
branch : trunk
  • Loading branch information
icculus committed Apr 4, 2008
1 parent ce1cc9a commit 97e1f97
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
11 changes: 11 additions & 0 deletions mojoshader.c
Expand Up @@ -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);

Expand Down
26 changes: 26 additions & 0 deletions mojoshader.h
Expand Up @@ -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...
Expand Down Expand Up @@ -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().
*/
Expand Down
17 changes: 17 additions & 0 deletions testparse.c
Expand Up @@ -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
Expand Down

0 comments on commit 97e1f97

Please sign in to comment.