cogl: Add new function cogl_pipeline_set_layer_max_mipmap_level()

To configure an exact value of `GL_TEXTURE_MAX_LEVEL` clamped to within
the range of possible levels.

https://gitlab.gnome.org/GNOME/mutter/merge_requests/1003
This commit is contained in:
Daniel van Vugt 2020-04-16 17:34:42 +08:00 committed by Jonas Ådahl
parent f4301b77fa
commit c5fbab6bad
5 changed files with 32 additions and 2 deletions

View File

@ -1361,6 +1361,17 @@ cogl_pipeline_set_layer_filters (CoglPipeline *pipeline,
sampler_state); 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 * const CoglSamplerCacheEntry *
_cogl_pipeline_layer_get_sampler_state (CoglPipelineLayer *layer) _cogl_pipeline_layer_get_sampler_state (CoglPipelineLayer *layer)
{ {

View File

@ -568,6 +568,11 @@ cogl_pipeline_add_layer_snippet (CoglPipeline *pipeline,
int layer, int layer,
CoglSnippet *snippet); CoglSnippet *snippet);
COGL_EXPORT void
cogl_pipeline_set_layer_max_mipmap_level (CoglPipeline *pipeline,
int layer,
int max_level);
G_END_DECLS G_END_DECLS
#endif /* __COGL_PIPELINE_LAYER_STATE_H__ */ #endif /* __COGL_PIPELINE_LAYER_STATE_H__ */

View File

@ -205,6 +205,7 @@ struct _CoglTexture
CoglTextureLoader *loader; CoglTextureLoader *loader;
GList *framebuffers; GList *framebuffers;
int max_level_set; int max_level_set;
int max_level_requested;
int width; int width;
int height; int height;
gboolean allocated; gboolean allocated;
@ -377,6 +378,10 @@ _cogl_texture_needs_premult_conversion (CoglPixelFormat src_format,
int int
_cogl_texture_get_n_levels (CoglTexture *texture); _cogl_texture_get_n_levels (CoglTexture *texture);
void
cogl_texture_set_max_level (CoglTexture *texture,
int max_level);
void void
_cogl_texture_get_level_size (CoglTexture *texture, _cogl_texture_get_level_size (CoglTexture *texture,
int level, int level,

View File

@ -116,6 +116,7 @@ _cogl_texture_init (CoglTexture *texture,
{ {
texture->context = context; texture->context = context;
texture->max_level_set = 0; texture->max_level_set = 0;
texture->max_level_requested = 1000; /* OpenGL default GL_TEXTURE_MAX_LEVEL */
texture->width = width; texture->width = width;
texture->height = height; texture->height = height;
texture->allocated = FALSE; texture->allocated = FALSE;
@ -229,8 +230,16 @@ _cogl_texture_get_n_levels (CoglTexture *texture)
int width = cogl_texture_get_width (texture); int width = cogl_texture_get_width (texture);
int height = cogl_texture_get_height (texture); int height = cogl_texture_get_height (texture);
int max_dimension = MAX (width, height); 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 void

View File

@ -137,7 +137,7 @@ _cogl_texture_gl_generate_mipmaps (CoglTexture *texture)
GLuint gl_handle; GLuint gl_handle;
GLenum gl_target; 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_gl_set_max_level (texture, n_levels - 1);
cogl_texture_get_gl_texture (texture, &gl_handle, &gl_target); cogl_texture_get_gl_texture (texture, &gl_handle, &gl_target);