From baf53e7a2db1c27376a04b088b6954eeee81f009 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Wed, 14 Apr 2021 18:07:50 +0300 Subject: [PATCH] Fix loading sRGB external images for textures This fixes bugs introduced in 9087cc0 (sRGB state ignored when setting internal format) and 635e5dc (external_image_srgb handled incorrectly). --- source/core/pixelformat.cpp | 5 +++++ source/core/pixelformat.h | 2 ++ source/core/texture.cpp | 4 ++-- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/source/core/pixelformat.cpp b/source/core/pixelformat.cpp index 8cc7c9c9..9a28cdce 100644 --- a/source/core/pixelformat.cpp +++ b/source/core/pixelformat.cpp @@ -336,6 +336,11 @@ DataType get_component_type(PixelFormat pf) } } +bool is_srgb(PixelFormat pf) +{ + return (pf==SRGB8 || pf==SRGB8_ALPHA8 || pf==SBGR8 || pf==SBGR8_ALPHA8); +} + unsigned get_pixel_size(PixelFormat pf) { return get_component_count(pf)*get_type_size(get_component_type(pf)); diff --git a/source/core/pixelformat.h b/source/core/pixelformat.h index 213328a5..c9d813ce 100644 --- a/source/core/pixelformat.h +++ b/source/core/pixelformat.h @@ -83,6 +83,8 @@ DataType get_component_type(PixelFormat); inline unsigned get_component_size(PixelFormat f) { return get_type_size(get_component_type(f)); } +bool is_srgb(PixelFormat); + unsigned get_pixel_size(PixelFormat); void require_pixelformat(PixelFormat); diff --git a/source/core/texture.cpp b/source/core/texture.cpp index 155dcae1..3a4b1096 100644 --- a/source/core/texture.cpp +++ b/source/core/texture.cpp @@ -75,7 +75,7 @@ void Texture::set_format(PixelFormat fmt) default:; } - PixelFormat st_fmt = make_pixelformat(st_comp, get_component_type(fmt)); + PixelFormat st_fmt = make_pixelformat(st_comp, get_component_type(fmt), is_srgb(fmt)); require_pixelformat(st_fmt); if(swiz!=NO_SWIZZLE) static Require _req(ARB_texture_swizzle); @@ -287,7 +287,7 @@ void Texture::Loader::init() levels = 0; add("external_image", &Loader::external_image); - add("external_image_srgb", &Loader::external_image); + add("external_image_srgb", &Loader::external_image_srgb); add("filter", &Loader::filter); add("generate_mipmap", &Loader::generate_mipmap); add("image_data", &Loader::image_data); -- 2.43.0