From 9abac6d28dafe5014f98159233f34d69863b70a2 Mon Sep 17 00:00:00 2001 From: ffreyer Date: Tue, 24 Dec 2024 21:47:28 +0100 Subject: [PATCH] use dedicated framebuffers --- GLMakie/src/GLAbstraction/GLAbstraction.jl | 2 +- GLMakie/src/GLAbstraction/GLFrameBuffer.jl | 8 +- GLMakie/src/glwindow.jl | 90 ++++++++++++---- GLMakie/src/picking.jl | 8 +- GLMakie/src/postprocessing.jl | 118 ++++++++------------- GLMakie/src/precompiles.jl | 2 +- GLMakie/src/rendering.jl | 8 +- GLMakie/src/screen.jl | 20 ++-- 8 files changed, 141 insertions(+), 115 deletions(-) diff --git a/GLMakie/src/GLAbstraction/GLAbstraction.jl b/GLMakie/src/GLAbstraction/GLAbstraction.jl index 1b0044ba4d4..cd8f38132ea 100644 --- a/GLMakie/src/GLAbstraction/GLAbstraction.jl +++ b/GLMakie/src/GLAbstraction/GLAbstraction.jl @@ -102,7 +102,7 @@ export getAttributesInfo include("GLFrameBuffer.jl") export GLRenderbuffer export GLFramebuffer -export attach_colorbuffer, attach_depthbuffer, attach_stencilbuffer +export attach_colorbuffer, attach_depthbuffer, attach_stencilbuffer, attach_depthstencilbuffer export get_attachment, get_buffer export check_framebuffer diff --git a/GLMakie/src/GLAbstraction/GLFrameBuffer.jl b/GLMakie/src/GLAbstraction/GLFrameBuffer.jl index e55bfef7068..6f89fb89bec 100644 --- a/GLMakie/src/GLAbstraction/GLFrameBuffer.jl +++ b/GLMakie/src/GLAbstraction/GLFrameBuffer.jl @@ -76,6 +76,7 @@ function bind(fb::GLFramebuffer) glBindFramebuffer(GL_FRAMEBUFFER, fb.id) return end +unbind(::GLFramebuffer) = glBindFramebuffer(GL_FRAMEBUFFER, 0) function unsafe_free(x::GLFramebuffer) # don't free if already freed @@ -113,6 +114,7 @@ end attach_colorbuffer(fb::GLFramebuffer, key::Symbol, buffer) = attach(fb, key, buffer, get_next_colorbuffer_attachment(fb)) attach_depthbuffer(fb::GLFramebuffer, key::Symbol, buffer) = attach(fb, key, buffer, GL_DEPTH_ATTACHMENT) attach_stencilbuffer(fb::GLFramebuffer, key::Symbol, buffer) = attach(fb, key, buffer, GL_STENCIL_ATTACHMENT) +attach_depthstencilbuffer(fb::GLFramebuffer, key::Symbol, buffer) = attach(fb, key, buffer, GL_DEPTH_STENCIL_ATTACHMENT) function attach(fb::GLFramebuffer, key::Symbol, buffer, attachment::GLenum) haskey(fb, key) && error("Cannot attach $key to Framebuffer because it is already set.") @@ -121,6 +123,8 @@ function attach(fb::GLFramebuffer, key::Symbol, buffer, attachment::GLenum) type = "depth" elseif attachment == GL_STENCIL_ATTACHMENT type = "stencil" + elseif attachment == GL_DEPTH_STENCIL_ATTACHMENT + type = "depth-stencil" else type = "color" end @@ -178,7 +182,7 @@ function Base.show(io::IO, fb::GLFramebuffer) X, Y = fb.size print(io, "$X×$Y GLFrameBuffer(:") join(io, string.(keys(fb.buffers)), ", :") - print(io, ")") + print(io, ") with id ", fb.id) end function attachment_enum_to_string(x::GLenum) @@ -190,7 +194,7 @@ end function Base.show(io::IO, ::MIME"text/plain", fb::GLFramebuffer) X, Y = fb.size - print(io, "$X×$Y GLFrameBuffer()") + print(io, "$X×$Y GLFrameBuffer() with id ", fb.id) ks = collect(keys(fb.buffers)) key_strings = [":$k" for k in ks] diff --git a/GLMakie/src/glwindow.jl b/GLMakie/src/glwindow.jl index b7e580b7b59..bf920a595a1 100644 --- a/GLMakie/src/glwindow.jl +++ b/GLMakie/src/glwindow.jl @@ -10,31 +10,30 @@ end Base.convert(::Type{SelectionID{T}}, s::SelectionID) where T = SelectionID{T}(T(s.id), T(s.index)) Base.zero(::Type{GLMakie.SelectionID{T}}) where T = SelectionID{T}(T(0), T(0)) -mutable struct Framebuffer +mutable struct FramebufferFactory fb::GLFramebuffer + buffers::Dict{Symbol, Texture} # TODO: temp, should be unnamed collection render_buffer_ids::Vector{GLuint} + children::Vector{GLFramebuffer} # TODO: how else can we handle resizing? end # it's guaranteed, that they all have the same size -# forwards... for now -Base.size(fb::Framebuffer) = size(fb.fb) -Base.haskey(fb::Framebuffer, key::Symbol) = haskey(fb.fb, key) -GLAbstraction.get_attachment(fb::Framebuffer, key::Symbol) = get_attachment(fb.fb, key) -GLAbstraction.get_buffer(fb::Framebuffer, key::Symbol) = get_buffer(fb.fb, key) -GLAbstraction.bind(fb::Framebuffer) = GLAbstraction.bind(fb.fb) -GLAbstraction.attach_colorbuffer(fb::Framebuffer, key, val) = GLAbstraction.attach_colorbuffer(fb.fb, key, val) -function getfallback_attachment(fb::Framebuffer, key::Symbol, fallback_key::Symbol) - haskey(fb, key) ? get_attachment(fb, key) : get_attachment(fb, fallback_key) -end -function getfallback_buffer(fb::Framebuffer, key::Symbol, fallback_key::Symbol) - haskey(fb, key) ? get_buffer(fb, key) : get_buffer(fb, fallback_key) -end +# TODO: forwards... for now +Base.size(fb::FramebufferFactory) = size(fb.fb) +Base.haskey(fb::FramebufferFactory, key::Symbol) = haskey(fb.buffers, key) +GLAbstraction.get_buffer(fb::FramebufferFactory, key::Symbol) = fb.buffers[key] +GLAbstraction.bind(fb::FramebufferFactory) = GLAbstraction.bind(fb.fb) +function Base.resize!(fb::FramebufferFactory, w::Int, h::Int) + foreach(tex -> GLAbstraction.resize_nocopy!(tex, (w, h)), values(fb.buffers)) + resize!(fb.fb, w, h) + filter!(fb -> fb.id != 0, fb.children) # TODO: is this ok? + foreach(fb -> resize!(fb, w, h), fb.children) + return +end -Makie.@noconstprop function Framebuffer(fb_size::NTuple{2, Int}) - # Create framebuffer - fb = GLFramebuffer(fb_size) +Makie.@noconstprop function FramebufferFactory(fb_size::NTuple{2, Int}) # Buffers we always need # Holds the image that eventually gets displayed color_buffer = Texture( @@ -59,20 +58,65 @@ Makie.@noconstprop function Framebuffer(fb_size::NTuple{2, Int}) N0f8, fb_size, minfilter = :nearest, x_repeat = :clamp_to_edge ) + buffers = Dict{Symbol, Texture}( + :color => color_buffer, + :objectid => objectid_buffer, + :HDR_color => HDR_color_buffer, + :OIT_weight => OIT_weight_buffer, + :depth_stencil => depth_buffer, + ) + + # Create render framebuffer + fb = GLFramebuffer(fb_size) + # attach buffers color_attachment = attach_colorbuffer(fb, :color, color_buffer) objectid_attachment = attach_colorbuffer(fb, :objectid, objectid_buffer) - attach_colorbuffer(fb, :HDR_color, HDR_color_buffer) - attach_colorbuffer(fb, :OIT_weight, OIT_weight_buffer) - attach_depthbuffer(fb, :depth, depth_buffer) - attach_stencilbuffer(fb, :stencil, depth_buffer) + attach_depthstencilbuffer(fb, :depth_stencil, depth_buffer) + attach_colorbuffer(fb, :HDR_color, HDR_color_buffer) # TODO: framebuffer for RenderPlots + attach_colorbuffer(fb, :OIT_weight, OIT_weight_buffer) # TODO: framebuffer for RenderPlots + + check_framebuffer() + + return FramebufferFactory(fb, buffers, [color_attachment, objectid_attachment], GLFramebuffer[]) +end + +# TODO: temporary +function Base.push!(factory::FramebufferFactory, kv::Pair{Symbol, <: Texture}) + if haskey(factory.buffers, kv[1]) + @error("Pushed buffer $(kv[1]) already assigned.") + return + end + push!(factory.buffers, kv) + return +end + +function generate_framebuffer(factory::FramebufferFactory, names...) + filter!(fb -> fb.id != 0, factory.children) # cleanup? + + parse_arg(name::Symbol) = name => name + parse_arg(p::Pair{Symbol, Symbol}) = p + parse_arg(x::Any) = error("$x not accepted") + + fb = GLFramebuffer(size(factory.fb)) + attach_depthstencilbuffer(fb, :depth_stencil, factory.buffers[:depth_stencil]) + + for arg in names + lookup, name = parse_arg(arg) + haskey(factory.buffers, lookup) || error("Add buffers yourself for now") + haskey(fb, name) && error("Can't add duplicate buffer $lookup => $name") + in(lookup, [:depth, :stencil]) && error("Depth and stencil always exist under the same name.") + + attach_colorbuffer(fb, name, factory.buffers[lookup]) + end check_framebuffer() - return Framebuffer(fb, [color_attachment, objectid_attachment]) + push!(factory.children, fb) + + return fb end -Base.resize!(fb::Framebuffer, w::Int, h::Int) = resize!(fb.fb, w, h) struct MonitorProperties diff --git a/GLMakie/src/picking.jl b/GLMakie/src/picking.jl index c785166be3e..c8f3c70821c 100644 --- a/GLMakie/src/picking.jl +++ b/GLMakie/src/picking.jl @@ -6,7 +6,7 @@ function pick_native(screen::Screen, rect::Rect2i) isopen(screen) || return Matrix{SelectionID{Int}}(undef, 0, 0) ShaderAbstractions.switch_context!(screen.glscreen) - fb = screen.framebuffer + fb = screen.framebuffer_factory buff = get_buffer(fb, :objectid) GLAbstraction.bind(fb) glReadBuffer(GL_COLOR_ATTACHMENT1) @@ -27,7 +27,7 @@ end function pick_native(screen::Screen, xy::Vec{2, Float64}) isopen(screen) || return SelectionID{Int}(0, 0) ShaderAbstractions.switch_context!(screen.glscreen) - fb = screen.framebuffer + fb = screen.framebuffer_factory buff = get_buffer(fb, :objectid) GLAbstraction.bind(fb) glReadBuffer(GL_COLOR_ATTACHMENT1) @@ -70,7 +70,7 @@ function Makie.pick_closest(scene::Scene, screen::Screen, xy, range) w, h = size(screen.scene) # unitless dimensions ((1.0 <= xy[1] <= w) && (1.0 <= xy[2] <= h)) || return (nothing, 0) - fb = screen.framebuffer + fb = screen.framebuffer_factory ppu = screen.px_per_unit[] w, h = size(fb) # pixel dimensions x0, y0 = max.(1, floor.(Int, ppu .* (xy .- range))) @@ -111,7 +111,7 @@ function Makie.pick_sorted(scene::Scene, screen::Screen, xy, range) return Tuple{AbstractPlot, Int}[] end - fb = screen.framebuffer + fb = screen.framebuffer_factory ppu = screen.px_per_unit[] w, h = size(fb) # pixel dimensions x0, y0 = max.(1, floor.(Int, ppu .* (xy .- range))) diff --git a/GLMakie/src/postprocessing.jl b/GLMakie/src/postprocessing.jl index bb1d18272a6..86b650ac82e 100644 --- a/GLMakie/src/postprocessing.jl +++ b/GLMakie/src/postprocessing.jl @@ -106,21 +106,21 @@ struct RenderPlots <: AbstractRenderStep end function RenderPlots(screen, stage) - fb = screen.framebuffer + fb = screen.framebuffer_factory.fb if stage === :SSAO return RenderPlots( - fb.fb, fb.render_buffer_ids, [3 => Vec4f(0), 4 => Vec4f(0)], + fb, screen.framebuffer_factory.render_buffer_ids, [3 => Vec4f(0), 4 => Vec4f(0)], FilterTrue, FilterFalse, FilterAny) elseif stage === :FXAA return RenderPlots( - fb.fb, get_attachment.(Ref(fb), [:color, :objectid]), Pair{Int, Vec4f}[], + fb, get_attachment.(Ref(fb), [:color, :objectid]), Pair{Int, Vec4f}[], FilterFalse, FilterFalse, FilterAny) elseif stage === :OIT targets = get_attachment.(Ref(fb), [:HDR_color, :objectid, :OIT_weight]) # HDR_color containing sums clears to 0 # OIT_weight containing products clears to 1 clear = [1 => Vec4f(0), 3 => Vec4f(1)] - return RenderPlots(fb.fb, targets, clear, FilterAny, FilterTrue, FilterAny) + return RenderPlots(fb, targets, clear, FilterAny, FilterTrue, FilterAny) else error("Incorrect stage = $stage given. Should be :SSAO, :FXAA or :OIT.") end @@ -178,10 +178,6 @@ end struct RenderPass{Name} <: AbstractRenderStep framebuffer::GLFramebuffer passes::Vector{RenderObject} - renames::Dict{Symbol, Symbol} # TODO: temporary until GLFramebuffer not shared -end -function RenderPass{Name}(framebuffer::GLFramebuffer, passes::Vector{RenderObject}) where {Name} - return RenderPass{Name}(framebuffer, passes, Dict{Symbol, Symbol}()) end @@ -189,7 +185,8 @@ end function RenderPass{:OIT}(screen) @debug "Creating OIT postprocessor" - framebuffer = screen.framebuffer + factory = screen.framebuffer_factory + framebuffer = generate_framebuffer(factory, :color) # Based on https://jcgt.org/published/0002/02/09/, see #1390 # OIT setup @@ -199,8 +196,8 @@ function RenderPass{:OIT}(screen) loadshader("postprocessing/OIT_blend.frag") ) data = Dict{Symbol, Any}( - :sum_color => get_buffer(framebuffer, :HDR_color), - :prod_alpha => get_buffer(framebuffer, :OIT_weight), + :sum_color => get_buffer(factory.fb, :HDR_color), + :prod_alpha => get_buffer(factory.fb, :OIT_weight), ) pass = RenderObject( data, shader, @@ -221,12 +218,13 @@ function RenderPass{:OIT}(screen) ) pass.postrenderfunction = () -> draw_fullscreen(pass.vertexarray.id) - return RenderPass{:OIT}(framebuffer.fb, RenderObject[pass]) + return RenderPass{:OIT}(framebuffer, RenderObject[pass]) end function run_step(screen, glscene, step::RenderPass{:OIT}) # Blend transparent onto opaque - wh = size(screen.framebuffer) + GLAbstraction.bind(step.framebuffer) + wh = size(step.framebuffer) glViewport(0, 0, wh[1], wh[2]) glDrawBuffer(get_attachment(step.framebuffer, :color)) GLAbstraction.render(step.passes[1]) @@ -236,32 +234,22 @@ end function RenderPass{:SSAO}(screen) @debug "Creating SSAO postprocessor" - framebuffer = screen.framebuffer - renames = Dict{Symbol, Symbol}() + + factory = screen.framebuffer_factory # Add missing buffers - if !haskey(framebuffer, :position) - # GLAbstraction.bind(framebuffer) - position_buffer = Texture( - Vec3f, size(framebuffer), minfilter = :nearest, x_repeat = :clamp_to_edge - ) - pos_id = attach_colorbuffer(framebuffer, :position, position_buffer) - push!(framebuffer.render_buffer_ids, pos_id) - end - if !haskey(framebuffer, :normal) - if !haskey(framebuffer, :HDR_color) - # GLAbstraction.bind(framebuffer) - normal_occlusion_buffer = Texture( - Vec4{Float16}, size(framebuffer), minfilter = :nearest, x_repeat = :clamp_to_edge - ) - normal_occ_id = attach_colorbuffer(framebuffer, :normal_occlusion, normal_occlusion_buffer) - renames[:normal_occlusion] = :normal_occlusion - else - normal_occ_id = get_attachment(framebuffer, :HDR_color) - renames[:normal_occlusion] = :HDR_color - end - push!(framebuffer.render_buffer_ids, normal_occ_id) - end + pos_tex = Texture(Vec3f, size(screen), minfilter = :nearest, x_repeat = :clamp_to_edge) + push!(factory, :position => pos_tex) + # HDR_color always exists... + + # TODO: temp - update renderbuffers and main renderbuffer + # eventually RenderPlots should have dedicated GLFramebuffers too, which + # derive their draw buffers from the abstracted render pipeline + pos_id = attach_colorbuffer(factory.fb, :position, pos_tex) + normal_id = attach_colorbuffer(factory.fb, :normal, get_buffer(factory, :HDR_color)) + push!(factory.render_buffer_ids, pos_id, normal_id) + + framebuffer = generate_framebuffer(factory, :color, :HDR_color => :normal_occlusion) # SSAO setup N_samples = 64 @@ -283,14 +271,14 @@ function RenderPass{:SSAO}(screen) ) ) data1 = Dict{Symbol, Any}( - :position_buffer => get_buffer(framebuffer, :position), - :normal_occlusion_buffer => getfallback_buffer(framebuffer, :normal_occlusion, :HDR_color), + :position_buffer => get_buffer(factory.fb, :position), + :normal_occlusion_buffer => get_buffer(factory.fb, :normal), :kernel => kernel, :noise => Texture( [normalize(Vec2f(2.0rand(2) .- 1.0)) for _ in 1:4, __ in 1:4], minfilter = :nearest, x_repeat = :repeat ), - :noise_scale => Vec2f(0.25f0 .* size(framebuffer)), + :noise_scale => Vec2f(0.25f0 .* size(screen)), :projection => Observable(Mat4f(I)), :bias => 0.025f0, :radius => 0.5f0 @@ -306,23 +294,24 @@ function RenderPass{:SSAO}(screen) loadshader("postprocessing/SSAO_blur.frag") ) data2 = Dict{Symbol, Any}( - :normal_occlusion => getfallback_buffer(framebuffer, :normal_occlusion, :HDR_color), - :color_texture => get_buffer(framebuffer, :color), - :ids => get_buffer(framebuffer, :objectid), - :inv_texel_size => rcpframe(size(framebuffer)), + :normal_occlusion => get_buffer(framebuffer, :normal_occlusion), + :color_texture => get_buffer(factory.fb, :color), + :ids => get_buffer(factory.fb, :objectid), + :inv_texel_size => rcpframe(size(screen)), :blur_range => Int32(2) ) pass2 = RenderObject(data2, shader2, PostprocessPrerender(), nothing) pass2.postrenderfunction = () -> draw_fullscreen(pass2.vertexarray.id) - return RenderPass{:SSAO}(framebuffer.fb, [pass1, pass2], renames) + return RenderPass{:SSAO}(framebuffer, [pass1, pass2]) end function run_step(screen, glscene, step::RenderPass{:SSAO}) - wh = size(screen.framebuffer) + GLAbstraction.bind(step.framebuffer) + wh = size(step.framebuffer) glViewport(0, 0, wh[1], wh[2]) - glDrawBuffer(get_attachment(step.framebuffer, step.renames[:normal_occlusion])) # occlusion buffer + glDrawBuffer(get_attachment(step.framebuffer, :normal_occlusion)) # occlusion buffer glEnable(GL_SCISSOR_TEST) ppu = (x) -> round.(Int, screen.px_per_unit[] .* x) @@ -364,23 +353,8 @@ end function RenderPass{:FXAA}(screen) @debug "Creating FXAA postprocessor" - framebuffer = screen.framebuffer - renames = Dict{Symbol, Symbol}() - - # Add missing buffers - if !haskey(framebuffer, :color_luma) - if !haskey(framebuffer, :HDR_color) - # GLAbstraction.bind(framebuffer) - color_luma_buffer = Texture( - RGBA{N0f8}, size(framebuffer), minfilter=:linear, x_repeat=:clamp_to_edge - ) - luma_id = attach_colorbuffer(framebuffer, :color_luma, color_luma_buffer) - renames[:color_luma] = :color_luma - else - luma_id = get_attachment(framebuffer, :HDR_color) - renames[:color_luma] = :HDR_color - end - end + factory = screen.framebuffer_factory + framebuffer = generate_framebuffer(factory, :color, :HDR_color => :color_luma) # calculate luma for FXAA shader1 = LazyShader( @@ -389,8 +363,8 @@ function RenderPass{:FXAA}(screen) loadshader("postprocessing/postprocess.frag") ) data1 = Dict{Symbol, Any}( - :color_texture => get_buffer(framebuffer, :color), - :object_ids => get_buffer(framebuffer, :objectid) + :color_texture => get_buffer(factory.fb, :color), + :object_ids => get_buffer(factory.fb, :objectid) ) pass1 = RenderObject(data1, shader1, PostprocessPrerender(), nothing) pass1.postrenderfunction = () -> draw_fullscreen(pass1.vertexarray.id) @@ -402,22 +376,24 @@ function RenderPass{:FXAA}(screen) loadshader("postprocessing/fxaa.frag") ) data2 = Dict{Symbol, Any}( - :color_texture => getfallback_buffer(framebuffer, :color_luma, :HDR_color), + :color_texture => get_buffer(framebuffer, :color_luma), :RCPFrame => rcpframe(size(framebuffer)), ) pass2 = RenderObject(data2, shader2, PostprocessPrerender(), nothing) pass2.postrenderfunction = () -> draw_fullscreen(pass2.vertexarray.id) - return RenderPass{:FXAA}(framebuffer.fb, RenderObject[pass1, pass2], renames) + return RenderPass{:FXAA}(framebuffer, RenderObject[pass1, pass2]) end function run_step(screen, glscene, step::RenderPass{:FXAA}) + GLAbstraction.bind(step.framebuffer) + # TODO: make scissor explicit? - wh = size(screen.framebuffer) + wh = size(step.framebuffer) glViewport(0, 0, wh[1], wh[2]) # FXAA - calculate LUMA - glDrawBuffer(get_attachment(step.framebuffer, step.renames[:color_luma])) + glDrawBuffer(get_attachment(step.framebuffer, :color_luma)) # necessary with negative SSAO bias... glClearColor(1, 1, 1, 1) glClear(GL_COLOR_BUFFER_BIT) @@ -441,7 +417,7 @@ struct BlitToScreen <: AbstractRenderStep # Screen not available yet function BlitToScreen(screen, screen_framebuffer_id::Integer = 0) @debug "Creating to screen postprocessor" - return new(screen.framebuffer.fb, screen_framebuffer_id) + return new(screen.framebuffer_factory.fb, screen_framebuffer_id) end end diff --git a/GLMakie/src/precompiles.jl b/GLMakie/src/precompiles.jl index a8b81d09e12..b27033a54dd 100644 --- a/GLMakie/src/precompiles.jl +++ b/GLMakie/src/precompiles.jl @@ -60,7 +60,7 @@ let end precompile(Screen, (Scene, ScreenConfig)) -precompile(Framebuffer, (NTuple{2,Int},)) +precompile(FramebufferFactory, (NTuple{2,Int},)) precompile(glTexImage, (GLenum, Int, GLenum, Int, Int, Int, GLenum, GLenum, Ptr{Float32})) precompile(glTexImage, (GLenum, Int, GLenum, Int, Int, Int, GLenum, GLenum, Ptr{RGBAf})) precompile(glTexImage, (GLenum, Int, GLenum, Int, Int, Int, GLenum, GLenum, Ptr{RGBf})) diff --git a/GLMakie/src/rendering.jl b/GLMakie/src/rendering.jl index 330aaaf44c6..1fd18750f6b 100644 --- a/GLMakie/src/rendering.jl +++ b/GLMakie/src/rendering.jl @@ -3,13 +3,15 @@ function setup!(screen::Screen, resize_buffers) ShaderAbstractions.switch_context!(to_native(screen)) # Resize framebuffer to window size - fb = screen.framebuffer - GLAbstraction.bind(fb) + fb = screen.framebuffer_factory.fb if resize_buffers && !isnothing(screen.scene) ppu = screen.px_per_unit[] - resize!(fb, round.(Int, ppu .* size(screen.scene))...) + resize!(screen.framebuffer_factory, round.(Int, ppu .* size(screen.scene))...) end + GLAbstraction.bind(fb) + glViewport(0, 0, size(fb)...) + # clear objectid, depth and stencil glDrawBuffer(get_attachment(fb, :objectid)) glClearColor(0, 0, 0, 0) diff --git a/GLMakie/src/screen.jl b/GLMakie/src/screen.jl index 8d319361c25..0707aa79705 100644 --- a/GLMakie/src/screen.jl +++ b/GLMakie/src/screen.jl @@ -162,7 +162,7 @@ mutable struct Screen{GLWindow} <: MakieScreen glscreen::GLWindow owns_glscreen::Bool shader_cache::GLAbstraction.ShaderCache - framebuffer::Framebuffer + framebuffer_factory::FramebufferFactory config::Union{Nothing, ScreenConfig} stop_renderloop::Threads.Atomic{Bool} rendertask::Union{Task, Nothing} @@ -190,7 +190,7 @@ mutable struct Screen{GLWindow} <: MakieScreen glscreen::GLWindow, owns_glscreen::Bool, shader_cache::GLAbstraction.ShaderCache, - framebuffer::Framebuffer, + framebuffer_factory::FramebufferFactory, config::Union{Nothing, ScreenConfig}, stop_renderloop::Bool, rendertask::Union{Nothing, Task}, @@ -203,9 +203,9 @@ mutable struct Screen{GLWindow} <: MakieScreen reuse::Bool ) where {GLWindow} - s = size(framebuffer) + s = size(framebuffer_factory) screen = new{GLWindow}( - glscreen, owns_glscreen, shader_cache, framebuffer, + glscreen, owns_glscreen, shader_cache, framebuffer_factory, config, Threads.Atomic{Bool}(stop_renderloop), rendertask, BudgetedTimer(1.0 / 30.0), Observable(0f0), screen2scene, screens, renderlist, AbstractRenderStep[], cache, cache2plot, @@ -217,7 +217,7 @@ mutable struct Screen{GLWindow} <: MakieScreen end end -framebuffer_size(screen::Screen) = size(screen.framebuffer) +framebuffer_size(screen::Screen) = size(screen.framebuffer_factory) Makie.isvisible(screen::Screen) = screen.config.visible @@ -279,7 +279,7 @@ Makie.@noconstprop function empty_screen(debugging::Bool, reuse::Bool, window) # This is important for resource tracking, and only needed for the first context ShaderAbstractions.switch_context!(window) shader_cache = GLAbstraction.ShaderCache(window) - fb = Framebuffer(initial_resolution) + fb = FramebufferFactory(initial_resolution) screen = Screen( window, owns_glscreen, shader_cache, fb, @@ -500,7 +500,7 @@ Base.wait(scene::Scene) = wait(Makie.getscreen(scene)) Base.show(io::IO, screen::Screen) = print(io, "GLMakie.Screen(...)") Base.isopen(x::Screen) = isopen(x.glscreen) -Base.size(x::Screen) = size(x.framebuffer) +Base.size(x::Screen) = size(x.framebuffer_factory) function add_scene!(screen::Screen, scene::Scene) get!(screen.screen2scene, WeakRef(scene)) do @@ -731,7 +731,7 @@ function Base.resize!(screen::Screen, w::Int, h::Int) # independently of the window scale factor. fbscale = screen.px_per_unit[] fbw, fbh = round.(Int, fbscale .* (w, h)) - resize!(screen.framebuffer, fbw, fbh) + resize!(screen.framebuffer_factory, fbw, fbh) return nothing end @@ -763,7 +763,7 @@ function depthbuffer(screen::Screen) ShaderAbstractions.switch_context!(screen.glscreen) render_frame(screen, resize_buffers=false) # let it render glFinish() # block until opengl is done rendering - source = get_buffer(screen.framebuffer, :depth) + source = get_buffer(screen.framebuffer_factory, :depth) depth = Matrix{Float32}(undef, size(source)) GLAbstraction.bind(source) GLAbstraction.glGetTexImage(source.texturetype, 0, GL_DEPTH_COMPONENT, GL_FLOAT, depth) @@ -776,7 +776,7 @@ function Makie.colorbuffer(screen::Screen, format::Makie.ImageStorageFormat = Ma error("Screen not open!") end ShaderAbstractions.switch_context!(screen.glscreen) - ctex = get_buffer(screen.framebuffer, :color) + ctex = get_buffer(screen.framebuffer_factory, :color) # polling may change window size, when its bigger than monitor! # we still need to poll though, to get all the newest events! pollevents(screen, Makie.BackendTick)