Skip to content

Commit

Permalink
fix invisible scenes (MakieOrg#2317)
Browse files Browse the repository at this point in the history
* fix invisible scenes

* add test

* fix other backends
  • Loading branch information
SimonDanisch authored and t-bltg committed Dec 31, 2022
1 parent 1884368 commit cfb4446
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 5 deletions.
3 changes: 2 additions & 1 deletion CairoMakie/src/infrastructure.jl
Expand Up @@ -173,6 +173,7 @@ function cairo_draw(screen::CairoScreen, scene::Scene)
# only prepare for scene when it changes
# this should reduce the number of unnecessary clipping masks etc.
pparent = p.parent::Scene
pparent.visible[] || continue
if pparent != last_scene
Cairo.restore(screen.context)
Cairo.save(screen.context)
Expand Down Expand Up @@ -390,7 +391,7 @@ function Makie.backend_show(x::CairoBackend, io::IO, ::MIME"image/png", scene::S
# while relative line and font sizes are unaffected
px_per_unit = get(io, :px_per_unit, x.px_per_unit)
antialias = get(io, :antialias, x.antialias)

# create an ARGB surface, to speed up drawing ops.
screen = CairoScreen(scene; device_scaling_factor = px_per_unit, antialias = antialias)
cairo_draw(screen, scene)
Expand Down
2 changes: 1 addition & 1 deletion GLMakie/src/rendering.jl
Expand Up @@ -227,7 +227,7 @@ function GLAbstraction.render(filter_elem_func, screen::GLScreen)

found, scene = id2scene(screen, screenid)
found || continue

scene.visible[] || continue
a = pixelarea(scene)[]
glViewport(minimum(a)..., widths(a)...)
if scene.clear
Expand Down
10 changes: 10 additions & 0 deletions ReferenceTests/src/tests/short_tests.jl
Expand Up @@ -222,3 +222,13 @@ end
Colorbar(f[1, 1]; size = 200)
f
end

@reference_test "scene visibility" begin
f, ax, pl = scatter(1:4, markersize=200)
ax2, pl = scatter(f[1, 2][1, 1], 1:4, color=1:4, markersize=200)
ax3, pl = scatter(f[1, 2][2, 1], 1:4, color=1:4, markersize=200)
ax3.scene.visible[] = false
ax2.scene.visible[] = false
ax2.blockscene.visible[] = false
f
end
1 change: 1 addition & 0 deletions WGLMakie/src/serialization.jl
Expand Up @@ -255,6 +255,7 @@ function serialize_scene(scene::Scene, serialized_scenes=[])
else
nothing
end

serialized = Dict(:pixelarea => pixel_area,
:backgroundcolor => lift(hexcolor, scene.backgroundcolor),
:clearscene => scene.clear,
Expand Down
6 changes: 3 additions & 3 deletions WGLMakie/src/wglmakie.js
Expand Up @@ -71,7 +71,7 @@ const WGLMakie = (function () {
0.0, 0.0, 0.0, 1.0
);
const id = new THREE.Uniform(new THREE.Matrix4());

if (plot_data.cam_space == "data") {
plot_data.uniforms.view = cam.view;
plot_data.uniforms.projection = cam.projection;
Expand Down Expand Up @@ -446,7 +446,7 @@ const WGLMakie = (function () {
scene.pixelarea = data.pixelarea;
scene.backgroundcolor = data.backgroundcolor;
scene.clearscene = data.clearscene;

scene.visible = data.visible;
const cam = {
view: new THREE.Uniform(new THREE.Matrix4()),
projection: new THREE.Uniform(new THREE.Matrix4()),
Expand Down Expand Up @@ -599,7 +599,7 @@ const WGLMakie = (function () {
function render_scene(renderer, scene, cam) {
renderer.autoClear = scene.clearscene;
const area = JSServe.get_observable(scene.pixelarea);
if (area) {
if (area && JSServe.get_observable(scene.visible)) {
const [x, y, w, h] = area.map(t => t / pixelRatio);
renderer.setViewport(x, y, w, h);
renderer.setScissor(x, y, w, h);
Expand Down

0 comments on commit cfb4446

Please sign in to comment.