framebuffer: split GL code out from cogl-framebuffer.c

This splits out most of the OpenGL specific code from cogl-framebuffer.c
into cogl-framebuffer-gl.c and extends the CoglDriverVtable interface
for cogl-framebuffer.c to use.

There are hopes to support several different backends for Cogl
eventually to hopefully get us closer to the metal so this makes some
progress in organizing which parts of Cogl are OpenGL specific so these
parts can potentially be switched out later.

The only remaining use of OpenGL still in cogl-framebuffer.c is to
handle cogl_framebuffer_read_pixels.
This commit is contained in:
Robert Bragg 2012-09-01 00:04:00 +01:00
parent 87bc616d34
commit ce5d06afe1
12 changed files with 1403 additions and 1061 deletions

View File

@ -382,6 +382,8 @@ cogl_sources_c = \
$(srcdir)/cogl-magazine.c \ $(srcdir)/cogl-magazine.c \
$(srcdir)/cogl-gles2-context-private.h \ $(srcdir)/cogl-gles2-context-private.h \
$(srcdir)/cogl-gles2-context.c \ $(srcdir)/cogl-gles2-context.c \
$(srcdir)/cogl-framebuffer-gl-private.h \
$(srcdir)/cogl-framebuffer-gl.c \
$(NULL) $(NULL)
if USE_GLIB if USE_GLIB

View File

@ -61,15 +61,6 @@
#define GL_POINT_SPRITE 0x8861 #define GL_POINT_SPRITE 0x8861
#endif #endif
#ifdef HAVE_COGL_GL
extern const CoglTextureDriver _cogl_texture_driver_gl;
extern const CoglDriverVtable _cogl_driver_gl;
#endif
#if defined (HAVE_COGL_GLES) || defined (HAVE_COGL_GLES2)
extern const CoglTextureDriver _cogl_texture_driver_gles;
extern const CoglDriverVtable _cogl_driver_gles;
#endif
static void _cogl_context_free (CoglContext *context); static void _cogl_context_free (CoglContext *context);
COGL_OBJECT_DEFINE (Context, context); COGL_OBJECT_DEFINE (Context, context);
@ -216,26 +207,10 @@ cogl_context_new (CoglDisplay *display,
lot throughout Cogl */ lot throughout Cogl */
context->driver = display->renderer->driver; context->driver = display->renderer->driver;
switch (context->driver) /* Again this is duplicated data, but it convenient to be able
{ * access these from the context. */
#ifdef HAVE_COGL_GL context->driver_vtable = display->renderer->driver_vtable;
case COGL_DRIVER_GL: context->texture_driver = display->renderer->texture_driver;
context->driver_vtable = &_cogl_driver_gl;
context->texture_driver = &_cogl_texture_driver_gl;
break;
#endif
#if defined (HAVE_COGL_GLES) || defined (HAVE_COGL_GLES2)
case COGL_DRIVER_GLES1:
case COGL_DRIVER_GLES2:
context->driver_vtable = &_cogl_driver_gles;
context->texture_driver = &_cogl_texture_driver_gles;
break;
#endif
default:
g_assert_not_reached ();
}
winsys = _cogl_context_get_winsys (context); winsys = _cogl_context_get_winsys (context);
if (!winsys->context_init (context, error)) if (!winsys->context_init (context, error))

View File

@ -25,6 +25,8 @@
#define __COGL_DRIVER_H #define __COGL_DRIVER_H
#include "cogl-context.h" #include "cogl-context.h"
#include "cogl-offscreen.h"
#include "cogl-framebuffer-private.h"
typedef struct _CoglDriverVtable CoglDriverVtable; typedef struct _CoglDriverVtable CoglDriverVtable;
@ -45,6 +47,61 @@ struct _CoglDriverVtable
CoglBool CoglBool
(* update_features) (CoglContext *context, (* update_features) (CoglContext *context,
GError **error); GError **error);
CoglBool
(* offscreen_allocate) (CoglOffscreen *offscreen,
GError **error);
void
(* offscreen_free) (CoglOffscreen *offscreen);
void
(* framebuffer_flush_state) (CoglFramebuffer *draw_buffer,
CoglFramebuffer *read_buffer,
CoglFramebufferState state);
void
(* framebuffer_clear) (CoglFramebuffer *framebuffer,
unsigned long buffers,
float red,
float green,
float blue,
float alpha);
void
(* framebuffer_query_bits) (CoglFramebuffer *framebuffer,
int *red,
int *green,
int *blue,
int *alpha);
void
(* framebuffer_finish) (CoglFramebuffer *framebuffer);
void
(* framebuffer_discard_buffers) (CoglFramebuffer *framebuffer,
unsigned long buffers);
void
(* framebuffer_draw_attributes) (CoglFramebuffer *framebuffer,
CoglPipeline *pipeline,
CoglVerticesMode mode,
int first_vertex,
int n_vertices,
CoglAttribute **attributes,
int n_attributes,
CoglDrawFlags flags);
void
(* framebuffer_draw_indexed_attributes) (CoglFramebuffer *framebuffer,
CoglPipeline *pipeline,
CoglVerticesMode mode,
int first_vertex,
int n_vertices,
CoglIndices *indices,
CoglAttribute **attributes,
int n_attributes,
CoglDrawFlags flags);
}; };
#endif /* __COGL_DRIVER_H */ #endif /* __COGL_DRIVER_H */

