From 741c4bb5e92c5f7f86188a89b9697b842783d714 Mon Sep 17 00:00:00 2001 From: Robert Bragg Date: Fri, 24 Apr 2009 18:09:52 +0100 Subject: [PATCH] [cogl] Adds a bitfield argument to cogl_clear for specifying which buffers to clear Redundant clearing of depth and stencil buffers every render can be very expensive, so cogl now gives control over which auxiliary buffers are cleared. Note: For now clutter continues to clear the color, depth and stencil buffer each paint. --- README | 5 +++-- clutter/clutter-main.c | 5 ++++- clutter/clutter-stage.c | 5 ++++- clutter/clutter-texture.c | 8 +++++++- clutter/cogl/cogl.h.in | 21 ++++++++++++++++--- clutter/cogl/common/cogl.c | 42 +++++++++++++++++++++----------------- 6 files changed, 59 insertions(+), 27 deletions(-) diff --git a/README b/README index 6719889be..2bc9afb8d 100644 --- a/README +++ b/README @@ -295,8 +295,9 @@ Release Notes for Clutter 1.0 * cogl_clip_set* and cogl_clip_unset have been renamed to cogl_clip_push and cogl_clip_pop respectively so they self document their stacking semantics. -* cogl_paint_init was renamed to cogl_clear and no longer disables lighting - and fogging. +* cogl_paint_init was renamed to cogl_clear and no longer disables lighting and + fogging. cogl_clear also now takes a mask of the auxiliary buffers you want + to clear so you can avoid redundant clears of buffers you aren't using. * cogl_fog_set was renamed to cogl_set_fog and it now takes a mode argument giving control over the fogging blend factor equation, so that the diff --git a/clutter/clutter-main.c b/clutter/clutter-main.c index 31b24d23f..d759fb774 100644 --- a/clutter/clutter-main.c +++ b/clutter/clutter-main.c @@ -372,7 +372,10 @@ _clutter_do_pick (ClutterStage *stage, cogl_color_set_from_4ub (&white, 255, 255, 255, 255); cogl_disable_fog (); - cogl_clear (&white); + cogl_clear (&white, + COGL_BUFFER_BIT_COLOR | + COGL_BUFFER_BIT_DEPTH | + COGL_BUFFER_BIT_STENCIL); /* Disable dithering (if any) when doing the painting in pick mode */ dither_was_on = glIsEnabled (GL_DITHER); diff --git a/clutter/clutter-stage.c b/clutter/clutter-stage.c index a9a7bf942..0833dee63 100644 --- a/clutter/clutter-stage.c +++ b/clutter/clutter-stage.c @@ -222,7 +222,10 @@ clutter_stage_paint (ClutterActor *self) priv->color.green, priv->color.blue, priv->color.alpha); - cogl_clear (&stage_color); + cogl_clear (&stage_color, + COGL_BUFFER_BIT_COLOR | + COGL_BUFFER_BIT_DEPTH | + COGL_BUFFER_BIT_STENCIL); if (priv->use_fog) { diff --git a/clutter/clutter-texture.c b/clutter/clutter-texture.c index e4a380178..6580e0b02 100644 --- a/clutter/clutter-texture.c +++ b/clutter/clutter-texture.c @@ -593,7 +593,10 @@ clutter_texture_paint (ClutterActor *self) /* cogl_clear is called to clear the buffers */ cogl_color_set_from_4ub (&transparent_col, 0, 0, 0, 0); - cogl_clear (&transparent_col); + cogl_clear (&transparent_col, + COGL_BUFFER_BIT_COLOR | + COGL_BUFFER_BIT_DEPTH | + COGL_BUFFER_BIT_STENCIL); cogl_disable_fog (); /* Clear the clipping stack so that if the FBO actor is being @@ -1454,6 +1457,9 @@ clutter_texture_set_cogl_texture (ClutterTexture *texture, g_object_notify (G_OBJECT (texture), "cogl-texture"); + /* Re-assert the filter quality on the new cogl texture */ + clutter_texture_set_filter_quality (texture, CLUTTER_TEXTURE_QUALITY_MEDIUM); + /* If resized actor may need resizing but paint() will do this */ if (CLUTTER_ACTOR_IS_VISIBLE (texture)) clutter_actor_queue_redraw (CLUTTER_ACTOR (texture)); diff --git a/clutter/cogl/cogl.h.in b/clutter/cogl/cogl.h.in index 5b5347c16..134b03df1 100644 --- a/clutter/cogl/cogl.h.in +++ b/clutter/cogl/cogl.h.in @@ -363,14 +363,29 @@ void cogl_set_fog (const CoglColor *fog_color, */ void cogl_disable_fog (void); +/** + * CoglBufferBit: + * @COGL_BUFFER_BIT_COLOR: Selects the primary color buffer + * @COGL_BUFFER_BIT_DEPTH: Selects the depth buffer + * @COGL_BUFFER_BIT_STENCIL: Selects the stencil buffer + */ +typedef enum _CoglBufferBit +{ + COGL_BUFFER_BIT_COLOR = 1L<<0, + COGL_BUFFER_BIT_DEPTH = 1L<<1, + COGL_BUFFER_BIT_STENCIL = 1L<<2 +} CoglBufferBit; + /** * cogl_clear: * @color: Background color to clear to + * @buffers: A mask of @CoglBufferBit's identifying which auxiliary + * buffers to clear * - * Clears the color buffer to @color. The depth buffer and stencil - * buffers are also cleared. + * Clears all the auxiliary buffers identified in the @buffers mask, and if + * that includes the color buffer then the specified @color is used. */ -void cogl_clear (const CoglColor *color); +void cogl_clear (const CoglColor *color, gulong buffers); /** * cogl_set_source: diff --git a/clutter/cogl/common/cogl.c b/clutter/cogl/common/cogl.c index c077983e5..34165a57c 100644 --- a/clutter/cogl/common/cogl.c +++ b/clutter/cogl/common/cogl.c @@ -82,32 +82,36 @@ _cogl_error_string(GLenum errorCode) #endif void -cogl_clear (const CoglColor *color) +cogl_clear (const CoglColor *color, gulong buffers) { + GLbitfield gl_buffers = 0; + #if COGL_DEBUG fprintf(stderr, "\n ============== Paint Start ================ \n"); #endif - GE( glClearColor (cogl_color_get_red_float (color), - cogl_color_get_green_float (color), - cogl_color_get_blue_float (color), - 0.0) ); + if (buffers & COGL_BUFFER_BIT_COLOR) + { + GE( glClearColor (cogl_color_get_red_float (color), + cogl_color_get_green_float (color), + cogl_color_get_blue_float (color), + 0.0) ); + gl_buffers |= GL_COLOR_BUFFER_BIT; + } + if (buffers & COGL_BUFFER_BIT_DEPTH) + gl_buffers |= GL_DEPTH_BUFFER_BIT; + if (buffers & COGL_BUFFER_BIT_STENCIL) + gl_buffers |= GL_STENCIL_BUFFER_BIT; - glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); + if (!gl_buffers) + { + static gboolean shown = FALSE; + if (!shown) + g_warning ("You should specify at least one auxiliary buffer when calling cogl_clear"); + return; + } - /* - * Disable the depth test for now as has some strange side effects, - * mainly on x/y axis rotation with multiple layers at same depth - * (eg rotating text on a bg has very strange effect). Seems no clean - * 100% effective way to fix without other odd issues.. So for now - * move to application to handle and add cogl_enable_depth_test() - * as for custom actors (i.e groups) to enable if need be. - * - * glEnable (GL_DEPTH_TEST); - * glEnable (GL_ALPHA_TEST) - * glDepthFunc (GL_LEQUAL); - * glAlphaFunc (GL_GREATER, 0.1); - */ + glClear (gl_buffers); } static inline gboolean