diff options
author | Araq <rumpf_a@web.de> | 2012-10-13 01:27:13 -0700 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2012-10-13 01:27:13 -0700 |
commit | 6e4c23bd3225a51db6ff5a98b230d440127620a9 (patch) | |
tree | 61e4659bf23c76119a7c015203bdd92bd0d391fd /lib | |
parent | 4dde2137f7a63e9325efdcb9e87ce0c4ac26886f (diff) | |
parent | d1965590abe72e92d90165767e07b77c79c1d909 (diff) | |
download | Nim-6e4c23bd3225a51db6ff5a98b230d440127620a9.tar.gz |
Merge pull request #222 from fowlmouth/patch-2
opengl fix
Diffstat (limited to 'lib')
-rw-r--r-- | lib/wrappers/opengl/opengl.nim | 120 |
1 files changed, 60 insertions, 60 deletions
diff --git a/lib/wrappers/opengl/opengl.nim b/lib/wrappers/opengl/opengl.nim index fab8183f5..a61159016 100644 --- a/lib/wrappers/opengl/opengl.nim +++ b/lib/wrappers/opengl/opengl.nim @@ -8,13 +8,13 @@ # ## This module is a wrapper around `opengl`:idx:. If you define the symbol -## ``useGlew`` this wrapper does not use Nimrod's ``dynlib`` mechanism, -## but `glew`:idx: instead. However, this shouldn't be necessary anymore; even -## extension loading for the different operating systems is handled here. -## -## You need to call ``loadExtensions`` after a rendering context has been +## ``useGlew`` this wrapper does not use Nimrod's ``dynlib`` mechanism, +## but `glew`:idx: instead. However, this shouldn't be necessary anymore; even +## extension loading for the different operating systems is handled here. +## +## You need to call ``loadExtensions`` after a rendering context has been ## created to load any extension proc that your code uses. - + when defined(linux): import X, XLib, XUtil elif defined(windows): @@ -39,58 +39,58 @@ when defined(useGlew): {.pragma: wgl, header: "<GL/wglew.h>".} {.pragma: glu, dynlib: gludll.} else: - # quite complex ... thanks to extension support for various platforms: - import dynlib - - let oglHandle = LoadLib(ogldll) - if isNil(oglHandle): quit("could not load: " & ogldll) - - when defined(windows): - var wglGetProcAddress = cast[proc (s: cstring): pointer {.stdcall.}]( - symAddr(oglHandle, "wglGetProcAddress")) - elif defined(linux): - var glXGetProcAddress = cast[proc (s: cstring): pointer {.cdecl.}]( - symAddr(oglHandle, "glXGetProcAddress")) - var glXGetProcAddressARB = cast[proc (s: cstring): pointer {.cdecl.}]( - symAddr(oglHandle, "glXGetProcAddressARB")) - - proc glGetProc(h: TLibHandle; procName: cstring): pointer = - when defined(windows): - result = symAddr(h, procname) - if result != nil: return - if not isNil(wglGetProcAddress): result = wglGetProcAddress(ProcName) - elif defined(linux): - if not isNil(glXGetProcAddress): result = glXGetProcAddress(ProcName) - if result != nil: return - if not isNil(glXGetProcAddressARB): - result = glXGetProcAddressARB(ProcName) - if result != nil: return - result = symAddr(h, procname) - else: - result = symAddr(h, procName) - if result == nil: raiseInvalidLibrary(procName) - - var gluHandle: TLibHandle - - proc gluGetProc(procname: cstring): pointer = - if gluHandle == nil: - gluHandle = LoadLib(gludll) - if gluHandle == nil: quit("could not load: " & gludll) - result = glGetProc(gluHandle, procname) - - # undocumented 'dynlib' feature: the string literal is replaced by - # the imported proc name: - {.pragma: ogl, dynlib: glGetProc(oglHandle, "").} + # quite complex ... thanks to extension support for various platforms: + import dynlib + + let oglHandle = LoadLib(ogldll) + if isNil(oglHandle): quit("could not load: " & ogldll) + + when defined(windows): + var wglGetProcAddress = cast[proc (s: cstring): pointer {.stdcall.}]( + symAddr(oglHandle, "wglGetProcAddress")) + elif defined(linux): + var glXGetProcAddress = cast[proc (s: cstring): pointer {.cdecl.}]( + symAddr(oglHandle, "glXGetProcAddress")) + var glXGetProcAddressARB = cast[proc (s: cstring): pointer {.cdecl.}]( + symAddr(oglHandle, "glXGetProcAddressARB")) + + proc glGetProc(h: TLibHandle; procName: cstring): pointer = + when defined(windows): + result = symAddr(h, procname) + if result != nil: return + if not isNil(wglGetProcAddress): result = wglGetProcAddress(ProcName) + elif defined(linux): + if not isNil(glXGetProcAddress): result = glXGetProcAddress(ProcName) + if result != nil: return + if not isNil(glXGetProcAddressARB): + result = glXGetProcAddressARB(ProcName) + if result != nil: return + result = symAddr(h, procname) + else: + result = symAddr(h, procName) + if result == nil: raiseInvalidLibrary(procName) + + var gluHandle: TLibHandle + + proc gluGetProc(procname: cstring): pointer = + if gluHandle == nil: + gluHandle = LoadLib(gludll) + if gluHandle == nil: quit("could not load: " & gludll) + result = glGetProc(gluHandle, procname) + + # undocumented 'dynlib' feature: the string literal is replaced by + # the imported proc name: + {.pragma: ogl, dynlib: glGetProc(oglHandle, "0").} {.pragma: oglx, dynlib: glGetProc(oglHandle, "0").} - {.pragma: wgl, dynlib: glGetProc(oglHandle, "").} - {.pragma: glu, dynlib: gluGetProc("").} - - proc nimLoadProcs0() {.importc.} - - template loadExtensions*() = - ## call this after your rendering context has been setup if you use - ## extensions. - bind nimLoadProcs0 + {.pragma: wgl, dynlib: glGetProc(oglHandle, "0").} + {.pragma: glu, dynlib: gluGetProc("").} + + proc nimLoadProcs0() {.importc.} + + template loadExtensions*() = + ## call this after your rendering context has been setup if you use + ## extensions. + bind nimLoadProcs0 nimLoadProcs0() #============================================================================== @@ -9104,7 +9104,7 @@ proc glReplacementCodeuiTexCoord2fColor4fNormal3fVertex3fSUN*(rc: GLuint, proc glReplacementCodeuiTexCoord2fColor4fNormal3fVertex3fvSUN*(rc: PGLuint, tc: PGLfloat, c: PGLfloat, n: PGLfloat, v: PGLfloat){.stdcall, importc, ogl.} # window support functions -when defined(windows): +when defined(windows): when not defined(wglGetProcAddress): proc wglGetProcAddress*(ProcName: cstring): Pointer{.stdcall, importc, wgl.} proc wglCopyContext*(p1: HGLRC, p2: HGLRC, p3: int): BOOL{.stdcall, importc, wgl.} @@ -9446,11 +9446,11 @@ when defined(LINUX): stdcall, importc, oglx.} proc glXGetSelectedEvent*(dpy: PDisplay, draw: GLXDrawable, event_mask: PGLuint){.stdcall, importc, oglx.} - # GLX_VERSION_1_4 + # GLX_VERSION_1_4 when not defined(glXGetProcAddress): proc glXGetProcAddress*(name: cstring): pointer{.stdcall, importc, oglx.} # GLX_ARB_get_proc_address - when not defined(glXGetProcAddressARB): + when not defined(glXGetProcAddressARB): proc glXGetProcAddressARB*(name: cstring): pointer{.stdcall, importc, oglx.} # GLX_ARB_create_context proc glXCreateContextAttribsARB*(dpy: PDisplay, config: GLXFBConfig, |