From 55ece724b2bcd0f71bdac51ac9318e7c48398299 Mon Sep 17 00:00:00 2001 From: Anton Semenov Date: Tue, 13 Dec 2022 15:25:15 +0200 Subject: [PATCH] implemented basic sRGB sampling with SG_PIXELFORMAT_SRGB8A8 format --- sokol_app.h | 12 ++++++------ sokol_gfx.h | 11 +++++++++++ util/sokol_gfx_imgui.h | 1 + 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/sokol_app.h b/sokol_app.h index ceecd74ec..cf56a63da 100644 --- a/sokol_app.h +++ b/sokol_app.h @@ -262,9 +262,9 @@ where sg_pixel_format is expected). Possible values are: 23 == SG_PIXELFORMAT_RGBA8 - 27 == SG_PIXELFORMAT_BGRA8 - 41 == SG_PIXELFORMAT_DEPTH - 42 == SG_PIXELFORMAT_DEPTH_STENCIL + 28 == SG_PIXELFORMAT_BGRA8 + 42 == SG_PIXELFORMAT_DEPTH + 43 == SG_PIXELFORMAT_DEPTH_STENCIL int sapp_sample_count(void) Return the MSAA sample count of the default framebuffer. @@ -2638,9 +2638,9 @@ typedef struct { #define _SAPP_FALLBACK_DEFAULT_WINDOW_HEIGHT (480) /* NOTE: the pixel format values *must* be compatible with sg_pixel_format */ #define _SAPP_PIXELFORMAT_RGBA8 (23) -#define _SAPP_PIXELFORMAT_BGRA8 (27) -#define _SAPP_PIXELFORMAT_DEPTH (41) -#define _SAPP_PIXELFORMAT_DEPTH_STENCIL (42) +#define _SAPP_PIXELFORMAT_BGRA8 (28) +#define _SAPP_PIXELFORMAT_DEPTH (42) +#define _SAPP_PIXELFORMAT_DEPTH_STENCIL (43) #if defined(_SAPP_MACOS) || defined(_SAPP_IOS) // this is ARC compatible diff --git a/sokol_gfx.h b/sokol_gfx.h index e1c7c94e0..ae05e588b 100644 --- a/sokol_gfx.h +++ b/sokol_gfx.h @@ -1141,6 +1141,7 @@ typedef enum sg_pixel_format { SG_PIXELFORMAT_RG16SI, SG_PIXELFORMAT_RG16F, SG_PIXELFORMAT_RGBA8, + SG_PIXELFORMAT_SRGB8A8, SG_PIXELFORMAT_RGBA8SN, SG_PIXELFORMAT_RGBA8UI, SG_PIXELFORMAT_RGBA8SI, @@ -3153,6 +3154,7 @@ inline int sg_append_buffer(sg_buffer buf_id, const sg_range& data) { return sg_ #define GL_NEAREST_MIPMAP_LINEAR 0x2702 #define GL_RGB10_A2 0x8059 #define GL_RGBA8 0x8058 + #define GL_SRGB8_ALPHA8 0x8C43 #define GL_COLOR_ATTACHMENT1 0x8CE1 #define GL_RGBA4 0x8056 #define GL_RGB8 0x8051 @@ -4833,6 +4835,7 @@ _SOKOL_PRIVATE int _sg_pixelformat_bytesize(sg_pixel_format fmt) { case SG_PIXELFORMAT_RG16SI: case SG_PIXELFORMAT_RG16F: case SG_PIXELFORMAT_RGBA8: + case SG_PIXELFORMAT_SRGB8A8: case SG_PIXELFORMAT_RGBA8SN: case SG_PIXELFORMAT_RGBA8UI: case SG_PIXELFORMAT_RGBA8SI: @@ -5657,6 +5660,7 @@ _SOKOL_PRIVATE GLenum _sg_gl_teximage_type(sg_pixel_format fmt) { case SG_PIXELFORMAT_RG8: case SG_PIXELFORMAT_RG8UI: case SG_PIXELFORMAT_RGBA8: + case SG_PIXELFORMAT_SRGB8A8: case SG_PIXELFORMAT_RGBA8UI: case SG_PIXELFORMAT_BGRA8: return GL_UNSIGNED_BYTE; @@ -5756,6 +5760,7 @@ _SOKOL_PRIVATE GLenum _sg_gl_teximage_format(sg_pixel_format fmt) { return GL_RG_INTEGER; #endif case SG_PIXELFORMAT_RGBA8: + case SG_PIXELFORMAT_SRGB8A8: case SG_PIXELFORMAT_RGBA8SN: case SG_PIXELFORMAT_RGBA16: case SG_PIXELFORMAT_RGBA16SN: @@ -5857,6 +5862,7 @@ _SOKOL_PRIVATE GLenum _sg_gl_teximage_internal_format(sg_pixel_format fmt) { case SG_PIXELFORMAT_RG16SI: return GL_RG16I; case SG_PIXELFORMAT_RG16F: return GL_RG16F; case SG_PIXELFORMAT_RGBA8: return GL_RGBA8; + case SG_PIXELFORMAT_SRGB8A8: return GL_SRGB8_ALPHA8; case SG_PIXELFORMAT_RGBA8SN: return GL_RGBA8_SNORM; case SG_PIXELFORMAT_RGBA8UI: return GL_RGBA8UI; case SG_PIXELFORMAT_RGBA8SI: return GL_RGBA8I; @@ -5963,6 +5969,7 @@ _SOKOL_PRIVATE void _sg_gl_init_pixelformats(bool has_bgra) { _sg_pixelformat_all(&_sg.formats[SG_PIXELFORMAT_RGBA8]); #if !defined(SOKOL_GLES2) if (!_sg.gl.gles2) { + _sg_pixelformat_all(&_sg.formats[SG_PIXELFORMAT_SRGB8A8]); _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_RGBA8SN]); _sg_pixelformat_srm(&_sg.formats[SG_PIXELFORMAT_RGBA8UI]); _sg_pixelformat_srm(&_sg.formats[SG_PIXELFORMAT_RGBA8SI]); @@ -8581,6 +8588,7 @@ _SOKOL_PRIVATE DXGI_FORMAT _sg_d3d11_pixel_format(sg_pixel_format fmt) { case SG_PIXELFORMAT_RG16SI: return DXGI_FORMAT_R16G16_SINT; case SG_PIXELFORMAT_RG16F: return DXGI_FORMAT_R16G16_FLOAT; case SG_PIXELFORMAT_RGBA8: return DXGI_FORMAT_R8G8B8A8_UNORM; + case SG_PIXELFORMAT_SRGB8A8: return DXGI_FORMAT_R8G8B8A8_UNORM_SRGB; case SG_PIXELFORMAT_RGBA8SN: return DXGI_FORMAT_R8G8B8A8_SNORM; case SG_PIXELFORMAT_RGBA8UI: return DXGI_FORMAT_R8G8B8A8_UINT; case SG_PIXELFORMAT_RGBA8SI: return DXGI_FORMAT_R8G8B8A8_SINT; @@ -10138,6 +10146,7 @@ _SOKOL_PRIVATE MTLPixelFormat _sg_mtl_pixel_format(sg_pixel_format fmt) { case SG_PIXELFORMAT_RG16SI: return MTLPixelFormatRG16Sint; case SG_PIXELFORMAT_RG16F: return MTLPixelFormatRG16Float; case SG_PIXELFORMAT_RGBA8: return MTLPixelFormatRGBA8Unorm; + case SG_PIXELFORMAT_SRGB8A8: return MTLPixelFormatRGBA8Unorm_sRGB; case SG_PIXELFORMAT_RGBA8SN: return MTLPixelFormatRGBA8Snorm; case SG_PIXELFORMAT_RGBA8UI: return MTLPixelFormatRGBA8Uint; case SG_PIXELFORMAT_RGBA8SI: return MTLPixelFormatRGBA8Sint; @@ -10633,6 +10642,7 @@ _SOKOL_PRIVATE void _sg_mtl_init_caps(void) { _sg_pixelformat_srm(&_sg.formats[SG_PIXELFORMAT_RG16SI]); _sg_pixelformat_all(&_sg.formats[SG_PIXELFORMAT_RG16F]); _sg_pixelformat_all(&_sg.formats[SG_PIXELFORMAT_RGBA8]); + _sg_pixelformat_all(&_sg.formats[SG_PIXELFORMAT_SRGB8A8]); _sg_pixelformat_all(&_sg.formats[SG_PIXELFORMAT_RGBA8SN]); _sg_pixelformat_srm(&_sg.formats[SG_PIXELFORMAT_RGBA8UI]); _sg_pixelformat_srm(&_sg.formats[SG_PIXELFORMAT_RGBA8SI]); @@ -11965,6 +11975,7 @@ _SOKOL_PRIVATE WGPUTextureFormat _sg_wgpu_textureformat(sg_pixel_format p) { case SG_PIXELFORMAT_RG16SN: case SG_PIXELFORMAT_RGBA16: case SG_PIXELFORMAT_RGBA16SN: + case SG_PIXELFORMAT_SRGB8A8: case SG_PIXELFORMAT_RGB9E5: case SG_PIXELFORMAT_PVRTC_RGB_2BPP: case SG_PIXELFORMAT_PVRTC_RGB_4BPP: diff --git a/util/sokol_gfx_imgui.h b/util/sokol_gfx_imgui.h index 35bf326c1..9e97aa8c8 100644 --- a/util/sokol_gfx_imgui.h +++ b/util/sokol_gfx_imgui.h @@ -1115,6 +1115,7 @@ _SOKOL_PRIVATE const char* _sg_imgui_pixelformat_string(sg_pixel_format fmt) { case SG_PIXELFORMAT_RG16SI: return "SG_PIXELFORMAT_RG16SI"; case SG_PIXELFORMAT_RG16F: return "SG_PIXELFORMAT_RG16F"; case SG_PIXELFORMAT_RGBA8: return "SG_PIXELFORMAT_RGBA8"; + case SG_PIXELFORMAT_SRGB8A8: return "SG_PIXELFORMAT_SRGB8A8"; case SG_PIXELFORMAT_RGBA8SN: return "SG_PIXELFORMAT_RGBA8SN"; case SG_PIXELFORMAT_RGBA8UI: return "SG_PIXELFORMAT_RGBA8UI"; case SG_PIXELFORMAT_RGBA8SI: return "SG_PIXELFORMAT_RGBA8SI";