[cogl-material] Fixes some dirty flag checks

Flushing material layers wasn't clearing the right dirty flag and
some of the tests used to avoid re-submitting GL state weren't
complete.
This commit is contained in:
Robert Bragg 2009-02-06 16:05:08 +00:00
parent 06bfc00fbc
commit 9059367dcc

View File

@ -30,6 +30,8 @@ COGL_HANDLE_DEFINE (MaterialLayer,
material_layer,
material_layer_handles);
/* #define DISABLE_MATERIAL_CACHE 1 */
CoglHandle
cogl_material_new (void)
{
@ -748,9 +750,11 @@ _cogl_material_layer_flush_gl_sampler_state (CoglMaterialLayer *layer,
int n_rgb_func_args;
int n_alpha_func_args;
#ifndef DISABLE_MATERIAL_CACHE
if (!(gl_layer_info &&
gl_layer_info->flags & COGL_MATERIAL_LAYER_FLAG_DEFAULT_COMBINE &&
layer->flags & COGL_MATERIAL_LAYER_FLAG_DEFAULT_COMBINE))
#endif
{
GE (glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE));
@ -813,9 +817,11 @@ _cogl_material_layer_flush_gl_sampler_state (CoglMaterialLayer *layer,
}
}
#ifndef DISABLE_MATERIAL_CACHE
if (gl_layer_info &&
(gl_layer_info->flags & COGL_MATERIAL_LAYER_FLAG_HAS_USER_MATRIX ||
layer->flags & COGL_MATERIAL_LAYER_FLAG_HAS_USER_MATRIX))
#endif
{
GE (glMatrixMode (GL_TEXTURE));
GE (glLoadMatrixf ((GLfloat *)&layer->matrix));
@ -879,6 +885,15 @@ _cogl_material_flush_layers_gl_state (CoglMaterial *material,
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
/* TODO
if (ctx->current_material == material &&
!(material->flags & COGL_MATERIAL_FLAG_LAYERS_DIRTY) &&
ctx->current_material_fallback_mask == fallback_mask &&
ctx->current_material_disable_mask == disable_mask &&
ctx->current_material_layer0_override = layer0_override_texture)
return;
*/
for (tmp = material->layers, i = 0; tmp != NULL; tmp = tmp->next, i++)
{
CoglHandle layer_handle = (CoglHandle)tmp->data;
@ -899,22 +914,25 @@ _cogl_material_flush_layers_gl_state (CoglMaterial *material,
(fallback_mask & (1<<i)) ? TRUE : FALSE;
new_gl_layer_info.disabled =
(disable_mask & (1<<i)) ? TRUE : FALSE;
if (i < ctx->current_layers->len)
{
gl_layer_info =
&g_array_index (ctx->current_layers, CoglLayerInfo, i);
#ifndef DISABLE_MATERIAL_CACHE
if (gl_layer_info->handle == layer_handle &&
!(layer->flags & COGL_MATERIAL_LAYER_FLAG_DIRTY) &&
(gl_layer_info->layer0_overridden
== new_gl_layer_info.layer0_overridden) &&
!(gl_layer_info->layer0_overridden ||
new_gl_layer_info.layer0_overridden) &&
(gl_layer_info->fallback
== new_gl_layer_info.fallback) &&
(gl_layer_info->disabled
== new_gl_layer_info.disabled))
{
continue;
}
#endif
}
tex_handle = layer->texture;
cogl_texture_get_gl_texture (tex_handle, &gl_texture, &gl_target);
@ -966,26 +984,41 @@ _cogl_material_flush_layers_gl_state (CoglMaterial *material,
#endif
/* Disable the previous target if it was different */
#ifndef DISABLE_MATERIAL_CACHE
if (gl_layer_info &&
gl_layer_info->gl_target != gl_target &&
!gl_layer_info->disabled)
{
GE (glDisable (gl_layer_info->gl_target));
}
#else
if (gl_layer_info)
GE (glDisable (gl_layer_info->gl_target));
#endif
/* Enable/Disable the new target */
if (!new_gl_layer_info.disabled)
{
#ifndef DISABLE_MATERIAL_CACHE
if (!(gl_layer_info &&
gl_layer_info->gl_target == gl_target &&
!gl_layer_info->disabled))
#endif
{
GE (glEnable (gl_target));
}
}
else
{
#ifndef DISABLE_MATERIAL_CACHE
if (!(gl_layer_info &&
gl_layer_info->gl_target == gl_target &&
gl_layer_info->disabled))
#endif
{
GE (glDisable (gl_target));
}
}
_cogl_material_layer_flush_gl_sampler_state (layer, gl_layer_info);
@ -1011,7 +1044,9 @@ _cogl_material_flush_layers_gl_state (CoglMaterial *material,
CoglLayerInfo *gl_layer_info =
&g_array_index (ctx->current_layers, CoglLayerInfo, i);
#ifndef DISABLE_MATERIAL_CACHE
if (!gl_layer_info->disabled)
#endif
{
GE (glActiveTexture (GL_TEXTURE0 + i));
GE (glDisable (gl_layer_info->gl_target));
@ -1019,7 +1054,7 @@ _cogl_material_flush_layers_gl_state (CoglMaterial *material,
}
}
material->flags &= ~COGL_MATERIAL_FLAG_DIRTY;
material->flags &= ~COGL_MATERIAL_FLAG_LAYERS_DIRTY;
}
static void
@ -1027,6 +1062,12 @@ _cogl_material_flush_base_gl_state (CoglMaterial *material)
{
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
#ifndef DISABLE_MATERIAL_CACHE
if (ctx->current_material == material &&
!(material->flags & COGL_MATERIAL_FLAG_DIRTY))
return;
#endif
if (!(ctx->current_material_flags & COGL_MATERIAL_FLAG_DEFAULT_COLOR
&& material->flags & COGL_MATERIAL_FLAG_DEFAULT_COLOR))
{
@ -1076,18 +1117,8 @@ cogl_material_flush_gl_state (CoglHandle handle, ...)
material = _cogl_material_pointer_from_handle (handle);
if (ctx->current_material == material &&
!(material->flags & COGL_MATERIAL_FLAG_DIRTY) &&
!(material->flags & COGL_MATERIAL_FLAG_LAYERS_DIRTY))
return;
if (ctx->current_material != material ||
material->flags & COGL_MATERIAL_FLAG_DIRTY)
_cogl_material_flush_base_gl_state (material);
if (ctx->current_material != material ||
material->flags & COGL_MATERIAL_FLAG_LAYERS_DIRTY)
{
va_start (ap, handle);
while ((option = va_arg (ap, CoglMaterialFlushOption)))
{
@ -1104,7 +1135,6 @@ cogl_material_flush_gl_state (CoglHandle handle, ...)
fallback_layers,
disable_layers,
layer0_override_texture);
}
/* NB: we have to take a reference so that next time
* cogl_material_flush_gl_state is called, we can compare the incomming
@ -1117,8 +1147,6 @@ cogl_material_flush_gl_state (CoglHandle handle, ...)
ctx->current_material_flags = material->flags;
}
/* TODO: Should go in cogl.c, but that implies duplication which is also
* not ideal. */
void