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

Changes to support Plots glvisualize backend in Julia v0.7 #93

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 1 addition & 2 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
julia 0.6
julia 0.7

ModernGL 0.1.0

Expand All @@ -8,7 +8,6 @@ Reactive 0.6.0
FixedPointNumbers 0.3.0
ColorTypes 0.3.1


Quaternions
FileIO
GLFW
15 changes: 8 additions & 7 deletions src/AbstractGPUArray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import Base: size
import Base: start
import Base: next
import Base: done
using Serialization

import GeometryTypes.SimpleRectangle

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/GLAbstraction.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/GLBuffer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions src/GLCamera.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
using Reactive
using GeometryTypes
import GeometryTypes.Point2f0, GeometryTypes.Vec3f0

abstract type Camera{T} end
const Q = Quaternions # save some writing!

Expand Down
5 changes: 3 additions & 2 deletions src/GLExtendedFunctions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -65,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)

Expand Down
14 changes: 7 additions & 7 deletions src/GLShader.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/GLTexture.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions src/GLTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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) || 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
Expand Down
12 changes: 6 additions & 6 deletions src/GLUniforms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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"
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 9 additions & 3 deletions src/GLUtils.jl
Original file line number Diff line number Diff line change
@@ -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]
Expand Down Expand Up @@ -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)


"""
Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/accessors.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ end

using GLAbstraction, GeometryTypes, ModernGL, FileIO, GLWindow
using ColorTypes
using Base.Test
using Test
import GLAbstraction: N0f8


Expand Down