Skip to content

Commit

Permalink
More render on demand fixes (#2929)
Browse files Browse the repository at this point in the history
* add backgroundcolor and px_area as update triggers

* remove px_area trigger

* register callbacks and add ssao

* change scene.clear to Observable & track it

* Update NEWS.md
  • Loading branch information
ffreyer committed May 9, 2023
1 parent 9c66b49 commit 1a5309b
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion GLMakie/src/rendering.jl
Expand Up @@ -10,7 +10,7 @@ function setup!(screen)
a = pixelarea(scene)[]
rt = (minimum(a)..., widths(a)...)
glViewport(rt...)
if scene.clear
if scene.clear[]
c = scene.backgroundcolor[]
glScissor(rt...)
glClearColor(red(c), green(c), blue(c), alpha(c))
Expand Down
8 changes: 7 additions & 1 deletion GLMakie/src/screen.jl
Expand Up @@ -435,7 +435,13 @@ function Makie.insertplots!(screen::Screen, scene::Scene)
get!(screen.screen2scene, WeakRef(scene)) do
id = length(screen.screens) + 1
push!(screen.screens, (id, scene))
on(_ -> screen.requires_update = true, scene.visible)
screen.requires_update = true
onany(
(_, _, _, _, _, _) -> screen.requires_update = true,
scene,
scene.visible, scene.backgroundcolor, scene.clear,
scene.ssao.bias, scene.ssao.blur, scene.ssao.radius
)
return id
end
for elem in scene.plots
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Expand Up @@ -4,6 +4,7 @@

- Fixed incorrect line depth in GLMakie [#2843](https://github.com/MakieOrg/Makie.jl/pull/2843)
- Fixed incorrect line alpha in dense lines in GLMakie [#2843](https://github.com/MakieOrg/Makie.jl/pull/2843)
- Change `scene.clear` to an observable and make changes in `Scene` Observables trigger renders in GLMakie [#2929](https://github.com/MakieOrg/Makie.jl/pull/2929)

## v0.19.4

Expand Down
2 changes: 1 addition & 1 deletion WGLMakie/src/wglmakie.bundled.js
Expand Up @@ -20243,7 +20243,7 @@ function render_scene(scene, picking = false) {
if (!scene.visible.value) {
return true;
}
renderer.autoClear = scene.clearscene;
renderer.autoClear = scene.clearscene.value;
const area = scene.pixelarea.value;
if (area) {
const [x, y, w, h] = area.map((t)=>t / pixelRatio1);
Expand Down
12 changes: 7 additions & 5 deletions src/scenes.jl
Expand Up @@ -84,7 +84,7 @@ mutable struct Scene <: AbstractScene
px_area::Observable{Rect2i}

"Whether the scene should be cleared."
clear::Bool
clear::Observable{Bool}

"The `Camera` associated with the Scene."
camera::Camera
Expand Down Expand Up @@ -119,7 +119,7 @@ mutable struct Scene <: AbstractScene
parent::Union{Nothing, Scene},
events::Events,
px_area::Observable{Rect2i},
clear::Bool,
clear::Observable{Bool},
camera::Camera,
camera_controls::AbstractCamera,
transformation::Transformation,
Expand Down Expand Up @@ -217,7 +217,7 @@ end
function Scene(;
px_area::Union{Observable{Rect2i}, Nothing} = nothing,
events::Events = Events(),
clear::Union{Automatic, Bool} = automatic,
clear::Union{Automatic, Observable{Bool}, Bool} = automatic,
transform_func=identity,
camera::Union{Function, Camera, Nothing} = nothing,
camera_controls::AbstractCamera = EmptyCamera(),
Expand Down Expand Up @@ -246,7 +246,9 @@ function Scene(;

# if we have an opaque background, automatically set clear to true!
if clear isa Automatic
clear = alpha(bg[]) == 1 ? true : false
clear = Observable(alpha(bg[]) == 1 ? true : false)
else
clear = convert(Observable{Bool}, clear)
end
scene = Scene(
parent, events, px_area, clear, cam, camera_controls,
Expand Down Expand Up @@ -316,7 +318,7 @@ function Scene(
child = Scene(;
events=events,
px_area=child_px_area,
clear=clear,
clear=convert(Observable{Bool}, clear),
camera=camera,
camera_controls=camera_controls,
parent=parent,
Expand Down

0 comments on commit 1a5309b

Please sign in to comment.