natiny.surface.bind

Lua
natiny.surface.bind(surf [, slot] [, fn])

Makes the surface a render target. Bind it while a window is bound so drawing has an active frame command buffer. Multiple surfaces can be bound to distinct slots for one pass.

Parameters

Name Type Default Description
surf number Surface handle from natiny.surface.create
slot number 0 Target slot, 0 to natiny.surface.MAX_TARGETS - 1
fn function nil Callback run while the surface is bound

Example

Lua
natiny.window.bind(win, function()
    natiny.surface.bind(rt, function()
        draw_scene()
    end)
end)

Notes

  • Slot 0 opens a target set and determines its size, 2D projection, and depth attachment. Other slots add colour targets to that set. All surfaces in a set must have identical dimensions.
  • Surface binds may nest up to 64 stored levels. Deeper binds still take effect, but their previous state cannot be restored.
  • With fn, Lua unbinds the target set even if the callback raises an error, then propagates the error.