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

remove static arrays #1697

Merged
merged 10 commits into from
Mar 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions CairoMakie/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ GeometryBasics = "5c1252a2-5f33-56bf-86c9-59e7332b4326"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
SHA = "ea8e919c-243c-51af-8825-aaa63cd721ce"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"

[compat]
Cairo = "1.0.4"
Expand All @@ -24,7 +23,6 @@ FileIO = "1.1"
FreeType = "3, 4.0"
GeometryBasics = "0.4.1"
Makie = "=0.16.5"
StaticArrays = "0.12, 1.0"
julia = "1.3"

[extras]
Expand Down
2 changes: 1 addition & 1 deletion CairoMakie/src/CairoMakie.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module CairoMakie

using Makie, LinearAlgebra
using Colors, GeometryBasics, FileIO, StaticArrays
using Colors, GeometryBasics, FileIO
import SHA
import Base64
import Cairo
Expand Down
24 changes: 12 additions & 12 deletions CairoMakie/src/primitives.jl
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ end

function p3_to_p2(p::Point3{T}) where T
if p[3] == 0 || isnan(p[3])
Point2{T}(p[1:2]...)
Point2{T}(p[Vec(1,2)]...)
else
error("Can't reduce Point3 to Point2 with nonzero third component $(p[3]).")
end
Expand All @@ -333,7 +333,7 @@ end

function draw_glyph_collection(
scene, ctx, positions, glyph_collections::AbstractArray, rotation,
model::SMatrix, space, markerspace, offset
model::Mat, space, markerspace, offset
)

