From 5b6a42e5cd3b0803ed669740872a8e825212343e Mon Sep 17 00:00:00 2001 From: bkaradzic Date: Sat, 10 Aug 2013 22:15:59 -0700 Subject: [PATCH] Added SDL2 support. --- include/bgfxplatform.h | 43 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/include/bgfxplatform.h b/include/bgfxplatform.h index a25f54783..8a1d49fc0 100755 --- a/include/bgfxplatform.h +++ b/include/bgfxplatform.h @@ -17,13 +17,17 @@ namespace bgfx { + /// void androidSetWindow(::ANativeWindow* _window); + } // namespace bgfx #elif BX_PLATFORM_IOS namespace bgfx { + /// void iosSetEaglLayer(void* _layer); + } // namespace bgfx #elif BX_PLATFORM_LINUX @@ -31,7 +35,9 @@ namespace bgfx namespace bgfx { + /// void x11SetDisplayWindow(::Display* _display, ::Window _window); + } // namespace bgfx #elif BX_PLATFORM_NACL @@ -41,13 +47,18 @@ namespace bgfx namespace bgfx { typedef void (*PostSwapBuffersFn)(uint32_t _width, uint32_t _height); + + /// void naclSetIntefraces(::PP_Instance, const ::PPB_Instance*, const ::PPB_Graphics3D*, PostSwapBuffersFn); + } // namespace bgfx #elif BX_PLATFORM_OSX namespace bgfx { + /// void osxSetNSWindow(void* _window); + } // namespace bgfx #elif BX_PLATFORM_WINDOWS @@ -55,9 +66,41 @@ namespace bgfx namespace bgfx { + /// void winSetHwnd(::HWND _window); + } // namespace bgfx #endif // BX_PLATFORM_ +#ifdef _SDL_H +// If SDL is included before bgfxplatform.h we can enable SDL window interop +// convenience code. +# include + +namespace bgfx +{ + /// + inline bool sdlSetWindow(SDL_Window* _window) + { + SDL_SysWMinfo wmi; + SDL_VERSION(&wmi.version); + if (-1 == SDL_GetWindowWMInfo(_window, &wmi) ) + { + return false; + } + +#if BX_PLATFORM_LINUX + x11SetDisplayWindow(wmi.info.x11.display, wmi.info.x11.window); +#elif BX_PLATFORM_OSX + osxSetNSWindow(wmi.info.cocoa.window); +#elif BX_PLATFORM_WINDOWS + winSetHwnd(wmi.info.win.window); +#endif // BX_PLATFORM_ + + return true; + } +} // namespace bgfx +#endif // _SDL_H + #endif // __BGFXPLATFORM_H__