Skip to content

Commit

Permalink
Merge branch 'master' into ff/camera
Browse files Browse the repository at this point in the history
  • Loading branch information
ffreyer committed Jun 12, 2023
2 parents 64f7730 + 5f96457 commit fd9a04d
Show file tree
Hide file tree
Showing 72 changed files with 1,519 additions and 1,206 deletions.
2 changes: 1 addition & 1 deletion CITATION.bib
Expand Up @@ -7,6 +7,6 @@ @article{DanischKrumbiegel2021
number = {65},
pages = {3349},
author = {Simon Danisch and Julius Krumbiegel},
title = {Makie.jl: Flexible high-performance data visualization for Julia},
title = {{Makie.jl}: Flexible high-performance data visualization for {Julia}},
journal = {Journal of Open Source Software}
}
8 changes: 4 additions & 4 deletions CairoMakie/Project.toml
@@ -1,7 +1,7 @@
name = "CairoMakie"
uuid = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
author = ["Simon Danisch <sdanisch@gmail.com>"]
version = "0.10.4"
version = "0.10.6"

[deps]
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
Expand All @@ -14,7 +14,7 @@ GeometryBasics = "5c1252a2-5f33-56bf-86c9-59e7332b4326"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
SHA = "ea8e919c-243c-51af-8825-aaa63cd721ce"
SnoopPrecompile = "66db9d55-30c0-4569-8b51-7e840670fc0c"
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"

[compat]
Cairo = "1.0.4"
Expand All @@ -23,8 +23,8 @@ FFTW = "1"
FileIO = "1.1"
FreeType = "3, 4.0"
GeometryBasics = "0.4.1"
Makie = "=0.19.4"
SnoopPrecompile = "1.0"
Makie = "=0.19.6"
PrecompileTools = "1.0"
julia = "1.3"

[extras]
Expand Down
8 changes: 5 additions & 3 deletions CairoMakie/src/overrides.jl
Expand Up @@ -66,7 +66,6 @@ end

draw_poly(scene::Scene, screen::Screen, poly, rect::Rect2) = draw_poly(scene, screen, poly, [rect])


function draw_poly(scene::Scene, screen::Screen, poly, rects::Vector{<:Rect2})
model = poly.model[]
space = to_value(get(poly, :space, :data))
Expand All @@ -87,16 +86,19 @@ end

function polypath(ctx, polygon)
ext = decompose(Point2f, polygon.exterior)
Cairo.set_fill_type(ctx, Cairo.CAIRO_FILL_RULE_EVEN_ODD)
Cairo.move_to(ctx, ext[1]...)
for point in ext[2:end]
Cairo.line_to(ctx, point...)
end
Cairo.close_path(ctx)

interiors = decompose.(Point2f, polygon.interiors)
for interior in interiors
# Cairo needs to have interiors counter clockwise
n = length(interior)
Cairo.move_to(ctx, interior[1]...)
for point in interior[2:end]
for idx in 2:n
point = interior[idx]
Cairo.line_to(ctx, point...)
end
Cairo.close_path(ctx)
Expand Down
4 changes: 2 additions & 2 deletions CairoMakie/src/precompiles.jl
@@ -1,4 +1,4 @@
using SnoopPrecompile
using PrecompileTools

macro compile(block)
return quote
Expand All @@ -8,7 +8,7 @@ macro compile(block)
end

let
@precompile_all_calls begin
@compile_workload begin
CairoMakie.activate!()
base_path = normpath(joinpath(dirname(pathof(Makie)), "..", "precompile"))
shared_precompile = joinpath(base_path, "shared-precompile.jl")
Expand Down
2 changes: 1 addition & 1 deletion CairoMakie/src/screen.jl
Expand Up @@ -98,7 +98,7 @@ function device_scaling_factor(surface::Cairo.CairoSurface, sc::ScreenConfig)
return is_vector_backend(surface) ? sc.pt_per_unit : sc.px_per_unit
end

const LAST_INLINE = Ref(true)
const LAST_INLINE = Ref{Union{Makie.Automatic,Bool}}(Makie.automatic)

