From 4a4add9b3d379a26d5e238f3f3853353d9d49287 Mon Sep 17 00:00:00 2001 From: Leon Wabeke Date: Wed, 26 Sep 2018 11:58:49 +0200 Subject: [PATCH 1/3] Changes to support Plots glvisualize backend in Julia v0.7 --- REQUIRE | 3 +-- src/AbstractGPUArray.jl | 15 ++++++++------- src/GLAbstraction.jl | 1 + src/GLBuffer.jl | 2 +- src/GLCamera.jl | 4 ++++ src/GLExtendedFunctions.jl | 3 ++- src/GLShader.jl | 2 +- src/GLTexture.jl | 2 +- src/GLUniforms.jl | 12 ++++++------ src/GLUtils.jl | 12 +++++++++--- 10 files changed, 34 insertions(+), 22 deletions(-) diff --git a/REQUIRE b/REQUIRE index 6ceb155..a2203ff 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,4 +1,4 @@ -julia 0.6 +julia 0.7 ModernGL 0.1.0 @@ -8,7 +8,6 @@ Reactive 0.6.0 FixedPointNumbers 0.3.0 ColorTypes 0.3.1 - Quaternions FileIO GLFW diff --git a/src/AbstractGPUArray.jl b/src/AbstractGPUArray.jl index def24a0..4a3276d 100644 --- a/src/AbstractGPUArray.jl +++ b/src/AbstractGPUArray.jl @@ -14,6 +14,7 @@ import Base: size import Base: start import Base: next import Base: done +using Serialization import GeometryTypes.SimpleRectangle @@ -48,7 +49,7 @@ end function to_range(index) map(index) do val isa(val, Integer) && return val:val - isa(val, Range) && return val + isa(val, AbstractRange) && return val error("Indexing only defined for integers or ranges. Found: $val") end end @@ -225,19 +226,19 @@ function (::Type{T})(x::Signal) where T <: GPUArray gpu_mem end -const BaseSerializer = if isdefined(Base, :AbstractSerializer) - Base.AbstractSerializer -elseif isdefined(Base, :SerializationState) - Base.SerializationState +const BaseSerializer = if isdefined(Serialization, :AbstractSerializer) + Serialization.AbstractSerializer +elseif isdefined(Serialization, :SerializationState) + Serialization.SerializationState else error("No Serialization type found. Probably unsupported Julia version") end -function Base.serialize(s::BaseSerializer, t::T) where T<:GPUArray +function serialize(s::BaseSerializer, t::T) where T<:GPUArray Base.serialize_type(s, T) serialize(s, Array(t)) end -function Base.deserialize(s::BaseSerializer, ::Type{T}) where T<:GPUArray +function deserialize(s::BaseSerializer, ::Type{T}) where T<:GPUArray A = deserialize(s) T(A) end diff --git a/src/GLAbstraction.jl b/src/GLAbstraction.jl index ba3fa26..877ab7d 100644 --- a/src/GLAbstraction.jl +++ b/src/GLAbstraction.jl @@ -1,6 +1,7 @@ VERSION >= v"0.4.0-dev+6521" && __precompile__(true) module GLAbstraction +using LinearAlgebra import Quaternions const Q = Quaternions # save some writing! using StaticArrays diff --git a/src/GLBuffer.jl b/src/GLBuffer.jl index e09346f..e66f445 100644 --- a/src/GLBuffer.jl +++ b/src/GLBuffer.jl @@ -14,7 +14,7 @@ mutable struct GLBuffer{T} <: GPUArray{T, 1} glBindBuffer(buffertype, 0) obj = new(id, (buff_length,), buffertype, usage, current_context()) - finalizer(obj, free) + finalizer(free, obj) obj end end diff --git a/src/GLCamera.jl b/src/GLCamera.jl index cd1d816..ba46108 100644 --- a/src/GLCamera.jl +++ b/src/GLCamera.jl @@ -1,3 +1,7 @@ +using Reactive +using GeometryTypes +import GeometryTypes.Point2f0, GeometryTypes.Vec3f0 + abstract type Camera{T} end const Q = Quaternions # save some writing! diff --git a/src/GLExtendedFunctions.jl b/src/GLExtendedFunctions.jl index 9b1eb08..e998df7 100644 --- a/src/GLExtendedFunctions.jl +++ b/src/GLExtendedFunctions.jl @@ -26,7 +26,8 @@ end get_attribute_location(program::GLuint, name) = get_attribute_location(program, ascii(name)) get_attribute_location(program::GLuint, name::Symbol) = get_attribute_location(program, string(name)) function get_attribute_location(program::GLuint, name::String) - const location::GLint = glGetAttribLocation(program, name) + #const location::GLint = glGetAttribLocation(program, name) + location::GLint = glGetAttribLocation(program, name) if location == -1 warn( "Named attribute (:$(name)) is not an active attribute in the specified program object or\n diff --git a/src/GLShader.jl b/src/GLShader.jl index bb7b88e..2f8efa0 100644 --- a/src/GLShader.jl +++ b/src/GLShader.jl @@ -212,7 +212,7 @@ end function get_view(kw_dict) _view = kw_dict[:view] - extension = is_apple() ? "" : "#extension GL_ARB_draw_instanced : enable\n" + extension = Sys.isapple() ? "" : "#extension GL_ARB_draw_instanced : enable\n" _view["GLSL_EXTENSION"] = extension*get(_view, "GLSL_EXTENSIONS", "") _view["GLSL_VERSION"] = glsl_version_string() _view diff --git a/src/GLTexture.jl b/src/GLTexture.jl index 495dd3f..046d799 100644 --- a/src/GLTexture.jl +++ b/src/GLTexture.jl @@ -36,7 +36,7 @@ mutable struct Texture{T <: GLArrayEltypes, NDIM} <: OpenglTexture{T, NDIM} size, current_context() ) - finalizer(tex, free) + finalizer(free, tex) tex end end diff --git a/src/GLUniforms.jl b/src/GLUniforms.jl index 319e666..5fc964a 100644 --- a/src/GLUniforms.jl +++ b/src/GLUniforms.jl @@ -30,7 +30,7 @@ function uniformfunc(typ::DataType, dims::Tuple{Int}) end function uniformfunc(typ::DataType, dims::Tuple{Int, Int}) M, N = dims - Symbol(string("glUniformMatrix", M == N ? "$M":"$(M)x$(N)", opengl_postfix(typ))) + Symbol(string("glUniformMatrix", M == N ? "$M" : "$(M)x$(N)", opengl_postfix(typ))) end function gluniform(location::Integer, x::FSA) where FSA <: Union{StaticArray, Colorant} @@ -88,7 +88,7 @@ gluniform(location::GLint, x::Vector{GLuint}) = glUniform1uiv(location, length( glsl_typename(x::T) where {T} = glsl_typename(T) -glsl_typename(t::Type{Void}) = "Nothing" +glsl_typename(t::Type{Nothing}) = "Nothing" glsl_typename(t::Type{GLfloat}) = "float" glsl_typename(t::Type{GLdouble}) = "double" glsl_typename(t::Type{GLuint}) = "uint" @@ -106,7 +106,7 @@ function glsl_typename(t::Type{T}) where T <: SMatrix string(opengl_prefix(eltype(t)), "mat", M==N ? M : string(M, "x", N)) end toglsltype_string(t::Signal) = toglsltype_string(t.value) -toglsltype_string(x::T) where {T<:Union{Real, StaticArray, Texture, Colorant, TextureBuffer, Void}} = "uniform $(glsl_typename(x))" +toglsltype_string(x::T) where {T<:Union{Real, StaticArray, 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) @@ -197,18 +197,18 @@ gl_convert(x::Signal{T}) where {T <: HomogenousMesh} = gl_promote(T)(x) gl_convert(s::Vector{Matrix{T}}) where {T<:Colorant} = Texture(s) gl_convert(s::AABB) = s -gl_convert(s::Void) = s +gl_convert(s::Nothing) = s isa_gl_struct(x::Array) = false isa_gl_struct(x::NATIVE_TYPES) = false isa_gl_struct(x::Colorant) = false function isa_gl_struct(x::T) where T - !isleaftype(T) && return false + !isconcretetype(T) && return false if T <: Tuple return false end fnames = fieldnames(T) - !isempty(fnames) && all(name -> isleaftype(fieldtype(T, name)) && isbits(getfield(x, name)), fnames) + !isempty(fnames) && all(name -> isconcretetype(fieldtype(T, name)) && isbits(getfield(x, name)), fnames) end function gl_convert_struct(x::T, uniform_name::Symbol) where T if isa_gl_struct(x) diff --git a/src/GLUtils.jl b/src/GLUtils.jl index c6f6d1e..6004e42 100644 --- a/src/GLUtils.jl +++ b/src/GLUtils.jl @@ -1,3 +1,9 @@ +using Printf + +is_linenumber(ex::LineNumberNode) = true +is_linenumber(ex::Expr) = (ex.head == :line) +is_linenumber(ex) = false + macro gputime(codeblock) quote local const query = GLuint[1] @@ -46,7 +52,7 @@ function print_with_lines(out::IO, text::AbstractString) end write(out, take!(io)) end -print_with_lines(text::AbstractString) = print_with_lines(STDOUT, text) +print_with_lines(text::AbstractString) = print_with_lines(stdout, text) """ @@ -105,7 +111,7 @@ Needed to match the lazy gl_convert exceptions. matches_target(::Type{Target}, x::T) where {Target, T} = applicable(gl_convert, Target, x) || T <: Target # it can be either converted to Target, or it's already the target matches_target(::Type{Target}, x::Signal{T}) where {Target, T} = applicable(gl_convert, Target, x) || T <: Target matches_target(::Function, x) = true -matches_target(::Function, x::Void) = false +matches_target(::Function, x::Nothing) = false export matches_target @@ -139,7 +145,7 @@ macro gen_defaults!(dict, args) push!(return_expression.args, :(doc_strings = get!($dictsym, :doc_string, Dict{Symbol, Any}()))) # exceptions for glconvert. # @gen_defaults can be used multiple times, so we need to reuse gl_convert_targets if already in here for (i, elem) in enumerate(tuple_list) - if Base.is_linenumber(elem) + if is_linenumber(elem) push!(return_expression.args, elem) continue end From cd4d3232a26ecbb75688beccd9aebac2ad30ac58 Mon Sep 17 00:00:00 2001 From: Leon Wabeke Date: Wed, 26 Sep 2018 12:44:08 +0200 Subject: [PATCH 2/3] Fixed more deprecations --- src/GLBuffer.jl | 2 +- src/GLExtendedFunctions.jl | 2 +- src/GLShader.jl | 12 ++++++------ src/GLTexture.jl | 2 +- src/GLTypes.jl | 10 +++++----- test/accessors.jl | 2 +- test/runtests.jl | 2 +- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/GLBuffer.jl b/src/GLBuffer.jl index e66f445..bcfce4a 100644 --- a/src/GLBuffer.jl +++ b/src/GLBuffer.jl @@ -51,7 +51,7 @@ function indexbuffer( end # GPUArray interface function gpu_data(b::GLBuffer{T}) where T - data = Vector{T}(length(b)) + data = Vector{T}(undef, length(b)) bind(b) glGetBufferSubData(b.buffertype, 0, sizeof(data), data) bind(b, 0) diff --git a/src/GLExtendedFunctions.jl b/src/GLExtendedFunctions.jl index e998df7..7a6c3a8 100644 --- a/src/GLExtendedFunctions.jl +++ b/src/GLExtendedFunctions.jl @@ -66,7 +66,7 @@ function glGetActiveUniform(programID::GLuint, index::Integer) uniformSize = GLint[1] typ = GLenum[1] maxcharsize = glGetProgramiv(programID, GL_ACTIVE_UNIFORM_MAX_LENGTH) - name = Vector{GLchar}(maxcharsize) + name = Vector{GLchar}(undef, maxcharsize) glGetActiveUniform(programID, index, maxcharsize, actualLength, uniformSize, typ, name) diff --git a/src/GLShader.jl b/src/GLShader.jl index 2f8efa0..a945c26 100644 --- a/src/GLShader.jl +++ b/src/GLShader.jl @@ -155,7 +155,7 @@ function get_shader!(path, template_replacement, view, attributes) # this should always be in here, since we already have the template keys shader_dict = _shader_cache[path] get!(shader_dict, template_replacement) do - template_source = readstring(path) + template_source = read(path, String) source = mustache_replace(template_replacement, template_source) compile_shader(path, source)::Shader end::Shader @@ -165,7 +165,7 @@ function get_template!(path, view, attributes) _, ext = splitext(path) typ = shadertype(ext) - template_source = readstring(path) + template_source = read(path, String) source, replacements = template2source( template_source, view, attributes ) @@ -247,8 +247,8 @@ function gl_convert(lazyshader::AbstractLazyShader, data) Found: $paths" ) end - template_keys = Vector{Vector{String}}(length(paths)) - replacements = Vector{Vector{String}}(length(paths)) + template_keys = Vector{Vector{String}}(undef,length(paths)) + replacements = Vector{Vector{String}}(undef,length(paths)) for (i, path) in enumerate(paths) template = get_template!(path, v, data) template_keys[i] = template @@ -257,7 +257,7 @@ function gl_convert(lazyshader::AbstractLazyShader, data) program = get!(_program_cache, (paths, replacements)) do # when we're here, this means there were uncached shaders, meaning we definitely have # to compile a new program - shaders = Vector{Shader}(length(paths)) + shaders = Vector{Shader}(undef, length(paths)) for (i, path) in enumerate(paths) tr = Dict(zip(template_keys[i], replacements[i])) shaders[i] = get_shader!(path, tr, v, data) @@ -291,7 +291,7 @@ function mustache_replace(replace_view::Union{Dict, Function}, string) i = 0 replace_begin = i last_char = SubString(string, 1, 1) - len = endof(string) + len = lastindex(string) while i <= len i = nextind(string, i) i > len && break diff --git a/src/GLTexture.jl b/src/GLTexture.jl index 046d799..8a42684 100644 --- a/src/GLTexture.jl +++ b/src/GLTexture.jl @@ -285,7 +285,7 @@ end =# # Implementing the GPUArray interface function gpu_data(t::Texture{T, ND}) where {T, ND} - result = Array{T, ND}(size(t)) + result = Array{T, ND}(undef,size(t)) unsafe_copy!(result, t) return result end diff --git a/src/GLTypes.jl b/src/GLTypes.jl index 9a7c046..53ed885 100644 --- a/src/GLTypes.jl +++ b/src/GLTypes.jl @@ -81,7 +81,7 @@ mutable struct GLProgram context ::GLContext function GLProgram(id::GLuint, shader::Vector{Shader}, nametype::Dict{Symbol, GLenum}, uniformloc::Dict{Symbol, Tuple}) obj = new(id, shader, nametype, uniformloc, current_context()) - finalizer(obj, free) + finalizer(free, obj) obj end end @@ -229,7 +229,7 @@ function GLVertexArray(bufferdict::Dict, program::GLProgram) end glBindVertexArray(0) obj = GLVertexArray{typeof(indexes)}(program, id, len, buffers, indexes) - finalizer(obj, free) + finalizer(free, obj) obj end function Base.show(io::IO, vao::GLVertexArray) @@ -296,12 +296,12 @@ function RenderObject( end end # handle meshes seperately, since they need expansion - meshs = filter((key, value) -> isa(value, NativeMesh), data) + meshs = filter(p -> isa(p.second, NativeMesh), data) if !isempty(meshs) merge!(data, [v.data for (k,v) in meshs]...) end - buffers = filter((key, value) -> isa(value, GLBuffer) || key == :indices, data) - uniforms = filter((key, value) -> !isa(value, GLBuffer) && key != :indices, data) + buffers = filter(p -> isa(p.second, GLBuffer) || key == :indices, data) + uniforms = filter(p -> !isa(p.second, GLBuffer) && key != :indices, data) get!(data, :visible, true) # make sure, visibility is set merge!(data, passthrough) # in the end, we insert back the non opengl data, to keep things simple p = gl_convert(Reactive.value(program), data) # "compile" lazyshader diff --git a/test/accessors.jl b/test/accessors.jl index 32eaa6d..a972555 100644 --- a/test/accessors.jl +++ b/test/accessors.jl @@ -1,5 +1,5 @@ using GLAbstraction, GLWindow, GLFW, FixedPointNumbers, StaticArrays -using Base.Test +using Test struct SpriteStyle{T} <: FieldVector{2, T} color_id::T # lookup attribute_id for attribute texture diff --git a/test/runtests.jl b/test/runtests.jl index c9f940c..709332c 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -6,7 +6,7 @@ end using GLAbstraction, GeometryTypes, ModernGL, FileIO, GLWindow using ColorTypes -using Base.Test +using Test import GLAbstraction: N0f8 From 2407431bf15d95d84fd586903e303cfd6fdc48f7 Mon Sep 17 00:00:00 2001 From: Leon Wabeke Date: Wed, 26 Sep 2018 12:47:08 +0200 Subject: [PATCH 3/3] Rest of filter change --- src/GLTypes.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/GLTypes.jl b/src/GLTypes.jl index 53ed885..9979ffc 100644 --- a/src/GLTypes.jl +++ b/src/GLTypes.jl @@ -300,8 +300,8 @@ function RenderObject( if !isempty(meshs) merge!(data, [v.data for (k,v) in meshs]...) end - buffers = filter(p -> isa(p.second, GLBuffer) || key == :indices, data) - uniforms = filter(p -> !isa(p.second, GLBuffer) && key != :indices, data) + buffers = filter(p -> isa(p.second, GLBuffer) || p.first == :indices, data) + uniforms = filter(p -> !isa(p.second, GLBuffer) && p.first != :indices, data) get!(data, :visible, true) # make sure, visibility is set merge!(data, passthrough) # in the end, we insert back the non opengl data, to keep things simple p = gl_convert(Reactive.value(program), data) # "compile" lazyshader