Search
lxdream.org :: lxdream/src/tools/genglsl.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/tools/genglsl.c
changeset 1153:00e507e4025c
prev1151:e1848ca9b5b1
next1169:23a9613aceb1
author nkeynes
date Thu Dec 23 18:14:29 2010 +1000 (10 years ago)
permissions -rw-r--r--
last change Revert changes from r1151 that went in by accident (not ready from
prime-time yet)
file annotate diff log raw
1.1 --- a/src/tools/genglsl.c Wed Dec 08 18:33:23 2010 +1000
1.2 +++ b/src/tools/genglsl.c Thu Dec 23 18:14:29 2010 +1000
1.3 @@ -37,16 +37,10 @@
1.4 FRAGMENT_SHADER = 1
1.5 } shader_type_t;
1.6
1.7 -typedef struct uniform {
1.8 - const char *name;
1.9 - const char *var_name;
1.10 -} *uniform_t;
1.11 -
1.12 typedef struct shader {
1.13 shader_type_t type;
1.14 const char *name;
1.15 char *body;
1.16 - GList *uniforms;
1.17 } *shader_t;
1.18
1.19 typedef struct program {
1.20 @@ -92,7 +86,6 @@
1.21 shader->name = strdup(g_strstrip(buf+8));
1.22 shader->body = malloc(DEF_ALLOC_SIZE);
1.23 shader->body[0] = '\0';
1.24 - shader->uniforms = 0;
1.25 current_size = DEF_ALLOC_SIZE;
1.26 current_posn = 0;
1.27 result->shaders = g_list_append(result->shaders, shader);
1.28 @@ -103,14 +96,12 @@
1.29 shader->name = strdup(g_strstrip(buf+10));
1.30 shader->body = malloc(DEF_ALLOC_SIZE);
1.31 shader->body[0] = '\0';
1.32 - shader->uniforms = 0;
1.33 current_size = DEF_ALLOC_SIZE;
1.34 current_posn = 0;
1.35 result->shaders = g_list_append(result->shaders, shader);
1.36 } else if( strncmp( buf, "#program ", 9 ) == 0 ) {
1.37 shader = NULL;
1.38 program_t program = malloc(sizeof(struct program));
1.39 - assert( program != NULL );
1.40 char *rest = buf+9;
1.41 char *equals = strchr(rest, '=');
1.42 if( equals == NULL ) {
1.43 @@ -124,23 +115,6 @@
1.44 for(i=0;program->shader_names[i] != NULL; i++ );
1.45 if( i > result->max_shaders )
1.46 result->max_shaders = i;
1.47 - } else if( strncmp( buf, "#uniform ", 9 ) == 0 ) {
1.48 - uniform_t uniform = malloc(sizeof(struct uniform));
1.49 - assert( uniform != NULL );
1.50 - if( shader == NULL ) {
1.51 - fprintf( stderr, "Error: #uniform specified outside of shader: %s\n", buf );
1.52 - exit(2);
1.53 - }
1.54 - char *rest = buf+9;
1.55 - char *equals = strchr(rest, '=');
1.56 - if( equals == NULL ) {
1.57 - fprintf( stderr, "Error: invalid program line %s\n", buf );
1.58 - exit(2);
1.59 - }
1.60 - *equals = '\0';
1.61 - uniform->name = g_strdup(g_strstrip(rest));
1.62 - uniform->var_name = g_strdup(g_strstrip(equals+1));
1.63 - shader->uniforms = g_list_append(shader->uniforms, uniform);
1.64 } else if( shader != NULL ) {
1.65 size_t len = strlen(buf);
1.66 if( current_posn + len > current_size ) {
1.67 @@ -175,17 +149,6 @@
1.68 }
1.69 }
1.70
1.71 -static uniform_t find_uniform_name( GList *list, const char *name )
1.72 -{
1.73 - GList *ptr;
1.74 - for( ptr = list; ptr != NULL; ptr = ptr->next ) {
1.75 - uniform_t data = (uniform_t)list->data;
1.76 - if( strcmp( data->name, name ) == 0 )
1.77 - return data;
1.78 - }
1.79 - return NULL;
1.80 -}
1.81 -
1.82 static void writeHeader( FILE *out, glsldata_t data )
1.83 {
1.84 fprintf( out, "/*\n * This file automatically generated by genglsl from %s\n */\n", data->filename );
1.85 @@ -205,22 +168,12 @@
1.86 fprintf( f, "typedef enum {\n" );
1.87 const char *last_name = NULL;
1.88 int count = 0;
1.89 - GList *unique_uniforms;
1.90 - int uniform_count = 0;
1.91 GList *shader_ptr;
1.92 for( shader_ptr = data->shaders; shader_ptr != NULL; shader_ptr = shader_ptr->next ) {
1.93 count++;
1.94 shader_t shader = (shader_t)shader_ptr->data;
1.95 fprintf( f, " %s,\n", shader->name );
1.96 last_name = shader->name;
1.97 - GList *uniform_ptr;
1.98 - for( uniform_ptr = shader->uniforms; uniform_ptr != NULL; uniform_ptr = uniform_ptr->next ) {
1.99 - uniform_t uniform = (uniform_t)uniform_ptr->data;
1.100 - if( find_uniform_name(unique_uniforms, uniform->name) == NULL ) {
1.101 - unique_uniforms = g_list_append( unique_uniforms, uniform );
1.102 - uniform_count++;
1.103 - }
1.104 - }
1.105 }
1.106 fprintf( f, "} shader_id;\n\n" );
1.107
1.108 @@ -231,7 +184,6 @@
1.109 fprintf( f, "#define GLSL_NO_SHADER -1\n\n" );
1.110 fprintf( f, "#define GLSL_VERTEX_SHADER 1\n" );
1.111 fprintf( f, "#define GLSL_FRAGMENT_SHADER 2\n" );
1.112 - fprintf( f, "#define GLSL_NUM_UNIFORMS %d\n", uniform_count );
1.113
1.114 fprintf( f, "typedef enum {\n" );
1.115 last_name = NULL;
.