-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathcl_stencil_mask.lua
39 lines (30 loc) · 1.19 KB
/
cl_stencil_mask.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
-- https://github.com/Be1zebub/Small-GLua-Things/blob/master/cl_stencil_mask.lua
-- thx to stencil tutorial: https://github.com/Lexicality/stencil-tutorial
local function Mask(domask, dodraw, stencilCompareFunction)
render.ClearStencil()
render.SetStencilEnable(true)
render.SetStencilWriteMask(1)
render.SetStencilTestMask(1)
render.SetStencilFailOperation(STENCILOPERATION_REPLACE)
render.SetStencilPassOperation(STENCILOPERATION_ZERO)
render.SetStencilZFailOperation(STENCILOPERATION_ZERO)
render.SetStencilCompareFunction(STENCILCOMPARISONFUNCTION_NEVER)
render.SetStencilReferenceValue(1)
draw.NoTexture()
surface.SetDrawColor(255, 255, 255, 255)
domask()
render.SetStencilFailOperation(STENCILOPERATION_ZERO)
render.SetStencilPassOperation(STENCILOPERATION_REPLACE)
render.SetStencilZFailOperation(STENCILOPERATION_ZERO)
render.SetStencilCompareFunction(stencilCompareFunction)
render.SetStencilReferenceValue(1)
dodraw()
render.SetStencilEnable(false)
render.ClearStencil()
end
function draw.DrawMask(domask, dodraw)
Mask(domask, dodraw, STENCILCOMPARISONFUNCTION_EQUAL)
end
function draw.DrawMaskInverted(domask, dodraw)
Mask(domask, dodraw, STENCILCOMPARISONFUNCTION_NOTEQUAL)
end