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 debugging #44

Merged
merged 6 commits into from
Jul 12, 2018
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
deps/deps.jl
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ dist: trusty
julia:
- 0.7
- nightly
matrix:
allow_failures:
- julia: nightly

notifications:
email: false
addons:
Expand Down
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ OpenGL bindings for OpenGL 3.0 and upwards. As OpenGL 3.0 has a lot of overlaps

The philosophy is to keep this library strictly a low-level wrapper, so you won't find any error handling (besides for the function loading itself) or abstractions in this package.

### Debugging

You can rebuild ModernGL to include debug error checks:
```Julia
ENV["MODERNGL_DEBUGGING"] = "true"; Pkg.build("ModernGL")
# or to get back the default behaviour:
ENV["MODERNGL_DEBUGGING"] = "false"; Pkg.build("ModernGL")
```

### Installation notes
There are no dependencies, besides the graphic driver. If you have any problems, you should consider updating the driver first.

Expand Down Expand Up @@ -38,7 +47,7 @@ getProcAddress can be changed like this:
using ModernGL

function ModernGL.getprocaddress(name::ASCIIString)
# for example change it to GLUT
# for example change it to GLUT
glutGetProcAddress(name)
end
```
Expand All @@ -53,4 +62,4 @@ It seems, that there is actually no good way of testing if a function is support
Credits go certainly to the OpenGL.jl ([rennis250](https://github.com/rennis250) && [o-jasper](https://github.com/o-jasper)) package, where I have all the OpenGL definitions from.
Special thanks to rennis250 for all the support! :)

Also, I have to thank for the constructive discussion on Julia-Users, where I got a good solution for the function pointer loading (final solution was from [vtjnash](https://github.com/vtjnash) and got replaced by [aaalexandrov's](https://github.com/aaalexandrov/) solution which doubled the speed).
Also, I have to thank for the constructive discussion on Julia-Users, where I got a good solution for the function pointer loading (final solution was from [vtjnash](https://github.com/vtjnash) and got replaced by [aaalexandrov's](https://github.com/aaalexandrov/) solution which doubled the speed).
5 changes: 5 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ notifications:
on_build_failure: false
on_build_status_changed: false

matrix:
allow_failures:
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"

install:
- ps: "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12"
# Download most recent Julia Windows binary
Expand Down
4 changes: 4 additions & 0 deletions deps/build.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
debug_level = get(ENV, "MODERNGL_DEBUGGING", "false") == "true"
open(joinpath(@__DIR__, "deps.jl"), "w") do io
println(io, "const enable_opengl_debugging = $debug_level")
end
1 change: 1 addition & 0 deletions deps/deps.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const enable_opengl_debugging = false
30 changes: 28 additions & 2 deletions src/functionloading.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
mutable struct GLFunc
p::Ptr{Cvoid}
end

include(joinpath("..", "deps", "deps.jl"))

gl_represent(x::GLenum) = GLENUM(x).name
gl_represent(x) = repr(x)

function debug_opengl_expr(func_name, args)
if enable_opengl_debugging && func_name != :glGetError
quote
err = glGetError()
if err != GL_NO_ERROR
arguments = gl_represent.(tuple($(args...)))
warn("OpenGL call to $($func_name), with arguments: $(arguments)
Failed with error: $(GLENUM(err).name).")
end
end
else
:()
end
end

# based on getCFun macro
macro glfunc(opengl_func)
arguments = map(opengl_func.args[1].args[2:end]) do arg
Expand All @@ -22,7 +43,9 @@ macro glfunc(opengl_func)
ptr_expr = :(($func_name_sym, "opengl32"))
ret = quote
function $func_name($(arg_names...))
ccall($ptr_expr, $return_type, ($(input_types...),), $(arg_names...))
result = ccall($ptr_expr, $return_type, ($(input_types...),), $(arg_names...))
$(debug_opengl_expr(func_name, arg_names))
result
end
$(Expr(:export, func_name))
end
Expand All @@ -36,12 +59,15 @@ macro glfunc(opengl_func)
if $ptr_sym.p::Ptr{Cvoid} == C_NULL
$ptr_sym.p::Ptr{Cvoid} = $ptr_expr
end
ccall($ptr_sym.p::Ptr{Cvoid}, $return_type, ($(input_types...),), $(arg_names...))
result = ccall($ptr_sym.p::Ptr{Cvoid}, $return_type, ($(input_types...),), $(arg_names...))
$(debug_opengl_expr(func_name, arg_names))
result
end
$(Expr(:export, func_name))
end
return esc(ret)
end

if Sys.iswindows()
const gl_lib = Libdl.dlopen("opengl32")
end
Expand Down