Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow CairoMakie to use GLMakie to rasterize plots #2061

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

asinghvi17
Copy link
Member

Description

Using @jkrumbiegel's proposed alpha-colorbuffer by comparing the same scene with white v/s black background, we can obtain an image with transparency from GLMakie.

Basically, this is intended to use the same idea as the previously implemented rasterize feature, but instead of rendering to an image using Cairo, it renders using a given backend (usually GLMakie). This means that complex 3D plots like volumes or complicated meshes can be rendered (a) more efficiently and (b) more accurately (using features like depth buffering) if the user wishes it. However, line widths, marker sizes and text sizes are all reduced by 1/scale, because there is no change to pixel space. This could theoretically be addressed by going down to the atomic level and changing plots around, but that seems somewhat unsustainable. It could be an optional feature, though.

One could also render entire Scenes in order to obtain true 3d rendering.

The syntax for the plot rendering is rasterize = (backend::Module, scale::Int). backend must define an activate!() method. It's not the best interface right now, but I suppose that would have to wait until the display stack gets refactored, so that we could just cache a screen instead.

Internally, this works by manually creating a new Scene of resolution widths(pixelarea(scene)[]) .* scale), whose camera and transformation are then overridden.

Note that this is still a very experimental feature, and I haven't updated the code for the new GLMakie multi-screen feature yet.

@MakieBot
Copy link
Collaborator

MakieBot commented Jun 16, 2022

Compile Times benchmark

Note, that these numbers may fluctuate on the CI servers, so take them with a grain of salt. All benchmark results are based on the mean time and negative percent mean faster than master. Note, that GLMakie + WGLMakie run on an emulated GPU, so the runtime benchmark is much slower. Results are from running:

using_time = @ctime using Backend
# Compile time
create_time = @ctime fig = scatter(1:4; color=1:4, colormap=:turbo, markersize=20, visible=true)
display_time = @ctime Makie.colorbuffer(display(fig))
# Runtime
create_time = @benchmark fig = scatter(1:4; color=1:4, colormap=:turbo, markersize=20, visible=true)
display_time = @benchmark Makie.colorbuffer(display(fig))
using create display create display
GLMakie 33.77s (33.17, 34.72) 0.54+- 17.66s (17.24, 18.34) 0.47+- 16.55s (15.96, 17.41) 0.59+- 11.12ms (10.86, 11.51) 0.22+- 147.71ms (141.34, 151.92) 3.29+-
master 33.91s (33.16, 35.00) 0.76+- 18.01s (17.36, 18.41) 0.37+- 16.73s (16.08, 17.12) 0.38+- 11.15ms (10.96, 11.49) 0.20+- 149.49ms (141.84, 153.13) 3.76+-
evaluation -0.43%, -0.14s invariant (-0.22d, 0.69p, 0.65std) -1.97%, -0.35s invariant (-0.83d, 0.15p, 0.42std) -1.08%, -0.18s invariant (-0.36d, 0.52p, 0.48std) -0.24%, -0.03ms invariant (-0.13d, 0.82p, 0.21std) -1.21%, -1.78ms invariant (-0.51d, 0.36p, 3.53std)
CairoMakie 9.95s (9.88, 10.02) 0.05+- 25.91s (25.59, 26.15) 0.18+- 3.82s (3.80, 3.84) 0.02+- 19.18ms (18.79, 19.36) 0.20+- 26.71ms (26.44, 27.11) 0.21+-
master 9.93s (9.82, 9.99) 0.06+- 25.94s (25.77, 26.10) 0.14+- 4.00s (3.98, 4.04) 0.03+- 19.71ms (19.54, 19.96) 0.14+- 26.73ms (26.60, 26.88) 0.11+-
evaluation +0.13%, 0.01s invariant (0.24d, 0.66p, 0.05std) -0.09%, -0.02s invariant (-0.15d, 0.79p, 0.16std) -4.61%, -0.18s invariant (-8.26d, 0.00p, 0.02std) -2.78%, -0.53ms invariant (-3.14d, 0.00p, 0.17std) -0.08%, -0.02ms invariant (-0.14d, 0.80p, 0.16std)
WGLMakie 37.96s (37.19, 38.33) 0.41+- 20.24s (19.71, 20.86) 0.41+- 21.80s (21.25, 22.42) 0.48+- 13.69ms (13.12, 14.75) 0.55+- 1.73s (1.68, 1.81) 0.05+-
master 38.06s (37.44, 38.47) 0.34+- 20.20s (19.63, 20.67) 0.44+- 21.92s (21.14, 22.56) 0.56+- 13.29ms (12.07, 13.84) 0.64+- 1.69s (1.65, 1.73) 0.03+-
evaluation -0.27%, -0.1s invariant (-0.27d, 0.62p, 0.37std) +0.16%, 0.03s invariant (0.08d, 0.89p, 0.43std) -0.54%, -0.12s invariant (-0.23d, 0.68p, 0.52std) +2.92%, 0.4ms invariant (0.67d, 0.24p, 0.60std) +2.35%, 0.04s invariant (1.03d, 0.09p, 0.04std)

@asinghvi17
Copy link
Member Author

This will have to wait for #2544, because it otherwise has scaling issues. However, if that is merged, this should be smooth sailing!

@asinghvi17
Copy link
Member Author

This branch is pretty outdated, I have another one which is based off the GL-hidpi branch which might give us some better results.

The central issue there is that scenes in a tree share events, so if I display a non-root scene in a different window, that window area propagates to the root scene, which causes a loop of resizing which makes the scene smaller until it reaches 1x1px.

We could fix this by having some mechanism (standardized kwarg to Screen?) to not attach events to the scene when displayed through a Screen, or similar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants