cogl/framebuffer: Move discard_buffers() to driver sub types

It was implemented slightly different depending on whether it was for a
surface or FBO, so move it to their corresponding GL driver types.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1514>
This commit is contained in:
Jonas Ådahl 2020-10-20 10:04:04 +02:00 committed by Robert Mader
parent b7c6865225
commit 392ffaeeb4
14 changed files with 78 additions and 61 deletions

View File

@ -85,10 +85,6 @@ struct _CoglDriverVtable
CoglFramebuffer *read_buffer,
CoglFramebufferState state);
void
(* framebuffer_discard_buffers) (CoglFramebuffer *framebuffer,
unsigned long buffers);
void
(* framebuffer_draw_attributes) (CoglFramebuffer *framebuffer,
CoglPipeline *pipeline,

View File

@ -93,6 +93,13 @@ cogl_framebuffer_driver_flush (CoglFramebufferDriver *driver)
COGL_FRAMEBUFFER_DRIVER_GET_CLASS (driver)->flush (driver);
}
void
cogl_framebuffer_driver_discard_buffers (CoglFramebufferDriver *driver,
unsigned long buffers)
{
COGL_FRAMEBUFFER_DRIVER_GET_CLASS (driver)->discard_buffers (driver, buffers);
}
static void
cogl_framebuffer_driver_get_property (GObject *object,
guint prop_id,

View File

@ -55,6 +55,9 @@ struct _CoglFramebufferDriverClass
void (* finish) (CoglFramebufferDriver *driver);
void (* flush) (CoglFramebufferDriver *driver);
void (* discard_buffers) (CoglFramebufferDriver *driver,
unsigned long buffers);
};
CoglFramebuffer *
@ -78,4 +81,8 @@ cogl_framebuffer_driver_finish (CoglFramebufferDriver *driver);
void
cogl_framebuffer_driver_flush (CoglFramebufferDriver *driver);
void
cogl_framebuffer_driver_discard_buffers (CoglFramebufferDriver *driver,
unsigned long buffers);
#endif /* COGL_FRAMEBUFFER_DRIVER_H */

View File

@ -1695,11 +1695,10 @@ cogl_framebuffer_discard_buffers (CoglFramebuffer *framebuffer,
{
CoglFramebufferPrivate *priv =
cogl_framebuffer_get_instance_private (framebuffer);
CoglContext *ctx = priv->context;
g_return_if_fail (buffers & COGL_BUFFER_BIT_COLOR);
ctx->driver_vtable->framebuffer_discard_buffers (framebuffer, buffers);
cogl_framebuffer_driver_discard_buffers (priv->driver, buffers);
}
void

View File

@ -51,10 +51,6 @@ struct _CoglGlFramebufferClass
GLenum target);
};
void
_cogl_framebuffer_gl_discard_buffers (CoglFramebuffer *framebuffer,
unsigned long buffers);
void
cogl_gl_framebuffer_bind (CoglGlFramebuffer *gl_framebuffer,
GLenum target);

View File

@ -328,44 +328,6 @@ cogl_gl_framebuffer_flush (CoglFramebufferDriver *driver)
GE (ctx, glFlush ());
}
void
_cogl_framebuffer_gl_discard_buffers (CoglFramebuffer *framebuffer,
unsigned long buffers)
{
CoglContext *ctx = cogl_framebuffer_get_context (framebuffer);
if (ctx->glDiscardFramebuffer)
{
GLenum attachments[3];
int i = 0;
if (COGL_IS_ONSCREEN (framebuffer))
{
if (buffers & COGL_BUFFER_BIT_COLOR)
attachments[i++] = GL_COLOR;
if (buffers & COGL_BUFFER_BIT_DEPTH)
attachments[i++] = GL_DEPTH;
if (buffers & COGL_BUFFER_BIT_STENCIL)
attachments[i++] = GL_STENCIL;
}
else
{
if (buffers & COGL_BUFFER_BIT_COLOR)
attachments[i++] = GL_COLOR_ATTACHMENT0;
if (buffers & COGL_BUFFER_BIT_DEPTH)
attachments[i++] = GL_DEPTH_ATTACHMENT;
if (buffers & COGL_BUFFER_BIT_STENCIL)
attachments[i++] = GL_STENCIL_ATTACHMENT;
}
cogl_context_flush_framebuffer_state (ctx,
framebuffer,
framebuffer,
COGL_FRAMEBUFFER_STATE_BIND);
GE (ctx, glDiscardFramebuffer (GL_FRAMEBUFFER, i, attachments));
}
}
void
_cogl_framebuffer_gl_draw_attributes (CoglFramebuffer *framebuffer,
CoglPipeline *pipeline,

View File

@ -155,6 +155,33 @@ cogl_gl_framebuffer_back_query_bits (CoglFramebufferDriver *driver,
*bits = gl_framebuffer_back->bits;
}
static void
cogl_gl_framebuffer_back_discard_buffers (CoglFramebufferDriver *driver,
unsigned long buffers)
{
CoglFramebuffer *framebuffer =
cogl_framebuffer_driver_get_framebuffer (driver);
CoglContext *ctx = cogl_framebuffer_get_context (framebuffer);
GLenum attachments[3];
int i = 0;
if (!ctx->glDiscardFramebuffer)
return;
if (buffers & COGL_BUFFER_BIT_COLOR)
attachments[i++] = GL_COLOR;
if (buffers & COGL_BUFFER_BIT_DEPTH)
attachments[i++] = GL_DEPTH;
if (buffers & COGL_BUFFER_BIT_STENCIL)
attachments[i++] = GL_STENCIL;
cogl_context_flush_framebuffer_state (ctx,
framebuffer,
framebuffer,
COGL_FRAMEBUFFER_STATE_BIND);
GE (ctx, glDiscardFramebuffer (GL_FRAMEBUFFER, i, attachments));
}
static void
cogl_gl_framebuffer_back_bind (CoglGlFramebuffer *gl_framebuffer,
GLenum target)
@ -232,6 +259,7 @@ cogl_gl_framebuffer_back_class_init (CoglGlFramebufferBackClass *klass)
COGL_GL_FRAMEBUFFER_CLASS (klass);
driver_class->query_bits = cogl_gl_framebuffer_back_query_bits;
driver_class->discard_buffers = cogl_gl_framebuffer_back_discard_buffers;
gl_framebuffer_class->bind = cogl_gl_framebuffer_back_bind;
}

