summaryrefslogtreecommitdiff
path: root/cogl
diff options
context:
space:
mode:
authorJonas Ã…dahl <jadahl@gmail.com>2020-10-20 11:55:57 +0200
committerRobert Mader <robert.mader@posteo.de>2021-01-30 09:11:46 +0000
commit102aa59ce304334553fe5ab007c1c2a34ea1fec5 (patch)
tree5e6c0942b000036200cb2847c11176d1d4f219ce /cogl
parentdd55c3699c650a2e95c45df2195f09a12aa65e9a (diff)
downloadmutter-102aa59ce304334553fe5ab007c1c2a34ea1fec5.tar.gz
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>
Diffstat (limited to 'cogl')
-rw-r--r--cogl/cogl/driver/gl/cogl-framebuffer-gl-private.h2
-rw-r--r--cogl/cogl/driver/gl/cogl-framebuffer-gl.c36
-rw-r--r--cogl/cogl/driver/gl/cogl-gl-framebuffer-back.c38
-rw-r--r--cogl/cogl/driver/gl/cogl-gl-framebuffer-fbo.c20
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 4bdd076a6..3f3f6b7c8 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 d7407bee5..6e807fa71 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 4788bb9be..cc2510fe5 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 0a9bbd680..e1cd38792 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;
}