diff options
| author | etherbound-dev <etherbound.dev@gmail.com> | 2025-12-01 14:06:56 -0800 |
|---|---|---|
| committer | etherbound-dev <etherbound.dev@gmail.com> | 2025-12-01 14:06:56 -0800 |
| commit | 6579577b9de45406c92a5bae9e1d64842e1bcccc (patch) | |
| tree | d8316a84ad5809296fd5a1d7117a0bc34a2db0fe | |
| parent | 3103277b7dc5c339a6f475816014e7963c9a5474 (diff) | |
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
| -rw-r--r-- | sokol_gfx.h | 8 |
1 files changed, 8 insertions, 0 deletions
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; |