cogl-program: gles2: bind programs lazily as for GL

This makes the gles2 cogl_program_use consistent with the GL version by
not binding the program immediately and instead leaving it to
cogl-material.c to bind the program when actually drawing something.
This commit is contained in:
Robert Bragg 2010-07-23 10:12:39 +01:00
parent 4a9321b60c
commit 10c5cb1800
5 changed files with 26 additions and 26 deletions

View File

@ -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 =

View File

@ -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,

View File

@ -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;

View File

@ -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)
{

View File

@ -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)