"""
CairoMakie.activate!(; screen_config...)
Expand Down
8 changes: 4 additions & 4 deletions GLMakie/Project.toml
@@ -1,6 +1,6 @@
name = "GLMakie"
uuid = "e9467ef8-e4e7-5192-8a1a-b1aee30e663a"
version = "0.8.4"
version = "0.8.6"

[deps]
ColorTypes = "3da002f7-5984-5a60-b8a6-cbb66c0b333f"
Expand All @@ -18,7 +18,7 @@ ModernGL = "66fc600b-dfda-50eb-8b99-91cfa97b1301"
Observables = "510215fc-4207-5dde-b226-833fc4488ee2"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
ShaderAbstractions = "65257c39-d410-5151-9873-9b3e5be5013e"
SnoopPrecompile = "66db9d55-30c0-4569-8b51-7e840670fc0c"
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"

[compat]
Expand All @@ -29,11 +29,11 @@ FixedPointNumbers = "0.7, 0.8"
FreeTypeAbstraction = "0.10"
GLFW = "3"
GeometryBasics = "0.4.1"
Makie = "=0.19.4"
Makie = "=0.19.6"
MeshIO = "0.4"
ModernGL = "1"
Observables = "0.5.1"
ShaderAbstractions = "0.3"
SnoopPrecompile = "1.0"
PrecompileTools = "1.0"
StaticArrays = "0.12, 1.0"
julia = "1"
2 changes: 1 addition & 1 deletion GLMakie/assets/shader/distance_shape.frag
Expand Up @@ -138,7 +138,7 @@ void main(){
else if(shape == ROUNDED_RECTANGLE)
signed_distance = rounded_rectangle(f_uv, vec2(0.2), vec2(0.8));
else if(shape == RECTANGLE)
signed_distance = 1.0; // rectangle(f_uv);
signed_distance = rectangle(f_uv);
else if(shape == TRIANGLE)
signed_distance = triangle(f_uv);

Expand Down
21 changes: 15 additions & 6 deletions GLMakie/assets/shader/lines.geom
Expand Up @@ -55,7 +55,8 @@ void emit_vertex(vec3 position, vec2 uv, int index)
f_color = g_color[index];
gl_Position = vec4((position.xy / resolution), position.z, 1.0);
f_id = g_id[index];
f_thickness = g_thickness[index];
// linewidth scaling may shrink the effective linewidth
f_thickness = abs(uv.y) - AA_THICKNESS;
EmitVertex();
}

Expand All @@ -77,7 +78,7 @@ void emit_vertex(vec3 position, vec2 uv, int index, vec4 color)
f_color = color;
gl_Position = vec4((position.xy / resolution), position.z, 1.0);
f_id = g_id[index];
f_thickness = g_thickness[index];
f_thickness = abs(uv.y) - AA_THICKNESS;
EmitVertex();
}
void emit_vertex(vec3 position, vec2 uv, vec4 color)
Expand Down Expand Up @@ -618,10 +619,6 @@ void draw_solid_line(bool isvalid[4])
vec3 p2 = screen_space(gl_in[2].gl_Position); // end of current segment, start of next segment
vec3 p3 = screen_space(gl_in[3].gl_Position); // end of next segment

// linewidth with padding for anti aliasing
float thickness_aa1 = g_thickness[1] + AA_THICKNESS;
float thickness_aa2 = g_thickness[2] + AA_THICKNESS;

// determine the direction of each of the 3 segments (previous, current, next)
vec3 v1 = p2 - p1;
float segment_length = length(v1.xy);
Expand All @@ -641,6 +638,14 @@ void draw_solid_line(bool isvalid[4])
vec2 n1 = vec2(-v1.y, v1.x);
vec2 n2 = vec2(-v2.y, v2.x);

// determine stretching of AA border due to linewidth change
float temp = (g_thickness[2] - g_thickness[1]) / segment_length;
float edge_scale = sqrt(1 + temp * temp);

// linewidth with padding for anti aliasing (used for geometry)
float thickness_aa1 = g_thickness[1] + edge_scale * AA_THICKNESS;
float thickness_aa2 = g_thickness[2] + edge_scale * AA_THICKNESS;

// Setup for sharp corners (see above)
vec2 miter_a = normalize(n0 + n1);
vec2 miter_b = normalize(n1 + n2);
Expand Down Expand Up @@ -717,6 +722,10 @@ void draw_solid_line(bool isvalid[4])
segment_length += corner_offset;
}

// scaling of uv.y due to different linewidths
// the padding for AA_THICKNESS should always have AA_THICKNESS width in uv
thickness_aa1 = g_thickness[1] / edge_scale + AA_THICKNESS;
thickness_aa2 = g_thickness[2] / edge_scale + AA_THICKNESS;

// Generate line segment
u1 *= px2uv;
Expand Down
6 changes: 1 addition & 5 deletions GLMakie/assets/shader/sprites.geom
Expand Up @@ -164,11 +164,7 @@ void main(void)
// Compute required amount of buffering
float sprite_from_viewport_scale = 1.0 / viewport_from_sprite_scale;
float bbox_buf = sprite_from_viewport_scale *
(// Hack!! antialiasing is disabled for RECTANGLE==1 for now
// because it's used for boxplots where the sprites are
// long and skinny (violating assumption 1 above)
(shape == 1 ? 0.0 : ANTIALIAS_RADIUS) +
max(glow_width, 0) + max(stroke_width, 0));
(ANTIALIAS_RADIUS + max(glow_width, 0) + max(stroke_width, 0));
// Compute xy bounding box of billboard (in model space units) after
// buffering and associated bounding box of uv coordinates.
vec2 bbox_radius_buf = bbox_signed_radius + sign(bbox_signed_radius)*bbox_buf;
Expand Down
71 changes: 64 additions & 7 deletions GLMakie/experiments/cuda_interop.jl
@@ -1,11 +1,68 @@
using CUDA, GLMakie
using CUDA, GLMakie, NVTX
using GLMakie.GLAbstraction
# from https://discourse.julialang.org/t/cuarray-glmakie/52461/11?u=maleadt

function cu_plot(; T=Float32, N=1024, resolution=(800, 600))
t = CUDA.rand(T, N)
X = CUDA.rand(T, N)

scene = scatter(rand(Point2f, 10_000), show_axis=false)
screen = display(scene)
# so that we can create a GLBuffer before having rendered anything.
fig = Figure(; resolution)
ax = Axis(fig[1, 1]; limits=(0, 1, 0, 1))
screen = display(fig)

buffer = screen.renderlist[1][3][:position]
resource =
cuGraphicsGLRegisterBuffer(&resource, pbo, cudaGraphicsRegisterFlagsReadOnly)
# get a buffer object and register it with CUDA
buffer = GLAbstraction.GLBuffer(Point2f, N)
resource = let
ref = Ref{CUDA.CUgraphicsResource}()
CUDA.cuGraphicsGLRegisterBuffer(ref, buffer.id,
CUDA.CU_GRAPHICS_MAP_RESOURCE_FLAGS_WRITE_DISCARD)
ref[]
end

CUDA.cuGraphicsMapResources
NVTX.@range "main" begin
# process data, generate points
NVTX.@range "CUDA" begin
# map OpenGL buffer object for writing from CUDA
CUDA.cuGraphicsMapResources(1, [resource], stream())

# get a CuArray object that we can work with
array = let
ptr_ref = Ref{CUDA.CUdeviceptr}()
numbytes_ref = Ref{Csize_t}()
CUDA.cuGraphicsResourceGetMappedPointer_v2(ptr_ref, numbytes_ref, resource)

ptr = reinterpret(CuPtr{Point2f}, ptr_ref[])
len = Int(numbytes_ref[] ÷ sizeof(Point2f))

unsafe_wrap(CuArray, ptr, len)
end

# generate points
broadcast!(array, t, X) do x, y
return Point2f(x, y)
end

# wait for the GPU to finish
synchronize()

CUDA.cuGraphicsUnmapResources(1, [resource], stream())
end

# generate and render plot
NVTX.@range "Makie" begin
scatter!(ax, buffer)
# force everything to render (for benchmarking purposes)
GLMakie.render_frame(screen; resize_buffers=false)
GLMakie.glFinish()
end
end

## clean-up

CUDA.cuGraphicsUnregisterResource(resource)

return
end

cu_plot()
8 changes: 4 additions & 4 deletions GLMakie/src/precompiles.jl
@@ -1,4 +1,4 @@
using SnoopPrecompile
using PrecompileTools

macro compile(block)
return quote
Expand All @@ -11,9 +11,9 @@ macro compile(block)
end

let
@precompile_setup begin
@setup_workload begin
x = rand(5)
@precompile_all_calls begin
@compile_workload begin
GLMakie.activate!()
screen = GLMakie.singleton_screen(false)
close(screen)
Expand All @@ -25,7 +25,7 @@ let
display(plot(x); visible=false)
catch
end
Makie._current_figure[] = nothing
Makie.CURRENT_FIGURE[] = nothing
empty!(atlas_texture_cache)
closeall()
@assert isempty(SCREEN_REUSE_POOL)
Expand Down
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
12 changes: 9 additions & 3 deletions GLMakie/src/screen.jl
Expand Up @@ -106,7 +106,7 @@ mutable struct ScreenConfig
end
end

const LAST_INLINE = Ref(false)
const LAST_INLINE = Ref{Union{Makie.Automatic, Bool}}(Makie.automatic)

"""
GLMakie.activate!(; screen_config...)
Expand Down 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 Expand Up @@ -646,7 +652,7 @@ end
"""
depthbuffer(screen::Screen)
Gets the depth buffer of `screen`. Returns a `Matrix{Float32}` of the dimensions of the screen's `framebuffer`.
Gets the depth buffer of `screen`. Returns a `Matrix{Float32}` of the dimensions of the screen's `framebuffer`.
A depth buffer is used to determine which plot's contents should be shown at each pixel.
Usage:
Expand Down
27 changes: 23 additions & 4 deletions NEWS.md
Expand Up @@ -4,8 +4,27 @@

- Improvements to 3D camera handling, hotkeys and functionality [#2746](https://github.com/MakieOrg/Makie.jl/pull/2746)
- Fixed some errors/problems with DataInspector [#2746](https://github.com/MakieOrg/Makie.jl/pull/2746)
- 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)

## v0.19.6

- Fix broken AA for lines with strongly varying linewidth [#2953](https://github.com/MakieOrg/Makie.jl/pull/2953).
- Fix WGLMakie JS popup [#2976](https://github.com/MakieOrg/Makie.jl/pull/2976).
- Fix legendelements when children have no elements [#2982](https://github.com/MakieOrg/Makie.jl/pull/2982).
- Bump compat for StatsBase to 0.34 [#2915](https://github.com/MakieOrg/Makie.jl/pull/2915).
- Improved thread safety [#2840](https://github.com/MakieOrg/Makie.jl/pull/2840).

## v0.19.5

- Add `loop` option for GIF outputs when recording videos with `record` [#2891](https://github.com/MakieOrg/Makie.jl/pull/2891).
- More fixes for line rendering 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).
- Added contour labels [#2496](https://github.com/MakieOrg/Makie.jl/pull/2496).
- Allow rich text to be used in Legends [#2902](https://github.com/MakieOrg/Makie.jl/pull/2902).
- More support for zero length Geometries [#2917](https://github.com/MakieOrg/Makie.jl/pull/2917).
- Make CairoMakie drawing for polygons with holes order independent [#2918](https://github.com/MakieOrg/Makie.jl/pull/2918).
- Fixes for `Makie.inline!()`, allowing now for `Makie.inline!(automatic)` (default), which is better at automatically opening a window/ inlining a plot into plotpane when needed [#2919](https://github.com/MakieOrg/Makie.jl/pull/2919) [#2937](https://github.com/MakieOrg/Makie.jl/pull/2937).
- Block/Axis doc improvements [#2940](https://github.com/MakieOrg/Makie.jl/pull/2940) [#2932](https://github.com/MakieOrg/Makie.jl/pull/2932) [#2894](https://github.com/MakieOrg/Makie.jl/pull/2894).

## v0.19.4

Expand Down Expand Up @@ -35,9 +54,9 @@
- Add `show_data` method for `band` which shows the min and max values of the band at the x position of the cursor [#2497](https://github.com/MakieOrg/Makie.jl/pull/2497).
- Added `xlabelrotation`, `ylabelrotation` (`Axis`) and `labelrotation` (`Colorbar`) [#2478](https://github.com/MakieOrg/Makie.jl/pull/2478).
- Fixed forced rasterization in CairoMakie svg files when polygons with colors specified as (color, alpha) tuples were used [#2535](https://github.com/MakieOrg/Makie.jl/pull/2535).
- Do less copies of Observables in Attributes + plot pipeline [#2443](https://github.com/MakieOrg/Makie.jl/pull/2443).
- Do less copies of Observables in Attributes + plot pipeline [#2443](https://github.com/MakieOrg/Makie.jl/pull/2443).
- Add Search Page and tweak Result Ordering [#2474](https://github.com/MakieOrg/Makie.jl/pull/2474).
- Remove all global attributes from TextureAtlas implementation and fix julia#master [#2498](https://github.com/MakieOrg/Makie.jl/pull/2498).
- Remove all global attributes from TextureAtlas implementation and fix julia#master [#2498](https://github.com/MakieOrg/Makie.jl/pull/2498).
- Use new JSServe, implement WGLMakie picking, improve performance and fix lots of WGLMakie bugs [#2428](https://github.com/MakieOrg/Makie.jl/pull/2428).

## v0.19.0
Expand Down

0 comments on commit fd9a04d

Please sign in to comment.