-- Create displays
When (your_area) is the rendering area [matching and unmatching with priorities (-100) and (0)]:
Call create_display_object() returning /VkDisplay* display/.
register_resource(display) -- this runs at priority -100
When unmatched [capturing (display)]: -- this runs at priority 0
unregister_resource(display, vkDestroyDisplay) -- the destructor is called at priority -99
End
Claim (display) is a “display”.
End
-- Create framebuffers
When /display/ is a “display" [matching and unmatching with priorities (-100) and (0)]:
Call create_framebuffer_object_for_display(display) returning /VkFramebuffer* framebuffer/.
register_resource(framebuffer)
When unmatched [capturing (framebuffer)]:
unregister_resource(framebuffer, vkDestroyFramebuffer)
End
Claim (display) has framebuffer (framebuffer).
End
-- Create color images
When /display/ has framebuffer /framebuffer/ [matching and unmatching with priorities (-100) and (0)]:
Call create_color_image_for_framebuffer(framebuffer) returning /VkImage* color_image/.
register_resource(color_image)
When unmatched [capturing (color_image)]:
unregister_resource(color_image, vkDestroyImage)
End
Claim (framebuffer) has color image (color_image).
End
-- Resource destruction
_rt.resources = _rt.resources or {} -- list of resources in order of registration
_rt.resource_destructors = _rt.resource_destructors or {}
function register_resource (resource)
table.insert(_rt.resources, resource) -- append resource to list
end
function unregister_resource (resource, destructor)
_rt.resource_destructors[resource] = destructor -- mark resource for destruction
end
When the time is /t/ [converging with priority (-99)]:
if not next(_rt.resource_destructors) then return end
for i = #_rt.resources, 1, -1 do -- go through resources from latest to earliest
local resource = _rt.resources[i]
local destructor = resource_destructors[resource]
if destructor then -- if it's been unregistered, destroy it and remove it
destructor(resource)
table.remove(_rt.resources, i)
end
end
_rt.resource_destructors = {}
End