framebuffer: lazily allocate framebuffers as needed

If the user doesn't explicitly allocate a CoglFramebuffer then Cogl
should automatically allocate the framebuffer when the user starts to
draw to the framebuffer. So this way calling cogl_framebuffer_allocate
is only required if you are explicitly interested in checking for and
gracefully handling failures to allocate a framebuffer. If automatic
allocation fails then application behaviour becomes undefined.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
This commit is contained in:
Robert Bragg 2011-08-03 17:03:09 +01:00
parent a3ad808f57
commit 8e8690a562

View File

@ -301,8 +301,6 @@ cogl_framebuffer_clear4f (CoglFramebuffer *framebuffer,
int scissor_x1;
int scissor_y1;
g_return_if_fail (framebuffer->allocated);
_cogl_clip_stack_get_bounds (clip_stack,
&scissor_x0, &scissor_y0,
&scissor_x1, &scissor_y1);
@ -452,8 +450,6 @@ cogl_framebuffer_clear (CoglFramebuffer *framebuffer,
unsigned long buffers,
const CoglColor *color)
{
g_return_if_fail (framebuffer->allocated);
cogl_framebuffer_clear4f (framebuffer, buffers,
cogl_color_get_red_float (color),
cogl_color_get_green_float (color),
@ -618,6 +614,8 @@ _cogl_framebuffer_init_bits (CoglFramebuffer *framebuffer)
{
CoglContext *ctx = framebuffer->context;
cogl_framebuffer_allocate (framebuffer, NULL);
if (G_LIKELY (!framebuffer->dirty_bitmasks))
return;
@ -1383,6 +1381,10 @@ _cogl_framebuffer_flush_state (CoglFramebuffer *draw_buffer,
{
CoglContext *ctx = draw_buffer->context;
/* Lazily ensure the framebuffer has been allocated */
cogl_framebuffer_allocate (draw_buffer, NULL);
cogl_framebuffer_allocate (read_buffer, NULL);
if (ctx->dirty_bound_framebuffer)
{
if (draw_buffer == read_buffer)