diff --git a/clutter/cogl/cogl/cogl-context.c b/clutter/cogl/cogl/cogl-context.c index cdbd99ec6..956ea0aa0 100644 --- a/clutter/cogl/cogl/cogl-context.c +++ b/clutter/cogl/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/clutter/cogl/cogl/cogl-framebuffer-private.h b/clutter/cogl/cogl/cogl-framebuffer-private.h index 71edfa046..09a9cd824 100644 --- a/clutter/cogl/cogl/cogl-framebuffer-private.h +++ b/clutter/cogl/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/clutter/cogl/cogl/cogl-framebuffer.c b/clutter/cogl/cogl/cogl-framebuffer.c index 082abf5f6..8727f607c 100644 --- a/clutter/cogl/cogl/cogl-framebuffer.c +++ b/clutter/cogl/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/clutter/cogl/cogl/cogl.c b/clutter/cogl/cogl/cogl.c index 0355af20d..2386b3ea5 100644 --- a/clutter/cogl/cogl/cogl.c +++ b/clutter/cogl/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/clutter/cogl/cogl/cogl.h b/clutter/cogl/cogl/cogl.h index ff0e1f9a1..075456fa1 100644 --- a/clutter/cogl/cogl/cogl.h +++ b/clutter/cogl/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.