glamor: Concentrate FBO's creation to one function.
And add status checking for it. Signed-off-by: Zhigang Gong <zhigang.gong@gmail.com>
This commit is contained in:
parent
b2bff334ce
commit
d66bd9714e
|
@ -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_fbo = 1;
|
||||||
pixmap_priv->gl_tex = 1;
|
pixmap_priv->gl_tex = 1;
|
||||||
glGenFramebuffers(1, &pixmap_priv->fb);
|
glamor_pixmap_ensure_fb(pixmap);
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, pixmap_priv->fb);
|
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER,
|
|
||||||
GL_COLOR_ATTACHMENT0,
|
|
||||||
GL_TEXTURE_2D,
|
|
||||||
pixmap_priv->tex,
|
|
||||||
0);
|
|
||||||
|
|
||||||
screen->ModifyPixmapHeader(pixmap, w, h, 0, 0,
|
screen->ModifyPixmapHeader(pixmap, w, h, 0, 0,
|
||||||
(((w * pixmap->drawable.bitsPerPixel +
|
(((w * pixmap->drawable.bitsPerPixel +
|
||||||
7) / 8) + 3) & ~3,
|
7) / 8) + 3) & ~3,
|
||||||
|
|
|
@ -359,6 +359,39 @@ _glamor_upload_pixmap_to_texture(PixmapPtr pixmap, GLenum format, GLenum type, i
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
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.
|
* 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);
|
glGenTextures(1, &pixmap_priv->tex);
|
||||||
|
|
||||||
if (need_fbo) {
|
if (need_fbo) {
|
||||||
if (pixmap_priv->fb == 0)
|
|
||||||
glGenFramebuffers(1, &pixmap_priv->fb);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, pixmap_priv->tex);
|
glBindTexture(GL_TEXTURE_2D, pixmap_priv->tex);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, pixmap->drawable.width,
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, pixmap->drawable.width,
|
||||||
pixmap->drawable.height, 0,
|
pixmap->drawable.height, 0,
|
||||||
GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
||||||
|
glamor_pixmap_ensure_fb(pixmap);
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, pixmap_priv->fb);
|
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER,
|
|
||||||
GL_COLOR_ATTACHMENT0,
|
|
||||||
GL_TEXTURE_2D,
|
|
||||||
pixmap_priv->tex,
|
|
||||||
0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -62,6 +62,10 @@
|
||||||
#define GL_PACK_ROW_LENGTH 0x0D02
|
#define GL_PACK_ROW_LENGTH 0x0D02
|
||||||
#define GL_UNPACK_ROW_LENGTH 0x0CF2
|
#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 GLEW_MESA_pack_invert 0
|
||||||
#define GL_PACK_INVERT_MESA 0x8758
|
#define GL_PACK_INVERT_MESA 0x8758
|
||||||
|
|
||||||
|
@ -802,6 +806,16 @@ glamor_download_pixmap_to_cpu(PixmapPtr pixmap, glamor_access_t access);
|
||||||
**/
|
**/
|
||||||
void
|
void
|
||||||
glamor_restore_pixmap_to_texture(PixmapPtr pixmap);
|
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
|
* Upload a pixmap to gl texture. Used by dynamic pixmap
|
||||||
|
|
Loading…
Reference in New Issue
Block a user