From d66bd9714e1e1af4267fb4eb208143a070e65ee3 Mon Sep 17 00:00:00 2001 From: Zhigang Gong Date: Thu, 11 Aug 2011 09:54:28 -0400 Subject: [PATCH] glamor: Concentrate FBO's creation to one function. And add status checking for it. Signed-off-by: Zhigang Gong --- glamor/glamor.c | 9 +-------- glamor/glamor_pixmap.c | 43 +++++++++++++++++++++++++++++++++--------- glamor/glamor_priv.h | 14 ++++++++++++++ 3 files changed, 49 insertions(+), 17 deletions(-) diff --git a/glamor/glamor.c b/glamor/glamor.c index eeb85f23a..dd0d69db7 100644 --- a/glamor/glamor.c +++ b/glamor/glamor.c @@ -74,14 +74,7 @@ glamor_set_pixmap_texture(PixmapPtr pixmap, int w, int h, unsigned int tex) */ pixmap_priv->gl_fbo = 1; pixmap_priv->gl_tex = 1; - glGenFramebuffers(1, &pixmap_priv->fb); - glBindFramebuffer(GL_FRAMEBUFFER, pixmap_priv->fb); - glFramebufferTexture2D(GL_FRAMEBUFFER, - GL_COLOR_ATTACHMENT0, - GL_TEXTURE_2D, - pixmap_priv->tex, - 0); - + glamor_pixmap_ensure_fb(pixmap); screen->ModifyPixmapHeader(pixmap, w, h, 0, 0, (((w * pixmap->drawable.bitsPerPixel + 7) / 8) + 3) & ~3, diff --git a/glamor/glamor_pixmap.c b/glamor/glamor_pixmap.c index 5dd59756d..d747ade43 100644 --- a/glamor/glamor_pixmap.c +++ b/glamor/glamor_pixmap.c @@ -359,6 +359,39 @@ _glamor_upload_pixmap_to_texture(PixmapPtr pixmap, GLenum format, GLenum type, i glBindFramebuffer(GL_FRAMEBUFFER, 0); } +void +glamor_pixmap_ensure_fb(PixmapPtr pixmap) +{ + int status; + glamor_pixmap_private *pixmap_priv = glamor_get_pixmap_private(pixmap); + if (pixmap_priv->fb == 0) + glGenFramebuffers(1, &pixmap_priv->fb); + assert(pixmap_priv->tex != 0); + glBindFramebuffer(GL_FRAMEBUFFER, pixmap_priv->fb); + glFramebufferTexture2D(GL_FRAMEBUFFER, + GL_COLOR_ATTACHMENT0, + GL_TEXTURE_2D, + pixmap_priv->tex, + 0); + status = glCheckFramebufferStatus (GL_FRAMEBUFFER); + if (status != GL_FRAMEBUFFER_COMPLETE) { + const char *str; + switch (status) { + case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT: str= "incomplete attachment"; break; + case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: str= "incomplete/missing attachment"; break; + case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER: str= "incomplete draw buffer"; break; + case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER: str= "incomplete read buffer"; break; + case GL_FRAMEBUFFER_UNSUPPORTED: str= "unsupported"; break; + case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE: str= "incomplete multiple"; break; + default: str = "unknown error"; break; + } + + LogMessageVerb(X_INFO, 0, + "destination is framebuffer incomplete: %s [%#x]\n", + str, status); + assert(0); + } +} /* * Prepare to upload a pixmap to texture memory. @@ -393,21 +426,13 @@ glamor_pixmap_upload_prepare(PixmapPtr pixmap, int ax) glGenTextures(1, &pixmap_priv->tex); if (need_fbo) { - if (pixmap_priv->fb == 0) - glGenFramebuffers(1, &pixmap_priv->fb); glBindTexture(GL_TEXTURE_2D, pixmap_priv->tex); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, pixmap->drawable.width, pixmap->drawable.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); - - glBindFramebuffer(GL_FRAMEBUFFER, pixmap_priv->fb); - glFramebufferTexture2D(GL_FRAMEBUFFER, - GL_COLOR_ATTACHMENT0, - GL_TEXTURE_2D, - pixmap_priv->tex, - 0); + glamor_pixmap_ensure_fb(pixmap); } return 0; diff --git a/glamor/glamor_priv.h b/glamor/glamor_priv.h index c04e118ed..bf032b1cb 100644 --- a/glamor/glamor_priv.h +++ b/glamor/glamor_priv.h @@ -62,6 +62,10 @@ #define GL_PACK_ROW_LENGTH 0x0D02 #define GL_UNPACK_ROW_LENGTH 0x0CF2 +#define GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER 0x8CDB +#define GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER 0x8CDC +#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE 0x8D56 + #define GLEW_MESA_pack_invert 0 #define GL_PACK_INVERT_MESA 0x8758 @@ -802,6 +806,16 @@ glamor_download_pixmap_to_cpu(PixmapPtr pixmap, glamor_access_t access); **/ void glamor_restore_pixmap_to_texture(PixmapPtr pixmap); +/** + * Ensure to have a fbo attached to the pixmap. + * If the pixmap already has one fbo then do nothing. + * Otherwise, it will generate a new fbo, and bind + * the pixmap's texture to the fbo. + * The pixmap must has a valid texture before call this + * API, othersie, it will trigger a assert. + */ +void +glamor_pixmap_ensure_fb(PixmapPtr pixmap); /** * Upload a pixmap to gl texture. Used by dynamic pixmap