# TODO: why is the Ref around model necessary? doesn't broadcast_foreach handle staticarrays matrices?
Expand Down Expand Up @@ -377,7 +377,7 @@ function draw_glyph_collection(scene, ctx, position, glyph_collection, rotation,

# offsets and scale apply in markerspace
glyph_pos = s2ms * to_ndim(Point4f, to_ndim(Point3f, position, 0), 1)
gp3 = glyph_pos[SOneTo(3)] ./ glyph_pos[4] .+ glyphoffset .+ p3_offset
gp3 = glyph_pos[Vec(1, 2, 3)] ./ glyph_pos[4] .+ glyphoffset .+ p3_offset

scale3 = scale isa Number ? Point3f(scale, scale, 0) : to_ndim(Point3f, scale, 0)

Expand Down Expand Up @@ -663,16 +663,16 @@ function draw_mesh3D(
@get_attribute(primitive, (color, shading, diffuse,
specular, shininess, faceculling))

colormap = get(primitive, :colormap, nothing) |> to_value |> to_colormap
colorrange = get(primitive, :colorrange, nothing) |> to_value
matcap = get(primitive, :matcap, nothing) |> to_value
colormap = to_colormap(to_value(get(primitive, :colormap, nothing)))
colorrange = to_value(get(primitive, :colorrange, nothing))
matcap = to_value(get(primitive, :matcap, nothing))
# Priorize colors of the mesh if present
color = hasproperty(mesh, :color) ? mesh.color : color

ctx = screen.context

model = primitive.model[]
space = to_value(get(primitive, :space, :data))
space = to_value(get(primitive, :space, :data))::Symbol
view = ifelse(is_data_space(space), scene.camera.view[], Mat4f(I))
projection = Makie.space_to_clip(scene.camera, space, false)
i = Vec(1, 2, 3)
Expand All @@ -694,9 +694,9 @@ function draw_mesh3D(
ns = map(n -> normalize(normalmatrix * n), decompose_normals(mesh))
cols = per_face_colors(
color, colormap, colorrange, matcap, vs, fs, ns, uv,
get(primitive, :lowclip, nothing) |> to_value |> color_or_nothing,
get(primitive, :highclip, nothing) |> to_value |> color_or_nothing,
get(primitive, :nan_color, nothing) |> to_value |> color_or_nothing
color_or_nothing(to_value(get(primitive, :lowclip, nothing))) ,
color_or_nothing(to_value(get(primitive, :highclip, nothing))) ,
color_or_nothing(to_value(get(primitive, :nan_color, nothing)))
)

# Liight math happens in view/camera space
Expand All @@ -723,7 +723,7 @@ function draw_mesh3D(
@inbounds begin
p = (clip ./ clip[4])[Vec(1, 2)]
p_yflip = Vec2f(p[1], -p[2])
p_0_to_1 = (p_yflip .+ 1f0) / 2f0
p_0_to_1 = (p_yflip .+ 1f0) ./ 2f0
end
p = p_0_to_1 .* scene.camera.resolution[]
return Vec3f(p[1], p[2], clip[3])
Expand All @@ -745,7 +745,7 @@ function draw_mesh3D(
map(ns[f], vs[f], cols[k]) do N, v, c
L = normalize(lightpos .- v[Vec(1,2,3)])
diff_coeff = max(dot(L, N), 0.0)
H = normalize(L + normalize(-v[SOneTo(3)]))
H = normalize(L + normalize(-v[Vec(1, 2, 3)]))
spec_coeff = max(dot(H, N), 0.0)^shininess
c = RGBA(c)
new_c = (ambient .+ diff_coeff .* diffuse) .* Vec3f(c.r, c.g, c.b) .+
Expand Down
4 changes: 2 additions & 2 deletions CairoMakie/src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function project_position(scene, space, point, model, yflip = true)
# flip y to match cairo
p_yflip = Vec2f(p[1], (1f0 - 2f0 * yflip) * p[2])
# normalize to between 0 and 1
p_0_to_1 = (p_yflip .+ 1f0) / 2f0
p_0_to_1 = (p_yflip .+ 1f0) ./ 2f0
end
# multiply with scene resolution for final position
return p_0_to_1 .* res
Expand Down Expand Up @@ -199,7 +199,7 @@ Base.getindex(fi::FaceIterator{:PerFace}, i::Integer) = fi.data[i]
Base.getindex(fi::FaceIterator{:PerVert}, i::Integer) = fi.data[fi.faces[i]]
Base.getindex(fi::FaceIterator{:Const}, i::Integer) = ntuple(i-> fi.data, 3)

color_or_nothing(c) = c === nothing ? nothing : to_color(c)
color_or_nothing(c) = isnothing(c) ? nothing : to_color(c)

function per_face_colors(
color, colormap, colorrange, matcap, vertices, faces, normals, uv,
Expand Down
7 changes: 1 addition & 6 deletions GLMakie/src/GLAbstraction/GLAbstraction.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module GLAbstraction

using StaticArrays
using GeometryBasics
using ModernGL
using Makie
Expand All @@ -12,6 +11,7 @@ using LinearAlgebra
using Observables
using ShaderAbstractions
using ShaderAbstractions: current_context, is_context_active, context_alive
using GeometryBasics: StaticVector

import FixedPointNumbers: N0f8, N0f16, N0f8, Normed

Expand Down Expand Up @@ -100,9 +100,4 @@ export getUniformsInfo
export getProgramInfo
export getAttributesInfo

if Base.VERSION >= v"1.4.2"
include("precompile.jl")
_precompile_()
end

end # module
18 changes: 9 additions & 9 deletions GLMakie/src/GLAbstraction/GLUniforms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

const GLSL_COMPATIBLE_NUMBER_TYPES = (GLfloat, GLint, GLuint, GLdouble)
const NATIVE_TYPES = Union{
StaticArray, GLSL_COMPATIBLE_NUMBER_TYPES...,
StaticVector, Mat, GLSL_COMPATIBLE_NUMBER_TYPES...,
ZeroIndex{GLint}, ZeroIndex{GLuint},
GLBuffer, GPUArray, Shader, GLProgram
}
Expand Down Expand Up @@ -33,7 +33,7 @@ function uniformfunc(typ::DataType, dims::Tuple{Int, Int})
Symbol(string("glUniformMatrix", M == N ? "$M" : "$(M)x$(N)", opengl_postfix(typ)))
end

function gluniform(location::Integer, x::FSA) where FSA <: Union{StaticArray, Colorant}
function gluniform(location::Integer, x::Union{StaticVector, Mat, Colorant})
xref = [x]
gluniform(location, xref)
end
Expand All @@ -44,7 +44,7 @@ _size(p::Type{T}) where {T <: Colorant} = (length(p),)
_ndims(p) = ndims(p)
_ndims(p::Type{T}) where {T <: Colorant} = 1

@generated function gluniform(location::Integer, x::Vector{FSA}) where FSA <: Union{StaticArray, Colorant}
@generated function gluniform(location::Integer, x::Vector{FSA}) where FSA <: Union{Mat, Colorant, StaticVector}
func = uniformfunc(eltype(FSA), _size(FSA))
callexpr = if _ndims(FSA) == 2
:($func(location, length(x), GL_FALSE, x))
Expand Down Expand Up @@ -101,12 +101,12 @@ function glsl_typename(t::Texture{T, D}) where {T, D}
str
end

function glsl_typename(t::Type{T}) where T <: SMatrix
function glsl_typename(t::Type{T}) where T <: Mat
M, N = size(t)
string(opengl_prefix(eltype(t)), "mat", M==N ? M : string(M, "x", N))
end
toglsltype_string(t::Observable) = toglsltype_string(to_value(t))
toglsltype_string(x::T) where {T<:Union{Real, StaticArray, Texture, Colorant, TextureBuffer, Nothing}} = "uniform $(glsl_typename(x))"
toglsltype_string(x::T) where {T<:Union{Real, Mat, StaticVector, Texture, Colorant, TextureBuffer, Nothing}} = "uniform $(glsl_typename(x))"
#Handle GLSL structs, which need to be addressed via single fields
function toglsltype_string(x::T) where T
if isa_gl_struct(x)
Expand All @@ -124,7 +124,7 @@ function glsl_variable_access(keystring, t::Texture{T, D}) where {T,D}
end
return string("getindex(", keystring, "index).", fields, ";")
end
function glsl_variable_access(keystring, ::Union{Real, GLBuffer, GPUVector, StaticArray, Colorant})
function glsl_variable_access(keystring, ::Union{Real, GLBuffer, GPUVector, Mat, Colorant})
string(keystring, ";")
end
function glsl_variable_access(keystring, s::Observable)
Expand Down Expand Up @@ -183,8 +183,8 @@ gl_promote(x::Type{T}) where {T <: Color4} = RGBA{gl_promote(eltype(T))}
gl_promote(x::Type{T}) where {T <: BGRA} = BGRA{gl_promote(eltype(T))}
gl_promote(x::Type{T}) where {T <: BGR} = BGR{gl_promote(eltype(T))}


gl_promote(x::Type{T}) where {T <: StaticVector} = similar_type(T, gl_promote(eltype(T)))
gl_promote(x::Type{Vec{N, T}}) where {N, T} = Vec{N, gl_promote(T)}
gl_promote(x::Type{Point{N, T}}) where {N, T} = Point{N, gl_promote(T)}

gl_convert(x::AbstractVector{Vec3f}) = x

Expand Down Expand Up @@ -225,7 +225,7 @@ gl_convert(a::T) where {T <: NATIVE_TYPES} = a
gl_convert(s::Observable{T}) where {T <: NATIVE_TYPES} = s
gl_convert(s::Observable{T}) where T = const_lift(gl_convert, s)
gl_convert(x::StaticVector{N, T}) where {N, T} = map(gl_promote(T), x)
gl_convert(x::SMatrix{N, M, T}) where {N, M, T} = map(gl_promote(T), x)
gl_convert(x::Mat{N, M, T}) where {N, M, T} = map(gl_promote(T), x)
gl_convert(a::AbstractVector{<: AbstractFace}) = indexbuffer(s)
gl_convert(t::Type{T}, a::T; kw_args...) where T <: NATIVE_TYPES = a
gl_convert(::Type{<: GPUArray}, a::StaticVector) = gl_convert(a)
Expand Down
107 changes: 0 additions & 107 deletions GLMakie/src/GLAbstraction/precompile.jl

This file was deleted.

3 changes: 2 additions & 1 deletion GLMakie/src/GLMakie.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module GLMakie

using ModernGL, FixedPointNumbers, Colors, GeometryBasics, StaticArrays
using ModernGL, FixedPointNumbers, Colors, GeometryBasics
using Makie, FileIO

using Makie: @key_str, Key, broadcast_foreach, to_ndim, NativeFont
Expand All @@ -12,6 +12,7 @@ using Makie: inline!
using Makie: spaces, is_data_space, is_pixel_space, is_relative_space, is_clip_space
using ShaderAbstractions
using FreeTypeAbstraction
using GeometryBasics: StaticVector

using Base: RefValue
import Base: push!, isopen, show
Expand Down
2 changes: 1 addition & 1 deletion GLMakie/src/GLVisualize/GLVisualize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ using Makie: RaymarchAlgorithm, IsoValue, Absorption, MaximumIntensityProjection

using ..GLMakie.GLFW
using ModernGL
using StaticArrays
using GeometryBasics
using Colors
using Makie
using FixedPointNumbers
using FileIO
using Markdown
using Observables
using GeometryBasics: StaticVector

import Base: merge, convert, show
using Base.Iterators: Repeated, repeated
Expand Down
2 changes: 1 addition & 1 deletion GLMakie/src/GLVisualize/visualize/particles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function char_scale_factor(char, font)
ta = Makie.get_texture_atlas()
lbrt = glyph_uv_width!(ta, char, font)
width = Vec(lbrt[3] - lbrt[1], lbrt[4] - lbrt[2])
width * Vec2f(size(ta.data)) / Makie.PIXELSIZE_IN_ATLAS[]
return width .* Vec2f(size(ta.data)) ./ Makie.PIXELSIZE_IN_ATLAS[]
end

# This works the same for x being widths and offsets
Expand Down
2 changes: 1 addition & 1 deletion GLMakie/src/drawing_primitives.jl
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ function draw_atomic(screen::GLScreen, scene::Scene, @nospecialize(x::Union{Scat
mspace = get(gl_attributes, :markerspace, :pixel)
cam = scene.camera
gl_attributes[:preprojection] = map(space, mspace, cam.projectionview) do space, mspace, pv
Makie.clip_to_space(cam, mspace) * Makie.space_to_clip(cam, space)
return Makie.clip_to_space(cam, mspace) * Makie.space_to_clip(cam, space)
end
if !(marker[] isa FastPixel)
# fast pixel does its own camera setup
Expand Down
7 changes: 4 additions & 3 deletions GLMakie/src/glwindow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ Selection of random objects on the screen is realized by rendering an
object id + plus an arbitrary index into the framebuffer.
The index can be used for e.g. instanced geometries.
"""
struct SelectionID{T <: Integer} <: FieldVector{2, T}
struct SelectionID{T <: Integer}
id::T
index::T
end

Base.convert(::Type{SelectionID{T}}, s::SelectionID) where T = SelectionID{T}(T(s.id), T(s.index))
Base.zero(::Type{GLMakie.SelectionID{T}}) where T = SelectionID{T}(T(0), T(0))

mutable struct GLFramebuffer
resolution::Observable{NTuple{2, Int}}
Expand Down Expand Up @@ -96,7 +97,7 @@ function GLFramebuffer(fb_size::NTuple{2, Int})

fb_size_node = Observable(fb_size)

# To allow adding postprocessors in various combinations we need to keep
# To allow adding postprocessors in various combinations we need to keep
# track of the buffer ids that are already in use. We may also want to reuse
# buffers so we give them names for easy fetching.
buffer_ids = Dict(
Expand Down
Loading