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

Add debug #12

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
8 changes: 4 additions & 4 deletions src/GLCamera.jl
Original file line number Diff line number Diff line change
@@ -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}
Expand Down Expand Up @@ -315,9 +315,9 @@ function PerspectiveCamera{T <: Real}(
)
eyepositionstart = Vector3{T}(1,0,0)
origin = lookatvec

vup = Vector3{T}(0,0,1)
xaxis = eyeposition - origin
yaxis = cross(xaxis, Vector3{T}(0,0,1))
yaxis = cross(xaxis, vup)
zaxis = cross(yaxis, xaxis)

translate = Vector3{T}(0,0,0)
Expand Down
8 changes: 3 additions & 5 deletions src/GLMatrixMath.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ function scalematrix{T}(scale::Vector3{T})
result[1,1] = scale[1]
result[2,2] = scale[2]
result[3,3] = scale[3]

return Matrix4x4(result)
end

Expand Down Expand Up @@ -89,10 +88,9 @@ end
View frustum matrix (4x4).
=#
function frustum{T}(left::T, right::T, bottom::T, top::T, znear::T, zfar::T)
@assert right != left
@assert bottom != top
@assert znear != zfar

@assert right != left "right is equal to left: $right"
@assert bottom != top "bottom is equal to top: $bottom"
@assert znear != zfar "znear is equal to zfar: $znear"
M = zeros(T, 4, 4)
M[1, 1] = +2.0 * znear / (right - left)
M[3, 1] = (right + left) / (right - left)
Expand Down
69 changes: 69 additions & 0 deletions src/GLRender.jl
Original file line number Diff line number Diff line change
@@ -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, C_NULL)
Expand Down
4 changes: 3 additions & 1 deletion src/GLTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,10 @@ include("GLRenderObject.jl")


####################################################################################

# freeing
free(x::GLProgram) = try glDeleteProgram(x.id) end # context might not be active anymore, so it errors and doesn' need to be freed anymore
free(x::GLBuffer) = try glDeleteBuffers(x.id) end
free(x::Texture) = try glDeleteTextures(x.id) end
free(x::GLVertexArray) = try glDeleteVertexArrays(x.id) end
free(x::GLVertexArray) = try glDeleteVertexArrays(x.id) end

1 change: 1 addition & 0 deletions src/GLUniforms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ macro genuniformfunctions(maxdim::Integer)
#########################################################################
push!(expressions, :(toglsltype_string(x::Type{$imalias}) = $(lowercase(string("uniform ", glslalias))))) # method for shader type mapping
push!(expressions, :(toglsltype_string(x::$imalias) = $(lowercase(string("uniform ", glslalias))))) # method for shader type mapping

end
for n=2:maxdim, n2=2:maxdim, typ in [GLdouble, GLfloat]
glsldim = n==n2 ? "$n" : "$(n)x$(n2)"
Expand Down