[mutter] cogl/gl-framebuffer: Move stereo mode state flushing to backend



commit 102aa59ce304334553fe5ab007c1c2a34ea1fec5
Author: Jonas Ã…dahl <jadahl gmail com>
Date:   Tue Oct 20 11:55:57 2020 +0200

    cogl/gl-framebuffer: Move stereo mode state flushing to backend
    
    It's currently only handled by a surface backend framebuffer (assuming
    the right GLX extensions are available). While it's theoretically
    possible to do the same with the offcreen by having multiple textures,
    it's not supported, so leave the FBO variant with a single warning if we
    end up there.
    
    Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1514>

 cogl/cogl/driver/gl/cogl-framebuffer-gl-private.h |  2 ++
 cogl/cogl/driver/gl/cogl-framebuffer-gl.c         | 36 ++-------------------
 cogl/cogl/driver/gl/cogl-gl-framebuffer-back.c    | 38 +++++++++++++++++++++++
 cogl/cogl/driver/gl/cogl-gl-framebuffer-fbo.c     | 20 ++++++++++++
 4 files changed, 63 insertions(+), 33 deletions(-)
---
diff --git a/cogl/cogl/driver/gl/cogl-framebuffer-gl-private.h 
b/cogl/cogl/driver/gl/cogl-framebuffer-gl-private.h
index 4bdd076a67..3f3f6b7c88 100644
--- a/cogl/cogl/driver/gl/cogl-framebuffer-gl-private.h
+++ b/cogl/cogl/driver/gl/cogl-framebuffer-gl-private.h
@@ -49,6 +49,8 @@ struct _CoglGlFramebufferClass
 
   void (* bind) (CoglGlFramebuffer *gl_framebuffer,
                  GLenum             target);
+
+  void (* flush_stereo_mode_state) (CoglGlFramebuffer *gl_framebuffer);
 };
 
 void
diff --git a/cogl/cogl/driver/gl/cogl-framebuffer-gl.c b/cogl/cogl/driver/gl/cogl-framebuffer-gl.c
index d7407bee5c..6e807fa714 100644
--- a/cogl/cogl/driver/gl/cogl-framebuffer-gl.c
+++ b/cogl/cogl/driver/gl/cogl-framebuffer-gl.c
@@ -194,40 +194,10 @@ cogl_gl_framebuffer_flush_front_face_winding_state (CoglGlFramebuffer *gl_frameb
 static void
 cogl_gl_framebuffer_flush_stereo_mode_state (CoglGlFramebuffer *gl_framebuffer)
 {
-  CoglFramebufferDriver *driver = COGL_FRAMEBUFFER_DRIVER (gl_framebuffer);
-  CoglFramebuffer *framebuffer =
-    cogl_framebuffer_driver_get_framebuffer (driver);
-  CoglContext *ctx = cogl_framebuffer_get_context (framebuffer);
-  GLenum draw_buffer = GL_BACK;
-
-  if (COGL_IS_OFFSCREEN (framebuffer))
-    return;
-
-  if (!ctx->glDrawBuffer)
-    return;
+  CoglGlFramebufferClass *klass =
+    COGL_GL_FRAMEBUFFER_GET_CLASS (gl_framebuffer);
 
-  /* The one-shot default draw buffer setting in _cogl_framebuffer_gl_bind
-   * must have already happened. If not it would override what we set here. */
-  g_assert (ctx->was_bound_to_onscreen);
-
-  switch (cogl_framebuffer_get_stereo_mode (framebuffer))
-    {
-    case COGL_STEREO_BOTH:
-      draw_buffer = GL_BACK;
-      break;
-    case COGL_STEREO_LEFT:
-      draw_buffer = GL_BACK_LEFT;
-      break;
-    case COGL_STEREO_RIGHT:
-      draw_buffer = GL_BACK_RIGHT;
-      break;
-    }
-
-  if (ctx->current_gl_draw_buffer != draw_buffer)
-    {
-      GE (ctx, glDrawBuffer (draw_buffer));
-      ctx->current_gl_draw_buffer = draw_buffer;
-    }
+  klass->flush_stereo_mode_state (gl_framebuffer);
 }
 
 void
diff --git a/cogl/cogl/driver/gl/cogl-gl-framebuffer-back.c b/cogl/cogl/driver/gl/cogl-gl-framebuffer-back.c
index 4788bb9be8..cc2510fe5b 100644
--- a/cogl/cogl/driver/gl/cogl-gl-framebuffer-back.c
+++ b/cogl/cogl/driver/gl/cogl-gl-framebuffer-back.c
@@ -227,6 +227,42 @@ cogl_gl_framebuffer_back_bind (CoglGlFramebuffer *gl_framebuffer,
     }
 }
 
