From fb933c5f04241364854a5c716eed93e05c870665 Mon Sep 17 00:00:00 2001 From: Luigi Rosso Date: Thu, 15 Jan 2026 12:48:58 -0800 Subject: fix: enable MRT independent write mask on GLES 3.2+ --- sokol_gfx.h | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/sokol_gfx.h b/sokol_gfx.h index aaadb456..d7bba87d 100644 --- a/sokol_gfx.h +++ b/sokol_gfx.h @@ -5579,7 +5579,11 @@ inline int sg_append_buffer(sg_buffer buf_id, const sg_range& data) { return sg_ #include #endif #elif defined(__ANDROID__) - #include + #if __ANDROID_API__ >= 24 + #include + #else + #include + #endif #elif defined(__linux__) || defined(__unix__) #if defined(SOKOL_GLCORE) #define GL_GLEXT_PROTOTYPES @@ -5615,6 +5619,9 @@ inline int sg_append_buffer(sg_buffer buf_id, const sg_range& data) { return sg_ #elif defined(__ANDROID__) #define _SOKOL_GL_HAS_COMPUTE (1) #define _SOKOL_GL_HAS_TEXSTORAGE (1) + #if __ANDROID_API__ >= 24 + #define _SOKOL_GL_HAS_COLORMASKI (1) + #endif #elif defined(__linux__) || defined(__unix__) #if defined(SOKOL_GLCORE) #if defined(GL_VERSION_4_3) @@ -5632,6 +5639,7 @@ inline int sg_append_buffer(sg_buffer buf_id, const sg_range& data) { return sg_ #define _SOKOL_GL_HAS_COMPUTE (1) #define _SOKOL_GL_HAS_TEXSTORAGE (1) #define _SOKOL_GL_HAS_BASEVERTEX (1) + #define _SOKOL_GL_HAS_COLORMASKI (1) #endif #endif @@ -9989,8 +9997,13 @@ _SOKOL_PRIVATE void _sg_gl_init_caps_gles3(void) { const int version = major_version * 100 + minor_version * 10; _sg.features.origin_top_left = false; _sg.features.image_clamp_to_border = false; + #if defined(_SOKOL_GL_HAS_COLORMASKI) + _sg.features.mrt_independent_blend_state = version >= 320; + _sg.features.mrt_independent_write_mask = version >= 320; + #else _sg.features.mrt_independent_blend_state = false; _sg.features.mrt_independent_write_mask = false; + #endif _sg.features.compute = version >= 310; _sg.features.msaa_texture_bindings = false; _sg.features.gl_texture_views = version >= 430; @@ -11707,7 +11720,22 @@ _SOKOL_PRIVATE void _sg_gl_apply_render_pipeline_state(_sg_pipeline_t* pip) { (cm & SG_COLORMASK_G) != 0, (cm & SG_COLORMASK_B) != 0, (cm & SG_COLORMASK_A) != 0); + #elif defined(_SOKOL_GL_HAS_COLORMASKI) + // Native GLES 3.2+ supports glColorMaski + if (_sg.features.mrt_independent_write_mask) { + glColorMaski(i, + (cm & SG_COLORMASK_R) != 0, + (cm & SG_COLORMASK_G) != 0, + (cm & SG_COLORMASK_B) != 0, + (cm & SG_COLORMASK_A) != 0); + } else if (0 == i) { + glColorMask((cm & SG_COLORMASK_R) != 0, + (cm & SG_COLORMASK_G) != 0, + (cm & SG_COLORMASK_B) != 0, + (cm & SG_COLORMASK_A) != 0); + } #else + // WebGL2 - no indexed color mask support if (0 == i) { glColorMask((cm & SG_COLORMASK_R) != 0, (cm & SG_COLORMASK_G) != 0, -- cgit v1.2.3 From 496565d80042bb3b3c897da4566106146e68f8e0 Mon Sep 17 00:00:00 2001 From: Andre Weissflog Date: Mon, 19 Jan 2026 11:50:13 +0100 Subject: sokol_gfx.h gl: simplify glColorMask vs glColorMaski code --- sokol_gfx.h | 45 +++++++++++++++++---------------------------- 1 file changed, 17 insertions(+), 28 deletions(-) diff --git a/sokol_gfx.h b/sokol_gfx.h index 9bfb3fb2..926a04e4 100644 --- a/sokol_gfx.h +++ b/sokol_gfx.h @@ -5597,6 +5597,7 @@ inline int sg_append_buffer(sg_buffer buf_id, const sg_range& data) { return sg_ // broad GL feature availability defines (DON'T merge this into the above ifdef-block!) #if defined(_WIN32) + #define _SOKOL_GL_HAS_COLORMASKI (1) #if defined(GL_VERSION_4_3) || defined(_SOKOL_USE_WIN32_GL_LOADER) #define _SOKOL_GL_HAS_COMPUTE (1) #define _SOKOL_GL_HAS_TEXVIEWS (1) @@ -5609,6 +5610,7 @@ inline int sg_append_buffer(sg_buffer buf_id, const sg_range& data) { return sg_ #define _SOKOL_GL_HAS_BASEVERTEX (1) #endif #elif defined(__APPLE__) + #define _SOKOL_GL_HAS_COLORMASKI (1) #if defined(TARGET_OS_IPHONE) && !TARGET_OS_IPHONE #define _SOKOL_GL_HAS_BASEVERTEX (1) #else @@ -5619,10 +5621,11 @@ inline int sg_append_buffer(sg_buffer buf_id, const sg_range& data) { return sg_ #elif defined(__ANDROID__) #define _SOKOL_GL_HAS_COMPUTE (1) #define _SOKOL_GL_HAS_TEXSTORAGE (1) - #if __ANDROID_API__ >= 24 + #if defined(GL_ES_VERSION_3_2) #define _SOKOL_GL_HAS_COLORMASKI (1) #endif #elif defined(__linux__) || defined(__unix__) + #define _SOKOL_GL_HAS_COLORMASKI (1) #if defined(SOKOL_GLCORE) #if defined(GL_VERSION_4_3) #define _SOKOL_GL_HAS_COMPUTE (1) @@ -5639,7 +5642,6 @@ inline int sg_append_buffer(sg_buffer buf_id, const sg_range& data) { return sg_ #define _SOKOL_GL_HAS_COMPUTE (1) #define _SOKOL_GL_HAS_TEXSTORAGE (1) #define _SOKOL_GL_HAS_BASEVERTEX (1) - #define _SOKOL_GL_HAS_COLORMASKI (1) #endif #endif @@ -9997,11 +9999,10 @@ _SOKOL_PRIVATE void _sg_gl_init_caps_gles3(void) { const int version = major_version * 100 + minor_version * 10; _sg.features.origin_top_left = false; _sg.features.image_clamp_to_border = false; + _sg.features.mrt_independent_blend_state = false; #if defined(_SOKOL_GL_HAS_COLORMASKI) - _sg.features.mrt_independent_blend_state = version >= 320; _sg.features.mrt_independent_write_mask = version >= 320; #else - _sg.features.mrt_independent_blend_state = false; _sg.features.mrt_independent_write_mask = false; #endif _sg.features.compute = version >= 310; @@ -11722,35 +11723,23 @@ _SOKOL_PRIVATE void _sg_gl_apply_render_pipeline_state(_sg_pipeline_t* pip) { if (pip->gl.color_write_mask[i] != _sg.gl.cache.color_write_mask[i]) { const sg_color_mask cm = pip->gl.color_write_mask[i]; _sg.gl.cache.color_write_mask[i] = cm; - #ifdef SOKOL_GLCORE + if (_sg.features.mrt_independent_write_mask) { + #if defined(_SOKOL_GL_HAS_COLORMASKI) glColorMaski(i, (cm & SG_COLORMASK_R) != 0, (cm & SG_COLORMASK_G) != 0, (cm & SG_COLORMASK_B) != 0, (cm & SG_COLORMASK_A) != 0); - #elif defined(_SOKOL_GL_HAS_COLORMASKI) - // Native GLES 3.2+ supports glColorMaski - if (_sg.features.mrt_independent_write_mask) { - glColorMaski(i, - (cm & SG_COLORMASK_R) != 0, - (cm & SG_COLORMASK_G) != 0, - (cm & SG_COLORMASK_B) != 0, - (cm & SG_COLORMASK_A) != 0); - } else if (0 == i) { - glColorMask((cm & SG_COLORMASK_R) != 0, - (cm & SG_COLORMASK_G) != 0, - (cm & SG_COLORMASK_B) != 0, - (cm & SG_COLORMASK_A) != 0); - } - #else - // WebGL2 - no indexed color mask support - if (0 == i) { - glColorMask((cm & SG_COLORMASK_R) != 0, - (cm & SG_COLORMASK_G) != 0, - (cm & SG_COLORMASK_B) != 0, - (cm & SG_COLORMASK_A) != 0); - } - #endif + #else + // can't happen + SOKOL_ASSERT(false); + #endif + } else if (0 == i) { + glColorMask((cm & SG_COLORMASK_R) != 0, + (cm & SG_COLORMASK_G) != 0, + (cm & SG_COLORMASK_B) != 0, + (cm & SG_COLORMASK_A) != 0); + } _sg_stats_inc(gl.num_render_state); } } -- cgit v1.2.3 From 867bf09677e9c619dfba67e0acffe263e0d6ca1b Mon Sep 17 00:00:00 2001 From: Andre Weissflog Date: Mon, 19 Jan 2026 11:51:44 +0100 Subject: update changelog (https://github.com/floooh/sokol/pull/1414) --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e9043c0..3f15a136 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ ## Updates +### 19-Jan-2026 + +- sokol_gfx.h gl: merged PR https://github.com/floooh/sokol/pull/1414, this enables + per-multiple-render-target color write masks on GLES3.2. Many thanks to + @luigi-rosso for the PR! + ### 18-Jan-2026 Happy New Year! -- cgit v1.2.3