1
0
Fork 0
mirror of https://github.com/yshui/picom.git synced 2024-11-11 13:51:02 -05:00

backend: gl: try different back buffer formats

Prefer RGB formats first, because they use less memory; but fallback to
RGBA formats, as they are formats required by OpenGL.

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui 2022-12-01 18:54:22 +00:00
parent d704e0f80e
commit d38b0ead7d
No known key found for this signature in database
GPG key ID: D3A4405BE6CC17F4
2 changed files with 20 additions and 11 deletions

View file

@ -622,16 +622,13 @@ void gl_resize(struct gl_data *gd, int width, int height) {
gd->height = height; gd->height = height;
gd->width = width; gd->width = width;
GLint format = GL_RGB8;
if (gd->dithered_present) {
format = GL_RGB16;
}
assert(viewport_dimensions[0] >= gd->width); assert(viewport_dimensions[0] >= gd->width);
assert(viewport_dimensions[1] >= gd->height); assert(viewport_dimensions[1] >= gd->height);
glBindTexture(GL_TEXTURE_2D, gd->back_texture); glBindTexture(GL_TEXTURE_2D, gd->back_texture);
glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, GL_BGR, GL_UNSIGNED_BYTE, NULL); glTexImage2D(GL_TEXTURE_2D, 0, gd->back_format, width, height, 0, GL_BGR,
GL_UNSIGNED_BYTE, NULL);
gl_check_err(); gl_check_err();
} }
@ -919,14 +916,25 @@ bool gl_init(struct gl_data *gd, session_t *ps) {
glUniformMatrix4fv(pml, 1, false, projection_matrix[0]); glUniformMatrix4fv(pml, 1, false, projection_matrix[0]);
glUseProgram(0); glUseProgram(0);
// Set up the size of the back texture // Set up the size and format of the back texture
gl_resize(gd, ps->root_width, ps->root_height);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, gd->back_fbo); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, gd->back_fbo);
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
gd->back_texture, 0);
glDrawBuffer(GL_COLOR_ATTACHMENT0); glDrawBuffer(GL_COLOR_ATTACHMENT0);
if (!gl_check_fb_complete(GL_FRAMEBUFFER)) { const GLint *format = (const GLint[]){GL_RGB8, GL_RGBA8};
if (gd->dithered_present) {
format = (const GLint[]){GL_RGB16, GL_RGBA16};
}
for (int i = 0; i < 2; i++) {
gd->back_format = format[i];
gl_resize(gd, ps->root_width, ps->root_height);
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
GL_TEXTURE_2D, gd->back_texture, 0);
if (glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE) {
log_info("Using back buffer format %#x", gd->back_format);
break;
}
}
if (!gl_check_fb_complete(GL_DRAW_FRAMEBUFFER)) {
return false; return false;
} }
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);

View file

@ -107,6 +107,7 @@ struct gl_data {
gl_fill_shader_t fill_shader; gl_fill_shader_t fill_shader;
gl_shadow_shader_t shadow_shader; gl_shadow_shader_t shadow_shader;
GLuint back_texture, back_fbo; GLuint back_texture, back_fbo;
GLint back_format;
GLuint present_prog; GLuint present_prog;
bool dithered_present; bool dithered_present;