[cogl] Move the texture filters to be a property of the material layer
The texture filters are now a property of the material layer rather than the texture object. Whenever a texture is painted with a material it sets the filters on all of the GL textures in the Cogl texture. The filter is cached so that it won't be changed unnecessarily. The automatic mipmap generation has changed so that the mipmaps are only generated when the texture is painted instead of every time the data changes. Changing the texture sets a flag to mark that the mipmaps are dirty. This works better if the FBO extension is available because we can use glGenerateMipmap. If the extension is not available it will temporarily enable automatic mipmap generation and reupload the first pixel of each slice. This requires tracking the data for the first pixel. The COGL_TEXTURE_AUTO_MIPMAP flag has been replaced with COGL_TEXTURE_NO_AUTO_MIPMAP so that it will default to auto-mipmapping. The mipmap generation is now effectively free if you are not using a mipmap filter mode so you would only want to disable it if you had some special reason to generate your own mipmaps. ClutterTexture no longer has to store its own copy of the filter mode. Instead it stores it in the material and the property is directly set and read from that. This fixes problems with the filters getting out of sync when a cogl handle is set on the texture directly. It also avoids the mess of having to rerealize the texture if the filter quality changes to HIGH because Cogl will take of generating the mipmaps if needed.
This commit is contained in:
@@ -68,6 +68,9 @@ struct _CoglMaterialLayer
|
||||
CoglHandle texture; /*!< The texture for this layer, or COGL_INVALID_HANDLE
|
||||
for an empty layer */
|
||||
|
||||
CoglMaterialFilter mag_filter;
|
||||
CoglMaterialFilter min_filter;
|
||||
|
||||
/* Determines how the color of individual texture fragments
|
||||
* are calculated. */
|
||||
GLint texture_combine_rgb_func;
|
||||
|
@@ -637,6 +637,8 @@ _cogl_material_get_layer (CoglMaterial *material,
|
||||
layer_handle = _cogl_material_layer_handle_new (layer);
|
||||
layer->index = index_;
|
||||
layer->flags = COGL_MATERIAL_LAYER_FLAG_DEFAULT_COMBINE;
|
||||
layer->mag_filter = COGL_MATERIAL_FILTER_LINEAR;
|
||||
layer->min_filter = COGL_MATERIAL_FILTER_LINEAR;
|
||||
layer->texture = COGL_INVALID_HANDLE;
|
||||
|
||||
/* Choose the same default combine mode as OpenGL:
|
||||
@@ -1014,6 +1016,15 @@ get_n_args_for_combine_func (GLint func)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
is_mipmap_filter (CoglMaterialFilter filter)
|
||||
{
|
||||
return (filter == COGL_MATERIAL_FILTER_NEAREST_MIPMAP_NEAREST
|
||||
|| filter == COGL_MATERIAL_FILTER_LINEAR_MIPMAP_NEAREST
|
||||
|| filter == COGL_MATERIAL_FILTER_NEAREST_MIPMAP_LINEAR
|
||||
|| filter == COGL_MATERIAL_FILTER_LINEAR_MIPMAP_LINEAR);
|
||||
}
|
||||
|
||||
static void
|
||||
_cogl_material_layer_flush_gl_sampler_state (CoglMaterialLayer *layer,
|
||||
CoglLayerInfo *gl_layer_info)
|
||||
@@ -1214,6 +1225,13 @@ _cogl_material_flush_layers_gl_state (CoglMaterial *material,
|
||||
|
||||
GE (glActiveTexture (GL_TEXTURE0 + i));
|
||||
|
||||
_cogl_texture_set_filters (layer->texture,
|
||||
layer->min_filter,
|
||||
layer->mag_filter);
|
||||
if (is_mipmap_filter (layer->min_filter)
|
||||
|| is_mipmap_filter (layer->mag_filter))
|
||||
_cogl_texture_ensure_mipmaps (layer->texture);
|
||||
|
||||
/* FIXME: We could be more clever here and only bind the texture
|
||||
if it is different from gl_layer_info->gl_texture to avoid
|
||||
redundant GL calls. However a few other places in Cogl and
|
||||
@@ -1474,3 +1492,44 @@ cogl_set_source_texture (CoglHandle texture_handle)
|
||||
cogl_set_source (ctx->default_material);
|
||||
}
|
||||
|
||||
CoglMaterialFilter
|
||||
cogl_material_layer_get_min_filter (CoglHandle layer_handle)
|
||||
{
|
||||
CoglMaterialLayer *layer;
|
||||
|
||||
g_return_val_if_fail (cogl_is_material_layer (layer_handle), 0);
|
||||
|
||||
layer = _cogl_material_layer_pointer_from_handle (layer_handle);
|
||||
|
||||
return layer->min_filter;
|
||||
}
|
||||
|
||||
CoglMaterialFilter
|
||||
cogl_material_layer_get_mag_filter (CoglHandle layer_handle)
|
||||
{
|
||||
CoglMaterialLayer *layer;
|
||||
|
||||
g_return_val_if_fail (cogl_is_material_layer (layer_handle), 0);
|
||||
|
||||
layer = _cogl_material_layer_pointer_from_handle (layer_handle);
|
||||
|
||||
return layer->mag_filter;
|
||||
}
|
||||
|
||||
void
|
||||
cogl_material_set_layer_filters (CoglHandle handle,
|
||||
gint layer_index,
|
||||
CoglMaterialFilter min_filter,
|
||||
CoglMaterialFilter mag_filter)
|
||||
{
|
||||
CoglMaterial *material;
|
||||
CoglMaterialLayer *layer;
|
||||
|
||||
g_return_if_fail (cogl_is_material (handle));
|
||||
|
||||
material = _cogl_material_pointer_from_handle (handle);
|
||||
layer = _cogl_material_get_layer (material, layer_index, TRUE);
|
||||
|
||||
layer->min_filter = min_filter;
|
||||
layer->mag_filter = mag_filter;
|
||||
}
|
||||
|
@@ -1186,7 +1186,8 @@ cogl_polygon (CoglTextureVertex *vertices,
|
||||
use_sliced_polygon_fallback = TRUE;
|
||||
n_layers = 1;
|
||||
|
||||
if (tex->min_filter != GL_NEAREST || tex->mag_filter != GL_NEAREST)
|
||||
if (cogl_material_layer_get_min_filter (layer) != GL_NEAREST
|
||||
|| cogl_material_layer_get_mag_filter (layer) != GL_NEAREST)
|
||||
{
|
||||
static gboolean warning_seen = FALSE;
|
||||
if (!warning_seen)
|
||||
|
Reference in New Issue
Block a user