cogl-framebuffer: Use the FBO extension for color sizes

OpenGL 3.0 deprecated querying of the GL_{RED,GREEN,BLUE}_BITS
constants, and the FBO extension provides a mechanism to query for the
color buffer sizes which *should* work even with the default
framebuffer. Unfortunately, this doesn't seem to hold for Mesa - so we
just use this for the offscreen CoglFramebuffer type, and we fall back
to glGetIntegerv() for the onscreen one.

http://bugzilla.openedhand.com/show_bug.cgi?id=2094
This commit is contained in:
Emmanuele Bassi 2010-05-26 17:14:53 +01:00 committed by Robert Bragg
parent 3daafd4711
commit 15881e0f24
4 changed files with 87 additions and 5 deletions

View File

@ -50,7 +50,8 @@ static const GDebugKey cogl_log_debug_keys[] = {
{ "draw", COGL_DEBUG_DRAW }, { "draw", COGL_DEBUG_DRAW },
{ "opengl", COGL_DEBUG_OPENGL }, { "opengl", COGL_DEBUG_OPENGL },
{ "pango", COGL_DEBUG_PANGO }, { "pango", COGL_DEBUG_PANGO },
{ "show-source", COGL_DEBUG_SHOW_SOURCE} { "show-source", COGL_DEBUG_SHOW_SOURCE},
{ "offscreen", COGL_DEBUG_OFFSCREEN }
}; };
static const int n_cogl_log_debug_keys = static const int n_cogl_log_debug_keys =
G_N_ELEMENTS (cogl_log_debug_keys); G_N_ELEMENTS (cogl_log_debug_keys);
@ -124,6 +125,7 @@ _cogl_parse_debug_string (const char *value,
OPT ("disable-glsl:", "disable use of GLSL"); OPT ("disable-glsl:", "disable use of GLSL");
OPT ("show-source:", "show generated ARBfp/GLSL"); OPT ("show-source:", "show generated ARBfp/GLSL");
OPT ("opengl:", "traces some select OpenGL calls"); OPT ("opengl:", "traces some select OpenGL calls");
OPT ("offscreen:", "debug offscreen support");
g_printerr ("\n%28s\n", "Special debug values:"); g_printerr ("\n%28s\n", "Special debug values:");
OPT ("all:", "Enables all non-behavioural debug options"); OPT ("all:", "Enables all non-behavioural debug options");
OPT ("verbose:", "Enables all non-behavioural debug options"); OPT ("verbose:", "Enables all non-behavioural debug options");

View File

@ -51,6 +51,8 @@
#define glFramebufferRenderbuffer ctx->drv.pf_glFramebufferRenderbuffer #define glFramebufferRenderbuffer ctx->drv.pf_glFramebufferRenderbuffer
#define glCheckFramebufferStatus ctx->drv.pf_glCheckFramebufferStatus #define glCheckFramebufferStatus ctx->drv.pf_glCheckFramebufferStatus
#define glDeleteFramebuffers ctx->drv.pf_glDeleteFramebuffers #define glDeleteFramebuffers ctx->drv.pf_glDeleteFramebuffers
#define glGetFramebufferAttachmentParameteriv \
ctx->drv.pf_glGetFramebufferAttachmentParameteriv
#endif #endif
@ -81,6 +83,24 @@
#ifndef GL_DEPTH_COMPONENT16 #ifndef GL_DEPTH_COMPONENT16
#define GL_DEPTH_COMPONENT16 0x81A5 #define GL_DEPTH_COMPONENT16 0x81A5
#endif #endif
#ifndef GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
#define GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE 0x8212
#endif
#ifndef GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
#define GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE 0x8213
#endif
#ifndef GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
#define GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE 0x8214
#endif
#ifndef GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
#define GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE 0x8215
#endif
#ifndef GL_FRAMEBUFFER_ATTCHMENT_DEPTH_SIZE
#define GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE 0x8216
#endif
#ifndef GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
#define GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE 0x8217
#endif
typedef enum { typedef enum {
_TRY_DEPTH_STENCIL = 1L<<0, _TRY_DEPTH_STENCIL = 1L<<0,
@ -253,13 +273,63 @@ _cogl_framebuffer_get_projection_stack (CoglHandle handle)
static inline void static inline void
_cogl_framebuffer_init_bits (CoglFramebuffer *framebuffer) _cogl_framebuffer_init_bits (CoglFramebuffer *framebuffer)
{ {
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
if (G_LIKELY (!framebuffer->dirty_bitmasks)) if (G_LIKELY (!framebuffer->dirty_bitmasks))
return; return;
GE( glGetIntegerv (GL_RED_BITS, &framebuffer->red_bits) ); #ifdef HAVE_COGL_GL
GE( glGetIntegerv (GL_GREEN_BITS, &framebuffer->green_bits) ); if (cogl_features_available (COGL_FEATURE_OFFSCREEN)
GE( glGetIntegerv (GL_BLUE_BITS, &framebuffer->blue_bits) ); && framebuffer->type == COGL_FRAMEBUFFER_TYPE_OFFSCREEN)
GE( glGetIntegerv (GL_ALPHA_BITS, &framebuffer->alpha_bits) ); {
GLenum attachment, pname;
attachment = GL_COLOR_ATTACHMENT0;
pname = GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE;
GE( glGetFramebufferAttachmentParameteriv (GL_FRAMEBUFFER,
attachment,
pname,
&framebuffer->red_bits) );
pname = GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE;
GE( glGetFramebufferAttachmentParameteriv (GL_FRAMEBUFFER,
attachment,
pname,
&framebuffer->green_bits) );
pname = GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE;
GE( glGetFramebufferAttachmentParameteriv (GL_FRAMEBUFFER,
attachment,
pname,
&framebuffer->blue_bits) );
pname = GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE;
GE( glGetFramebufferAttachmentParameteriv (GL_FRAMEBUFFER,
attachment,
pname,
&framebuffer->alpha_bits) );
}
else
#endif /* HAVE_COGL_GL */
{
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) );
}
COGL_NOTE (OFFSCREEN,
"RGBA Bits for framebuffer[%p, %s]: %d, %d, %d, %d",
framebuffer,
framebuffer->type == COGL_FRAMEBUFFER_TYPE_OFFSCREEN
? "offscreen"
: "onscreen",
framebuffer->red_bits,
framebuffer->blue_bits,
framebuffer->green_bits,
framebuffer->alpha_bits);
framebuffer->dirty_bitmasks = FALSE; framebuffer->dirty_bitmasks = FALSE;
} }

View File

@ -70,6 +70,11 @@ COGL_FEATURE_FUNCTION (void, glDeleteFramebuffers,
const GLuint *framebuffers)) const GLuint *framebuffers))
COGL_FEATURE_FUNCTION (void, glGenerateMipmap, COGL_FEATURE_FUNCTION (void, glGenerateMipmap,
(GLenum target)) (GLenum target))
COGL_FEATURE_FUNCTION (void, glGetFramebufferAttachmentParameteriv,
(GLenum target,
GLenum attachment,
GLenum pname,
GLint *params))
COGL_FEATURE_END () COGL_FEATURE_END ()
COGL_FEATURE_BEGIN (offscreen_blit, 255, 255, COGL_FEATURE_BEGIN (offscreen_blit, 255, 255,

View File

@ -67,6 +67,11 @@ COGL_FEATURE_FUNCTION (void, glDeleteFramebuffers,
const GLuint *framebuffers)) const GLuint *framebuffers))
COGL_FEATURE_FUNCTION (void, glGenerateMipmap, COGL_FEATURE_FUNCTION (void, glGenerateMipmap,
(GLenum target)) (GLenum target))
COGL_FEATURE_FUNCTION (void, glGetFramebufferAttachmentParameteriv,
(GLenum target,
GLenum attachment,
GLenum pname,
GLint *params))
COGL_FEATURE_END () COGL_FEATURE_END ()
COGL_FEATURE_BEGIN (element_index_uint, 255, 255, COGL_FEATURE_BEGIN (element_index_uint, 255, 255,