+static void
+cogl_gl_framebuffer_back_flush_stereo_mode_state (CoglGlFramebuffer *gl_framebuffer)
+{
+  CoglFramebufferDriver *driver = COGL_FRAMEBUFFER_DRIVER (gl_framebuffer);
+  CoglFramebuffer *framebuffer =
+    cogl_framebuffer_driver_get_framebuffer (driver);
+  CoglContext *ctx = cogl_framebuffer_get_context (framebuffer);
+  GLenum draw_buffer = GL_BACK;
+
+  if (!ctx->glDrawBuffer)
+    return;
+
+  /* The one-shot default draw buffer setting in _cogl_framebuffer_gl_bind
+   * must have already happened. If not it would override what we set here. */
+  g_assert (ctx->was_bound_to_onscreen);
+
+  switch (cogl_framebuffer_get_stereo_mode (framebuffer))
+    {
+    case COGL_STEREO_BOTH:
+      draw_buffer = GL_BACK;
+      break;
+    case COGL_STEREO_LEFT:
+      draw_buffer = GL_BACK_LEFT;
+      break;
+    case COGL_STEREO_RIGHT:
+      draw_buffer = GL_BACK_RIGHT;
+      break;
+    }
+
+  if (ctx->current_gl_draw_buffer != draw_buffer)
+    {
+      GE (ctx, glDrawBuffer (draw_buffer));
+      ctx->current_gl_draw_buffer = draw_buffer;
+    }
+}
+
 CoglGlFramebufferBack *
 cogl_gl_framebuffer_back_new (CoglFramebuffer                    *framebuffer,
                               const CoglFramebufferDriverConfig  *driver_config,
@@ -262,4 +298,6 @@ cogl_gl_framebuffer_back_class_init (CoglGlFramebufferBackClass *klass)
   driver_class->discard_buffers = cogl_gl_framebuffer_back_discard_buffers;
 
   gl_framebuffer_class->bind = cogl_gl_framebuffer_back_bind;
+  gl_framebuffer_class->flush_stereo_mode_state =
+    cogl_gl_framebuffer_back_flush_stereo_mode_state;
 }
diff --git a/cogl/cogl/driver/gl/cogl-gl-framebuffer-fbo.c b/cogl/cogl/driver/gl/cogl-gl-framebuffer-fbo.c
index 0a9bbd680b..e1cd38792e 100644
--- a/cogl/cogl/driver/gl/cogl-gl-framebuffer-fbo.c
+++ b/cogl/cogl/driver/gl/cogl-gl-framebuffer-fbo.c
@@ -214,6 +214,24 @@ cogl_gl_framebuffer_fbo_bind (CoglGlFramebuffer *gl_framebuffer,
   GE (ctx, glBindFramebuffer (target, gl_framebuffer_fbo->gl_fbo.fbo_handle));
 }
 
+static void
+cogl_gl_framebuffer_fbo_flush_stereo_mode_state (CoglGlFramebuffer *gl_framebuffer)
+{
+  CoglFramebufferDriver *driver = COGL_FRAMEBUFFER_DRIVER (gl_framebuffer);
+  CoglFramebuffer *framebuffer =
+    cogl_framebuffer_driver_get_framebuffer (driver);
+
+  switch (cogl_framebuffer_get_stereo_mode (framebuffer))
+    {
+    case COGL_STEREO_BOTH:
+      break;
+    case COGL_STEREO_LEFT:
+    case COGL_STEREO_RIGHT:
+      g_warn_if_reached ();
+      break;
+    }
+}
+
 static GList *
 try_creating_renderbuffers (CoglContext                *ctx,
                             int                         width,
@@ -636,4 +654,6 @@ cogl_gl_framebuffer_fbo_class_init (CoglGlFramebufferFboClass *klass)
   driver_class->discard_buffers = cogl_gl_framebuffer_fbo_discard_buffers;
 
   gl_framebuffer_class->bind = cogl_gl_framebuffer_fbo_bind;
+  gl_framebuffer_class->flush_stereo_mode_state =
+    cogl_gl_framebuffer_fbo_flush_stereo_mode_state;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]