From 7b5b0bef8356b5d3f081d80505175c923510ea22 Mon Sep 17 00:00:00 2001 From: Robert Bragg Date: Thu, 6 Sep 2012 10:14:44 +0100 Subject: [PATCH] framebuffer: drop _ALLOCATE_FLAG_DEPTH24_STENCIL8 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. (cherry picked from commit 88a05fac6609f88c0f46d9df2611d9fbaf159939) --- 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 9922a1aa1..fe3fe25e0 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 f94bd00a6..31bf00973 100644 --- a/cogl/cogl-framebuffer.c +++ b/cogl/cogl-framebuffer.c @@ -831,11 +831,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)); @@ -1073,7 +1088,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, @@ -1083,17 +1099,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,