> On Dec 12, 2015, at 1:39 PM, David Turnbull via swift-users > <[email protected]> wrote: > > It's looking like the Epoxy requirement for SwiftGL is going away real soon > now. I was able to lookup the OpenGL symbols from pure Swift code. No > compiled C code is needed at all. What follows is roughly how I will do it. > It lazily loads the pointer the first time you use it. The Linux version is > only slightly different. > > Does anyone know a way to do this without the unsafeBitCast? > > import Darwin > > let handle = > dlopen("/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL", > RTLD_LAZY) > > func DLOADglGetIntegerv(a:GLenum, _ b:UnsafeMutablePointer<GLint>) -> Void { > glGetIntegerv = unsafeBitCast(dlsym(handle, "glGetIntegerv"), > glGetIntegerv.dynamicType) > glGetIntegerv(a,b) > } > > public var glGetIntegerv:@convention(c) (GLenum, UnsafeMutablePointer<GLint>) > -> Void = { DLOADglGetIntegerv($0,$1) }
I think the unsafeBitCast is fundamentally necessary here to coerce the void pointer you get from dlsym to a C function pointer. I don't think it's a problem. This is pretty awesome! -Joe
_______________________________________________ swift-users mailing list [email protected] https://lists.swift.org/mailman/listinfo/swift-users
