Search
lxdream.org :: lxdream :: r1208:6955202d6408
lxdream 0.9.1
released Jun 29
Download Now
changeset1208:6955202d6408
parent1207:f7ca985659c6
child1209:e606e65eaf54
authornkeynes
dateTue Feb 07 11:44:19 2012 +1000 (7 years ago)
Add enable/disable vertex attribute calls when making a shader active
src/pvr2/gl_sl.c
src/tools/genglsl.c
1.1 --- a/src/pvr2/gl_sl.c Tue Feb 07 11:20:00 2012 +1000
1.2 +++ b/src/pvr2/gl_sl.c Tue Feb 07 11:44:19 2012 +1000
1.3 @@ -43,6 +43,9 @@
1.4 void glsl_destroy_shader(gl_shader_t shader);
1.5 void glsl_destroy_program(gl_program_t program);
1.6
1.7 +typedef void (*program_cleanup_fn_t)();
1.8 +static void glsl_set_cleanup_fn( program_cleanup_fn_t );
1.9 +
1.10 #ifdef HAVE_OPENGL_SHADER_ARB
1.11
1.12 gboolean glsl_is_supported()
1.13 @@ -168,6 +171,8 @@
1.14 #define glsl_set_uniform_mat4(id,v) glUniformMatrix4fvARB(id,1,GL_FALSE,v)
1.15 #define glsl_set_attrib_vec3(id,stride,v) glVertexAttribPointerARB(id, 3, GL_FLOAT, GL_FALSE, stride, v)
1.16 #define glsl_set_attrib_vec4(id,stride,v) glVertexAttribPointerARB(id, 4, GL_FLOAT, GL_FALSE, stride, v)
1.17 +#define glsl_enable_attrib(id) glEnableVertexAttribArrayARB(id)
1.18 +#define glsl_disable_attrib(id) glDisableVertexAttribArrayARB(id)
1.19
1.20 #elif HAVE_OPENGL_SHADER
1.21
1.22 @@ -292,6 +297,8 @@
1.23 #define glsl_set_uniform_mat4(id,v) glUniformMatrix4fv(id,1,GL_FALSE,v)
1.24 #define glsl_set_attrib_vec3(id,stride,v) glVertexAttribPointer(id, 3, GL_FLOAT, GL_FALSE, stride, v)
1.25 #define glsl_set_attrib_vec4(id,stride,v) glVertexAttribPointer(id, 4, GL_FLOAT, GL_FALSE, stride, v)
1.26 +#define glsl_enable_attrib(id) glEnableVertexAttribArray(id)
1.27 +#define glsl_disable_attrib(id) glDisableVertexAttribArray(id)
1.28
1.29
1.30 #else
1.31 @@ -347,18 +354,23 @@
1.32 #define glsl_set_uniform_mat4(id,v)
1.33 #define glsl_set_attrib_vec3(id,stride,v)
1.34 #define glsl_set_attrib_vec4(id,stride,v)
1.35 +#define glsl_enable_attrib(id)
1.36 +#define glsl_disable_attrib(id)
1.37
1.38
1.39 #endif
1.40
1.41 /****************************************************************************/
1.42
1.43 +program_cleanup_fn_t current_cleanup_fn = NULL;
1.44 +
1.45 /* Pull in the auto-generated shader definitions */
1.46
1.47 #include "pvr2/shaders.def"
1.48
1.49 static gl_program_t program_array[GLSL_NUM_PROGRAMS];
1.50
1.51 +
1.52 gboolean glsl_load_shaders()
1.53 {
1.54 gl_shader_t shader_array[GLSL_NUM_SHADERS];
1.55 @@ -431,9 +443,28 @@
1.56 return TRUE;
1.57 }
1.58
1.59 +static void glsl_set_cleanup_fn( program_cleanup_fn_t fn )
1.60 +{
1.61 + if( fn != current_cleanup_fn ) {
1.62 + if( current_cleanup_fn != NULL ) {
1.63 + current_cleanup_fn();
1.64 + }
1.65 + current_cleanup_fn = fn;
1.66 + }
1.67 +}
1.68 +
1.69 +static void glsl_run_cleanup_fn()
1.70 +{
1.71 + if( current_cleanup_fn ) {
1.72 + current_cleanup_fn();
1.73 + }
1.74 + current_cleanup_fn = NULL;
1.75 +}
1.76 +
1.77 void glsl_unload_shaders()
1.78 {
1.79 unsigned i;
1.80 + glsl_run_cleanup_fn();
1.81 for( i=0; i<GLSL_NUM_PROGRAMS; i++ ) {
1.82 if( program_array[i] != INVALID_PROGRAM ) {
1.83 glsl_destroy_program(program_array[i]);
1.84 @@ -444,5 +475,7 @@
1.85
1.86 void glsl_clear_shader()
1.87 {
1.88 + glsl_run_cleanup_fn();
1.89 glsl_use_program(0);
1.90 }
1.91 +
2.1 --- a/src/tools/genglsl.c Tue Feb 07 11:20:00 2012 +1000
2.2 +++ b/src/tools/genglsl.c Tue Feb 07 11:44:19 2012 +1000
2.3 @@ -316,7 +316,7 @@
2.4 if( var->uniform ) {
2.5 fprintf( f, "void glsl_set_%s_%s(%s value); /* uniform %s %s */ \n", program->name, var->name, getCType(var->type,var->uniform), var->type, var->name );
2.6 } else {
2.7 - fprintf( f, "void glsl_set_%s_%s_pointer(%s ptr); /* attribute %s %s */ \n", program->name, var->name, getCType(var->type,var->uniform), var->type, var->name);
2.8 + fprintf( f, "void glsl_set_%s_%s_pointer(%s ptr, GLint stride); /* attribute %s %s */ \n", program->name, var->name, getCType(var->type,var->uniform), var->type, var->name);
2.9 }
2.10 }
2.11 }
2.12 @@ -373,7 +373,26 @@
2.13 }
2.14 for( program_ptr = data->programs; program_ptr != NULL; program_ptr = program_ptr->next ) {
2.15 program_t program = program_ptr->data;
2.16 - fprintf( f, "\nvoid glsl_use_%s() {\n glsl_use_program(prog_%s_id);\n}\n", program->name, program->name );
2.17 + fprintf( f, "\nstatic void glsl_cleanup_%s() {\n", program->name );
2.18 + for( var_ptr = program->variables; var_ptr != NULL; var_ptr = var_ptr->next ) {
2.19 + variable_t var = var_ptr->data;
2.20 + if( !var->uniform ) {
2.21 + fprintf( f, " glsl_disable_attrib(var_%s_%s_loc);\n", program->name, var->name );
2.22 + }
2.23 + }
2.24 + fprintf( f, "}\n");
2.25 +
2.26 + fprintf( f, "\nvoid glsl_use_%s() {\n", program->name );
2.27 + fprintf( f, " glsl_use_program(prog_%s_id);\n", program->name );
2.28 + for( var_ptr = program->variables; var_ptr != NULL; var_ptr = var_ptr->next ) {
2.29 + variable_t var = var_ptr->data;
2.30 + if( !var->uniform ) {
2.31 + fprintf( f, " glsl_enable_attrib(var_%s_%s_loc);\n", program->name, var->name );
2.32 + }
2.33 + }
2.34 + fprintf( f, " glsl_set_cleanup_fn(glsl_cleanup_%s);\n", program->name );
2.35 + fprintf( f, "}\n");
2.36 +
2.37
2.38 for( var_ptr = program->variables; var_ptr != NULL; var_ptr = var_ptr->next ) {
2.39 variable_t var = var_ptr->data;
.