From: Mikko Rasa Date: Wed, 14 Apr 2021 15:07:50 +0000 (+0300) Subject: Fix loading sRGB external images for textures X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=baf53e7a2db1c27376a04b088b6954eeee81f009;p=libs%2Fgl.git 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). --- 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);