From 2d94b3f46f1a783c0e1562da604d920affbadc43 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. --- cogl.h.in | 21 ++++++++++++++++++--- common/cogl.c | 42 +++++++++++++++++++++++------------------- 2 files changed, 41 insertions(+), 22 deletions(-) diff --git a/cogl.h.in b/cogl.h.in index 5b5347c16..134b03df1 100644 --- a/cogl.h.in +++ b/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/common/cogl.c b/common/cogl.c index c077983e5..34165a57c 100644 --- a/common/cogl.c +++ b/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