From 97e1f97562a7f50a1989588e8bbc3870478135d5 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Fri, 4 Apr 2008 09:45:04 -0400 Subject: [PATCH] Implemented foundation for reporting uniforms to calling app. Generation of uniforms not implemented, yet. --HG-- branch : trunk --- mojoshader.c | 11 +++++++++++ mojoshader.h | 26 ++++++++++++++++++++++++++ testparse.c | 17 +++++++++++++++++ 3 files changed, 54 insertions(+) diff --git a/mojoshader.c b/mojoshader.c index 4bbbd332..5b8ddd6d 100644 --- a/mojoshader.c +++ b/mojoshader.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); diff --git a/mojoshader.h b/mojoshader.h index de1b042f..6b901f32 100644 --- a/mojoshader.h +++ b/mojoshader.h @@ -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(). */ diff --git a/testparse.c b/testparse.c index 7c6d206f..fa912810 100644 --- a/testparse.c +++ b/testparse.c @@ -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