From 676c8a5fd4e0a9126a1a735f9e89513e5614a838 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Mon, 26 Apr 2010 18:08:45 +0100 Subject: [PATCH] Implement accessors for the color bits in a framebuffer Instead of using cogl_get_bitmasks() to query the GL machinery for the size of the color bits, we should store the values inside the CoglFramebuffer object and query them the first time we set the framebuffer as the current one. Currently, cogl_get_bitmasks() is re-implemented in terms of cogl_framebuffer_get_*_bits(). As soon as we are able to expose the CoglOnscreen framebuffer object in the public API we'll be able to deprecate cogl_get_bitmasks() altogether. http://bugzilla.openedhand.com/show_bug.cgi?id=2094 --- cogl/cogl-context.c | 1 + cogl/cogl-framebuffer-private.h | 18 +++++++++++ cogl/cogl-framebuffer.c | 57 +++++++++++++++++++++++++++++++++ cogl/cogl.c | 24 ++++---------- cogl/cogl.h | 52 ++++++++++++++++++++++++++++++ 5 files changed, 135 insertions(+), 17 deletions(-) diff --git a/cogl/cogl-context.c b/cogl/cogl-context.c index cdbd99ec6..956ea0aa0 100644 --- a/cogl/cogl-context.c +++ b/cogl/cogl-context.c @@ -100,6 +100,7 @@ cogl_create_context (void) _context->n_texcoord_arrays_enabled = 0; _context->framebuffer_stack = _cogl_create_framebuffer_stack (); + window_buffer = _cogl_onscreen_new (); cogl_set_framebuffer (window_buffer); /* XXX: the deprecated _cogl_set_draw_buffer API expects to diff --git a/cogl/cogl-framebuffer-private.h b/cogl/cogl-framebuffer-private.h index 71edfa046..09a9cd824 100644 --- a/cogl/cogl-framebuffer-private.h +++ b/cogl/cogl-framebuffer-private.h @@ -48,6 +48,12 @@ typedef struct int viewport_height; CoglClipState clip_state; + + gboolean dirty_bitmasks; + int red_bits; + int blue_bits; + int green_bits; + int alpha_bits; } CoglFramebuffer; #define COGL_FRAMEBUFFER(X) ((CoglFramebuffer *)(X)) @@ -71,12 +77,16 @@ typedef struct _CoglOnscreen void _cogl_framebuffer_state_init (void); + int _cogl_framebuffer_get_width (CoglHandle handle); + int _cogl_framebuffer_get_height (CoglHandle handle); + CoglClipState * _cogl_framebuffer_get_clip_state (CoglHandle handle); + void _cogl_framebuffer_set_viewport (CoglHandle handle, int x, @@ -85,16 +95,22 @@ _cogl_framebuffer_set_viewport (CoglHandle handle, int height); int _cogl_framebuffer_get_viewport_x (CoglHandle handle); + int _cogl_framebuffer_get_viewport_y (CoglHandle handle); + int _cogl_framebuffer_get_viewport_width (CoglHandle handle); + int _cogl_framebuffer_get_viewport_height (CoglHandle handle); + void _cogl_framebuffer_get_viewport4fv (CoglHandle handle, int *viewport); + CoglMatrixStack * _cogl_framebuffer_get_modelview_stack (CoglHandle handle); + CoglMatrixStack * _cogl_framebuffer_get_projection_stack (CoglHandle handle); @@ -116,8 +132,10 @@ _cogl_onscreen_new (void); CoglHandle _cogl_get_framebuffer (void); + GSList * _cogl_create_framebuffer_stack (void); + void _cogl_free_framebuffer_stack (GSList *stack); diff --git a/cogl/cogl-framebuffer.c b/cogl/cogl-framebuffer.c index 082abf5f6..8727f607c 100644 --- a/cogl/cogl-framebuffer.c +++ b/cogl/cogl-framebuffer.c @@ -130,6 +130,8 @@ _cogl_framebuffer_init (CoglFramebuffer *framebuffer, framebuffer->modelview_stack = _cogl_matrix_stack_new (); framebuffer->projection_stack = _cogl_matrix_stack_new (); + framebuffer->dirty_bitmasks = TRUE; + /* Initialise the clip stack */ _cogl_clip_state_init (&framebuffer->clip_state); } @@ -248,6 +250,20 @@ _cogl_framebuffer_get_projection_stack (CoglHandle handle) return framebuffer->projection_stack; } +static inline void +_cogl_framebuffer_init_bits (CoglFramebuffer *framebuffer) +{ + if (G_LIKELY (!framebuffer->dirty_bitmasks)) + return; + + GE( glGetIntegerv (GL_RED_BITS, &framebuffer->red_bits) ); + GE( glGetIntegerv (GL_GREEN_BITS, &framebuffer->green_bits) ); + GE( glGetIntegerv (GL_BLUE_BITS, &framebuffer->blue_bits) ); + GE( glGetIntegerv (GL_ALPHA_BITS, &framebuffer->alpha_bits) ); + + framebuffer->dirty_bitmasks = FALSE; +} + static gboolean try_creating_fbo (CoglOffscreen *offscreen, TryFBOFlags flags, @@ -552,6 +568,8 @@ _cogl_set_framebuffer_real (CoglFramebuffer *framebuffer) _cogl_matrix_stack_dirty (framebuffer->modelview_stack); _cogl_matrix_stack_dirty (framebuffer->projection_stack); _cogl_clip_state_dirty (&framebuffer->clip_state); + + _cogl_framebuffer_init_bits (framebuffer); } void @@ -707,3 +725,42 @@ _cogl_framebuffer_flush_state (CoglHandle handle, COGL_MATRIX_PROJECTION); } +int +cogl_framebuffer_get_red_bits (CoglHandle framebuffer) +{ + CoglFramebuffer *fb = COGL_FRAMEBUFFER (framebuffer); + + _cogl_framebuffer_init_bits (fb); + + return fb->red_bits; +} + +int +cogl_framebuffer_get_green_bits (CoglHandle framebuffer) +{ + CoglFramebuffer *fb = COGL_FRAMEBUFFER (framebuffer); + + _cogl_framebuffer_init_bits (fb); + + return fb->green_bits; +} + +int +cogl_framebuffer_get_blue_bits (CoglHandle framebuffer) +{ + CoglFramebuffer *fb = COGL_FRAMEBUFFER (framebuffer); + + _cogl_framebuffer_init_bits (fb); + + return fb->blue_bits; +} + +int +cogl_framebuffer_get_alpha_bits (CoglHandle framebuffer) +{ + CoglFramebuffer *fb = COGL_FRAMEBUFFER (framebuffer); + + _cogl_framebuffer_init_bits (fb); + + return fb->alpha_bits; +} diff --git a/cogl/cogl.c b/cogl/cogl.c index 0355af20d..2386b3ea5 100644 --- a/cogl/cogl.c +++ b/cogl/cogl.c @@ -533,31 +533,21 @@ cogl_get_bitmasks (int *red, int *blue, int *alpha) { - GLint value; + CoglHandle framebuffer; + + framebuffer = _cogl_get_framebuffer (); if (red) - { - GE( glGetIntegerv(GL_RED_BITS, &value) ); - *red = value; - } + *red = cogl_framebuffer_get_red_bits (framebuffer); if (green) - { - GE( glGetIntegerv(GL_GREEN_BITS, &value) ); - *green = value; - } + *green = cogl_framebuffer_get_green_bits (framebuffer); if (blue) - { - GE( glGetIntegerv(GL_BLUE_BITS, &value) ); - *blue = value; - } + *blue = cogl_framebuffer_get_blue_bits (framebuffer); if (alpha) - { - GE( glGetIntegerv(GL_ALPHA_BITS, &value ) ); - *alpha = value; - } + *alpha = cogl_framebuffer_get_alpha_bits (framebuffer); } void diff --git a/cogl/cogl.h b/cogl/cogl.h index ff0e1f9a1..075456fa1 100644 --- a/cogl/cogl.h +++ b/cogl/cogl.h @@ -159,6 +159,58 @@ cogl_get_bitmasks (int *red, int *blue, int *alpha); +/** + * cogl_framebuffer_get_red_bits: + * @framebuffer: a handle for a framebuffer + * + * Retrieves the number of red bits of @framebuffer + * + * Return value: the number of bits + * + * Since: 1.4 + */ +int +cogl_framebuffer_get_red_bits (CoglHandle framebuffer); + +/** + * cogl_framebuffer_get_green_bits: + * @framebuffer: a handle for a framebuffer + * + * Retrieves the number of green bits of @framebuffer + * + * Return value: the number of bits + * + * Since: 1.4 + */ +int +cogl_framebuffer_get_green_bits (CoglHandle framebuffer); + +/** + * cogl_framebuffer_get_blue_bits: + * @framebuffer: a handle for a framebuffer + * + * Retrieves the number of blue bits of @framebuffer + * + * Return value: the number of bits + * + * Since: 1.4 + */ +int +cogl_framebuffer_get_blue_bits (CoglHandle framebuffer); + +/** + * cogl_framebuffer_get_alpha_bits: + * @framebuffer: a handle for a framebuffer + * + * Retrieves the number of alpha bits of @framebuffer + * + * Return value: the number of bits + * + * Since: 1.4 + */ +int +cogl_framebuffer_get_alpha_bits (CoglHandle framebuffer); + /** * cogl_perspective: * @fovy: Vertical of view angle in degrees.