[mutter] cogl: Add new function cogl_pipeline_set_layer_max_mipmap_level()



commit c5fbab6bad81e1c17138b0e8c9adbefc54f62ed9
Author: Daniel van Vugt <daniel van vugt canonical com>
Date:   Thu Apr 16 17:34:42 2020 +0800

    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

 cogl/cogl/cogl-pipeline-layer-state.c | 11 +++++++++++
 cogl/cogl/cogl-pipeline-layer-state.h |  5 +++++
 cogl/cogl/cogl-texture-private.h      |  5 +++++
 cogl/cogl/cogl-texture.c              | 11 ++++++++++-
 cogl/cogl/driver/gl/cogl-texture-gl.c |  2 +-
 5 files changed, 32 insertions(+), 2 deletions(-)
---
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);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]