diff --git a/cogl/cogl/cogl-pipeline-layer-state.c b/cogl/cogl/cogl-pipeline-layer-state.c index 4ab293c19..73be1ea89 100644 --- a/cogl/cogl/cogl-pipeline-layer-state.c +++ b/cogl/cogl/cogl-pipeline-layer-state.c @@ -1361,6 +1361,17 @@ cogl_pipeline_set_layer_filters (CoglPipeline *pipeline, sampler_state); } +void +cogl_pipeline_set_layer_max_mipmap_level (CoglPipeline *pipeline, + int layer, + int max_level) +{ + CoglTexture *texture = cogl_pipeline_get_layer_texture (pipeline, layer); + + if (texture != NULL) + cogl_texture_set_max_level (texture, max_level); +} + const CoglSamplerCacheEntry * _cogl_pipeline_layer_get_sampler_state (CoglPipelineLayer *layer) { diff --git a/cogl/cogl/cogl-pipeline-layer-state.h b/cogl/cogl/cogl-pipeline-layer-state.h index 44a604cdc..947b37b14 100644 --- a/cogl/cogl/cogl-pipeline-layer-state.h +++ b/cogl/cogl/cogl-pipeline-layer-state.h @@ -568,6 +568,11 @@ cogl_pipeline_add_layer_snippet (CoglPipeline *pipeline, int layer, CoglSnippet *snippet); +COGL_EXPORT void +cogl_pipeline_set_layer_max_mipmap_level (CoglPipeline *pipeline, + int layer, + int max_level); + G_END_DECLS #endif /* __COGL_PIPELINE_LAYER_STATE_H__ */ diff --git a/cogl/cogl/cogl-texture-private.h b/cogl/cogl/cogl-texture-private.h index c6a00ca0e..d20de6bce 100644 --- a/cogl/cogl/cogl-texture-private.h +++ b/cogl/cogl/cogl-texture-private.h @@ -205,6 +205,7 @@ struct _CoglTexture CoglTextureLoader *loader; GList *framebuffers; int max_level_set; + int max_level_requested; int width; int height; gboolean allocated; @@ -377,6 +378,10 @@ _cogl_texture_needs_premult_conversion (CoglPixelFormat src_format, int _cogl_texture_get_n_levels (CoglTexture *texture); +void +cogl_texture_set_max_level (CoglTexture *texture, + int max_level); + void _cogl_texture_get_level_size (CoglTexture *texture, int level, diff --git a/cogl/cogl/cogl-texture.c b/cogl/cogl/cogl-texture.c index 5c9848d68..c82481156 100644 --- a/cogl/cogl/cogl-texture.c +++ b/cogl/cogl/cogl-texture.c @@ -116,6 +116,7 @@ _cogl_texture_init (CoglTexture *texture, { texture->context = context; texture->max_level_set = 0; + texture->max_level_requested = 1000; /* OpenGL default GL_TEXTURE_MAX_LEVEL */ texture->width = width; texture->height = height; texture->allocated = FALSE; @@ -229,8 +230,16 @@ _cogl_texture_get_n_levels (CoglTexture *texture) int width = cogl_texture_get_width (texture); int height = cogl_texture_get_height (texture); int max_dimension = MAX (width, height); + int n_levels = _cogl_util_fls (max_dimension); - return _cogl_util_fls (max_dimension); + return MIN (n_levels, texture->max_level_requested + 1); +} + +void +cogl_texture_set_max_level (CoglTexture *texture, + int max_level) +{ + texture->max_level_requested = max_level; } void diff --git a/cogl/cogl/driver/gl/cogl-texture-gl.c b/cogl/cogl/driver/gl/cogl-texture-gl.c index 25a8537c9..f1367b0db 100644 --- a/cogl/cogl/driver/gl/cogl-texture-gl.c +++ b/cogl/cogl/driver/gl/cogl-texture-gl.c @@ -137,7 +137,7 @@ _cogl_texture_gl_generate_mipmaps (CoglTexture *texture) GLuint gl_handle; GLenum gl_target; - if (texture->max_level_set < n_levels - 1) + if (texture->max_level_set != n_levels - 1) cogl_texture_gl_set_max_level (texture, n_levels - 1); cogl_texture_get_gl_texture (texture, &gl_handle, &gl_target);