From 6725e1e7354bd74fc8ab98d208a3721bac132e89 Mon Sep 17 00:00:00 2001 From: Alain Lichnewsky Date: Wed, 18 Mar 2015 21:05:17 +0100 Subject: [PATCH 1/4] Make perspectiveCamera and OrthographicCamera mutable intent: permit one screen/camera to follow another Discussion with S.Danish ref=AlainLich/Romeo.jl/pull/3#issuecomment-82925423 --- src/GLCamera.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/GLCamera.jl b/src/GLCamera.jl index 4fbae6e..4ac16fc 100644 --- a/src/GLCamera.jl +++ b/src/GLCamera.jl @@ -1,11 +1,11 @@ abstract Camera{T} -immutable OrthographicCamera{T} <: Camera{T} +type OrthographicCamera{T} <: Camera{T} window_size::Signal{Vector4{Int}} view::Signal{Matrix4x4{T}} projection::Signal{Matrix4x4{T}} projectionview::Signal{Matrix4x4{T}} end -immutable PerspectiveCamera{T} <: Camera{T} +type PerspectiveCamera{T} <: Camera{T} pivot::Signal{Pivot{T}} window_size::Signal{Vector4{Int}} nearclip::Signal{T} From de674aa5074cc9f845d642fbc8fd1e6af624ad4f Mon Sep 17 00:00:00 2001 From: Alain Lichnewsky Date: Sat, 21 Mar 2015 17:30:13 +0100 Subject: [PATCH 2/4] Add debugging tools, looking to trace Romeo/visualize down to GLAbstraction and calls to OGL lib --- src/GLRender.jl | 69 +++++++++++++++++++++++++++++++++++++++++++++++++ src/GLTypes.jl | 25 +++++++++++++++++- 2 files changed, 93 insertions(+), 1 deletion(-) diff --git a/src/GLRender.jl b/src/GLRender.jl index d1ea6b1..c8a2d8d 100644 --- a/src/GLRender.jl +++ b/src/GLRender.jl @@ -1,25 +1,94 @@ +#== + Make debugging interface flexible (hopefully the compile step will remove + dead code when not optimizing. Higher level values mean more intrusive + (may render app unusable if too much output is generated) + Level (ORed bit values) + 1 : add traceback for constructors and related + 4 : print uniforms + 8 : print vertices + 16 : reserved for GLTypes.GLVertexArray + 32 : reserved for postRenderFunctions +==# +debugFlagOn = isdefined(:GLRenderDebugLevel) +debugLevel = debugFlagOn ? GLRenderDebugLevel : 0 +#== Set the debug parameters; if this function is not used, GLRenderDebugLevel + must be set at time of package loading. +==# +function setDebugLevels(flagOn::Bool,level::Int) + global debugFlagOn + global debugLevel + debugFlagOn = flagOn + debugLevel = flagOn ? level : 0 +end + +function debugRenderUnif(program,renderobject) + debugLevel & 4 == 0 && return + id = program.id + println("In debugRenderUnif program.id=$id") + for (key,value) in program.uniformloc + if haskey(renderobject.uniforms, key) + tv=typeof(value) + tu=typeof(renderobject.uniforms[key]) + println("\t$key corresponds to value with type=$tv") + println("\t and renderobject.uniform[$key] with type=$tu") + else + println("\t key $key not found in renderobject") + end + end +end + +function debugRenderVertex(va::GLVertexArray, mode::GLenum=GL_TRIANGLES) + debugLevel & 8 == 0 && return + ln = va.length + iln = va.indexlength + id = va.id + println("In debugVertex mode=$mode, \tGLVertexArray.id=$id,\tlength=$ln,\tindexlength=$iln") +end + + +function debugPostRenderFn(fn,args...) + debugLevel & 32 == 0 && return + fntyp = typeof(fn) + + println("In debugPostRenderFn\t$fntyp\t$fn" ) + println(" args=$args") + println("++++ end debugPostRenderFn output ++++\n") +end + +############ end of debugging section ############ + function render(list::AbstractVector) for elem in list render(elem) end end + function render(renderobject::RenderObject, vertexarray=renderobject.vertexarray) for elem in renderobject.prerenderfunctions elem[1](elem[2]...) end program = vertexarray.program glUseProgram(program.id) + + debugFlagOn && debugRenderUnif(program,renderobject) ## debug + for (key,value) in program.uniformloc haskey(renderobject.uniforms, key) && gluniform(value..., renderobject.uniforms[key]) end for elem in renderobject.postrenderfunctions + + debugFlagOn && debugPostRenderFn(elem[1],elem[2]...) ## debug + # apply elem[1] elem[1](elem[2]...) end end + function render(vao::GLVertexArray, mode::GLenum=GL_TRIANGLES) + debugFlagOn && debugRenderVertex(vao, mode) ## debug + glBindVertexArray(vao.id) if vao.indexlength > 0 glDrawElements(mode, vao.indexlength, GL_UNSIGNED_INT, GL_NONE) diff --git a/src/GLTypes.jl b/src/GLTypes.jl index dc1f0ef..0c1b147 100644 --- a/src/GLTypes.jl +++ b/src/GLTypes.jl @@ -144,6 +144,8 @@ type GLVertexArray function GLVertexArray(bufferDict::Dict{Symbol, GLBuffer}, program::GLProgram) @assert !isempty(bufferDict) + debugFlagOn && debugGLVertexAConstruct(bufferDict, program) + #get the size of the first array, to assert later, that all have the same size indexSize = -1 _length = -1 @@ -220,7 +222,7 @@ function Base.show(io::IO, obj::RenderObject) println(io, " ", name, "\n ", uniform) end println(io, "vertexarray length: ", obj.vertexarray.length) - println(io, "vertexarray indexlength: ", obj.vertexarray.indexlength) + println(io, "vertexarray indexlength: ", obj.vertexarray.indexlength) end RenderObject{T}(data::Dict{Symbol, T}, program::GLProgram) = RenderObject(Dict{Symbol, Any}(data), program) @@ -311,3 +313,24 @@ end Style(x::Symbol) = Style{x}() Style() = Style{:Default}() mergedefault!{S}(style::Style{S}, styles, customdata) = merge!(copy(styles[S]), Dict{Symbol, Any}(customdata)) + + +#== + Debugging, see conventions in GLRender.jl +==# + +function debugGLVertexAConstruct(bufferDict::Dict{Symbol, GLBuffer}, + program::GLProgram) + debugLevel & 16 == 0 && return + id = program.id + println("In debugGLVertexAConstruct program.id=$id") + map (bufferDict) do kv + k=kv[1] + v=kv[2] + println("\tkey=$k\tvalue type:", typeof(v)) + end + if debugLevel & 1 + println("Traceback for debugGLVertexAConstruct") + Base.show_backtrace(STDOUT, backtrace()) + end +end From 6274656ef3003b2d8bf6009278e4adfc1cfcad21 Mon Sep 17 00:00:00 2001 From: Alain Lichnewsky Date: Sun, 22 Mar 2015 08:20:53 +0100 Subject: [PATCH 3/4] Merge change from upstream, correct bug in debug print selection --- src/GLTypes.jl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/GLTypes.jl b/src/GLTypes.jl index cb1a1af..8d6073f 100644 --- a/src/GLTypes.jl +++ b/src/GLTypes.jl @@ -167,7 +167,7 @@ type GLVertexArray glBindBuffer(buffer.buffertype, buffer.id) attribLocation = get_attribute_location(program.id, attribute) - glVertexAttribPointer(attribLocation, cardinality(buffer), GL_FLOAT, GL_FALSE, 0, C_NULL) + glVertexAttribPointer(attribLocation, cardinality(buffer), GL_FLOAT, GL_FALSE, 0, 0) glEnableVertexAttribArray(attribLocation) end end @@ -329,8 +329,9 @@ function debugGLVertexAConstruct(bufferDict::Dict{Symbol, GLBuffer}, v=kv[2] println("\tkey=$k\tvalue type:", typeof(v)) end - if debugLevel & 1 + if debugLevel & 1 != 0 println("Traceback for debugGLVertexAConstruct") Base.show_backtrace(STDOUT, backtrace()) + println("") end end From 29ffee45a42628bc94ae19f2d542f42e74021f1f Mon Sep 17 00:00:00 2001 From: Alain Lichnewsky Date: Thu, 2 Apr 2015 08:36:45 +0200 Subject: [PATCH 4/4] Added manipVirtuals (Dict) field in RenderObject, intent is to represent standard virtual function for manip from subscreen mgr Intent is that each RenderObject may export the set of functions to be used for object manipulation in its representation. The virtual interface will have a fixed specification close to OpenGL definitions (model view, projections, viewport etc...). The upshot is if you want to rotate in model space, you will look for the rotateFn (name may still vary), if it exists then it will provide the rotation, if it does not exist, then the object has not been designed with this capability. --- src/GLRenderObject.jl | 2 +- src/GLTypes.jl | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/GLRenderObject.jl b/src/GLRenderObject.jl index 18ac987..1da68ec 100644 --- a/src/GLRenderObject.jl +++ b/src/GLRenderObject.jl @@ -118,4 +118,4 @@ function pushfunction!(target::Dict{Function, Tuple}, fs...) target[func] = tuple(args...) end prerender!(x::RenderObject, fs...) = pushfunction!(x.prerenderfunctions, fs...) -postrender!(x::RenderObject, fs...) = pushfunction!(x.postrenderfunctions, fs...) \ No newline at end of file +postrender!(x::RenderObject, fs...) = pushfunction!(x.postrenderfunctions, fs...) diff --git a/src/GLTypes.jl b/src/GLTypes.jl index 8d6073f..43ef652 100644 --- a/src/GLTypes.jl +++ b/src/GLTypes.jl @@ -188,6 +188,7 @@ type RenderObject prerenderfunctions::Dict{Function, Tuple} postrenderfunctions::Dict{Function, Tuple} id::GLushort + manipVirtuals::Dict{Symbol,Any} # added a hook for virtual interfaces boundingbox::Function # workaround for having lazy boundingbox queries, while not using multiple dispatch for boundingbox function (No type hierarchy for RenderObjects) objectid::GLushort = 0 @@ -211,7 +212,7 @@ type RenderObject optimizeduniforms[uniform_name] = uniforms[uniform_name] end end # only use active uniforms && check the type - new(optimizeduniforms, uniforms, vertexarray, Dict{Function, Tuple}(), Dict{Function, Tuple}(), objectid, bbf) + new(optimizeduniforms, uniforms, vertexarray, Dict{Function, Tuple}(), Dict{Function, Tuple}(), objectid, Dict{Symbol,Any}() ,bbf) end end function Base.show(io::IO, obj::RenderObject)