diff --git a/GLMakie/src/picking.jl b/GLMakie/src/picking.jl index d83c4d6f9d2..2adda1a2137 100644 --- a/GLMakie/src/picking.jl +++ b/GLMakie/src/picking.jl @@ -7,6 +7,7 @@ function pick_native(screen::Screen, rect::Rect2i) isopen(screen) || return Matrix{SelectionID{Int}}(undef, 0, 0) ShaderAbstractions.switch_context!(screen.glscreen) window_size = size(screen) + sf = screen.px_per_unit[] fb = screen.framebuffer buff = fb.buffers[:objectid] glBindFramebuffer(GL_FRAMEBUFFER, fb.id[1]) @@ -14,8 +15,9 @@ function pick_native(screen::Screen, rect::Rect2i) rx, ry = minimum(rect) rw, rh = widths(rect) w, h = window_size - sid = zeros(SelectionID{UInt32}, widths(rect)...) if rx > 0 && ry > 0 && rx + rw <= w && ry + rh <= h + rx, ry, rw, rh = round.(Int, sf .* (rx, ry, rw, rh)) + sid = zeros(SelectionID{UInt32}, rw, rh) glReadPixels(rx, ry, rw, rh, buff.format, buff.pixeltype, sid) return sid else @@ -26,8 +28,8 @@ end function pick_native(screen::Screen, xy::Vec{2, Float64}) isopen(screen) || return SelectionID{Int}(0, 0) ShaderAbstractions.switch_context!(screen.glscreen) - sid = Base.RefValue{SelectionID{UInt32}}() window_size = size(screen) + sf = screen.px_per_unit[] fb = screen.framebuffer buff = fb.buffers[:objectid] glBindFramebuffer(GL_FRAMEBUFFER, fb.id[1]) @@ -35,6 +37,8 @@ function pick_native(screen::Screen, xy::Vec{2, Float64}) x, y = floor.(Int, xy) w, h = window_size if x > 0 && y > 0 && x <= w && y <= h + sid = Base.RefValue{SelectionID{UInt32}}() + x, y = round.(Int, sf .* (x, y)) glReadPixels(x, y, 1, 1, buff.format, buff.pixeltype, sid) return convert(SelectionID{Int}, sid[]) end