Skip to content

Commit

Permalink
Use render.PushRenderTarget and render.PopRenderTarget instead (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Cheatoid authored Jan 17, 2025
1 parent b10794a commit cd72f68
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 34 deletions.
12 changes: 4 additions & 8 deletions garrysmod/lua/includes/extensions/client/render.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@ STENCIL_DECR = STENCILOPERATION_DECR
-----------------------------------------------------------]]
function render.ClearRenderTarget( rt, color )

local OldRT = render.GetRenderTarget();
render.SetRenderTarget( rt )
render.PushRenderTarget( rt )
render.Clear( color.r, color.g, color.b, color.a )
render.SetRenderTarget( OldRT )
render.PopRenderTarget()

end

Expand All @@ -60,12 +59,9 @@ end
-----------------------------------------------------------]]
function render.CopyTexture( from, to )

local OldRT = render.GetRenderTarget();

render.SetRenderTarget( from )
render.PushRenderTarget( from )
render.CopyRenderTargetToTexture( to )

render.SetRenderTarget( OldRT )
render.PopRenderTarget()

end

Expand Down
13 changes: 5 additions & 8 deletions garrysmod/lua/postprocess/bloom.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,19 @@ function DrawBloom( darken, multiply, sizex, sizey, passes, color, colr, colg, c
-- Copy the backbuffer to the screen effect texture
render.CopyRenderTargetToTexture( render.GetScreenEffectTexture() )

-- Store the render target so we can swap back at the end
local OldRT = render.GetRenderTarget()

-- The downsample material adjusts the contrast
mat_Downsample:SetFloat( "$darken", darken )
mat_Downsample:SetFloat( "$multiply", multiply )

-- Downsample to BloomTexture0
render.SetRenderTarget( tex_Bloom0 )
render.PushRenderTarget( tex_Bloom0 )

render.SetMaterial( mat_Downsample )
render.DrawScreenQuad()
render.SetMaterial( mat_Downsample )
render.DrawScreenQuad()

render.BlurRenderTarget( tex_Bloom0, sizex, sizey, passes )
render.BlurRenderTarget( tex_Bloom0, sizex, sizey, passes )

render.SetRenderTarget( OldRT )
render.PopRenderTarget()

mat_Bloom:SetFloat( "$levelr", colr )
mat_Bloom:SetFloat( "$levelg", colg )
Expand Down
14 changes: 6 additions & 8 deletions garrysmod/lua/postprocess/frame_blend.lua
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,14 @@ frame_blend.CompleteFrame = function()
matFSB:SetFloat( "$alpha", 1.0 )
matFSB:SetTexture( "$basetexture", texMB0 )

local OldRT = render.GetRenderTarget()
render.SetRenderTarget( texMB1 )
render.PushRenderTarget( texMB1 )
render.SetMaterial( matFSB )
render.DrawScreenQuad()
render.SetRenderTarget( OldRT )
render.PopRenderTarget()

render.SetRenderTarget( texMB0 )
render.PushRenderTarget( texMB0 )
render.Clear( 0, 0, 0, 255, true, true )
render.SetRenderTarget( OldRT )
render.PopRenderTarget()

end

Expand Down Expand Up @@ -161,11 +160,10 @@ frame_blend.BlendFrame = function()

matFB:SetFloat( "$alpha", curve )

local OldRT = render.GetRenderTarget()
render.SetRenderTarget( texMB0 )
render.PushRenderTarget( texMB0 )
render.SetMaterial( matFB )
render.DrawScreenQuad()
render.SetRenderTarget( OldRT )
render.PopRenderTarget()

end

Expand Down
16 changes: 6 additions & 10 deletions garrysmod/lua/postprocess/motion_blur.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ function DrawMotionBlur( addalpha, drawalpha, delay )

mat_Screen:SetFloat( "$alpha", 1 )

local OldRT = render.GetRenderTarget()
render.SetRenderTarget( tex_MotionBlur )
render.PushRenderTarget( tex_MotionBlur )
render.SetMaterial( mat_Screen )
render.DrawScreenQuad()
render.SetRenderTarget( OldRT )
render.PopRenderTarget()

end

Expand All @@ -43,13 +42,10 @@ function DrawMotionBlur( addalpha, drawalpha, delay )
NextDraw = CurTime() + delay

mat_Screen:SetFloat( "$alpha", addalpha )
local OldRT = render.GetRenderTarget()
render.SetRenderTarget( tex_MotionBlur )

render.SetMaterial( mat_Screen )
render.DrawScreenQuad()

render.SetRenderTarget( OldRT )
render.PushRenderTarget( tex_MotionBlur )
render.SetMaterial( mat_Screen )
render.DrawScreenQuad()
render.PopRenderTarget()

end

Expand Down

0 comments on commit cd72f68

Please sign in to comment.