[Cogl] [PATCH] tweak: Support retrieving depth textures from framebuffers
Robert Bragg
robert at sixbynine.org
Thu Sep 6 11:18:05 PDT 2012
From: Robert Bragg <robert at linux.intel.com>
Ok I went with renaming the enable_ function to
set_depth_texture_enabled. Although I'm quite tempted by the idea of
using other verbs than 'set' and 'get' for some reason I was feeling
conservative since we have no precedent for that in Cogl currently.
That said it really is quite verbose now so maybe it would be worth
introducing _enable and _disable verbs.
This patch should hopefully address the points you raised, and
should be folded back into Damien's original patch.
kind regards,
- Robert
-- >8 --
Renames cogl_framebuffer_enable_depth_texture to
cogl_framebuffer_set_depth_texture_enabled, adds a corresponding
_get_depth_texture function, actually references the enabled argument
in _set_depth_texture_enabled, no longer assert that the api is only
used with offscreen framebuffers but rather report a suitable error
during allocation and frees any allocated depth_texture in
_cogl_offscreen_free().
---
cogl/cogl-framebuffer.c | 28 ++++++++++++++++++++++------
cogl/cogl-framebuffer.h | 23 +++++++++++++++++++----
2 files changed, 41 insertions(+), 10 deletions(-)
diff --git a/cogl/cogl-framebuffer.c b/cogl/cogl-framebuffer.c
index 984b3b8..4dd93cd 100644
--- a/cogl/cogl-framebuffer.c
+++ b/cogl/cogl-framebuffer.c
@@ -817,6 +817,9 @@ _cogl_offscreen_free (CoglOffscreen *offscreen)
if (offscreen->texture != NULL)
cogl_object_unref (offscreen->texture);
+ if (offscreen->depth_texture != NULL)
+ cogl_object_unref (offscreen->depth_texture);
+
g_free (offscreen);
}
@@ -1291,6 +1294,15 @@ cogl_framebuffer_allocate (CoglFramebuffer *framebuffer,
if (framebuffer->type == COGL_FRAMEBUFFER_TYPE_ONSCREEN)
{
+ if (framebuffer->config.depth_texture_enabled)
+ {
+ g_set_error (error, COGL_FRAMEBUFFER_ERROR,
+ COGL_FRAMEBUFFER_ERROR_ALLOCATE,
+ "Can't allocate onscreen framebuffer with a "
+ "texture based depth buffer");
+ return FALSE;
+ }
+
if (!winsys->onscreen_init (onscreen, error))
return FALSE;
}
@@ -2032,24 +2044,28 @@ cogl_framebuffer_get_color_format (CoglFramebuffer *framebuffer)
}
void
-cogl_framebuffer_enable_depth_texture (CoglFramebuffer *framebuffer,
- CoglBool enabled)
+cogl_framebuffer_set_depth_texture_enabled (CoglFramebuffer *framebuffer,
+ CoglBool enabled)
{
_COGL_RETURN_IF_FAIL (!framebuffer->allocated);
- _COGL_RETURN_IF_FAIL (cogl_is_offscreen (framebuffer));
- framebuffer->config.depth_texture_enabled = TRUE;
+ framebuffer->config.depth_texture_enabled = enabled;
+}
+
+CoglBool
+cogl_framebuffer_get_depth_texture_enabled (CoglFramebuffer *framebuffer)
+{
+ return framebuffer->config.depth_texture_enabled;
}
CoglTexture *
cogl_framebuffer_get_depth_texture (CoglFramebuffer *framebuffer)
{
- _COGL_RETURN_VAL_IF_FAIL (cogl_is_offscreen (framebuffer), NULL);
-
/* lazily allocate the framebuffer... */
if (!cogl_framebuffer_allocate (framebuffer, NULL))
return NULL;
+ _COGL_RETURN_VAL_IF_FAIL (cogl_is_offscreen (framebuffer), NULL);
return COGL_OFFSCREEN(framebuffer)->depth_texture;
}
diff --git a/cogl/cogl-framebuffer.h b/cogl/cogl-framebuffer.h
index 6b303eb..1046190 100644
--- a/cogl/cogl-framebuffer.h
+++ b/cogl/cogl-framebuffer.h
@@ -800,7 +800,7 @@ CoglPixelFormat
cogl_framebuffer_get_color_format (CoglFramebuffer *framebuffer);
/**
- * cogl_framebuffer_enable_depth_texture:
+ * cogl_framebuffer_set_depth_texture_enabled:
* @framebuffer: A #CoglFramebuffer
* @enabled: TRUE or FALSE
*
@@ -809,7 +809,7 @@ cogl_framebuffer_get_color_format (CoglFramebuffer *framebuffer);
* cogl_framebuffer_get_depth_texture().
*
* <note>It's possible that your GPU does not support depth textures. You
- * should check the COGL_FEATURE_ID_DEPTH_TEXTURE feature before using this
+ * should check the %COGL_FEATURE_ID_DEPTH_TEXTURE feature before using this
* function.</note>
* <note>It's not valid to call this function after the framebuffer has been
* allocated as the creation of the depth texture is done at allocation time.
@@ -818,8 +818,23 @@ cogl_framebuffer_get_color_format (CoglFramebuffer *framebuffer);
* Since: 2.0
*/
void
-cogl_framebuffer_enable_depth_texture (CoglFramebuffer *framebuffer,
- gboolean enabled);
+cogl_framebuffer_set_depth_texture_enabled (CoglFramebuffer *framebuffer,
+ CoglBool enabled);
+
+/**
+ * cogl_framebuffer_get_depth_texture_enabled:
+ * @framebuffer: A #CoglFramebuffer
+ *
+ * Queries whether texture based depth buffer has been enabled via
+ * cogl_framebuffer_set_depth_texture_enabled().
+ *
+ * Return value: %TRUE if a depth texture has been enabled, else
+ * %FALSE.
+ *
+ * Since: 2.0
+ */
+CoglBool
+cogl_framebuffer_get_depth_texture_enabled (CoglFramebuffer *framebuffer);
/**
* cogl_framebuffer_get_depth_texture:
--
1.7.7.6
More information about the Cogl
mailing list