mirror of
https://github.com/nim-lang/Nim.git
synced 2026-06-08 21:04:20 +00:00
website improvements; better opengl wrapper (still broken)
This commit is contained in:
@@ -21,19 +21,22 @@ proc LoadLib*(path: string): TLibHandle
|
||||
proc UnloadLib*(lib: TLibHandle)
|
||||
## unloads the library `lib`
|
||||
|
||||
proc symAddr*(lib: TLibHandle, name: string): pointer
|
||||
proc raiseInvalidLibrary*(name: cstring) {.noinline, noreturn.} =
|
||||
## raises an `EInvalidLibrary` exception.
|
||||
var e: ref EInvalidLibrary
|
||||
new(e)
|
||||
e.msg = "could not find symbol: " & $name
|
||||
raise e
|
||||
|
||||
proc symAddr*(lib: TLibHandle, name: cstring): pointer
|
||||
## retrieves the address of a procedure/variable from `lib`. Returns nil
|
||||
## if the symbol could not be found.
|
||||
|
||||
proc checkedSymAddr*(lib: TLibHandle, name: string): pointer =
|
||||
proc checkedSymAddr*(lib: TLibHandle, name: cstring): pointer =
|
||||
## retrieves the address of a procedure/variable from `lib`. Raises
|
||||
## `EInvalidLibrary` if the symbol could not be found.
|
||||
result = symAddr(lib, name)
|
||||
if result == nil:
|
||||
var e: ref EInvalidLibrary
|
||||
new(e)
|
||||
e.msg = "could not find symbol: " & name
|
||||
raise e
|
||||
if result == nil: raiseInvalidLibrary(name)
|
||||
|
||||
when defined(posix):
|
||||
#
|
||||
@@ -55,7 +58,7 @@ when defined(posix):
|
||||
|
||||
proc LoadLib(path: string): TLibHandle = return dlopen(path, RTLD_NOW)
|
||||
proc UnloadLib(lib: TLibHandle) = dlclose(lib)
|
||||
proc symAddr(lib: TLibHandle, name: string): pointer =
|
||||
proc symAddr(lib: TLibHandle, name: cstring): pointer =
|
||||
return dlsym(lib, name)
|
||||
|
||||
elif defined(windows) or defined(dos):
|
||||
@@ -77,7 +80,7 @@ elif defined(windows) or defined(dos):
|
||||
result = cast[TLibHandle](winLoadLibrary(path))
|
||||
proc UnloadLib(lib: TLibHandle) = FreeLibrary(cast[THINSTANCE](lib))
|
||||
|
||||
proc symAddr(lib: TLibHandle, name: string): pointer =
|
||||
proc symAddr(lib: TLibHandle, name: cstring): pointer =
|
||||
result = GetProcAddress(cast[THINSTANCE](lib), name)
|
||||
|
||||
else:
|
||||
|
||||
@@ -8,8 +8,27 @@
|
||||
#
|
||||
|
||||
## This module is a wrapper around `opengl`:idx:. If you define the symbol
|
||||
## ``useGlew`` this wrapper does not use Nimrod's ``dynlib`` mechanism (which
|
||||
## ends up calling ``dlsym`` or ``GetProcAddress``), but `glew`:idx: instead.
|
||||
## ``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.
|
||||
|
||||
when defined(linux):
|
||||
import X, XLib, XUtil
|
||||
elif defined(windows):
|
||||
import winlean, os
|
||||
|
||||
when defined(windows):
|
||||
const
|
||||
ogldll* = "OpenGL32.dll"
|
||||
gludll* = "GLU32.dll"
|
||||
elif defined(macosx):
|
||||
const
|
||||
ogldll* = "libGL.dylib"
|
||||
gludll* = "libGLU.dylib"
|
||||
else:
|
||||
const
|
||||
ogldll* = "libGL.so.1"
|
||||
gludll* = "libGLU.so.1"
|
||||
|
||||
when defined(useGlew):
|
||||
{.pragma: ogl, header: "<GL/glew.h>".}
|
||||
@@ -17,11 +36,51 @@ when defined(useGlew):
|
||||
{.pragma: wgl, header: "<GL/wglew.h>".}
|
||||
{.pragma: glu, dynlib: gludll.}
|
||||
else:
|
||||
{.pragma: ogl, dynlib: ogldll.}
|
||||
{.pragma: oglx, dynlib: ogldll.}
|
||||
{.pragma: wgl, dynlib: ogldll.}
|
||||
{.pragma: glu, dynlib: gludll.}
|
||||
|
||||
# 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 empty string literal is replaced by
|
||||
# the imported proc name:
|
||||
{.pragma: ogl, dynlib: glGetProc(oglHandle, "").}
|
||||
{.pragma: oglx, dynlib: glGetProc(oglHandle, "").}
|
||||
{.pragma: wgl, dynlib: glGetProc(oglHandle, "").}
|
||||
{.pragma: glu, dynlib: gluGetProc("").}
|
||||
|
||||
#==============================================================================
|
||||
#
|
||||
@@ -398,27 +457,6 @@ else:
|
||||
|
||||
{.deadCodeElim: on.}
|
||||
|
||||
when defined(LINUX):
|
||||
import
|
||||
X, XLib, XUtil
|
||||
|
||||
when defined(windows):
|
||||
import
|
||||
winlean, os
|
||||
|
||||
when defined(windows):
|
||||
const
|
||||
ogldll* = "OpenGL32.dll"
|
||||
gludll* = "GLU32.dll"
|
||||
elif defined(macosx):
|
||||
const
|
||||
ogldll* = "libGL.dylib"
|
||||
gludll* = "libGLU.dylib"
|
||||
else:
|
||||
const
|
||||
ogldll* = "libGL.so.1"
|
||||
gludll* = "libGLU.so.1"
|
||||
|
||||
type
|
||||
PPointer* = ptr Pointer
|
||||
GLenum* = int
|
||||
@@ -9396,10 +9434,12 @@ when defined(LINUX):
|
||||
stdcall, importc, oglx.}
|
||||
proc glXGetSelectedEvent*(dpy: PDisplay, draw: GLXDrawable,
|
||||
event_mask: PGLuint){.stdcall, importc, oglx.}
|
||||
# GLX_VERSION_1_4
|
||||
proc glXGetProcAddress*(name: cstring): pointer{.stdcall, importc, oglx.}
|
||||
# GLX_VERSION_1_4
|
||||
when not defined(glXGetProcAddress):
|
||||
proc glXGetProcAddress*(name: cstring): pointer{.stdcall, importc, oglx.}
|
||||
# GLX_ARB_get_proc_address
|
||||
proc glXGetProcAddressARB*(name: cstring): pointer{.stdcall, importc, oglx.}
|
||||
when not defined(glXGetProcAddressARB):
|
||||
proc glXGetProcAddressARB*(name: cstring): pointer{.stdcall, importc, oglx.}
|
||||
# GLX_ARB_create_context
|
||||
proc glXCreateContextAttribsARB*(dpy: PDisplay, config: GLXFBConfig,
|
||||
share_context: GLXContext, direct: GLboolean,
|
||||
|
||||
Reference in New Issue
Block a user