feat(srgb): swap textures and framebuffers to SRGB

This commit is contained in:
Martin Wernstål 2023-01-23 14:12:14 +01:00
parent a7cbe3776d
commit 02d1a3c1c3
3 changed files with 8 additions and 5 deletions

View File

@ -71,7 +71,7 @@ update_surface_size(int w, int h, GLuint offscreen_texture_id) {
glViewport(0, 0, w, h); glViewport(0, 0, w, h);
if (offscreen_texture_id) { if (offscreen_texture_id) {
glBindTexture(GL_TEXTURE_2D, offscreen_texture_id); glBindTexture(GL_TEXTURE_2D, offscreen_texture_id);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); glTexImage2D(GL_TEXTURE_2D, 0, GL_SRGB_ALPHA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
} }
} }

View File

@ -11,6 +11,7 @@
#include "charsets.h" #include "charsets.h"
#include <structmember.h> #include <structmember.h>
#include "glfw-wrapper.h" #include "glfw-wrapper.h"
#include "gl.h"
#ifndef __APPLE__ #ifndef __APPLE__
#include "freetype_render_ui_text.h" #include "freetype_render_ui_text.h"
#endif #endif
@ -870,6 +871,8 @@ create_os_window(PyObject UNUSED *self, PyObject *args, PyObject *kw) {
if (is_first_window) { if (is_first_window) {
gl_init(); gl_init();
} }
// Will make the GPU automatically apply SRGB gamma curve on the resulting framebuffer
glEnable(GL_FRAMEBUFFER_SRGB);
bool is_semi_transparent = glfwGetWindowAttrib(glfw_window, GLFW_TRANSPARENT_FRAMEBUFFER); bool is_semi_transparent = glfwGetWindowAttrib(glfw_window, GLFW_TRANSPARENT_FRAMEBUFFER);
// blank the window once so that there is no initial flash of color // blank the window once so that there is no initial flash of color
// changing, in case the background color is not black // changing, in case the background color is not black

View File

@ -102,7 +102,7 @@ realloc_sprite_texture(FONTS_DATA_HANDLE fg) {
znum = z + 1; znum = z + 1;
SpriteMap *sprite_map = (SpriteMap*)fg->sprite_map; SpriteMap *sprite_map = (SpriteMap*)fg->sprite_map;
width = xnum * sprite_map->cell_width; height = ynum * sprite_map->cell_height; width = xnum * sprite_map->cell_width; height = ynum * sprite_map->cell_height;
glTexStorage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, width, height, znum); glTexStorage3D(GL_TEXTURE_2D_ARRAY, 1, GL_SRGB8_ALPHA8, width, height, znum);
if (sprite_map->texture_id) { if (sprite_map->texture_id) {
// need to re-alloc // need to re-alloc
src_ynum = MAX(1, sprite_map->last_ynum); src_ynum = MAX(1, sprite_map->last_ynum);
@ -159,7 +159,7 @@ send_image_to_gpu(GLuint *tex_id, const void* data, GLsizei width, GLsizei heigh
} }
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, r); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, r);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, r); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, r);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, is_opaque ? GL_RGB : GL_RGBA, GL_UNSIGNED_BYTE, data); glTexImage2D(GL_TEXTURE_2D, 0, GL_SRGB_ALPHA, width, height, 0, is_opaque ? GL_RGB : GL_RGBA, GL_UNSIGNED_BYTE, data);
} }
// }}} // }}}
@ -612,7 +612,7 @@ render_a_bar(OSWindow *os_window, Screen *screen, const CellRenderData *crd, Win
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, bar_width, bar_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, bar->buf); glTexImage2D(GL_TEXTURE_2D, 0, GL_SRGB_ALPHA, bar_width, bar_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, bar->buf);
set_cell_uniforms(1.f, false); set_cell_uniforms(1.f, false);
bind_program(GRAPHICS_PROGRAM); bind_program(GRAPHICS_PROGRAM);
send_graphics_data_to_gpu(1, os_window->gvao_idx, &data); send_graphics_data_to_gpu(1, os_window->gvao_idx, &data);
@ -793,7 +793,7 @@ draw_cells_interleaved_premult(ssize_t vao_idx, ssize_t gvao_idx, Screen *screen
glGenFramebuffers(1, &os_window->offscreen_framebuffer); glGenFramebuffers(1, &os_window->offscreen_framebuffer);
glGenTextures(1, &os_window->offscreen_texture_id); glGenTextures(1, &os_window->offscreen_texture_id);
glBindTexture(GL_TEXTURE_2D, os_window->offscreen_texture_id); glBindTexture(GL_TEXTURE_2D, os_window->offscreen_texture_id);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, os_window->viewport_width, os_window->viewport_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); glTexImage2D(GL_TEXTURE_2D, 0, GL_SRGB_ALPHA, os_window->viewport_width, os_window->viewport_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
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_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);