Skip to content

Lua GL: FBO attachment index and references, framebuffer restore after blits and RenderToTexture, attachment clears, cube map and multisample textures - #3482

Open
moss-orbit-9f339e wants to merge 2 commits into
beyond-all-reason:masterfrom
moss-orbit-9f339e:fix/lua-gl-fixes
Open

moss-orbit-9f339e wants to merge 2 commits into
beyond-all-reason:masterfrom
moss-orbit-9f339e:fix/lua-gl-fixes

Conversation

@moss-orbit-9f339e

@moss-orbit-9f339e moss-orbit-9f339e commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Fixes in the Lua GL API for FBOs, textures and framebuffer state.

  • FBO table attachments by assignment. LuaFBOs::ApplyAttachment converted the stack index the wrong way round: a positive index became gettop + index + 1, past the top of the stack. So fbo.color0 = {tex, target, level} (index 3 in meta_newindex) read the wrong stack slot.
  • RBOs given to gl.CreateFBO could be collected. fbo.key = value stores the value in the FBO reference table, which keeps the RBO alive. gl.CreateFBO did not do this for the attachments in its table.
  • Framebuffer bindings after gl.BlitFBO and gl.RenderToTexture. Both restored one combined binding (RenderToTexture restored 0 except in shadow drawing), so a separate read binding, or an FBO bound around a nested RenderToTexture, was lost. They now restore the read and draw bindings that were set before.
  • gl.ClearAttachmentFBO. lua_isstring is also true for numbers, so a numeric attachment was parsed as a name and failed. Stencil clears now use glClearBufferiv.
  • Textures. A GL_TEXTURE_CUBE_MAP texture got no storage for its faces. Sampler parameters are no longer set on GL_TEXTURE_2D_MULTISAMPLE (GL error). lodBias is applied also when it is 0, so it can be reset.
  • Safe mode also saves and restores the scissor and stencil state around Lua draw callins.
  • ParseTextureImage looks up the Lua texture index once.

Sync: No change (unsynced Lua GL only).

Testing (Windows, RTX 3080; master 01efdf4312 and this branch, each with the springcontent.sdz of its own build; a Zero-K replay on Nuclear Winter, 29 players and about 1,000 units, at full graphics with many Lua GL widgets):

  • The checksums (270 frames) and unit counts are the same as master. No Lua errors.
  • The screenshot differs from master in 1.60% of the pixels, all in animated content.
  • I did not write a widget test for each case (table attachment assignment, RBOs in gl.CreateFBO, nested RenderToTexture, cube map storage, numeric and stencil clears). These are checked by reading the code.

AI disclosure: OpenAI Codex (GPT-6.1 Sol) found these bugs in a code audit and drafted the fixes; a second Codex review checked the branch. Claude Code checked each finding against the code, reviewed every change, and ran the tests.

🤖 Generated with Claude Code

moss-orbit-9f339e and others added 2 commits October 13, 2026 02:16
… after blits and RenderToTexture, attachment clears, cube map and multisample textures, LOD bias reset

- LuaFBOs::ApplyAttachment converted the index the wrong way round: a
  positive index was turned into gettop + index + 1, past the top of the
  stack. So assigning a table attachment (fbo.color0 = {tex, target,
  level}, index 3 in meta_newindex) read the wrong stack slot.
- gl.CreateFBO did not store its attachments in the FBO reference
  table, as fbo.key = value does, so an RBO given at creation could be
  garbage collected while it was attached.
- gl.BlitFBO and gl.RenderToTexture restored only one framebuffer
  binding (RenderToTexture restored 0 except in shadow drawing). They
  now restore the read and draw bindings that were set before.
- gl.ClearAttachmentFBO: lua_isstring is also true for numbers, so a
  numeric attachment was parsed as a name and failed. Stencil clears
  now use glClearBufferiv.
- LuaTextures: a GL_TEXTURE_CUBE_MAP texture got no storage for its
  faces; sampler parameters are not set on GL_TEXTURE_2D_MULTISAMPLE
  (GL error); lodBias is applied also when it is 0, so it can be reset.
- Safe mode: also save and restore the scissor and stencil state around
  Lua draw callins.
- ParseTextureImage: look up the Lua texture index once.

Found by a Codex audit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant