From b7be6a6f865f00ed47414a9a57845e47b68489f2 Mon Sep 17 00:00:00 2001 From: Andre Weissflog Date: Thu, 27 Nov 2025 18:26:30 +0100 Subject: sokol_gfx.h gl: fix glDrawBuffers for the case that no color attachments are used --- sokol_gfx.h | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/sokol_gfx.h b/sokol_gfx.h index a6fa985b..c3fe87b9 100644 --- a/sokol_gfx.h +++ b/sokol_gfx.h @@ -5518,10 +5518,8 @@ inline int sg_append_buffer(sg_buffer buf_id, const sg_range& data) { return sg_ #define GL_PROGRAM_POINT_SIZE 0x8642 #define GL_DEPTH_ATTACHMENT 0x8D00 #define GL_DEPTH_STENCIL_ATTACHMENT 0x821A - #define GL_COLOR_ATTACHMENT2 0x8CE2 #define GL_COLOR_ATTACHMENT0 0x8CE0 #define GL_R16F 0x822D - #define GL_COLOR_ATTACHMENT22 0x8CF6 #define GL_DRAW_FRAMEBUFFER 0x8CA9 #define GL_FRAMEBUFFER_COMPLETE 0x8CD5 #define GL_NUM_EXTENSIONS 0x821D @@ -5563,7 +5561,6 @@ inline int sg_append_buffer(sg_buffer buf_id, const sg_range& data) { return sg_ #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 #define GL_ARRAY_BUFFER 0x8892 @@ -5646,7 +5643,6 @@ inline int sg_append_buffer(sg_buffer buf_id, const sg_range& data) { return sg_ #define GL_DST_COLOR 0x0306 #define GL_COMPILE_STATUS 0x8B81 #define GL_RED 0x1903 - #define GL_COLOR_ATTACHMENT3 0x8CE3 #define GL_DST_ALPHA 0x0304 #define GL_RGB5_A1 0x8057 #define GL_GREATER 0x0204 @@ -10927,13 +10923,16 @@ _SOKOL_PRIVATE void _sg_gl_begin_pass(const sg_pass* pass, const _sg_attachments _sg.cur_pass.valid = false; return; } - static const GLenum gl_draw_bufs[SG_MAX_COLOR_ATTACHMENTS] = { - GL_COLOR_ATTACHMENT0, - GL_COLOR_ATTACHMENT1, - GL_COLOR_ATTACHMENT2, - GL_COLOR_ATTACHMENT3 - }; - glDrawBuffers(atts->num_color_views, gl_draw_bufs); + GLenum gl_draw_bufs[SG_MAX_COLOR_ATTACHMENTS]; + SOKOL_ASSERT(_sg.limits.max_color_attachments <= SG_MAX_COLOR_ATTACHMENTS); + for (int i = 0; i < _sg.limits.max_color_attachments; i++) { + if (i < atts->num_color_views) { + gl_draw_bufs[i] = GL_COLOR_ATTACHMENT0 + i; + } else { + gl_draw_bufs[i] = GL_NONE; + } + } + glDrawBuffers(_sg.limits.max_color_attachments, gl_draw_bufs); #if defined(_SOKOL_GL_HAS_COMPUTE) _sg_gl_handle_memory_barriers(0, 0, atts); -- cgit v1.2.3 From 18dc988ae893efefe0f8e3000777cc97164ad220 Mon Sep 17 00:00:00 2001 From: Andre Weissflog Date: Thu, 27 Nov 2025 19:30:36 +0100 Subject: sokol_gfx.h gl: fix signed/unsigned warning on clang/gcc --- sokol_gfx.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sokol_gfx.h b/sokol_gfx.h index c3fe87b9..11d387e2 100644 --- a/sokol_gfx.h +++ b/sokol_gfx.h @@ -10927,7 +10927,7 @@ _SOKOL_PRIVATE void _sg_gl_begin_pass(const sg_pass* pass, const _sg_attachments SOKOL_ASSERT(_sg.limits.max_color_attachments <= SG_MAX_COLOR_ATTACHMENTS); for (int i = 0; i < _sg.limits.max_color_attachments; i++) { if (i < atts->num_color_views) { - gl_draw_bufs[i] = GL_COLOR_ATTACHMENT0 + i; + gl_draw_bufs[i] = (GLenum)(GL_COLOR_ATTACHMENT0 + i); } else { gl_draw_bufs[i] = GL_NONE; } -- cgit v1.2.3 From 611afa3d235443c633344b8db7b3f67c6c82cafc Mon Sep 17 00:00:00 2001 From: Andre Weissflog Date: Fri, 28 Nov 2025 18:47:57 +0100 Subject: odin bindings: fix static vs dll system library linkage on linux (see: https://github.com/floooh/sokol-odin/pull/37) --- bindgen/gen_odin.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/bindgen/gen_odin.py b/bindgen/gen_odin.py index 1d9bf82a..dc249b9e 100644 --- a/bindgen/gen_odin.py +++ b/bindgen/gen_odin.py @@ -33,10 +33,11 @@ system_libs = { }, 'macos': { 'metal': '"system:Cocoa.framework","system:QuartzCore.framework","system:Metal.framework","system:MetalKit.framework"', - 'gl': '"system:Cocoa.framework","system:QuartzCore.framework","system:OpenGL.framework"' + 'gl': '"system:Cocoa.framework","system:QuartzCore.framework","system:OpenGL.framework"', }, 'linux': { - 'gl': '"system:GL", "system:dl", "system:pthread"' + 'gl': '"system:GL", "system:dl", "system:pthread"', + 'gldll': '"system:GL", "system:dl", "system:pthread"', } }, 'sapp_': { @@ -49,7 +50,8 @@ system_libs = { 'gl': '"system:Cocoa.framework","system:QuartzCore.framework","system:OpenGL.framework"', }, 'linux': { - 'gl': '"system:X11", "system:Xi", "system:Xcursor", "system:GL", "system:dl", "system:pthread"' + 'gl': '"system:X11", "system:Xi", "system:Xcursor", "system:GL", "system:dl", "system:pthread"', + 'gldll': '"system:X11", "system:Xi", "system:Xcursor", "system:GL", "system:dl", "system:pthread"', } }, 'saudio_': { @@ -63,6 +65,7 @@ system_libs = { }, 'linux': { 'gl': '"system:asound", "system:dl", "system:pthread"', + 'gldll': '"system:dl", "system:pthread"', } } } @@ -358,6 +361,7 @@ def gen_c_imports(inp, c_prefix, prefix): macos_metal_libs = get_system_libs(prefix, 'macos', 'metal') macos_gl_libs = get_system_libs(prefix, 'macos', 'gl') linux_gl_libs = get_system_libs(prefix, 'linux', 'gl') + linux_gldll_libs = get_system_libs(prefix, 'linux', 'gldll') l( 'import "core:c"') l( '') l( '_ :: c') @@ -417,8 +421,8 @@ def gen_c_imports(inp, c_prefix, prefix): l( ' }') l( '} else when ODIN_OS == .Linux {') l( ' when USE_DLL {') - l(f' when DEBUG {{ foreign import {clib_import} {{ "{clib_prefix}_linux_x64_gl_debug.so"{linux_gl_libs} }} }}') - l(f' else {{ foreign import {clib_import} {{ "{clib_prefix}_linux_x64_gl_release.so"{linux_gl_libs} }} }}') + l(f' when DEBUG {{ foreign import {clib_import} {{ "{clib_prefix}_linux_x64_gl_debug.so"{linux_gldll_libs} }} }}') + l(f' else {{ foreign import {clib_import} {{ "{clib_prefix}_linux_x64_gl_release.so"{linux_gldll_libs} }} }}') l( ' } else {') l(f' when DEBUG {{ foreign import {clib_import} {{ "{clib_prefix}_linux_x64_gl_debug.a"{linux_gl_libs} }} }}') l(f' else {{ foreign import {clib_import} {{ "{clib_prefix}_linux_x64_gl_release.a"{linux_gl_libs} }} }}') -- cgit v1.2.3 From 6579577b9de45406c92a5bae9e1d64842e1bcccc Mon Sep 17 00:00:00 2001 From: etherbound-dev Date: Mon, 1 Dec 2025 14:06:56 -0800 Subject: fix(gl): detach unused FBO attachments in _sg_gl_begin_pass The GL backend uses a single shared FBO for all offscreen passes. When switching from a pass with depth-stencil to one without, the old depth-stencil attachment remained bound, causing rendering to be clipped to the smaller attachment's dimensions. This fix explicitly detaches: - Unused color attachment slots (beyond num_color_views) - Depth-stencil attachment when not used in the current pass Fixes rendering clipping when mixing render targets with and without depth-stencil attachments in the same frame. Reproduction: https://github.com/etherbound-dev/sokol-depth-stencil-bug --- sokol_gfx.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/sokol_gfx.h b/sokol_gfx.h index 11d387e2..1d08c14e 100644 --- a/sokol_gfx.h +++ b/sokol_gfx.h @@ -10909,6 +10909,11 @@ _SOKOL_PRIVATE void _sg_gl_begin_pass(const sg_pass* pass, const _sg_attachments _sg_gl_fb_attach_texture(view, gl_att_type); } } + // explicitly detach unused color attachments + for (int i = atts->num_color_views; i < SG_MAX_COLOR_ATTACHMENTS; i++) { + const GLenum gl_att_type = (GLenum)(GL_COLOR_ATTACHMENT0 + i); + glFramebufferTexture2D(GL_FRAMEBUFFER, gl_att_type, GL_TEXTURE_2D, 0, 0); + } if (atts->ds_view) { const _sg_view_t* view = atts->ds_view; const _sg_image_t* img = _sg_image_ref_ptr(&view->cmn.img.ref); @@ -10918,6 +10923,9 @@ _SOKOL_PRIVATE void _sg_gl_begin_pass(const sg_pass* pass, const _sg_attachments } else { _sg_gl_fb_attach_texture(view, gl_att_type); } + } else { + // explicitly detach depth-stencil attachment if not used in this pass + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, 0, 0); } if (!_sg_gl_check_framebuffer_status()) { _sg.cur_pass.valid = false; -- cgit v1.2.3 From 1a400a26a5dae74938d13df35755427bcbd82dde Mon Sep 17 00:00:00 2001 From: Andre Weissflog Date: Tue, 2 Dec 2025 14:12:03 +0100 Subject: sokol_gfx.h gl: when clearing framebuffer slots in begin-pass, also clear the renderbuffer attachments --- sokol_gfx.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sokol_gfx.h b/sokol_gfx.h index 1d08c14e..c53702b3 100644 --- a/sokol_gfx.h +++ b/sokol_gfx.h @@ -10910,8 +10910,9 @@ _SOKOL_PRIVATE void _sg_gl_begin_pass(const sg_pass* pass, const _sg_attachments } } // explicitly detach unused color attachments - for (int i = atts->num_color_views; i < SG_MAX_COLOR_ATTACHMENTS; i++) { + for (int i = atts->num_color_views; i < _sg.limits.max_color_attachments; i++) { const GLenum gl_att_type = (GLenum)(GL_COLOR_ATTACHMENT0 + i); + glFramebufferRenderbuffer(GL_FRAMEBUFFER, gl_att_type, GL_RENDERBUFFER, 0); glFramebufferTexture2D(GL_FRAMEBUFFER, gl_att_type, GL_TEXTURE_2D, 0, 0); } if (atts->ds_view) { @@ -10925,6 +10926,7 @@ _SOKOL_PRIVATE void _sg_gl_begin_pass(const sg_pass* pass, const _sg_attachments } } else { // explicitly detach depth-stencil attachment if not used in this pass + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, 0); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, 0, 0); } if (!_sg_gl_check_framebuffer_status()) { -- cgit v1.2.3 From ab5d26a475584ad04b3d53107aa79ab6c710e95d Mon Sep 17 00:00:00 2001 From: Andre Weissflog Date: Tue, 2 Dec 2025 14:13:48 +0100 Subject: update changelog (https://github.com/floooh/sokol/pull/1390) --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e87785cf..9f2aaf3d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ ## Updates +### 02-Dec-2025 + +- sokol_gfx.h gl: unused framebuffer attachment slots are now explicitly cleared + in `sg_begin_pass()`. See PR #1390 for details! Many thanks to @etherbound-dev + for catching and fixing the issue! + ### 13-Nov-2025 - sokol_audio.h gained a new backend for the Nintendo 3DS. -- cgit v1.2.3 From 406f1e908d7e957ee8484d9ea0aac4355fb7db7b Mon Sep 17 00:00:00 2001 From: Andre Weissflog Date: Tue, 2 Dec 2025 14:16:57 +0100 Subject: fix PR link in changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f2aaf3d..6e7850f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ ### 02-Dec-2025 - sokol_gfx.h gl: unused framebuffer attachment slots are now explicitly cleared - in `sg_begin_pass()`. See PR #1390 for details! Many thanks to @etherbound-dev + in `sg_begin_pass()`. See PR https://github.com/floooh/sokol/pull/1390 for details! Many thanks to @etherbound-dev for catching and fixing the issue! ### 13-Nov-2025 -- cgit v1.2.3