[Cogl] [PATCH 1/8] framebuffer: drop _ALLOCATE_FLAG_DEPTH24_STENCIL8

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


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

There are two extensions, GL_OES_packed_depth_stencil and
GL_EXT_packed_depth_stencil, that inform us that the hardware supports
packing the depth and stencil values together into one format.

The OES extension is the GLES equivalent of the EXT extension and the
two extensions provide the same enums with basically the same semantics,
except that the EXT extension is a lot more wordy due to a larger number
of features in the full OpenGL api and the OES extension has some
asymmetric limitations on when the GL_DEPTH_STENCIL and
GL_DEPTH24_STENCIL8 enums can be used as internal formats.

GL_OES_packed_depth_stencil doesn't allow the GL_DEPTH_STENCIL enum
to be passed to glRenderbufferStorage (GL_DEPTH24_STENCIL8 should be
used instead) and GL_OES_packed_depth_stencil doesn't allow
GL_DEPTH24_STENCIL8 to be passed as an internal format to glTexImage2D.

We had been handling the two extensions differently in Cogl by calling
try_creating_fbo with different flags depending on whether the OES or
EXT extension was available and passing GL_DEPTH_STENCIL to
glRenderbufferStorage when we have the EXT extension or
GL_DEPTH24_STENCIL8 with the OES extension.

To localize the code that deals with the differences between the
extensions this patch does away with the need for separate flags
so we now just have COGL_OFFSCREEN_ALLOCATE_FLAG_DEPTH_DEPTH_STENCIL and
right before calling glRenderbufferStorage we check which extension we
are using to decide whether to use the GL_DEPTH_STENCIL or
GL_DEPTH24_STENCIL8 enums.
---
 cogl/cogl-framebuffer-private.h |    5 ++---
 cogl/cogl-framebuffer.c         |   37 +++++++++++++++++++++----------------
 2 files changed, 23 insertions(+), 19 deletions(-)

diff --git a/cogl/cogl-framebuffer-private.h b/cogl/cogl-framebuffer-private.h
index 9922a1a..fe3fe25 100644
--- a/cogl/cogl-framebuffer-private.h
+++ b/cogl/cogl-framebuffer-private.h
@@ -168,9 +168,8 @@ struct _CoglFramebuffer
 
 typedef enum {
   COGL_OFFSCREEN_ALLOCATE_FLAG_DEPTH_STENCIL    = 1L<<0,
-  COGL_OFFSCREEN_ALLOCATE_FLAG_DEPTH24_STENCIL8 = 1L<<1,
-  COGL_OFFSCREEN_ALLOCATE_FLAG_DEPTH            = 1L<<2,
-  COGL_OFFSCREEN_ALLOCATE_FLAG_STENCIL          = 1L<<3
+  COGL_OFFSCREEN_ALLOCATE_FLAG_DEPTH            = 1L<<1,
+  COGL_OFFSCREEN_ALLOCATE_FLAG_STENCIL          = 1L<<2
 } CoglOffscreenAllocateFlags;
 
 typedef struct _CoglGLFramebuffer
diff --git a/cogl/cogl-framebuffer.c b/cogl/cogl-framebuffer.c
index 2add6e6..231ef6c 100644
--- a/cogl/cogl-framebuffer.c
+++ b/cogl/cogl-framebuffer.c
@@ -830,11 +830,26 @@ try_creating_renderbuffers (CoglContext *ctx,
   GList *renderbuffers = NULL;
   GLuint gl_depth_stencil_handle;
 
-  if (flags & (COGL_OFFSCREEN_ALLOCATE_FLAG_DEPTH_STENCIL |
-               COGL_OFFSCREEN_ALLOCATE_FLAG_DEPTH24_STENCIL8))
+  if (flags & COGL_OFFSCREEN_ALLOCATE_FLAG_DEPTH_STENCIL)
     {
-      GLenum format = ((flags & COGL_OFFSCREEN_ALLOCATE_FLAG_DEPTH_STENCIL) ?
-                       GL_DEPTH_STENCIL : GL_DEPTH24_STENCIL8);
+      GLenum format;
+
+      /* Although GL_OES_packed_depth_stencil is mostly equivalent to
+       * GL_EXT_packed_depth_stencil, one notable difference is that
+       * GL_OES_packed_depth_stencil doesn't allow GL_DEPTH_STENCIL to
+       * be passed as an internal format to glRenderbufferStorage.
+       */
+      if (ctx->private_feature_flags &
+          COGL_PRIVATE_FEATURE_EXT_PACKED_DEPTH_STENCIL)
+        format = GL_DEPTH_STENCIL;
+      else
+        {
+          _COGL_RETURN_VAL_IF_FAIL (
+                                  ctx->private_feature_flags &
+                                  COGL_PRIVATE_FEATURE_OES_PACKED_DEPTH_STENCIL,
+                                  NULL);
+          format = GL_DEPTH24_STENCIL8;
+        }
 
       /* Create a renderbuffer for depth and stenciling */
       GE (ctx, glGenRenderbuffers (1, &gl_depth_stencil_handle));
@@ -1072,7 +1087,8 @@ _cogl_offscreen_allocate (CoglOffscreen *offscreen,
                          gl_framebuffer)) ||
 
       ((ctx->private_feature_flags &
-        COGL_PRIVATE_FEATURE_EXT_PACKED_DEPTH_STENCIL) &&
+        (COGL_PRIVATE_FEATURE_EXT_PACKED_DEPTH_STENCIL |
+         COGL_PRIVATE_FEATURE_OES_PACKED_DEPTH_STENCIL)) &&
        try_creating_fbo (ctx,
                          offscreen->texture,
                          offscreen->texture_level,
@@ -1082,17 +1098,6 @@ _cogl_offscreen_allocate (CoglOffscreen *offscreen,
                          flags = COGL_OFFSCREEN_ALLOCATE_FLAG_DEPTH_STENCIL,
                          gl_framebuffer)) ||
 
-      ((ctx->private_feature_flags &
-        COGL_PRIVATE_FEATURE_OES_PACKED_DEPTH_STENCIL) &&
-       try_creating_fbo (ctx,
-                         offscreen->texture,
-                         offscreen->texture_level,
-                         offscreen->texture_level_width,
-                         offscreen->texture_level_height,
-                         &fb->config,
-                         flags = COGL_OFFSCREEN_ALLOCATE_FLAG_DEPTH24_STENCIL8,
-                         gl_framebuffer)) ||
-
       try_creating_fbo (ctx,
                         offscreen->texture,
                         offscreen->texture_level,
-- 
1.7.7.6



More information about the Cogl mailing list