[Cogl] [PATCH 3/3] webgl: use DEPTH_STENCIL_ATTACHMENT

Robert Bragg robert at sixbynine.org
Thu May 30 10:08:28 PDT 2013


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

WebGL doesn't allow you to separately attach buffers to the
STENCIL_ATTACHMENT and DEPTH_ATTACHMENT framebuffer attachment points
and instead requires you to use the DEPTH_STENCIL_ATTACHMENT whenever
you want a depth and stencil buffer.
---
 cogl/driver/gl/cogl-framebuffer-gl.c | 29 ++++++++++++++++++++++++++---
 1 file changed, 26 insertions(+), 3 deletions(-)

diff --git a/cogl/driver/gl/cogl-framebuffer-gl.c b/cogl/driver/gl/cogl-framebuffer-gl.c
index b30b3cd..12c6bbd 100644
--- a/cogl/driver/gl/cogl-framebuffer-gl.c
+++ b/cogl/driver/gl/cogl-framebuffer-gl.c
@@ -65,6 +65,9 @@
 #ifndef GL_DEPTH_ATTACHMENT
 #define GL_DEPTH_ATTACHMENT     0x8D00
 #endif
+#ifndef GL_DEPTH_STENCIL_ATTACHMENT
+#define GL_DEPTH_STENCIL_ATTACHMENT 0x821A
+#endif
 #ifndef GL_DEPTH_COMPONENT16
 #define GL_DEPTH_COMPONENT16    0x81A5
 #endif
@@ -459,6 +462,11 @@ try_creating_renderbuffers (CoglContext *ctx,
     {
       GLenum format;
 
+      /* WebGL adds a GL_DEPTH_STENCIL_ATTACHMENT and requires that we
+       * use the GL_DEPTH_STENCIL format. */
+#ifdef HAVE_COGL_WEBGL
+      format = GL_DEPTH_STENCIL;
+#else
       /* 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
@@ -475,6 +483,7 @@ try_creating_renderbuffers (CoglContext *ctx,
                                   NULL);
           format = GL_DEPTH24_STENCIL8;
         }
+#endif
 
       /* Create a renderbuffer for depth and stenciling */
       GE (ctx, glGenRenderbuffers (1, &gl_depth_stencil_handle));
@@ -488,6 +497,14 @@ try_creating_renderbuffers (CoglContext *ctx,
         GE (ctx, glRenderbufferStorage (GL_RENDERBUFFER, format,
                                         width, height));
       GE (ctx, glBindRenderbuffer (GL_RENDERBUFFER, 0));
+
+
+#ifdef HAVE_COGL_WEBGL
+      GE (ctx, glFramebufferRenderbuffer (GL_FRAMEBUFFER,
+                                          GL_DEPTH_STENCIL_ATTACHMENT,
+                                          GL_RENDERBUFFER,
+                                          gl_depth_stencil_handle));
+#else
       GE (ctx, glFramebufferRenderbuffer (GL_FRAMEBUFFER,
                                           GL_STENCIL_ATTACHMENT,
                                           GL_RENDERBUFFER,
@@ -496,6 +513,7 @@ try_creating_renderbuffers (CoglContext *ctx,
                                           GL_DEPTH_ATTACHMENT,
                                           GL_RENDERBUFFER,
                                           gl_depth_stencil_handle));
+#endif
       renderbuffers =
         g_list_prepend (renderbuffers,
                         GUINT_TO_POINTER (gl_depth_stencil_handle));
@@ -768,9 +786,14 @@ _cogl_offscreen_gl_allocate (CoglOffscreen *offscreen,
                          flags = ctx->last_offscreen_allocate_flags,
                          gl_framebuffer)) ||
 
-      ((ctx->private_feature_flags &
-        (COGL_PRIVATE_FEATURE_EXT_PACKED_DEPTH_STENCIL |
-         COGL_PRIVATE_FEATURE_OES_PACKED_DEPTH_STENCIL)) &&
+      (
+       /* NB: WebGL introduces a DEPTH_STENCIL_ATTACHMENT and doesn't
+        * need an extension to handle _FLAG_DEPTH_STENCIL */
+#ifndef HAVE_COGL_WEBGL
+       (ctx->private_feature_flags
+        & (COGL_PRIVATE_FEATURE_EXT_PACKED_DEPTH_STENCIL |
+           COGL_PRIVATE_FEATURE_OES_PACKED_DEPTH_STENCIL)) &&
+#endif
        try_creating_fbo (ctx,
                          offscreen->texture,
                          offscreen->texture_level,
-- 
1.8.2.1



More information about the Cogl mailing list