Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove stencil buffer #2389

Merged
merged 3 commits into from
Nov 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions GLMakie/src/postprocessing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ function OIT_postprocessor(framebuffer, shader_cache)
# Blend transparent onto opaque
glDrawBuffer(color_id)
glViewport(0, 0, w, h)
glDisable(GL_STENCIL_TEST)
GLAbstraction.render(pass)
end

Expand Down Expand Up @@ -162,7 +161,6 @@ function ssao_postprocessor(framebuffer, shader_cache)
# SSAO - calculate occlusion
glDrawBuffer(normal_occ_id) # occlusion buffer
glViewport(0, 0, w, h)
glDisable(GL_STENCIL_TEST)
glEnable(GL_SCISSOR_TEST)

for (screenid, scene) in screen.screens
Expand Down
29 changes: 1 addition & 28 deletions GLMakie/src/rendering.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,11 @@ function setup!(screen)
a = pixelarea(scene)[]
rt = (minimum(a)..., widths(a)...)
glViewport(rt...)
bits = GL_STENCIL_BUFFER_BIT
glClearStencil(id)
if scene.clear
c = scene.backgroundcolor[]
glScissor(rt...)
glClearColor(red(c), green(c), blue(c), alpha(c))
bits |= GL_COLOR_BUFFER_BIT
glClear(bits)
glClear(GL_COLOR_BUFFER_BIT)
end
end
end
Expand Down Expand Up @@ -55,13 +52,8 @@ function render_frame(screen::Screen; resize_buffers=true)
w, h = size(fb)

# prepare stencil (for sub-scenes)
glEnable(GL_STENCIL_TEST)
glBindFramebuffer(GL_FRAMEBUFFER, fb.id)
glDrawBuffers(length(fb.render_buffer_ids), fb.render_buffer_ids)
glEnable(GL_STENCIL_TEST)
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE)
glStencilMask(0xff)
glClearStencil(0)
glClearColor(0, 0, 0, 0)
glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT)

Expand All @@ -71,8 +63,6 @@ function render_frame(screen::Screen; resize_buffers=true)

# render with SSAO
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE)
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE)
glStencilMask(0x00)
GLAbstraction.render(screen) do robj
return !Bool(robj[:transparency][]) && Bool(robj[:ssao][])
end
Expand All @@ -81,14 +71,10 @@ function render_frame(screen::Screen; resize_buffers=true)

# render no SSAO
glDrawBuffers(2, [GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1])
glEnable(GL_STENCIL_TEST)
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE)
glStencilMask(0x00)
# render all non ssao
GLAbstraction.render(screen) do robj
return !Bool(robj[:transparency][]) && !Bool(robj[:ssao][])
end
glDisable(GL_STENCIL_TEST)

# TRANSPARENT RENDER
# clear sums to 0
Expand All @@ -101,14 +87,10 @@ function render_frame(screen::Screen; resize_buffers=true)
glClear(GL_COLOR_BUFFER_BIT)
# draw
glDrawBuffers(3, [GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT3])
glEnable(GL_STENCIL_TEST)
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE)
glStencilMask(0x00)
# Render only transparent objects
GLAbstraction.render(screen) do robj
return Bool(robj[:transparency][])
end
glDisable(GL_STENCIL_TEST)

# TRANSPARENT BLEND
screen.postprocessors[2].render(screen)
Expand Down Expand Up @@ -141,15 +123,6 @@ function GLAbstraction.render(filter_elem_func, screen::Screen)
scene.visible[] || continue
a = pixelarea(scene)[]
glViewport(minimum(a)..., widths(a)...)
if scene.clear
glStencilFunc(GL_EQUAL, screenid, 0xff)
else
# if we don't clear, that means we have a screen that is overlaid
# on top of another, which means it doesn't have a stencil value
# so we can't do the stencil test
glStencilFunc(GL_ALWAYS, screenid, 0xff)
end

render(elem)
end
catch e
Expand Down
2 changes: 1 addition & 1 deletion GLMakie/src/screen.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const ScreenID = UInt8
const ScreenID = UInt16
const ZIndex = Int
# ID, Area, clear, is visible, background color
const ScreenArea = Tuple{ScreenID, Scene}
Expand Down