No: it evaluates once at compile time, and thereafter the function pointer is directly embedded.
On Wed, Apr 2, 2014 at 7:16 AM, Simon Danisch <[email protected]> wrote: > @Isaiah > If I understand the code correctly, your solution would call the > getProcAddress with every OpenGL call. > This wouldn't be very desirable, even if getProcAddress is fast... > > Using the native getProcAddress is a nice idea though, with which I played > around as well. > But I think in the end it's better to leave this to a third party library. > I played around with it a little and run into a few platform dependent > inconsistencies quite quickly. > Maybe we can use this as a fall back, if no getProcAddress function is > defined. > > @ Mike Innes > Cool, that seems to be exactly what I need. =) > I tried something similar, but it seems like I didn't understand Julia > macros well enough to make it work... > Your solution at least satisfies my simple test case that I came up with. > Good thing is, that I should be able to quickly emit code for the whole > OpenGL package, as I generate all the code automatically anyways. > I keep you updated, if this works out alright! > > Best, > Simon > > > > Am Dienstag, 1. April 2014 14:30:12 UTC+2 schrieb Simon Danisch: > >> Hi, >> I'm working on the OpenGL package and I want to make it finally usable in >> a nice and clean way on all platforms. >> The problem is, that one needs pointer for the GL functions, which you >> can only get, after initialization of the OpenGL context. >> But initializing the context and creating a window shouldn't be part of >> the OpenGL package. >> >> So I tried two different approaches, which both seem to have their >> downsides: >> >> 1. >> Initialize OpenGL context when including the OpenGL package >> This is bad, because this makes the OpenGL package dependent on some >> third party OpenGL context creation library. >> >> 2. >> Load the functions later with a loading Function. >> Bad, because the function definitions are not visible for any other >> module, that relies on the OpenGL package. >> >> My ideal solution would be, to evaluate a macro when the function is >> called and not when the module is included. >> Like this, I can define all the OpenGL functions already in the OpenGL >> module, and when you call them the first time, >> the right function ptr gets inserted into the ccall, or an error is >> raised, when OpenGL context is not initialized. >> >> this could look like this: >> >> >> module OpenGL >> >> macro getFuncPointer(name::ASCIIString) >> return getProcAddress(name) >> end >> >> glGetString(name::GLenum) = ccall(@getFuncPointer("glGetString"), ...., >> ...., name) >> export glGetString >> end >> >> >> using OpenGL >> ...create OpenGL context >> #define getProcAddress >> global const getProcAddress = glutGetProcAddress # If using GLUT for GL >> context creation >> #call gl Functions >> glGetString(GL_VERSION) >> >> Any ideas how to do this in a clean way? >> >> >> Cheers, >> >> Simon >> >
