Skip to content
/ glfw Public

Commit 9ee4039

Browse files
committed
Fix names and add definitions of native glfw header
1 parent d9dc8ca commit 9ee4039

File tree

5 files changed

+73
-12
lines changed

5 files changed

+73
-12
lines changed

src/glfw.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ else:
2525

2626
# Thanks to ephja for making this build system
2727
when defined(windows):
28-
{.passC: "-D_GLFW_WIN32 -DGLFW_EXPOSE_NATIVE_WIN32",
28+
{.passC: "-D_GLFW_WIN32",
2929
passL: "-lopengl32 -lgdi32",
3030
compile: "glfw/private/glfw/src/win32_init.c",
3131
compile: "glfw/private/glfw/src/win32_joystick.c",

src/glfw/native.nim

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
## Turning ``glfwMakeContextCurrent(window)`` into ``window.makeContextCurrent()``.
1111
##
1212
## You can check the original documentation `here <http://www.glfw.org/docs/latest/>`_.
13+
##
14+
## **By using the native access functions you assert that you know what you're
15+
## doing and how to fix problems caused by using them. If you don't, you
16+
## shouldn't be using them.**
17+
##
18+
## Please assert that you are using the right system for the right procedures.
1319

1420
import glfw
1521

@@ -21,6 +27,27 @@ when defined(glfwDLL):
2127
else:
2228
const glfw_dll* = "libglfw.so.3"
2329

30+
when defined(windows):
31+
{.passC: "-DGLFW_EXPOSE_NATIVE_WIN32".}
32+
if not defined(vulkan):
33+
{.passC: "-DGLFW_EXPOSE_NATIVE_WGL".}
34+
elif defined(macosx):
35+
{.passC: "-DGLFW_EXPOSE_NATIVE_COCOA".}
36+
if not defined(vulkan):
37+
{.passC: "-DGLFW_EXPOSE_NATIVE_NSGL".}
38+
else:
39+
if defined(wayland):
40+
{.passC: "-DGLFW_EXPOSE_NATIVE_WAYLAND".}
41+
else:
42+
{.passC: "-DGLFW_EXPOSE_NATIVE_X11".}
43+
44+
if defined(mesa):
45+
{.passC: "-DGLFW_EXPOSE_NATIVE_OSMESA".}
46+
elif defined(egl):
47+
{.passC: "-DGLFW_EXPOSE_NATIVE_EGL".}
48+
elif not defined(vulkan):
49+
{.passC: "-DGLFW_EXPOSE_NATIVE_GLX".}
50+
2451
# Procs
2552
when defined(glfwDLL):
2653
{.push dynlib: glfw_dll, cdecl.}
@@ -231,7 +258,7 @@ proc getGLXWindow*(window: GLFWWindow): pointer #[GLXWindow]# {.importc: "glfwGe
231258
## @since Added in version 3.2.
232259
##
233260
## @ingroup native
234-
proc wl_display*(): pointer #[struct]# {.importc: "wl_display*".}
261+
proc getWaylandDisplay*(): pointer #[struct]# {.importc: "glfwGetWaylandDisplay".}
235262
## @brief Returns the `struct wl_display*` used by GLFW.
236263
##
237264
## @return The `struct wl_display*` used by GLFW, or `NULL` if an
@@ -243,7 +270,7 @@ proc wl_display*(): pointer #[struct]# {.importc: "wl_display*".}
243270
## @since Added in version 3.2.
244271
##
245272
## @ingroup native
246-
proc wl_output*(monitor: GLFWMonitor): pointer #[struct]# {.importc: "wl_output*".}
273+
proc getWaylandMonitor*(monitor: GLFWMonitor): pointer #[struct]# {.importc: "glfwGetWaylandMonitor".}
247274
## @brief Returns the `struct wl_output*` of the specified monitor.
248275
##
249276
## @return The `struct wl_output*` of the specified monitor, or `NULL` if an
@@ -255,7 +282,7 @@ proc wl_output*(monitor: GLFWMonitor): pointer #[struct]# {.importc: "wl_output*
255282
## @since Added in version 3.2.
256283
##
257284
## @ingroup native
258-
proc wl_surface*(window: GLFWWindow): pointer #[struct]# {.importc: "wl_surface*".}
285+
proc getWaylandWindow*(window: GLFWWindow): pointer #[struct]# {.importc: "glfwGetWaylandWindow".}
259286
## @brief Returns the main `struct wl_surface*` of the specified window.
260287
##
261288
## @return The main `struct wl_surface*` of the specified window, or `NULL` if

tests/test.nim

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright 2019, NimGL contributors.
22

33
import unittest
4-
import glfw
4+
import glfw, glfw/native
55

66
proc keyProc(window: GLFWWindow, key: int32, scancode: int32, action: int32, mods: int32): void {.cdecl.} =
77
if key == GLFWKey.Escape and action == GLFWPress:
@@ -20,6 +20,10 @@ suite "GLFW":
2020
discard window.setKeyCallback(keyProc)
2121
window.makeContextCurrent()
2222

23+
var hwnd = window.getWGLContext()
24+
if hwnd == nil:
25+
echo "oh no"
26+
2327
test "main loop":
2428
while not window.windowShouldClose:
2529
glfwPollEvents()

tools/generator.nim

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ proc genProcs*(output: var string, isNative: bool) =
311311
parts.delete(0, 0)
312312
returnType = returnType.translateType()
313313

314-
let originalName = parts[1].split('(')[0]
314+
var originalName = parts[1].split('(')[0]
315315
var argsLine = line.split("(")[1]
316316
var argsTypes = argsLine.split(",")
317317
argsTypes = argsTypes.filter(proc (x: string): bool = x != "void" and x != "")
@@ -341,12 +341,15 @@ proc genProcs*(output: var string, isNative: bool) =
341341
procName[0] = procName[0].toLowerAscii()
342342

343343
if isNative:
344-
if procName == "urface*":
345-
procName = "wl_surface"
346-
elif procName == "wl_display*":
347-
procName = "wl_display"
344+
if procName == "wl_display*":
345+
procName = "getWaylandDisplay"
346+
originalName = "glfwGetWaylandDisplay"
348347
elif procName == "utput*":
349-
procName = "wl_output"
348+
procName = "getWaylandMonitor"
349+
originalName = "glfwGetWaylandMonitor"
350+
elif procName == "urface*":
351+
procName = "getWaylandWindow"
352+
originalName = "glfwGetWaylandWindow"
350353

351354
argsTypes = argsTypes.map(translateType)
352355
if procName == "glfwCreateWindow":

tools/utils.nim

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ else:
2828
2929
# Thanks to ephja for making this build system
3030
when defined(windows):
31-
{.passC: "-D_GLFW_WIN32 -DGLFW_EXPOSE_NATIVE_WIN32",
31+
{.passC: "-D_GLFW_WIN32",
3232
passL: "-lopengl32 -lgdi32",
3333
compile: "glfw/private/glfw/src/win32_init.c",
3434
compile: "glfw/private/glfw/src/win32_joystick.c",
@@ -101,6 +101,12 @@ const srcNativeHeader* = """
101101
## Turning ``glfwMakeContextCurrent(window)`` into ``window.makeContextCurrent()``.
102102
##
103103
## You can check the original documentation `here <http://www.glfw.org/docs/latest/>`_.
104+
##
105+
## **By using the native access functions you assert that you know what you're
106+
## doing and how to fix problems caused by using them. If you don't, you
107+
## shouldn't be using them.**
108+
##
109+
## Please assert that you are using the right system for the right procedures.
104110
105111
import glfw
106112
@@ -111,6 +117,27 @@ when defined(glfwDLL):
111117
const glfw_dll* = "libglfw3.dylib"
112118
else:
113119
const glfw_dll* = "libglfw.so.3"
120+
121+
when defined(windows):
122+
{.passC: "-DGLFW_EXPOSE_NATIVE_WIN32".}
123+
if not defined(vulkan):
124+
{.passC: "-DGLFW_EXPOSE_NATIVE_WGL".}
125+
elif defined(macosx):
126+
{.passC: "-DGLFW_EXPOSE_NATIVE_COCOA".}
127+
if not defined(vulkan):
128+
{.passC: "-DGLFW_EXPOSE_NATIVE_NSGL".}
129+
else:
130+
if defined(wayland):
131+
{.passC: "-DGLFW_EXPOSE_NATIVE_WAYLAND".}
132+
else:
133+
{.passC: "-DGLFW_EXPOSE_NATIVE_X11".}
134+
135+
if defined(mesa):
136+
{.passC: "-DGLFW_EXPOSE_NATIVE_OSMESA".}
137+
elif defined(egl):
138+
{.passC: "-DGLFW_EXPOSE_NATIVE_EGL".}
139+
elif not defined(vulkan):
140+
{.passC: "-DGLFW_EXPOSE_NATIVE_GLX".}
114141
"""
115142

116143
const preProcs* = """

0 commit comments

Comments
 (0)