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
This commit is contained in:
Emmanuele Bassi 2010-04-26 18:08:45 +01:00
parent 6243a5dc34
commit 676c8a5fd4
5 changed files with 135 additions and 17 deletions

View File

@ -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

View File

@ -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);

View File

@ -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;
}

View File

@ -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

View File

@ -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.