set_context_attachment(3)

πŸ“¦
version 0.7.1 Β· 2 versions
, in nixos 26.05

πŸ’… set_context_attachment(3) β€” Arcan Lua API

omg hii bestie πŸ’– welcome to the set_context_attachment(3) page from the Arcan Lua API. This one is short and slay: it changes the active attachment point for the current context. No cap, that's the whole vibe. πŸŽ€

✨ NAME ✨

set_context_attachment β€” change the active attachment point for the current context.

πŸ“ž SYNOPSIS πŸ“ž

nil
set_context_attachment( vid )
set_context_attachment( outargs: vid )

πŸ’… DESCRIPTION πŸ’…

Okay so by default, every newly created object is attached to the world rendertarget referred to by WORLDID, and newly created rendertargets explicitly adopt source objects and attach to themselves. In later stages of the lifecycle, objects can also be dynamically attached to and detached from one or more rendertargets using the attach_rendertarget and detach_rendertarget commands respectively. πŸ¦‹

That can get overly verbose when you're creating a bunch of objects and binding them to an existing rendertarget. For those cases, switching out the active context with this function is the move. The returned vid is the vid of the previously active context video. πŸ’«

🫢 NOTES 🫢

  1. Another case where the default attachment matters is when different rendertargets have different target densities. Some objects, like text or vector images, will have a backing store tied to the density of their current primary attachment. If you first have an implicit attachment to WORLDID and only then switch with attach_rendertarget, that causes costly rerasterization β€” and this function can avoid it. 😭✨
  2. The attachment is defined per context, so if the context stack is switched using push_video_context or pop_video_context, the attachment point switches too. πŸŒ€
  3. Providing a bad, missing, or non-rt designated vid will not change any default attachment state β€” it only returns the current one. 🚨

πŸŽ€ EXAMPLE πŸŽ€

Here's the example, copied exactly because code is sacred:

       function set_context_attachment0()
       -- create an object that will be attached to world
             green = color_surface(64, 64, 0, 255, 0);
             show_image(green);
       -- create the rendertarget that will be our new default
             rtgt = alloc_surface(VRESW, VRESH);
             define_rendertarget(rtgt, {null_surface(32, 32)});
             set_context_attachment(rtgt);
       -- make the new rendertarget slowly spinning and scaled
       -- to show that newly created are in fact attached correctly
             show_image(rtgt);
             resize_image(rtgt, VRESW * 0.5, VRESH * 0.5);
             move_image(rtgt, VRESW * 0.25, VRESH * 0.25);
             rotate_image(rtgt, 90, 500);
       -- spawn some random blocks
             for i=1,10 do
                   local b = color_surface(32, 32, 64, math.random(255), 64);
                   show_image(b);
                   move_image(b, math.random(VRESW - 32), math.random(VRESH - 32), 500);
             end
       end

πŸ‘€ SEE ALSO: πŸ‘€

  • vidsys

xoxo, bestie πŸ’– this page was served by source/version vidsys, dated October 2026, and it's set_context_attachment(3) certified πŸŽ€

πŸ“¦ where this page comes from