2013-01-13 18:35:06 -05:00
|
|
|
/*
|
2015-01-01 18:04:46 -05:00
|
|
|
* Copyright 2011-2015 Branimir Karadzic. All rights reserved.
|
2014-06-06 01:49:51 -04:00
|
|
|
* License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE
|
2013-01-13 18:35:06 -05:00
|
|
|
*/
|
|
|
|
|
2013-11-14 00:54:36 -05:00
|
|
|
#ifndef BGFX_PLATFORM_H_HEADER_GUARD
|
|
|
|
#define BGFX_PLATFORM_H_HEADER_GUARD
|
2013-01-13 18:35:06 -05:00
|
|
|
|
2013-01-14 01:44:04 -05:00
|
|
|
// NOTICE:
|
|
|
|
// This header file contains platform specific interfaces. It is only
|
|
|
|
// necessary to use this header in conjunction with creating windows.
|
|
|
|
|
2014-06-06 01:49:51 -04:00
|
|
|
#include <bx/platform.h>
|
2013-01-13 18:35:06 -05:00
|
|
|
|
2013-11-18 23:43:17 -05:00
|
|
|
namespace bgfx
|
|
|
|
{
|
|
|
|
struct RenderFrame
|
|
|
|
{
|
|
|
|
enum Enum
|
|
|
|
{
|
|
|
|
NoContext,
|
|
|
|
Render,
|
|
|
|
Exiting,
|
|
|
|
|
|
|
|
Count
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
/// WARNING: This call should be only used on platforms that don't
|
2014-01-19 17:58:05 -05:00
|
|
|
/// allow creating separate rendering thread. If it is called before
|
|
|
|
/// to bgfx::init, render thread won't be created by bgfx::init call.
|
2013-11-18 23:43:17 -05:00
|
|
|
RenderFrame::Enum renderFrame();
|
2015-04-20 19:22:40 -04:00
|
|
|
|
|
|
|
struct PlatformData
|
|
|
|
{
|
2015-05-04 17:05:04 -04:00
|
|
|
void* ndt; //< Native display type
|
|
|
|
void* nwh; //< Native window handle
|
|
|
|
void* context; //< GL context, or D3D device
|
|
|
|
void* backBuffer; //< GL backbuffer, or D3D render target view
|
|
|
|
void* backBufferDS; //< Backbuffer depth/stencil.
|
2015-04-20 19:22:40 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
void setPlatformData(const PlatformData& _hooks);
|
|
|
|
|
|
|
|
} // namespace bgfx
|
2013-11-18 23:43:17 -05:00
|
|
|
|
2013-04-16 02:10:32 -04:00
|
|
|
#if BX_PLATFORM_ANDROID
|
2013-04-19 00:16:09 -04:00
|
|
|
# include <android/native_window.h>
|
2013-04-16 02:10:32 -04:00
|
|
|
|
|
|
|
namespace bgfx
|
|
|
|
{
|
2013-08-11 01:15:59 -04:00
|
|
|
///
|
2015-04-20 19:22:40 -04:00
|
|
|
inline void androidSetWindow(::ANativeWindow* _window)
|
|
|
|
{
|
|
|
|
PlatformData pd;
|
2015-05-04 17:05:04 -04:00
|
|
|
pd.ndt = NULL;
|
|
|
|
pd.nwh = _window;
|
|
|
|
pd.context = NULL;
|
|
|
|
pd.backBuffer = NULL;
|
|
|
|
pd.backBufferDS = NULL;
|
2015-04-20 19:22:40 -04:00
|
|
|
setPlatformData(pd);
|
|
|
|
}
|
2013-08-11 01:15:59 -04:00
|
|
|
|
2013-04-16 02:10:32 -04:00
|
|
|
} // namespace bgfx
|
|
|
|
|
2013-07-21 17:44:53 -04:00
|
|
|
#elif BX_PLATFORM_IOS
|
|
|
|
namespace bgfx
|
|
|
|
{
|
2013-08-11 01:15:59 -04:00
|
|
|
///
|
2015-04-20 19:22:40 -04:00
|
|
|
inline void iosSetEaglLayer(void* _window)
|
|
|
|
{
|
|
|
|
PlatformData pd;
|
2015-05-04 17:05:04 -04:00
|
|
|
pd.ndt = NULL;
|
|
|
|
pd.nwh = _window;
|
|
|
|
pd.context = NULL;
|
|
|
|
pd.backBuffer = NULL;
|
|
|
|
pd.backBufferDS = NULL;
|
2015-04-20 19:22:40 -04:00
|
|
|
setPlatformData(pd);
|
|
|
|
}
|
2013-08-11 01:15:59 -04:00
|
|
|
|
2013-07-21 17:44:53 -04:00
|
|
|
} // namespace bgfx
|
|
|
|
|
2014-08-24 20:41:41 -04:00
|
|
|
#elif BX_PLATFORM_FREEBSD || BX_PLATFORM_LINUX || BX_PLATFORM_RPI
|
2013-01-13 18:35:06 -05:00
|
|
|
|
|
|
|
namespace bgfx
|
|
|
|
{
|
2013-08-11 01:15:59 -04:00
|
|
|
///
|
2015-04-20 22:05:41 -04:00
|
|
|
inline void x11SetDisplayWindow(void* _display, uint32_t _window, void* _glx = NULL)
|
2015-04-20 19:22:40 -04:00
|
|
|
{
|
|
|
|
PlatformData pd;
|
2015-05-04 17:05:04 -04:00
|
|
|
pd.ndt = _display;
|
|
|
|
pd.nwh = (void*)(uintptr_t)_window;
|
|
|
|
pd.context = _glx;
|
|
|
|
pd.backBuffer = NULL;
|
|
|
|
pd.backBufferDS = NULL;
|
2015-04-20 19:22:40 -04:00
|
|
|
setPlatformData(pd);
|
|
|
|
}
|
2013-08-11 01:15:59 -04:00
|
|
|
|
2013-01-13 18:35:06 -05:00
|
|
|
} // namespace bgfx
|
|
|
|
|
|
|
|
#elif BX_PLATFORM_NACL
|
|
|
|
# include <ppapi/c/ppb_graphics_3d.h>
|
|
|
|
# include <ppapi/c/ppb_instance.h>
|
|
|
|
|
|
|
|
namespace bgfx
|
|
|
|
{
|
|
|
|
typedef void (*PostSwapBuffersFn)(uint32_t _width, uint32_t _height);
|
2013-08-11 01:15:59 -04:00
|
|
|
|
|
|
|
///
|
2014-01-20 01:34:58 -05:00
|
|
|
bool naclSetInterfaces(::PP_Instance, const ::PPB_Instance*, const ::PPB_Graphics3D*, PostSwapBuffersFn);
|
2013-08-11 01:15:59 -04:00
|
|
|
|
2013-01-13 18:35:06 -05:00
|
|
|
} // namespace bgfx
|
|
|
|
|
2013-04-19 00:16:09 -04:00
|
|
|
#elif BX_PLATFORM_OSX
|
2013-01-13 18:35:06 -05:00
|
|
|
namespace bgfx
|
|
|
|
{
|
2013-08-11 01:15:59 -04:00
|
|
|
///
|
2015-04-20 19:22:40 -04:00
|
|
|
inline void osxSetNSWindow(void* _window, void* _nsgl = NULL)
|
|
|
|
{
|
|
|
|
PlatformData pd;
|
2015-05-04 17:05:04 -04:00
|
|
|
pd.ndt = NULL;
|
|
|
|
pd.nwh = _window;
|
|
|
|
pd.context = _nsgl;
|
|
|
|
pd.backBuffer = NULL;
|
|
|
|
pd.backBufferDS = NULL;
|
2015-04-20 19:22:40 -04:00
|
|
|
setPlatformData(pd);
|
|
|
|
}
|
2013-08-11 01:15:59 -04:00
|
|
|
|
2013-01-13 18:35:06 -05:00
|
|
|
} // namespace bgfx
|
|
|
|
|
2013-04-19 00:16:09 -04:00
|
|
|
#elif BX_PLATFORM_WINDOWS
|
|
|
|
# include <windows.h>
|
2013-01-15 23:37:07 -05:00
|
|
|
|
|
|
|
namespace bgfx
|
|
|
|
{
|
2013-08-11 01:15:59 -04:00
|
|
|
///
|
2015-04-20 19:22:40 -04:00
|
|
|
inline void winSetHwnd(::HWND _window)
|
|
|
|
{
|
|
|
|
PlatformData pd;
|
2015-05-04 17:05:04 -04:00
|
|
|
pd.ndt = NULL;
|
|
|
|
pd.nwh = _window;
|
|
|
|
pd.context = NULL;
|
|
|
|
pd.backBuffer = NULL;
|
|
|
|
pd.backBufferDS = NULL;
|
2015-04-20 19:22:40 -04:00
|
|
|
setPlatformData(pd);
|
|
|
|
}
|
2013-08-11 01:15:59 -04:00
|
|
|
|
2013-01-15 23:37:07 -05:00
|
|
|
} // namespace bgfx
|
|
|
|
|
2014-11-14 08:19:33 -05:00
|
|
|
#elif BX_PLATFORM_WINRT
|
|
|
|
# include <Unknwn.h>
|
|
|
|
|
|
|
|
namespace bgfx
|
|
|
|
{
|
2014-12-04 22:56:19 -05:00
|
|
|
///
|
2015-04-20 19:22:40 -04:00
|
|
|
inline void winrtSetWindow(::IUnknown* _window)
|
|
|
|
{
|
|
|
|
PlatformData pd;
|
2015-05-04 17:05:04 -04:00
|
|
|
pd.ndt = NULL;
|
|
|
|
pd.nwh = _window;
|
|
|
|
pd.context = NULL;
|
|
|
|
pd.backBuffer = NULL;
|
|
|
|
pd.backBufferDS = NULL;
|
2015-04-20 19:22:40 -04:00
|
|
|
setPlatformData(pd);
|
|
|
|
}
|
2014-11-14 08:19:33 -05:00
|
|
|
|
|
|
|
} // namespace bgfx
|
|
|
|
|
2013-01-13 18:35:06 -05:00
|
|
|
#endif // BX_PLATFORM_
|
|
|
|
|
2015-04-22 12:30:28 -04:00
|
|
|
#if defined(_SDL_syswm_h)
|
|
|
|
// If SDL_syswm.h is included before bgfxplatform.h we can enable SDL window
|
2013-08-11 02:30:57 -04:00
|
|
|
// interop convenience code.
|
2013-08-11 02:22:40 -04:00
|
|
|
|
2013-08-11 01:15:59 -04:00
|
|
|
namespace bgfx
|
|
|
|
{
|
|
|
|
///
|
|
|
|
inline bool sdlSetWindow(SDL_Window* _window)
|
|
|
|
{
|
|
|
|
SDL_SysWMinfo wmi;
|
|
|
|
SDL_VERSION(&wmi.version);
|
2014-01-25 00:49:15 -05:00
|
|
|
if (!SDL_GetWindowWMInfo(_window, &wmi) )
|
2013-08-11 01:15:59 -04:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-04-22 12:30:28 -04:00
|
|
|
PlatformData pd;
|
2014-08-07 00:53:32 -04:00
|
|
|
# if BX_PLATFORM_LINUX || BX_PLATFORM_FREEBSD
|
2015-05-04 17:05:04 -04:00
|
|
|
pd.ndt = wmi.info.x11.display;
|
|
|
|
pd.nwh = (void*)(uintptr_t)wmi.info.x11.window;
|
2013-08-11 02:22:40 -04:00
|
|
|
# elif BX_PLATFORM_OSX
|
2015-05-04 17:05:04 -04:00
|
|
|
pd.ndt = NULL;
|
|
|
|
pd.nwh = wmi.info.cocoa.window;
|
2013-08-11 02:22:40 -04:00
|
|
|
# elif BX_PLATFORM_WINDOWS
|
2015-05-04 17:05:04 -04:00
|
|
|
pd.ndt = NULL;
|
|
|
|
pd.nwh = wmi.info.win.window;
|
2013-08-11 02:22:40 -04:00
|
|
|
# endif // BX_PLATFORM_
|
2015-05-04 17:05:04 -04:00
|
|
|
pd.context = NULL;
|
|
|
|
pd.backBuffer = NULL;
|
|
|
|
pd.backBufferDS = NULL;
|
2015-04-22 12:30:28 -04:00
|
|
|
setPlatformData(pd);
|
2013-08-11 01:15:59 -04:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2013-08-12 23:47:41 -04:00
|
|
|
|
2013-08-11 01:15:59 -04:00
|
|
|
} // namespace bgfx
|
2013-08-11 02:22:40 -04:00
|
|
|
|
|
|
|
#elif defined(_glfw3_h_)
|
2013-08-11 02:30:57 -04:00
|
|
|
// If GLFW/glfw3.h is included before bgfxplatform.h we can enable GLFW3
|
|
|
|
// window interop convenience code.
|
2013-08-11 02:22:40 -04:00
|
|
|
|
2014-08-07 00:53:32 -04:00
|
|
|
# if BX_PLATFORM_LINUX || BX_PLATFORM_FREEBSD
|
2013-08-11 02:22:40 -04:00
|
|
|
# define GLFW_EXPOSE_NATIVE_X11
|
|
|
|
# define GLFW_EXPOSE_NATIVE_GLX
|
|
|
|
# elif BX_PLATFORM_OSX
|
|
|
|
# define GLFW_EXPOSE_NATIVE_COCOA
|
|
|
|
# define GLFW_EXPOSE_NATIVE_NSGL
|
|
|
|
# elif BX_PLATFORM_WINDOWS
|
|
|
|
# define GLFW_EXPOSE_NATIVE_WIN32
|
|
|
|
# define GLFW_EXPOSE_NATIVE_WGL
|
|
|
|
# endif //
|
|
|
|
# include <GLFW/glfw3native.h>
|
|
|
|
|
|
|
|
namespace bgfx
|
|
|
|
{
|
|
|
|
inline void glfwSetWindow(GLFWwindow* _window)
|
|
|
|
{
|
2015-04-22 12:30:28 -04:00
|
|
|
PlatformData pd;
|
2014-08-07 00:53:32 -04:00
|
|
|
# if BX_PLATFORM_LINUX || BX_PLATFORM_FREEBSD
|
2015-05-04 17:05:04 -04:00
|
|
|
pd.ndt = glfwGetX11Display();
|
|
|
|
pd.nwh = (void*)(uintptr_t)glfwGetX11Window(_window);
|
|
|
|
pd.context = glfwGetGLXContext(_window);
|
2013-08-11 02:22:40 -04:00
|
|
|
# elif BX_PLATFORM_OSX
|
2015-05-04 17:05:04 -04:00
|
|
|
pd.ndt = NULL;
|
|
|
|
pd.nwh = glfwGetCocoaWindow(_window);
|
|
|
|
pd.context = glfwGetNSGLContext(_window);
|
2013-08-11 02:22:40 -04:00
|
|
|
# elif BX_PLATFORM_WINDOWS
|
2015-05-04 17:05:04 -04:00
|
|
|
pd.ndt = NULL;
|
|
|
|
pd.nwh = glfwGetWin32Window(_window);
|
|
|
|
pd.context = NULL;
|
2015-03-25 00:24:13 -04:00
|
|
|
# endif // BX_PLATFORM_WINDOWS
|
2015-05-04 17:05:04 -04:00
|
|
|
pd.backBuffer = NULL;
|
|
|
|
pd.backBufferDS = NULL;
|
2015-04-22 12:30:28 -04:00
|
|
|
setPlatformData(pd);
|
2013-08-11 02:22:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace bgfx
|
|
|
|
|
|
|
|
#endif // defined(_SDL_H)
|
2013-08-11 01:15:59 -04:00
|
|
|
|
2013-11-14 00:54:36 -05:00
|
|
|
#endif // BGFX_PLATFORM_H_HEADER_GUARD
|