cogl-framebuffer: Return gboolean from try_creating_fbo

When try_creating_fbo fails it returns 0 to report the error and if it
succeeds it returns ‘flags’. However cogl_offscreen_new_to_texture
also passes in 0 for the flags as the last fallback to create the fbo
with nothing but the color buffer. In that case it will return 0
regardless of whether it succeeded so the last fallback will always be
considered a failure.

To fix this it now just returns a gboolean to indicate whether it
succeeded and the flags used for each attempt is assigned when passing
the argument rather than from the return value of the function.

Also if the only configuration that succeeded was with flags==0 then
it would always try all combinations because last_working_flags would
also be zero. To avoid this it now uses a separate gboolean to mark
whether we found a successful set of flags.

http://bugzilla.openedhand.com/show_bug.cgi?id=1873
This commit is contained in:
Neil Roberts 2010-01-12 21:44:40 +00:00
parent deecf83c4a
commit 18b96c84bf

View File

@ -247,7 +247,7 @@ _cogl_framebuffer_get_projection_stack (CoglHandle handle)
return framebuffer->projection_stack; return framebuffer->projection_stack;
} }
static TryFBOFlags static gboolean
try_creating_fbo (CoglOffscreen *offscreen, try_creating_fbo (CoglOffscreen *offscreen,
TryFBOFlags flags, TryFBOFlags flags,
CoglHandle texture) CoglHandle texture)
@ -263,14 +263,14 @@ try_creating_fbo (CoglOffscreen *offscreen,
_COGL_GET_CONTEXT (ctx, FALSE); _COGL_GET_CONTEXT (ctx, FALSE);
if (!cogl_texture_get_gl_texture (texture, &tex_gl_handle, &tex_gl_target)) if (!cogl_texture_get_gl_texture (texture, &tex_gl_handle, &tex_gl_target))
return 0; return FALSE;
if (tex_gl_target != GL_TEXTURE_2D if (tex_gl_target != GL_TEXTURE_2D
#ifdef HAVE_COGL_GL #ifdef HAVE_COGL_GL
&& tex_gl_target != GL_TEXTURE_RECTANGLE_ARB && tex_gl_target != GL_TEXTURE_RECTANGLE_ARB
#endif #endif
) )
return 0; return FALSE;
/* We are about to generate and bind a new fbo, so when next flushing the /* We are about to generate and bind a new fbo, so when next flushing the
* journal, we will need to rebind the current framebuffer... */ * journal, we will need to rebind the current framebuffer... */
@ -352,18 +352,18 @@ try_creating_fbo (CoglOffscreen *offscreen,
GLuint renderbuffer = GPOINTER_TO_UINT (l->data); GLuint renderbuffer = GPOINTER_TO_UINT (l->data);
GE (glDeleteRenderbuffers (1, &renderbuffer)); GE (glDeleteRenderbuffers (1, &renderbuffer));
} }
return 0; return FALSE;
} }
return flags; return TRUE;
} }
CoglHandle CoglHandle
cogl_offscreen_new_to_texture (CoglHandle texhandle) cogl_offscreen_new_to_texture (CoglHandle texhandle)
{ {
CoglOffscreen *offscreen; CoglOffscreen *offscreen;
TryFBOFlags flags; static TryFBOFlags flags;
static TryFBOFlags last_working_flags = 0; static gboolean have_working_flags = FALSE;
_COGL_GET_CONTEXT (ctx, COGL_INVALID_HANDLE); _COGL_GET_CONTEXT (ctx, COGL_INVALID_HANDLE);
@ -393,26 +393,18 @@ cogl_offscreen_new_to_texture (CoglHandle texhandle)
offscreen = g_new0 (CoglOffscreen, 1); offscreen = g_new0 (CoglOffscreen, 1);
offscreen->texture = cogl_handle_ref (texhandle); offscreen->texture = cogl_handle_ref (texhandle);
if (!(last_working_flags && if ((have_working_flags &&
(flags = try_creating_fbo (offscreen, last_working_flags, try_creating_fbo (offscreen, flags, texhandle)) ||
texhandle))) && try_creating_fbo (offscreen, flags = _TRY_DEPTH_STENCIL, texhandle) ||
!(flags = try_creating_fbo (offscreen, _TRY_DEPTH_STENCIL, try_creating_fbo (offscreen, flags = _TRY_DEPTH | _TRY_STENCIL,
texhandle)) && texhandle) ||
!(flags = try_creating_fbo (offscreen, _TRY_DEPTH | _TRY_STENCIL, try_creating_fbo (offscreen, flags = _TRY_STENCIL, texhandle) ||
texhandle)) && try_creating_fbo (offscreen, flags = _TRY_DEPTH, texhandle) ||
!(flags = try_creating_fbo (offscreen, _TRY_STENCIL, texhandle)) && try_creating_fbo (offscreen, flags = 0, texhandle))
!(flags = try_creating_fbo (offscreen, _TRY_DEPTH, texhandle)) &&
!(flags = try_creating_fbo (offscreen, 0, texhandle)))
{ {
g_free (offscreen); /* Record that the last set of flags succeeded so that we can
last_working_flags = 0; try that set first next time */
/* XXX: This API should probably have been defined to take a GError */ have_working_flags = TRUE;
g_warning ("%s: Failed to create an OpenGL framebuffer", G_STRLOC);
return COGL_INVALID_HANDLE;
}
/* Save the final set of flags that worked so we can hopefully construct
* subsequent buffers faster. */
last_working_flags = flags;
_cogl_framebuffer_init (COGL_FRAMEBUFFER (offscreen), _cogl_framebuffer_init (COGL_FRAMEBUFFER (offscreen),
COGL_FRAMEBUFFER_TYPE_OFFSCREEN, COGL_FRAMEBUFFER_TYPE_OFFSCREEN,
@ -420,6 +412,14 @@ cogl_offscreen_new_to_texture (CoglHandle texhandle)
cogl_texture_get_height (texhandle)); cogl_texture_get_height (texhandle));
return _cogl_offscreen_handle_new (offscreen); return _cogl_offscreen_handle_new (offscreen);
}
else
{
g_free (offscreen);
/* XXX: This API should probably have been defined to take a GError */
g_warning ("%s: Failed to create an OpenGL framebuffer", G_STRLOC);
return COGL_INVALID_HANDLE;
}
} }
static void static void