View File

@ -0,0 +1,91 @@
/*
* Cogl
*
* An object oriented GL/GLES Abstraction/Utility Layer
*
* Copyright (C) 2008,2009,2010,2011 Intel Corporation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <http://www.gnu.org/licenses/>.
*
*
*
* Authors:
* Robert Bragg <robert@linux.intel.com>
*/
#ifndef __COGL_FRAMEBUFFER_GL_PRIVATE_H__
#define __COGL_FRAMEBUFFER_GL_PRIVATE_H__
CoglBool
_cogl_offscreen_gl_allocate (CoglOffscreen *offscreen,
GError **error);
void
_cogl_offscreen_gl_free (CoglOffscreen *offscreen);
void
_cogl_framebuffer_gl_flush_state (CoglFramebuffer *draw_buffer,
CoglFramebuffer *read_buffer,
CoglFramebufferState state);
void
_cogl_framebuffer_gl_clear (CoglFramebuffer *framebuffer,
unsigned long buffers,
float red,
float green,
float blue,
float alpha);
void
_cogl_framebuffer_gl_query_bits (CoglFramebuffer *framebuffer,
int *red,
int *green,
int *blue,
int *alpha);
void
_cogl_framebuffer_gl_finish (CoglFramebuffer *framebuffer);
void
_cogl_framebuffer_gl_discard_buffers (CoglFramebuffer *framebuffer,
unsigned long buffers);
void
_cogl_framebuffer_gl_bind (CoglFramebuffer *framebuffer, GLenum target);
void
_cogl_framebuffer_gl_draw_attributes (CoglFramebuffer *framebuffer,
CoglPipeline *pipeline,
CoglVerticesMode mode,
int first_vertex,
int n_vertices,
CoglAttribute **attributes,
int n_attributes,
CoglDrawFlags flags);
void
_cogl_framebuffer_gl_draw_indexed_attributes (CoglFramebuffer *framebuffer,
CoglPipeline *pipeline,
CoglVerticesMode mode,
int first_vertex,
int n_vertices,
CoglIndices *indices,
CoglAttribute **attributes,
int n_attributes,
CoglDrawFlags flags);
#endif /* __COGL_FRAMEBUFFER_GL_PRIVATE_H__ */

