Derpius / VisTrace

Garry's Mod binary module for tracing meshes at high speed on the CPU (and much more)
https://derpius.github.io/VisTrace
MIT License
27 stars 1 forks source link

Add RenderTarget:Clone #83

Closed yogwoggf closed 2 years ago

yogwoggf commented 2 years ago

Fixes #82

PR Type (tick all that are applicable)

Tested Targets (only applicable for changes to the binary module, delete otherwise)

Checklist

Description Allows Lua and C++ to clone RenderTargets. C++ has to delete them, but Lua clones are garbage collected.

I did not test all aspects. I didn't have enough time to test if MIPs worked correctly, but they should if you see how I made the Clone function and given that the base image (MIP 0) works fine.

I used some code that's internal to my codebase but otherwise readable. This code passed.

local display = vgui.Create("RTDisplay")
local rt = vistrace.CreateRenderTarget(512, 512, VisTraceRTFormat.RGBFFF)
rt:Load("512x512_gm_construct_1spp_5bounces_20220924180109.png")
rt:GenerateMIPs()

display:SetSize(512, 512)
display:SetVRT(rt)
display:Update()

timer.Simple(3, function()
    local newRT = rt:Clone()
    display:SetVRT(newRT)
    display:Update()
    print("Cloned!")

    timer.Simple(3, function()
        newRT:Load("512x512_gm_construct_1spp_5bounces_20220923192755.png")
        display:Update()
        timer.Simple(3, function()
            display:Remove()
        end)
    end)
end)
Derpius commented 2 years ago

Quicker to just do it myself in 389c88640c365a8f9df885ed0ded2947dc198a24