Skip to content

Commit a6494d7

Browse files
authored
Merge pull request #14 from vixorien/expose-window-handle
Added a getter to expose native window handle
2 parents c9581e3 + 4819f18 commit a6494d7

1 file changed

Lines changed: 20 additions & 6 deletions

File tree

thirteen.h

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,16 @@ namespace Thirteen
8989
using uint8 = unsigned char;
9090
using uint32 = unsigned int;
9191

92+
#if defined(THIRTEEN_PLATFORM_WINDOWS)
93+
using NativeWindowHandle = HWND;
94+
#elif defined(THIRTEEN_PLATFORM_WEB)
95+
using NativeWindowHandle = void*;
96+
#elif defined(THIRTEEN_PLATFORM_MACOS)
97+
using NativeWindowHandle = void*;
98+
#elif defined(THIRTEEN_PLATFORM_LINUX)
99+
using NativeWindowHandle = int;
100+
#endif
101+
92102
// ========== Function Prototypes ==========
93103

94104
// Initializes window and DX12. Returns a pointer to the pixel buffer on success, or nullptr on failure.
@@ -121,6 +131,9 @@ namespace Thirteen
121131
// Returns the current height of the rendering surface in pixels.
122132
[[nodiscard]] uint32 GetHeight();
123133

134+
// Returns the platform-specific window handle.
135+
[[nodiscard]] NativeWindowHandle GetWindowHandle();
136+
124137
// Sets the size of the rendering surface. Recreates internal buffers. Returns the new pixel buffer pointer on success, or nullptr on failure. The returned pointer may differ from the one returned by Init().
125138
[[nodiscard]] uint8* SetSize(uint32 width, uint32 height);
126139

@@ -191,8 +204,6 @@ namespace Thirteen
191204

192205
#if defined(THIRTEEN_PLATFORM_WINDOWS)
193206

194-
using NativeWindowHandle = HWND;
195-
196207
struct PlatformWin32
197208
{
198209
HWND hwnd = nullptr;
@@ -646,7 +657,7 @@ namespace Thirteen
646657
}
647658
};
648659
#elif defined(__EMSCRIPTEN__)
649-
using NativeWindowHandle = void*;
660+
650661
struct PlatformWeb
651662
{
652663
static constexpr const char* c_canvasSelector = "#canvas";
@@ -1200,7 +1211,7 @@ namespace Thirteen
12001211
}
12011212
};
12021213
#elif defined(THIRTEEN_PLATFORM_MACOS)
1203-
using NativeWindowHandle = void*;
1214+
12041215
extern "C" void* MTLCreateSystemDefaultDevice(void);
12051216

12061217
using NSUInteger = unsigned long;
@@ -1571,8 +1582,6 @@ namespace Thirteen
15711582

15721583
#elif defined(THIRTEEN_PLATFORM_LINUX)
15731584

1574-
using NativeWindowHandle = int;
1575-
15761585
struct PlatformLinuxX11GL
15771586
{
15781587
void * x11Library = nullptr;
@@ -2242,6 +2251,11 @@ namespace Thirteen
22422251
return Internal::height;
22432252
}
22442253

2254+
NativeWindowHandle GetWindowHandle()
2255+
{
2256+
return Internal::platform->GetWindowHandle();
2257+
}
2258+
22452259
uint8* SetSize(uint32 width, uint32 height)
22462260
{
22472261
using namespace Internal;

0 commit comments

Comments
 (0)