Skip to content

Commit

Permalink
Delete code obsoleted by improved GLMakie embedding support
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesWrigley committed Jul 30, 2024
1 parent 38eadb5 commit 5a2dd4e
Showing 1 changed file with 2 additions and 65 deletions.
67 changes: 2 additions & 65 deletions ext/MakieIntegration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,8 @@ function destroy_context()
end

Base.isopen(window::ImMakieWindow) = isopen(window.glfw_window)

# Specialization of Base.resize(::GLMakie.Screen, ::Int, ::Int) to not do GLFW things
# See: https://github.com/MakieOrg/Makie.jl/blob/4c4eaa1f3a7f7b3777a4b8ab38388a48c0eee6ce/GLMakie/src/screen.jl#L664
function Base.resize!(screen::GLMakie.Screen{ImMakieWindow}, w::Int, h::Int)
fbscale = screen.px_per_unit[]
fbw, fbh = round.(Int, fbscale .* (w, h))
resize!(screen.framebuffer, fbw, fbh)
end

# Not sure if this is correct, it should probably be the figure size
GLMakie.framebuffer_size(window::ImMakieWindow) = GLMakie.framebuffer_size(window.glfw_window)
GLMakie.scale_factor(window::ImMakieWindow) = GLMakie.scale_factor(window.glfw_window)

# ShaderAbstractions support
GLMakie.ShaderAbstractions.native_switch_context!(x::ImMakieWindow) = GLFW.MakeContextCurrent(x.glfw_window)
Expand All @@ -49,68 +40,14 @@ GLMakie.ShaderAbstractions.native_context_alive(x::ImMakieWindow) = GLFW.is_init
# events in an immediate-mode fashion within MakieFigure().
GLMakie.connect_screen(::GLMakie.Scene, ::GLMakie.Screen{ImMakieWindow}) = nothing

# Modified copy of apply_config!() with all GLFW/renderloop things removed
# See: https://github.com/MakieOrg/Makie.jl/blob/4c4eaa1f3a7f7b3777a4b8ab38388a48c0eee6ce/GLMakie/src/screen.jl#L343
function apply_config!(screen::GLMakie.Screen, config::GLMakie.ScreenConfig)
screen.scalefactor[] = !isnothing(config.scalefactor) ? config.scalefactor : 1
screen.px_per_unit[] = !isnothing(config.px_per_unit) ? config.px_per_unit : screen.scalefactor[]
function replace_processor!(postprocessor, idx)
fb = screen.framebuffer
shader_cache = screen.shader_cache
post = screen.postprocessors[idx]
if post.constructor !== postprocessor
GLMakie.destroy!(screen.postprocessors[idx])
screen.postprocessors[idx] = postprocessor(fb, shader_cache)
end

nothing
end

replace_processor!(config.ssao ? GLMakie.ssao_postprocessor : GLMakie.empty_postprocessor, 1)
replace_processor!(config.oit ? GLMakie.OIT_postprocessor : GLMakie.empty_postprocessor, 2)
replace_processor!(config.fxaa ? GLMakie.fxaa_postprocessor : GLMakie.empty_postprocessor, 3)

# Set the config
screen.config = config
end

function ig.MakieFigure(title_id::String, f::GLMakie.Figure; auto_resize_x=true, auto_resize_y=false)
ig.PushID(title_id)
id = ig.GetID(title_id)

if !haskey(makie_context, id)
# The code in this block combines the screen creation code from
# GLMakie.empty_screen() and the screen configuration code from
# GLMakie.Screen().
# See:
# - https://github.com/MakieOrg/Makie.jl/blob/4c4eaa1f3a7f7b3777a4b8ab38388a48c0eee6ce/GLMakie/src/screen.jl#L223
# - https://github.com/MakieOrg/Makie.jl/blob/4c4eaa1f3a7f7b3777a4b8ab38388a48c0eee6ce/GLMakie/src/screen.jl#L388
window = ig.current_window()
makie_window = ImMakieWindow(window)
GLMakie.ShaderAbstractions.switch_context!(makie_window)
shader_cache = GLMakie.GLAbstraction.ShaderCache(makie_window)

fb = GLMakie.GLFramebuffer((10, 10))
gl.glBindFramebuffer(gl.GL_FRAMEBUFFER, 0) # Have to unbind after creating the framebuffer
postprocessors = [
GLMakie.empty_postprocessor(),
GLMakie.empty_postprocessor(),
GLMakie.empty_postprocessor(),
GLMakie.to_screen_postprocessor(fb, shader_cache)
]

screen = GLMakie.Screen(makie_window, shader_cache, fb,
nothing, false,
nothing,
Dict{WeakRef, GLMakie.ScreenID}(),
GLMakie.ScreenArea[],
Tuple{GLMakie.ZIndex, GLMakie.ScreenID, GLMakie.RenderObject}[],
postprocessors,
Dict{UInt64, GLMakie.RenderObject}(),
Dict{UInt32, GLMakie.AbstractPlot}(),
true)
config = Makie.merge_screen_config(GLMakie.ScreenConfig, Dict{Symbol, Any}())
apply_config!(screen, config)
screen = GLMakie.Screen(; window=makie_window, start_renderloop=false)

makie_context[id] = ImMakieFigure(f, screen)
scene = Makie.get_scene(f)
Expand Down

0 comments on commit 5a2dd4e

Please sign in to comment.