Skip to content

Commit

Permalink
Improve CairoMakie's 2D mesh performance (#4132)
Browse files Browse the repository at this point in the history
* Remove splats in draw_mesh2d inner loop

This also restores parity in the loop body with `draw_mesh3d`.

* Squash point type instability in project_position

This shaves ~20% runtime from mesh2d

* Fix types in function signature

* Add changelog entry

---------

Co-authored-by: Simon <sdanisch@protonmail.com>
Co-authored-by: Frederic Freyer <frederic481994@hotmail.de>
  • Loading branch information
3 people authored Oct 22, 2024
1 parent 49b29b6 commit e3c7521
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## [Unreleased]

- Improved CairoMakie's 2D mesh drawing performance by ~30% [#4132](https://github.com/MakieOrg/Makie.jl/pull/4132).
- Allow `width` to be set per box in `boxplot` [#4447](https://github.com/MakieOrg/Makie.jl/pull/4447).
- For `Textbox`es in which a fixed width is specified, the text is now scrolled
if the width is exceeded [#4293](https://github.com/MakieOrg/Makie.jl/pull/4293)
Expand Down
10 changes: 5 additions & 5 deletions CairoMakie/src/primitives.jl
Original file line number Diff line number Diff line change
Expand Up @@ -908,11 +908,11 @@ function draw_atomic(scene::Scene, screen::Screen, @nospecialize(primitive::Maki
return nothing
end

function draw_mesh2D(scene, screen, @nospecialize(plot), @nospecialize(mesh))
function draw_mesh2D(scene, screen, @nospecialize(plot::Makie.Mesh), @nospecialize(mesh::GeometryBasics.Mesh))
space = to_value(get(plot, :space, :data))::Symbol
transform_func = Makie.transform_func(plot)
model = plot.model[]::Mat4d
vs = project_position(scene, transform_func, space, decompose(Point, mesh), model)
vs = project_position(scene, transform_func, space, GeometryBasics.metafree(GeometryBasics.coordinates(mesh)), model)::Vector{Point2f}
fs = decompose(GLTriangleFace, mesh)::Vector{GLTriangleFace}
uv = decompose_uv(mesh)::Union{Nothing, Vector{Vec2f}}
# Note: This assume the function is only called from mesh plots
Expand Down Expand Up @@ -943,9 +943,9 @@ function draw_mesh2D(screen, per_face_cols, vs::Vector{<: Point2}, fs::Vector{GL

Cairo.mesh_pattern_begin_patch(pattern)

Cairo.mesh_pattern_move_to(pattern, t1...)
Cairo.mesh_pattern_line_to(pattern, t2...)
Cairo.mesh_pattern_line_to(pattern, t3...)
Cairo.mesh_pattern_move_to(pattern, t1[1], t1[2])
Cairo.mesh_pattern_line_to(pattern, t2[1], t2[2])
Cairo.mesh_pattern_line_to(pattern, t3[1], t3[2])

mesh_pattern_set_corner_color(pattern, 0, c1)
mesh_pattern_set_corner_color(pattern, 1, c2)
Expand Down

0 comments on commit e3c7521

Please sign in to comment.