Merge pull request #222 from fowlmouth/patch-2

opengl fix
This commit is contained in:
Araq 2012-10-13 01:27:13 -07:00
commit 6e4c23bd32

View file

@ -8,13 +8,13 @@
# #
## This module is a wrapper around `opengl`:idx:. If you define the symbol ## This module is a wrapper around `opengl`:idx:. If you define the symbol
## ``useGlew`` this wrapper does not use Nimrod's ``dynlib`` mechanism, ## ``useGlew`` this wrapper does not use Nimrod's ``dynlib`` mechanism,
## but `glew`:idx: instead. However, this shouldn't be necessary anymore; even ## but `glew`:idx: instead. However, this shouldn't be necessary anymore; even
## extension loading for the different operating systems is handled here. ## extension loading for the different operating systems is handled here.
## ##
## You need to call ``loadExtensions`` after a rendering context has been ## You need to call ``loadExtensions`` after a rendering context has been
## created to load any extension proc that your code uses. ## created to load any extension proc that your code uses.
when defined(linux): when defined(linux):
import X, XLib, XUtil import X, XLib, XUtil
elif defined(windows): elif defined(windows):
@ -39,58 +39,58 @@ when defined(useGlew):
{.pragma: wgl, header: "<GL/wglew.h>".} {.pragma: wgl, header: "<GL/wglew.h>".}
{.pragma: glu, dynlib: gludll.} {.pragma: glu, dynlib: gludll.}
else: else:
# quite complex ... thanks to extension support for various platforms: # quite complex ... thanks to extension support for various platforms:
import dynlib import dynlib
let oglHandle = LoadLib(ogldll) let oglHandle = LoadLib(ogldll)
if isNil(oglHandle): quit("could not load: " & ogldll) if isNil(oglHandle): quit("could not load: " & ogldll)
when defined(windows): when defined(windows):
var wglGetProcAddress = cast[proc (s: cstring): pointer {.stdcall.}]( var wglGetProcAddress = cast[proc (s: cstring): pointer {.stdcall.}](
symAddr(oglHandle, "wglGetProcAddress")) symAddr(oglHandle, "wglGetProcAddress"))
elif defined(linux): elif defined(linux):
var glXGetProcAddress = cast[proc (s: cstring): pointer {.cdecl.}]( var glXGetProcAddress = cast[proc (s: cstring): pointer {.cdecl.}](
symAddr(oglHandle, "glXGetProcAddress")) symAddr(oglHandle, "glXGetProcAddress"))
var glXGetProcAddressARB = cast[proc (s: cstring): pointer {.cdecl.}]( var glXGetProcAddressARB = cast[proc (s: cstring): pointer {.cdecl.}](
symAddr(oglHandle, "glXGetProcAddressARB")) symAddr(oglHandle, "glXGetProcAddressARB"))
proc glGetProc(h: TLibHandle; procName: cstring): pointer = proc glGetProc(h: TLibHandle; procName: cstring): pointer =
when defined(windows): when defined(windows):
result = symAddr(h, procname) result = symAddr(h, procname)
if result != nil: return if result != nil: return
if not isNil(wglGetProcAddress): result = wglGetProcAddress(ProcName) if not isNil(wglGetProcAddress): result = wglGetProcAddress(ProcName)
elif defined(linux): elif defined(linux):
if not isNil(glXGetProcAddress): result = glXGetProcAddress(ProcName) if not isNil(glXGetProcAddress): result = glXGetProcAddress(ProcName)
if result != nil: return if result != nil: return
if not isNil(glXGetProcAddressARB): if not isNil(glXGetProcAddressARB):
result = glXGetProcAddressARB(ProcName) result = glXGetProcAddressARB(ProcName)
if result != nil: return if result != nil: return
result = symAddr(h, procname) result = symAddr(h, procname)
else: else:
result = symAddr(h, procName) result = symAddr(h, procName)
if result == nil: raiseInvalidLibrary(procName) if result == nil: raiseInvalidLibrary(procName)
var gluHandle: TLibHandle var gluHandle: TLibHandle
proc gluGetProc(procname: cstring): pointer = proc gluGetProc(procname: cstring): pointer =
if gluHandle == nil: if gluHandle == nil:
gluHandle = LoadLib(gludll) gluHandle = LoadLib(gludll)
if gluHandle == nil: quit("could not load: " & gludll) if gluHandle == nil: quit("could not load: " & gludll)
result = glGetProc(gluHandle, procname) result = glGetProc(gluHandle, procname)
# undocumented 'dynlib' feature: the string literal is replaced by # undocumented 'dynlib' feature: the string literal is replaced by
# the imported proc name: # the imported proc name:
{.pragma: ogl, dynlib: glGetProc(oglHandle, "").} {.pragma: ogl, dynlib: glGetProc(oglHandle, "0").}
{.pragma: oglx, dynlib: glGetProc(oglHandle, "0").} {.pragma: oglx, dynlib: glGetProc(oglHandle, "0").}
{.pragma: wgl, dynlib: glGetProc(oglHandle, "").} {.pragma: wgl, dynlib: glGetProc(oglHandle, "0").}
{.pragma: glu, dynlib: gluGetProc("").} {.pragma: glu, dynlib: gluGetProc("").}
proc nimLoadProcs0() {.importc.} proc nimLoadProcs0() {.importc.}
template loadExtensions*() = template loadExtensions*() =
## call this after your rendering context has been setup if you use ## call this after your rendering context has been setup if you use
## extensions. ## extensions.
bind nimLoadProcs0 bind nimLoadProcs0
nimLoadProcs0() nimLoadProcs0()
#============================================================================== #==============================================================================
@ -9104,7 +9104,7 @@ proc glReplacementCodeuiTexCoord2fColor4fNormal3fVertex3fSUN*(rc: GLuint,
proc glReplacementCodeuiTexCoord2fColor4fNormal3fVertex3fvSUN*(rc: PGLuint, proc glReplacementCodeuiTexCoord2fColor4fNormal3fVertex3fvSUN*(rc: PGLuint,
tc: PGLfloat, c: PGLfloat, n: PGLfloat, v: PGLfloat){.stdcall, importc, ogl.} tc: PGLfloat, c: PGLfloat, n: PGLfloat, v: PGLfloat){.stdcall, importc, ogl.}
# window support functions # window support functions
when defined(windows): when defined(windows):
when not defined(wglGetProcAddress): when not defined(wglGetProcAddress):
proc wglGetProcAddress*(ProcName: cstring): Pointer{.stdcall, importc, wgl.} proc wglGetProcAddress*(ProcName: cstring): Pointer{.stdcall, importc, wgl.}
proc wglCopyContext*(p1: HGLRC, p2: HGLRC, p3: int): BOOL{.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.} stdcall, importc, oglx.}
proc glXGetSelectedEvent*(dpy: PDisplay, draw: GLXDrawable, proc glXGetSelectedEvent*(dpy: PDisplay, draw: GLXDrawable,
event_mask: PGLuint){.stdcall, importc, oglx.} event_mask: PGLuint){.stdcall, importc, oglx.}
# GLX_VERSION_1_4 # GLX_VERSION_1_4
when not defined(glXGetProcAddress): when not defined(glXGetProcAddress):
proc glXGetProcAddress*(name: cstring): pointer{.stdcall, importc, oglx.} proc glXGetProcAddress*(name: cstring): pointer{.stdcall, importc, oglx.}
# GLX_ARB_get_proc_address # GLX_ARB_get_proc_address
when not defined(glXGetProcAddressARB): when not defined(glXGetProcAddressARB):
proc glXGetProcAddressARB*(name: cstring): pointer{.stdcall, importc, oglx.} proc glXGetProcAddressARB*(name: cstring): pointer{.stdcall, importc, oglx.}
# GLX_ARB_create_context # GLX_ARB_create_context
proc glXCreateContextAttribsARB*(dpy: PDisplay, config: GLXFBConfig, proc glXCreateContextAttribsARB*(dpy: PDisplay, config: GLXFBConfig,