Add sdl gpu and refactor some code
This commit is contained in:
parent
7a3d6c4f15
commit
aaedb8f6ab
9 changed files with 168 additions and 18 deletions
2
nim.cfg
2
nim.cfg
|
|
@ -1 +1 @@
|
|||
-d:SDL_DL -d:SDL_Static -d:SDL_image_Static -d:SDL_mixer_Static -d:SDL_net_Static -d:SDL_ttf_Static -d:SDL_image_DL -d:SDL_mixer_DL -d:SDL_net_DL -d:SDL_ttf_DL
|
||||
-d:SDL_DL -d:SDL_Static -d:SDL_image_Static -d:SDL_mixer_Static -d:SDL_net_Static -d:SDL_ttf_Static -d:SDL_gpu_Static -d:SDL_image_DL -d:SDL_mixer_DL -d:SDL_net_DL -d:SDL_ttf_DL -d:SDL_gpu_Git
|
||||
|
|
@ -3,7 +3,8 @@ import nimterop/[cimport, build]
|
|||
|
||||
const
|
||||
baseDir = currentSourcePath.parentDir().parentDir().parentDir()
|
||||
srcDir = baseDir/"build"/"sdl2"
|
||||
srcDir = baseDir / "build" / "sdl2"
|
||||
buildDir = srcDir / "buildcache"
|
||||
|
||||
getHeader(
|
||||
"SDL.h",
|
||||
|
|
@ -148,4 +149,19 @@ cPlugin:
|
|||
when defined(SDL_Static):
|
||||
cImport(SDL_Path, recurse = true)
|
||||
else:
|
||||
cImport(SDL_Path, recurse = true, dynlib = "SDL_LPath")
|
||||
cImport(SDL_Path, recurse = true, dynlib = "SDL_LPath")
|
||||
|
||||
proc getDynlibExt(): string =
|
||||
when defined(windows):
|
||||
result = ".dll"
|
||||
elif defined(linux):
|
||||
result = ".so[0-9.]*"
|
||||
elif defined(macosx):
|
||||
result = ".dylib[0-9.]*"
|
||||
|
||||
proc findDynlib(): string =
|
||||
const pathRegex = "(lib)?SDL2[_-]?(static)?[0-9.\\-]*\\" & getDynlibExt()
|
||||
return findFile(pathRegex, buildDir, regex = true)
|
||||
|
||||
const SDLDyLibPath* = findDynlib()
|
||||
const SDLMainLib* = buildDir / "libSDL2main.a"
|
||||
118
src/nim_sdl2_gpu/wrapper.nim
Normal file
118
src/nim_sdl2_gpu/wrapper.nim
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
import os, strformat
|
||||
import ../nim_sdl2/wrapper
|
||||
import nimterop/[build, cimport]
|
||||
|
||||
const
|
||||
baseDir = currentSourcePath.parentDir().parentDir().parentDir()
|
||||
buildDir = baseDir / "build"
|
||||
sdlDir = buildDir / "sdl2"
|
||||
sdlIncludeDir = sdlDir / "include"
|
||||
cmakeModPath = baseDir / "cmake" / "sdl2"
|
||||
srcDir = buildDir / "sdl2_gpu"
|
||||
|
||||
getHeader(
|
||||
"SDL_gpu.h",
|
||||
giturl = "https://github.com/grimfang4/sdl-gpu",
|
||||
outdir = srcDir,
|
||||
altNames = "SDL2_gpu",
|
||||
cmakeFlags = &"-DCMAKE_C_FLAGS=-I{sdlIncludeDir} -DCMAKE_MODULE_PATH={cmakeModPath} -DSDL2_LIBRARY={SDLDyLibPath} " &
|
||||
&"-DSDL2MAIN_LIBRARY={SDLMainLib} -DSDL2_PATH={sdlDir} -DSDL2_INCLUDE_DIR={sdlIncludeDir} -DSDL_gpu_BUILD_DEMOS=OFF"
|
||||
)
|
||||
|
||||
static:
|
||||
cDebug()
|
||||
cDisableCaching()
|
||||
|
||||
cOverride:
|
||||
type
|
||||
LogLevelEnum* = enum
|
||||
LOG_LEVEL_INFO = 0
|
||||
LOG_LEVEL_WARNING
|
||||
LOG_LEVEL_ERROR
|
||||
|
||||
cPlugin:
|
||||
import strutils, nre
|
||||
import sets
|
||||
|
||||
const EVENT_TYPES = toHashSet([
|
||||
"FIRSTEVENT",
|
||||
"QUIT",
|
||||
"APP_TERMINATING",
|
||||
"APP_LOWMEMORY",
|
||||
"APP_WILLENTERBACKGROUND",
|
||||
"APP_DIDENTERBACKGROUND",
|
||||
"APP_WILLENTERFOREGROUND",
|
||||
"APP_DIDENTERFOREGROUND",
|
||||
"DISPLAYEVENT",
|
||||
"WINDOWEVENT",
|
||||
"SYSWMEVENT",
|
||||
"KEYDOWN",
|
||||
"KEYUP",
|
||||
"TEXTEDITING",
|
||||
"TEXTINPUT",
|
||||
"KEYMAPCHANGED",
|
||||
"MOUSEMOTION",
|
||||
"MOUSEBUTTONDOWN",
|
||||
"MOUSEBUTTONUP",
|
||||
"MOUSEWHEEL",
|
||||
"JOYAXISMOTION",
|
||||
"JOYBALLMOTION",
|
||||
"JOYHATMOTION",
|
||||
"JOYBUTTONDOWN",
|
||||
"JOYBUTTONUP",
|
||||
"JOYDEVICEADDED",
|
||||
"JOYDEVICEREMOVED",
|
||||
"CONTROLLERAXISMOTION",
|
||||
"CONTROLLERBUTTONDOWN",
|
||||
"CONTROLLERBUTTONUP",
|
||||
"CONTROLLERDEVICEADDED",
|
||||
"CONTROLLERDEVICEREMOVED",
|
||||
"CONTROLLERDEVICEREMAPPED",
|
||||
"FINGERDOWN",
|
||||
"FINGERUP",
|
||||
"FINGERMOTION",
|
||||
"DOLLARGESTURE",
|
||||
"DOLLARRECORD",
|
||||
"MULTIGESTURE",
|
||||
"CLIPBOARDUPDATE",
|
||||
"DROPFILE",
|
||||
"DROPTEXT",
|
||||
"DROPBEGIN",
|
||||
"DROPCOMPLETE",
|
||||
"AUDIODEVICEADDED",
|
||||
"AUDIODEVICEREMOVED",
|
||||
"SENSORUPDATE",
|
||||
"RENDER_TARGETS_RESET",
|
||||
"RENDER_DEVICE_RESET",
|
||||
"USEREVENT",
|
||||
"LASTEVENT",
|
||||
])
|
||||
|
||||
# Symbol renaming examples
|
||||
proc onSymbol*(sym: var Symbol) {.exportc, dynlib.} =
|
||||
# Remove prefixes or suffixes from procs
|
||||
sym.name = sym.name.replace(re"^GPU_", "")
|
||||
|
||||
if sym.kind == nskProc or sym.kind == nskType or sym.kind == nskConst:
|
||||
if sym.name != "_":
|
||||
sym.name = sym.name.strip(chars = {'_'})
|
||||
|
||||
sym.name = sym.name.replace(re"^SDL_", "")
|
||||
|
||||
if sym.name.startsWith("SDLK_"):
|
||||
sym.name = sym.name.replace("SDLK_", "KEYCODE_")
|
||||
|
||||
if EVENT_TYPES.contains(sym.name):
|
||||
sym.name = "EVENT_" & sym.name
|
||||
|
||||
if sym.name == "ThreadID":
|
||||
sym.name = "CurrentThreadID"
|
||||
if sym.name == "GLContextResetNotification":
|
||||
sym.name = "GLContextResetNotificationEnum"
|
||||
if sym.name == "KeyCode":
|
||||
sym.name = "KeyCodeEnum"
|
||||
|
||||
when defined(SDL_gpu_Static):
|
||||
cImport(SDL_gpuPath, recurse = true, flags = &"-I={sdlIncludeDir} -f=ast2")
|
||||
else:
|
||||
cImport(SDL_gpuPath, recurse = true, dynlib = "SDL_gpuLPath", flags = &"-I={sdlIncludeDir} -f=ast2")
|
||||
|
|
@ -106,7 +106,7 @@ cPlugin:
|
|||
sym.name = "KeyCodeEnum"
|
||||
|
||||
|
||||
when defined(SDL_Static):
|
||||
cImport(SDL_image_Path, recurse = false, flags = &"-I={sdlIncludeDir}")
|
||||
when defined(SDL_image_Static):
|
||||
cImport(SDL_image_Path, recurse = false, flags = &"-I={sdlIncludeDir} -f=ast2")
|
||||
else:
|
||||
cImport(SDL_image_Path, recurse = false, dynlib = "SDL_image_LPath", flags = &"-I={sdlIncludeDir}")
|
||||
cImport(SDL_image_Path, recurse = false, dynlib = "SDL_image_LPath", flags = &"-I={sdlIncludeDir} -f=ast2")
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ cPlugin:
|
|||
if sym.name == "KeyCode":
|
||||
sym.name = "KeyCodeEnum"
|
||||
|
||||
when defined(SDL_Static):
|
||||
cImport(SDL_mixer_Path, recurse = false, flags = &"-I={sdlIncludeDir}")
|
||||
when defined(SDL_mixer_Static):
|
||||
cImport(SDL_mixer_Path, recurse = false, flags = &"-I={sdlIncludeDir} -f=ast2")
|
||||
else:
|
||||
cImport(SDL_mixer_Path, recurse = false, dynlib = "SDL_mixer_LPath", flags = &"-I={sdlIncludeDir}")
|
||||
cImport(SDL_mixer_Path, recurse = false, dynlib = "SDL_mixer_LPath", flags = &"-I={sdlIncludeDir} -f=ast2")
|
||||
|
|
|
|||
|
|
@ -106,9 +106,9 @@ cPlugin:
|
|||
sym.name = "KeyCodeEnum"
|
||||
|
||||
|
||||
when defined(SDL_Static):
|
||||
cImport(SDL_net_Path, recurse = false, flags = &"-I={sdlIncludeDir}")
|
||||
cImport(srcDir / "SDLnetsys.h", recurse = false, flags = &"-I={sdlIncludeDir}")
|
||||
when defined(SDL_net_Static):
|
||||
cImport(SDL_net_Path, recurse = false, flags = &"-I={sdlIncludeDir} -f=ast2")
|
||||
cImport(srcDir / "SDLnetsys.h", recurse = false, flags = &"-I={sdlIncludeDir} -f=ast2")
|
||||
else:
|
||||
cImport(SDL_net_Path, recurse = false, dynlib = "SDL_net_LPath", flags = &"-I={sdlIncludeDir}")
|
||||
cImport(srcDir / "SDLnetsys.h", recurse = false, flags = &"-I={sdlIncludeDir}")
|
||||
cImport(SDL_net_Path, recurse = false, dynlib = "SDL_net_LPath", flags = &"-I={sdlIncludeDir} -f=ast2")
|
||||
cImport(srcDir / "SDLnetsys.h", recurse = false, flags = &"-I={sdlIncludeDir} -f=ast2")
|
||||
|
|
@ -15,7 +15,8 @@ getHeader(
|
|||
dlurl = "https://www.libsdl.org/projects/SDL_ttf/release/SDL2_ttf-2.0.15.tar.gz",
|
||||
outdir = srcDir,
|
||||
altNames = "SDL2_ttf",
|
||||
cmakeFlags = &"-DCMAKE_C_FLAGS=-I{sdlIncludeDir} -DCMAKE_MODULE_PATH={cmakeModPath} -DSDL2_LIBRARY=2.0.12 -DSDL2_PATH={sdlDir}"
|
||||
cmakeFlags = &"-DCMAKE_C_FLAGS=-I{sdlIncludeDir} -DCMAKE_MODULE_PATH={cmakeModPath} " &
|
||||
&"-DSDL2MAIN_LIBRARY={SDLMainLib} -DSDL2_LIBRARY={SDLDyLibPath} -DSDL2_PATH={sdlDir}"
|
||||
)
|
||||
|
||||
# static:
|
||||
|
|
@ -107,7 +108,7 @@ cPlugin:
|
|||
if sym.name == "KeyCode":
|
||||
sym.name = "KeyCodeEnum"
|
||||
|
||||
when defined(SDL_Static):
|
||||
cImport(SDL_ttf_Path, recurse = false, flags = &"-I={sdlIncludeDir}")
|
||||
when defined(SDL_ttf_Static):
|
||||
cImport(SDL_ttf_Path, recurse = false, flags = &"-I={sdlIncludeDir} -f=ast2")
|
||||
else:
|
||||
cImport(SDL_ttf_Path, recurse = false, dynlib = "SDL_ttf_LPath", flags = &"-I={sdlIncludeDir}")
|
||||
cImport(SDL_ttf_Path, recurse = false, dynlib = "SDL_ttf_LPath", flags = &"-I={sdlIncludeDir} -f=ast2")
|
||||
|
|
|
|||
13
src/sdl2_all.nim
Normal file
13
src/sdl2_all.nim
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import sdl2
|
||||
import sdl2_gpu
|
||||
import sdl2_image
|
||||
import sdl2_mixer
|
||||
import sdl2_net
|
||||
import sdl2_ttf
|
||||
|
||||
export sdl2
|
||||
export sdl2_gpu
|
||||
export sdl2_image
|
||||
export sdl2_mixer
|
||||
export sdl2_net
|
||||
export sdl2_ttf
|
||||
2
src/sdl2_gpu.nim
Normal file
2
src/sdl2_gpu.nim
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
import nim_sdl2_gpu / wrapper
|
||||
export wrapper
|
||||
Loading…
Add table
Add a link
Reference in a new issue