>
> (1) and (2) do equivalent operations at runtime, they only differ in
> how the memoization is implemented (dict vs. global variable). Neither
> requires an OpenGL context at compile time, making them roughly
> equivalent
> (3) caches information derived from the OpenGL context, which may be
> different from the OpenGL context that is used at runtime.
Ok, there seems to be some confusion about how (3) actually works, perhaps
due to the misapprehension that Julia has strictly separate compile- and
run-time phases.
To be clear, solution (3) is *exactly* equivalent to the others insofar as
it caches the function pointers at runtime (and therefore does not require
a context at compile time). The only difference is that they are loaded in
one go rather than as each function is called. Yes, there is compilation
involved in the caching, but that is only *triggered* by init_opengl_fns(),
which is called *at runtime*. init_opengl_fns() will only be called after
the relevant OpenGL context is loaded (again, at run time), meaning that
the problem of different compile/run time contexts simply does not apply.
Also, Simon, I know you've gone with Jameson's solution for now, but just
in case you're interested I thought I'd spitball how you could multiple
contexts might work. Basically, the idea is to dispatch on the type of the
context, dynamically generating the methods via init_opengl_fns().
module OpenGL
function init_opengl_fns(getProcAddr, ctx_type)
@eval begin
export glGetString, ...
glGetString(ctx::$ctx_type, name::GLenum) =
ccall($(getProcAddr("glGetString")), ...., ...., name)
# further definitions
end
end
end
# then...
using OpenGL, CUDA, GLUT
# You can call this as many times as you want, generating specialised methods
for each type.
# (The function pointers are cached and methods generated when these lines are
run, not compiled)
OpenGL.init_opengl_fns(CUDA.getProcAddr, CUDAContext)
OpenGL.init_opengl_fns(GLUT.getProcAddr, GLUTContext)
ctx1 = CUDA.new_context()
glGetString(ctx1, ...) # calls correct C function
I don't know if this is necessarily applicable, just an idea.