[Cogl] [PATCH 7/8] framebuffer: alloc depth-textures during fb _allocate()

Robert Bragg robert at sixbynine.org
Thu Sep 6 09:29:35 PDT 2012


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

Instead of allocating depth-textures up-front when
cogl_framebuffer_enable_depth_texture() is called we now defer the
allocation until cogl_framebuffer_allocate() is called so have a way to
report an error if the allocation fails.
---
 cogl/cogl-framebuffer-private.h |    1 +
 cogl/cogl-framebuffer.c         |   35 ++++++++++++++++++++---------------
 2 files changed, 21 insertions(+), 15 deletions(-)

diff --git a/cogl/cogl-framebuffer-private.h b/cogl/cogl-framebuffer-private.h
index 839768f..a13f2b9 100644
--- a/cogl/cogl-framebuffer-private.h
+++ b/cogl/cogl-framebuffer-private.h
@@ -53,6 +53,7 @@ typedef struct
   CoglBool need_stencil;
   int samples_per_pixel;
   CoglBool swap_throttled;
+  CoglBool depth_texture_enabled;
 } CoglFramebufferConfig;
 
 /* Flags to pass to _cogl_offscreen_new_to_texture_full */
diff --git a/cogl/cogl-framebuffer.c b/cogl/cogl-framebuffer.c
index f2a696a..528abcd 100644
--- a/cogl/cogl-framebuffer.c
+++ b/cogl/cogl-framebuffer.c
@@ -1147,6 +1147,24 @@ _cogl_offscreen_allocate (CoglOffscreen *offscreen,
   CoglOffscreenAllocateFlags flags;
   CoglGLFramebuffer *gl_framebuffer = &offscreen->gl_framebuffer;
 
+  if (fb->config.depth_texture_enabled &&
+      offscreen->depth_texture == NULL)
+    {
+      offscreen->depth_texture =
+        create_depth_texture (ctx,
+                              offscreen->texture_level_width,
+                              offscreen->texture_level_height);
+
+      if (offscreen->depth_texture)
+        _cogl_texture_associate_framebuffer (offscreen->depth_texture, fb);
+      else
+        {
+          g_set_error (error, COGL_FRAMEBUFFER_ERROR,
+                       COGL_FRAMEBUFFER_ERROR_ALLOCATE,
+                       "Failed to allocate depth texture for framebuffer");
+        }
+    }
+
   /* XXX: The framebuffer_object spec isn't clear in defining whether attaching
    * a texture as a renderbuffer with mipmap filtering enabled while the
    * mipmaps have not been uploaded should result in an incomplete framebuffer
@@ -1245,7 +1263,7 @@ _cogl_offscreen_allocate (CoglOffscreen *offscreen,
           ctx->have_last_offscreen_allocate_flags = TRUE;
         }
 
-      /* Save the flags we managed so successfully allocate the
+      /* Save the flags we managed to successfully allocate the
        * renderbuffers with in case we need to make renderbuffers for a
        * GLES2 context later */
       offscreen->allocation_flags = flags;
@@ -2017,23 +2035,10 @@ void
 cogl_framebuffer_enable_depth_texture (CoglFramebuffer *framebuffer,
                                        CoglBool         enabled)
 {
-  CoglOffscreen *offscreen;
-  CoglContext *ctx = framebuffer->context;
-
   _COGL_RETURN_IF_FAIL (!framebuffer->allocated);
   _COGL_RETURN_IF_FAIL (cogl_is_offscreen (framebuffer));
 
-  offscreen = COGL_OFFSCREEN (framebuffer);
-  if (offscreen->depth_texture != NULL)
-    return;
-
-  offscreen->depth_texture =
-    create_depth_texture (ctx,
-                          offscreen->texture_level_width,
-                          offscreen->texture_level_height);
-
-  if (offscreen->depth_texture)
-    _cogl_texture_associate_framebuffer (offscreen->depth_texture, framebuffer);
+  framebuffer->config.depth_texture_enabled = TRUE;
 }
 
 CoglTexture *
-- 
1.7.7.6



More information about the Cogl mailing list