Skip to content

Commit

Permalink
merge render_colorbuffer into render_frame
Browse files Browse the repository at this point in the history
  • Loading branch information
ffreyer committed May 14, 2020
1 parent 32e7cfd commit 7668c54
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 57 deletions.
10 changes: 6 additions & 4 deletions src/rendering.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,15 @@ const selection_queries = Function[]
"""
Renders a single frame of a `window`
"""
function render_frame(screen::Screen)
function render_frame(screen::Screen; resize_buffers=true)
nw = to_native(screen)
ShaderAbstractions.is_context_active(nw) || return
fb = screen.framebuffer
wh = Int.(framebuffer_size(nw))
resize!(fb, wh)
w, h = wh
if resize_buffers
wh = Int.(framebuffer_size(nw))
resize!(fb, wh)
end
w, h = size(fb)

# prepare stencil (for sub-scenes)
glEnable(GL_STENCIL_TEST)
Expand Down
55 changes: 2 additions & 53 deletions src/screen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -151,65 +151,14 @@ function fast_color_data!(dest::Array{RGB{N0f8}, 2}, source::Texture{T, 2}) wher
end


function render_colorbuffer(screen)
nw = to_native(screen)
GLAbstraction.is_context_active(nw) || return
fb = screen.framebuffer
w, h = size(fb)
glEnable(GL_STENCIL_TEST)
#prepare for geometry in need of anti aliasing
glBindFramebuffer(GL_FRAMEBUFFER, fb.id[1]) # color framebuffer
glDrawBuffers(2, [GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1])
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)
setup!(screen)

glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE)
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE)
glStencilMask(0x00)
GLAbstraction.render(screen, true)
glDisable(GL_STENCIL_TEST)

# transfer color to luma buffer and apply fxaa
glBindFramebuffer(GL_FRAMEBUFFER, fb.id[2]) # luma framebuffer
glDrawBuffer(GL_COLOR_ATTACHMENT0)
glViewport(0, 0, w, h)
glClearColor(0,0,0,0)
glClear(GL_COLOR_BUFFER_BIT)
GLAbstraction.render(fb.postprocess[1]) # add luma and preprocess

glBindFramebuffer(GL_FRAMEBUFFER, fb.id[1]) # transfer to non fxaa framebuffer
glViewport(0, 0, w, h)
glDrawBuffer(GL_COLOR_ATTACHMENT0)
GLAbstraction.render(fb.postprocess[2]) # copy with fxaa postprocess

#prepare for non anti aliased pass
glDrawBuffers(2, [GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1])

glEnable(GL_STENCIL_TEST)
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE)
glStencilMask(0x00)
GLAbstraction.render(screen, false)
glDisable(GL_STENCIL_TEST)
glBindFramebuffer(GL_FRAMEBUFFER, 0) # transfer back to window
glViewport(0, 0, w, h)
glClearColor(0, 0, 0, 0)
glClear(GL_COLOR_BUFFER_BIT)
GLAbstraction.render(fb.postprocess[3]) # copy postprocess
end

function AbstractPlotting.colorbuffer(screen::Screen)
if isopen(screen)
ctex = screen.framebuffer.color
# polling may change window size, when its bigger than monitor!
# we still need to poll though, to get all the newest events!
# GLFW.PollEvents()
# we need to resize the framebuffer to the dimensions before polling
render_colorbuffer(screen) # let it render
# keep current buffer size to allows larger-than-window renders
render_frame(screen, resize_buffers=false) # let it render
glFinish() # block until opengl is done rendering
if size(ctex) != size(screen.framecache[1])
s = size(ctex)
Expand Down

0 comments on commit 7668c54

Please sign in to comment.