diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4871ef8 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +deps/deps.jl diff --git a/.travis.yml b/.travis.yml index 505e010..046994f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,10 @@ dist: trusty julia: - 0.7 - nightly +matrix: + allow_failures: + - julia: nightly + notifications: email: false addons: diff --git a/README.md b/README.md index 6772538..c32b7a4 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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 ``` @@ -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). diff --git a/appveyor.yml b/appveyor.yml index 93aa461..bd2f18c 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -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 diff --git a/deps/build.jl b/deps/build.jl new file mode 100644 index 0000000..fc4fb98 --- /dev/null +++ b/deps/build.jl @@ -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 diff --git a/deps/deps.jl b/deps/deps.jl new file mode 100644 index 0000000..064f0e2 --- /dev/null +++ b/deps/deps.jl @@ -0,0 +1 @@ +const enable_opengl_debugging = false diff --git a/src/functionloading.jl b/src/functionloading.jl index e406c64..6c8346d 100644 --- a/src/functionloading.jl +++ b/src/functionloading.jl @@ -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 @@ -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 @@ -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