diff --git a/cogl/cogl-material-glsl.c b/cogl/cogl-material-glsl.c index 74d2dbe9e..0b2cf6eb8 100644 --- a/cogl/cogl-material-glsl.c +++ b/cogl/cogl-material-glsl.c @@ -68,9 +68,6 @@ _cogl_material_backend_glsl_start (CoglMaterial *material, if (!cogl_features_available (COGL_FEATURE_SHADERS_GLSL)) return FALSE; - /* FIXME: This will likely conflict with the GLES 2 backends use of - * glUseProgram. - */ if (materials_difference & COGL_MATERIAL_STATE_USER_SHADER) { CoglMaterial *authority = diff --git a/cogl/cogl-material-opengl-private.h b/cogl/cogl-material-opengl-private.h index fdd5a19a6..d12a555db 100644 --- a/cogl/cogl-material-opengl-private.h +++ b/cogl/cogl-material-opengl-private.h @@ -145,7 +145,7 @@ void _cogl_delete_gl_texture (GLuint gl_texture); void -_cogl_gl_use_program_wrapper (GLuint program); +_cogl_gl_use_program_wrapper (CoglHandle program); void _cogl_material_flush_gl_state (CoglMaterial *material, diff --git a/cogl/cogl-material-opengl.c b/cogl/cogl-material-opengl.c index 336d2e2fa..d7f7f03c8 100644 --- a/cogl/cogl-material-opengl.c +++ b/cogl/cogl-material-opengl.c @@ -282,21 +282,30 @@ _cogl_material_texture_storage_change_notify (CoglHandle texture) } void -_cogl_gl_use_program_wrapper (GLuint program) +_cogl_gl_use_program_wrapper (CoglHandle program_handle) { #ifdef COGL_MATERIAL_BACKEND_GLSL _COGL_GET_CONTEXT (ctx, NO_RETVAL); - if (ctx->current_gl_program == program) +#ifndef HAVE_COGL_GLES2 + CoglProgram *program = (CoglProgram *)program_handle; + GLuint gl_program; + + if (program_handle != COGL_INVALID_HANDLE) + gl_program = program->gl_handle; + else + gl_program = 0; + + if (ctx->current_gl_program == gl_program) return; - if (program) + if (gl_program != 0) { GLenum gl_error; while ((gl_error = glGetError ()) != GL_NO_ERROR) ; - glUseProgram (program); + glUseProgram (gl_program); if (glGetError () != GL_NO_ERROR) { GE (glUseProgram (0)); @@ -307,7 +316,12 @@ _cogl_gl_use_program_wrapper (GLuint program) else GE (glUseProgram (0)); - ctx->current_gl_program = program; + ctx->current_gl_program = gl_program; +#else /* HAVE_COGL_GLES2 */ + ctx->drv.gles2.settings.user_program = program_handle; + ctx->drv.gles2.settings_dirty = TRUE; +#endif /* HAVE_COGL_GLES2 */ + #endif } @@ -332,16 +346,8 @@ _cogl_use_program (CoglHandle program_handle, CoglMaterialProgramType type) #ifdef COGL_MATERIAL_BACKEND_GLSL case COGL_MATERIAL_PROGRAM_TYPE_GLSL: { - /* The GLES2 backend currently manages its own codegen for - * fixed function API fallbacks and manages its own shader - * state. */ -#ifndef HAVE_COGL_GLES2 - CoglProgram *program = - _cogl_program_pointer_from_handle (program_handle); - - _cogl_gl_use_program_wrapper (program->gl_handle); + _cogl_gl_use_program_wrapper (program_handle); disable_arbfp (); -#endif ctx->current_use_program_type = type; break; diff --git a/cogl/driver/gl/cogl-program.c b/cogl/driver/gl/cogl-program.c index bf630adc8..fd0a546af 100644 --- a/cogl/driver/gl/cogl-program.c +++ b/cogl/driver/gl/cogl-program.c @@ -169,7 +169,7 @@ cogl_program_uniform_1f (int uniform_no, g_return_if_fail (program != NULL); - _cogl_gl_use_program_wrapper (program->gl_handle); + _cogl_gl_use_program_wrapper (program); GE (glUniform1f (uniform_no, value)); } @@ -186,7 +186,7 @@ cogl_program_uniform_1i (int uniform_no, g_return_if_fail (program != NULL); - _cogl_gl_use_program_wrapper (program->gl_handle); + _cogl_gl_use_program_wrapper (program); GE (glUniform1i (uniform_no, value)); } @@ -205,7 +205,7 @@ cogl_program_uniform_float (int uniform_no, g_return_if_fail (program != NULL); - _cogl_gl_use_program_wrapper (program->gl_handle); + _cogl_gl_use_program_wrapper (program); switch (size) { @@ -240,7 +240,7 @@ cogl_program_uniform_int (int uniform_no, g_return_if_fail (program != NULL); - _cogl_gl_use_program_wrapper (program->gl_handle); + _cogl_gl_use_program_wrapper (program); switch (size) { @@ -276,7 +276,7 @@ cogl_program_uniform_matrix (int uniform_no, g_return_if_fail (program != NULL); - _cogl_gl_use_program_wrapper (program->gl_handle); + _cogl_gl_use_program_wrapper (program); switch (size) { diff --git a/cogl/driver/gles/cogl-program.c b/cogl/driver/gles/cogl-program.c index a3c51cdcb..7852cf99a 100644 --- a/cogl/driver/gles/cogl-program.c +++ b/cogl/driver/gles/cogl-program.c @@ -127,9 +127,6 @@ cogl_program_use (CoglHandle handle) else if (handle == 0 && ctx->current_program != 0) ctx->legacy_state_set--; - ctx->drv.gles2.settings.user_program = handle; - ctx->drv.gles2.settings_dirty = TRUE; - if (handle != COGL_INVALID_HANDLE) cogl_handle_ref (handle); if (ctx->current_program != COGL_INVALID_HANDLE)