Skip to content

Commit

Permalink
PlatformCore: Conditionally set texture format
Browse files Browse the repository at this point in the history
sRGB texture format is needed for the output to look right with
sRGB framebuffer enabled and no color correction shader applied.
  • Loading branch information
GranMinigun committed Dec 13, 2023
1 parent c12611d commit 06550d2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/platform/core/src/device/ogl_video_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,14 @@ void OGLVideoDevice::UpdateTextures() {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
};

const bool color_correction_active = config->video.color != Video::Color::No;
const auto texture_format = color_correction_active ? GL_RGBA8 : GL_SRGB8_ALPHA8;

// Alternating input sampler and output framebuffer attachment.
for(const auto texture : {textures[input_index], textures[output_index]}) {
glBindTexture(GL_TEXTURE_2D, texture);

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, gba_screen_width,
glTexImage2D(GL_TEXTURE_2D, 0, texture_format, gba_screen_width,
gba_screen_height, 0, GL_BGRA, GL_UNSIGNED_BYTE, nullptr);

set_texture_params(texture_filter);
Expand All @@ -110,12 +113,13 @@ void OGLVideoDevice::UpdateTextures() {
const bool xbrz_ghosting =
config->video.filter == Video::Filter::xBRZ && config->video.lcd_ghosting;
if(config->video.lcd_ghosting) {
const GLint history_texture_format = (!color_correction_active || xbrz_ghosting) ? GL_SRGB8_ALPHA8 : GL_RGBA8;
const GLsizei texture_width = xbrz_ghosting ? view_width : gba_screen_width;
const GLsizei texture_height = xbrz_ghosting ? view_height : gba_screen_height;

glBindTexture(GL_TEXTURE_2D, textures[history_index]);

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, texture_width, texture_height, 0,
glTexImage2D(GL_TEXTURE_2D, 0, history_texture_format, texture_width, texture_height, 0,
GL_BGRA, GL_UNSIGNED_BYTE, nullptr);

set_texture_params(GL_NEAREST);
Expand All @@ -124,7 +128,7 @@ void OGLVideoDevice::UpdateTextures() {
if(xbrz_ghosting) {
glBindTexture(GL_TEXTURE_2D, textures[xbrz_output_index]);

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, view_width, view_height, 0,
glTexImage2D(GL_TEXTURE_2D, 0, texture_format, view_width, view_height, 0,
GL_BGRA, GL_UNSIGNED_BYTE, nullptr);

set_texture_params(GL_NEAREST);
Expand Down
1 change: 1 addition & 0 deletions src/platform/qt/src/widget/screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ void Screen::SetForceClear(bool force_clear) {
}

void Screen::ReloadConfig() {
makeCurrent(); // Workaround for Intel graphics.
ogl_video_device.ReloadConfig();
UpdateViewport();
}
Expand Down

0 comments on commit 06550d2

Please sign in to comment.