From 8e8690a562395d96485115a7f437a55f8db2af77 Mon Sep 17 00:00:00 2001 From: Robert Bragg Date: Wed, 3 Aug 2011 17:03:09 +0100 Subject: [PATCH] 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 --- cogl/cogl-framebuffer.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/cogl/cogl-framebuffer.c b/cogl/cogl-framebuffer.c index 48a421872..a7a442c1e 100644 --- a/cogl/cogl-framebuffer.c +++ b/cogl/cogl-framebuffer.c @@ -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)