View File

@ -173,6 +173,33 @@ cogl_gl_framebuffer_fbo_query_bits (CoglFramebufferDriver *driver,
*bits = gl_framebuffer_fbo->bits;
}
static void
cogl_gl_framebuffer_fbo_discard_buffers (CoglFramebufferDriver *driver,
unsigned long buffers)
{
CoglFramebuffer *framebuffer =
cogl_framebuffer_driver_get_framebuffer (driver);
CoglContext *ctx = cogl_framebuffer_get_context (framebuffer);
GLenum attachments[3];
int i = 0;
if (!ctx->glDiscardFramebuffer)
return;
if (buffers & COGL_BUFFER_BIT_COLOR)
attachments[i++] = GL_COLOR_ATTACHMENT0;
if (buffers & COGL_BUFFER_BIT_DEPTH)
attachments[i++] = GL_DEPTH_ATTACHMENT;
if (buffers & COGL_BUFFER_BIT_STENCIL)
attachments[i++] = GL_STENCIL_ATTACHMENT;
cogl_context_flush_framebuffer_state (ctx,
framebuffer,
framebuffer,
COGL_FRAMEBUFFER_STATE_BIND);
GE (ctx, glDiscardFramebuffer (GL_FRAMEBUFFER, i, attachments));
}
static void
cogl_gl_framebuffer_fbo_bind (CoglGlFramebuffer *gl_framebuffer,
GLenum target)
@ -606,6 +633,7 @@ cogl_gl_framebuffer_fbo_class_init (CoglGlFramebufferFboClass *klass)
object_class->dispose = cogl_gl_framebuffer_fbo_dispose;
driver_class->query_bits = cogl_gl_framebuffer_fbo_query_bits;
driver_class->discard_buffers = cogl_gl_framebuffer_fbo_discard_buffers;
gl_framebuffer_class->bind = cogl_gl_framebuffer_fbo_bind;
}

View File

@ -571,7 +571,6 @@ _cogl_driver_gl =
_cogl_driver_update_features,
_cogl_driver_gl_create_framebuffer_driver,
_cogl_driver_gl_flush_framebuffer_state,
_cogl_framebuffer_gl_discard_buffers,
_cogl_framebuffer_gl_draw_attributes,
_cogl_framebuffer_gl_draw_indexed_attributes,
_cogl_framebuffer_gl_read_pixels_into_bitmap,

View File

@ -459,7 +459,6 @@ _cogl_driver_gles =
_cogl_driver_update_features,
_cogl_driver_gl_create_framebuffer_driver,
_cogl_driver_gl_flush_framebuffer_state,
_cogl_framebuffer_gl_discard_buffers,
_cogl_framebuffer_gl_draw_attributes,
_cogl_framebuffer_gl_draw_indexed_attributes,
_cogl_framebuffer_gl_read_pixels_into_bitmap,

View File

@ -99,7 +99,6 @@ _cogl_driver_nop =
_cogl_driver_update_features,
_cogl_driver_nop_create_framebuffer_driver,
_cogl_driver_nop_flush_framebuffer_state,
_cogl_framebuffer_nop_discard_buffers,
_cogl_framebuffer_nop_draw_attributes,
_cogl_framebuffer_nop_draw_indexed_attributes,
_cogl_framebuffer_nop_read_pixels_into_bitmap,

View File

@ -37,10 +37,6 @@
#include "cogl-types.h"
#include "cogl-context-private.h"
void
_cogl_framebuffer_nop_discard_buffers (CoglFramebuffer *framebuffer,
unsigned long buffers);
void
_cogl_framebuffer_nop_draw_attributes (CoglFramebuffer *framebuffer,
CoglPipeline *pipeline,

View File

@ -35,12 +35,6 @@
#include <glib.h>
#include <string.h>
void
_cogl_framebuffer_nop_discard_buffers (CoglFramebuffer *framebuffer,
unsigned long buffers)
{
}
void
_cogl_framebuffer_nop_draw_attributes (CoglFramebuffer *framebuffer,
CoglPipeline *pipeline,

View File

@ -64,6 +64,12 @@ cogl_nop_framebuffer_flush (CoglFramebufferDriver *driver)
{
}
static void
cogl_nop_framebuffer_discard_buffers (CoglFramebufferDriver *driver,
unsigned long buffers)
{
}
static void
cogl_nop_framebuffer_init (CoglNopFramebuffer *nop_framebuffer)
{
@ -79,4 +85,5 @@ cogl_nop_framebuffer_class_init (CoglNopFramebufferClass *klass)
driver_class->clear = cogl_nop_framebuffer_clear;
driver_class->finish = cogl_nop_framebuffer_finish;
driver_class->flush = cogl_nop_framebuffer_flush;
driver_class->discard_buffers = cogl_nop_framebuffer_discard_buffers;
}