1091
cogl/cogl-framebuffer-gl.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -130,17 +130,9 @@ struct _CoglFramebuffer
CoglClipState clip_state; CoglClipState clip_state;
CoglBool dirty_bitmasks;
int red_bits;
int blue_bits;
int green_bits;
int alpha_bits;
CoglBool dither_enabled; CoglBool dither_enabled;
CoglColorMask color_mask; CoglColorMask color_mask;
int samples_per_pixel;
/* We journal the textured rectangles we want to submit to OpenGL so /* We journal the textured rectangles we want to submit to OpenGL so
* we have an oppertunity to batch them together into less draw * we have an oppertunity to batch them together into less draw
* calls. */ * calls. */
@ -165,6 +157,15 @@ struct _CoglFramebuffer
int clear_clip_x1; int clear_clip_x1;
int clear_clip_y1; int clear_clip_y1;
CoglBool clear_clip_dirty; CoglBool clear_clip_dirty;
/* driver specific */
CoglBool dirty_bitmasks;
int red_bits;
int blue_bits;
int green_bits;
int alpha_bits;
int samples_per_pixel;
}; };
typedef enum { typedef enum {
@ -429,7 +430,26 @@ _cogl_framebuffer_try_creating_gl_fbo (CoglContext *ctx,
CoglOffscreenAllocateFlags flags, CoglOffscreenAllocateFlags flags,
CoglGLFramebuffer *gl_framebuffer); CoglGLFramebuffer *gl_framebuffer);
void unsigned long
_cogl_gl_framebuffer_bind (CoglFramebuffer *framebuffer, GLenum target); _cogl_framebuffer_compare (CoglFramebuffer *a,
CoglFramebuffer *b,
unsigned long state);
static inline CoglMatrixEntry *
_cogl_framebuffer_get_modelview_entry (CoglFramebuffer *framebuffer)
{
CoglMatrixStack *modelview_stack =
_cogl_framebuffer_get_modelview_stack (framebuffer);
return modelview_stack->last_entry;
}
static inline CoglMatrixEntry *
_cogl_framebuffer_get_projection_entry (CoglFramebuffer *framebuffer)
{
CoglMatrixStack *projection_stack =
_cogl_framebuffer_get_projection_stack (framebuffer);
return projection_stack->last_entry;
}
#endif /* __COGL_FRAMEBUFFER_PRIVATE_H */ #endif /* __COGL_FRAMEBUFFER_PRIVATE_H */

File diff suppressed because it is too large Load Diff

View File

@ -39,6 +39,7 @@
#include "cogl-context-private.h" #include "cogl-context-private.h"
#include "cogl-display-private.h" #include "cogl-display-private.h"
#include "cogl-framebuffer-private.h" #include "cogl-framebuffer-private.h"
#include "cogl-framebuffer-gl-private.h"
#include "cogl-onscreen-template-private.h" #include "cogl-onscreen-template-private.h"
#include "cogl-renderer-private.h" #include "cogl-renderer-private.h"
#include "cogl-swap-chain-private.h" #include "cogl-swap-chain-private.h"
@ -424,7 +425,7 @@ transient_bind_read_buffer (CoglGLES2Context *gles2_ctx)
} }
else else
{ {
_cogl_gl_framebuffer_bind (gles2_ctx->read_buffer, _cogl_framebuffer_gl_bind (gles2_ctx->read_buffer,
0 /* target ignored */); 0 /* target ignored */);
return RESTORE_FB_FROM_ONSCREEN; return RESTORE_FB_FROM_ONSCREEN;
@ -448,14 +449,14 @@ restore_write_buffer (CoglGLES2Context *gles2_ctx,
case RESTORE_FB_FROM_ONSCREEN: case RESTORE_FB_FROM_ONSCREEN:
/* Note: we can't restore the original write buffer using /* Note: we can't restore the original write buffer using
* _cogl_gl_framebuffer_bind() if it's an offscreen * _cogl_framebuffer_gl_bind() if it's an offscreen
* framebuffer because _cogl_gl_framebuffer_bind() doesn't * framebuffer because _cogl_framebuffer_gl_bind() doesn't
* know about the fbo handle owned by the gles2 context. * know about the fbo handle owned by the gles2 context.
*/ */
if (cogl_is_offscreen (gles2_ctx->write_buffer)) if (cogl_is_offscreen (gles2_ctx->write_buffer))
gl_bind_framebuffer_wrapper (GL_FRAMEBUFFER, 0); gl_bind_framebuffer_wrapper (GL_FRAMEBUFFER, 0);
else else
_cogl_gl_framebuffer_bind (gles2_ctx->write_buffer, GL_FRAMEBUFFER); _cogl_framebuffer_gl_bind (gles2_ctx->write_buffer, GL_FRAMEBUFFER);
break; break;
case RESTORE_FB_NONE: case RESTORE_FB_NONE:

View File

@ -29,6 +29,8 @@
#include "cogl-object-private.h" #include "cogl-object-private.h"
#include "cogl-winsys-private.h" #include "cogl-winsys-private.h"
#include "cogl-internal.h" #include "cogl-internal.h"
#include "cogl-driver.h"
#include "cogl-texture-driver.h"
#ifdef COGL_HAS_XLIB_SUPPORT #ifdef COGL_HAS_XLIB_SUPPORT
#include <X11/Xlib.h> #include <X11/Xlib.h>
@ -43,6 +45,8 @@ struct _CoglRenderer
CoglObject _parent; CoglObject _parent;
CoglBool connected; CoglBool connected;
CoglDriver driver_override; CoglDriver driver_override;
const CoglDriverVtable *driver_vtable;
const CoglTextureDriver *texture_driver;
const CoglWinsysVtable *winsys_vtable; const CoglWinsysVtable *winsys_vtable;
CoglWinsysID winsys_id_override; CoglWinsysID winsys_id_override;
GList *constraints; GList *constraints;

View File

@ -78,6 +78,15 @@
typedef const CoglWinsysVtable *(*CoglWinsysVtableGetter) (void); typedef const CoglWinsysVtable *(*CoglWinsysVtableGetter) (void);
#ifdef HAVE_COGL_GL
extern const CoglTextureDriver _cogl_texture_driver_gl;
extern const CoglDriverVtable _cogl_driver_gl;
#endif
#if defined (HAVE_COGL_GLES) || defined (HAVE_COGL_GLES2)
extern const CoglTextureDriver _cogl_texture_driver_gles;
extern const CoglDriverVtable _cogl_driver_gles;
#endif
static CoglWinsysVtableGetter _cogl_winsys_vtable_getters[] = static CoglWinsysVtableGetter _cogl_winsys_vtable_getters[] =
{ {
#ifdef COGL_HAS_GLX_SUPPORT #ifdef COGL_HAS_GLX_SUPPORT
@ -332,6 +341,27 @@ found:
#endif /* HAVE_DIRECTLY_LINKED_GL_LIBRARY */ #endif /* HAVE_DIRECTLY_LINKED_GL_LIBRARY */
switch (renderer->driver)
{
#ifdef HAVE_COGL_GL
case COGL_DRIVER_GL:
renderer->driver_vtable = &_cogl_driver_gl;
renderer->texture_driver = &_cogl_texture_driver_gl;
break;
#endif
#if defined (HAVE_COGL_GLES) || defined (HAVE_COGL_GLES2)
case COGL_DRIVER_GLES1:
case COGL_DRIVER_GLES2:
renderer->driver_vtable = &_cogl_driver_gles;
renderer->texture_driver = &_cogl_texture_driver_gles;
break;
#endif
default:
g_assert_not_reached ();
}
return TRUE; return TRUE;
} }

View File

@ -32,6 +32,7 @@
#include "cogl-context-private.h" #include "cogl-context-private.h"
#include "cogl-feature-private.h" #include "cogl-feature-private.h"
#include "cogl-renderer-private.h" #include "cogl-renderer-private.h"
#include "cogl-framebuffer-gl-private.h"
static CoglBool static CoglBool
_cogl_driver_pixel_format_from_gl_internal (CoglContext *context, _cogl_driver_pixel_format_from_gl_internal (CoglContext *context,
@ -522,5 +523,14 @@ _cogl_driver_gl =
{ {
_cogl_driver_pixel_format_from_gl_internal, _cogl_driver_pixel_format_from_gl_internal,
_cogl_driver_pixel_format_to_gl, _cogl_driver_pixel_format_to_gl,
_cogl_driver_update_features _cogl_driver_update_features,
_cogl_offscreen_gl_allocate,
_cogl_offscreen_gl_free,
_cogl_framebuffer_gl_flush_state,
_cogl_framebuffer_gl_clear,
_cogl_framebuffer_gl_query_bits,
_cogl_framebuffer_gl_finish,
_cogl_framebuffer_gl_discard_buffers,
_cogl_framebuffer_gl_draw_attributes,
_cogl_framebuffer_gl_draw_indexed_attributes,
}; };

View File

@ -32,6 +32,7 @@
#include "cogl-feature-private.h" #include "cogl-feature-private.h"
#include "cogl-renderer-private.h" #include "cogl-renderer-private.h"
#include "cogl-private.h" #include "cogl-private.h"
#include "cogl-framebuffer-gl-private.h"
#ifndef GL_UNSIGNED_INT_24_8 #ifndef GL_UNSIGNED_INT_24_8
#define GL_UNSIGNED_INT_24_8 0x84FA #define GL_UNSIGNED_INT_24_8 0x84FA
@ -341,5 +342,14 @@ _cogl_driver_gles =
{ {
_cogl_driver_pixel_format_from_gl_internal, _cogl_driver_pixel_format_from_gl_internal,
_cogl_driver_pixel_format_to_gl, _cogl_driver_pixel_format_to_gl,
_cogl_driver_update_features _cogl_driver_update_features,
_cogl_offscreen_gl_allocate,
_cogl_offscreen_gl_free,
_cogl_framebuffer_gl_flush_state,
_cogl_framebuffer_gl_clear,
_cogl_framebuffer_gl_query_bits,
_cogl_framebuffer_gl_finish,
_cogl_framebuffer_gl_discard_buffers,
_cogl_framebuffer_gl_draw_attributes,
_cogl_framebuffer_gl_draw_indexed_attributes,
}; };