[Cogl] [PATCH] Allow npot Texture2D creation with only basic npot support

Robert Bragg robert at sixbynine.org
Tue Apr 24 10:04:05 PDT 2012


From: Robert Bragg <robert at linux.intel.com>

Cogl has feature flags for basic npot texture support and then separate
flags for npot + repeat and npot + mipmap. If those three features are
available then there is a feature for full-npot support too for
convenience. The cogl_texture_2d_new_ constructors were checking for
full npot support and failing if not available but since we expose the
fine grained features to the user the user should be able to check the
limitations of npot textures and still choose to allocate them.

_cogl_texture_2d_can_create() now only checks for basic npot support
when creating a npot texture.  Since this change also affects the
automagic cogl_texture_ constructors they now check for basic npot +
mipmap support before considering using a Texture2D.

Notably the cogl_texture_ constructors will try constructing a Texture2D
even if we don't have npot + repeat support since the alternative is a
sliced texture which will need manual repeating anyway. Accordingly the
Texture2D::can_hardware_repeat vfunc has been made aware of the npot +
repeat feature flag.
---
 cogl/cogl-texture-2d.c |   13 +++++++++++--
 cogl/cogl-texture.c    |   23 +++++++++++++++++------
 2 files changed, 28 insertions(+), 8 deletions(-)

diff --git a/cogl/cogl-texture-2d.c b/cogl/cogl-texture-2d.c
index 4905dbf..e7df732 100644
--- a/cogl/cogl-texture-2d.c
+++ b/cogl/cogl-texture-2d.c
@@ -115,7 +115,7 @@ _cogl_texture_2d_can_create (unsigned int width,
 
   /* If NPOT textures aren't supported then the size must be a power
      of two */
-  if (!cogl_has_feature (ctx, COGL_FEATURE_ID_TEXTURE_NPOT) &&
+  if (!cogl_has_feature (ctx, COGL_FEATURE_ID_TEXTURE_NPOT_BASIC) &&
       (!_cogl_util_is_pot (width) ||
        !_cogl_util_is_pot (height)))
     return FALSE;
@@ -631,7 +631,16 @@ _cogl_texture_2d_is_sliced (CoglTexture *tex)
 static CoglBool
 _cogl_texture_2d_can_hardware_repeat (CoglTexture *tex)
 {
-  return TRUE;
+  CoglTexture2D *tex_2d = COGL_TEXTURE_2D (tex);
+
+  _COGL_GET_CONTEXT (ctx, FALSE);
+
+  if (cogl_has_feature (ctx, COGL_FEATURE_ID_TEXTURE_NPOT_REPEAT) ||
+      (_cogl_util_is_pot (tex_2d->width) &&
+       _cogl_util_is_pot (tex_2d->height)))
+    return TRUE;
+  else
+    return FALSE;
 }
 
 static void
diff --git a/cogl/cogl-texture.c b/cogl/cogl-texture.c
index 5d591d5..0207678 100644
--- a/cogl/cogl-texture.c
+++ b/cogl/cogl-texture.c
@@ -322,11 +322,18 @@ cogl_texture_new_with_size (unsigned int     width,
 
   _COGL_GET_CONTEXT (ctx, NULL);
 
-  /* First try creating a fast-path non-sliced texture */
-  tex = COGL_TEXTURE (cogl_texture_2d_new_with_size (ctx,
-                                                     width, height,
-                                                     internal_format,
-                                                     NULL));
+  if ((_cogl_util_is_pot (width) && _cogl_util_is_pot (height)) ||
+      (cogl_has_feature (ctx, COGL_FEATURE_ID_TEXTURE_NPOT_BASIC) &&
+       cogl_has_feature (ctx, COGL_FEATURE_ID_TEXTURE_NPOT_MIPMAP)))
+    {
+      /* First try creating a fast-path non-sliced texture */
+      tex = COGL_TEXTURE (cogl_texture_2d_new_with_size (ctx,
+                                                         width, height,
+                                                         internal_format,
+                                                         NULL));
+    }
+  else
+    tex = NULL;
 
   if (tex)
     {
@@ -395,6 +402,8 @@ cogl_texture_new_from_bitmap (CoglBitmap *bitmap,
   CoglAtlasTexture *atlas_tex;
   CoglTexture2D *tex_2d;
 
+  _COGL_GET_CONTEXT (ctx, FALSE);
+
   /* First try putting the texture in the atlas */
   if ((atlas_tex = _cogl_atlas_texture_new_from_bitmap (bitmap,
                                                         flags,
@@ -402,7 +411,9 @@ cogl_texture_new_from_bitmap (CoglBitmap *bitmap,
     return COGL_TEXTURE (atlas_tex);
 
   /* If that doesn't work try a fast path 2D texture */
-  if ((tex_2d = cogl_texture_2d_new_from_bitmap (bitmap,
+  if (cogl_has_feature (ctx, COGL_FEATURE_ID_TEXTURE_NPOT_BASIC) &&
+      cogl_has_feature (ctx, COGL_FEATURE_ID_TEXTURE_NPOT_MIPMAP) &&
+      (tex_2d = cogl_texture_2d_new_from_bitmap (bitmap,
                                                  internal_format,
                                                  NULL)))
     {
-- 
1.7.7.6



More information about the Cogl mailing list