2013-01-14 03:35:06 +04:00
|
|
|
/*
|
2014-02-11 10:07:04 +04:00
|
|
|
* Copyright 2011-2014 Branimir Karadzic. All rights reserved.
|
2014-06-06 09:49:51 +04:00
|
|
|
* License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE
|
2013-01-14 03:35:06 +04:00
|
|
|
*/
|
|
|
|
|
2013-11-14 09:54:36 +04:00
|
|
|
#ifndef BGFX_PLATFORM_H_HEADER_GUARD
|
|
|
|
#define BGFX_PLATFORM_H_HEADER_GUARD
|
2013-01-14 03:35:06 +04:00
|
|
|
|
2013-01-14 10:44:04 +04: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 09:49:51 +04:00
|
|
|
#include <bx/platform.h>
|
2013-01-14 03:35:06 +04:00
|
|
|
|
2013-11-19 08:43:17 +04: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-20 02:58:05 +04: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-19 08:43:17 +04:00
|
|
|
RenderFrame::Enum renderFrame();
|
|
|
|
}
|
|
|
|
|
2013-04-16 10:10:32 +04:00
|
|
|
#if BX_PLATFORM_ANDROID
|
2013-04-19 08:16:09 +04:00
|
|
|
# include <android/native_window.h>
|
2013-04-16 10:10:32 +04:00
|
|
|
|
|
|
|
namespace bgfx
|
|
|
|
{
|
2013-08-11 09:15:59 +04:00
|
|
|
///
|
2013-04-19 08:16:09 +04:00
|
|
|
void androidSetWindow(::ANativeWindow* _window);
|
2013-08-11 09:15:59 +04:00
|
|
|
|
2013-04-16 10:10:32 +04:00
|
|
|
} // namespace bgfx
|
|
|
|
|
2013-07-22 01:44:53 +04:00
|
|
|
#elif BX_PLATFORM_IOS
|
|
|
|
namespace bgfx
|
|
|
|
{
|
2013-08-11 09:15:59 +04:00
|
|
|
///
|
2013-07-22 02:38:44 +04:00
|
|
|
void iosSetEaglLayer(void* _layer);
|
2013-08-11 09:15:59 +04:00
|
|
|
|
2013-07-22 01:44:53 +04:00
|
|
|
} // namespace bgfx
|
|
|
|
|
2013-04-16 10:10:32 +04:00
|
|
|
#elif BX_PLATFORM_LINUX
|
2013-01-14 03:35:06 +04:00
|
|
|
# include <X11/Xlib.h>
|
|
|
|
|
|
|
|
namespace bgfx
|
|
|
|
{
|
2013-08-11 09:15:59 +04:00
|
|
|
///
|
2013-01-14 03:35:06 +04:00
|
|
|
void x11SetDisplayWindow(::Display* _display, ::Window _window);
|
2013-08-11 09:15:59 +04:00
|
|
|
|
2013-01-14 03:35:06 +04: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 09:15:59 +04:00
|
|
|
|
|
|
|
///
|
2014-01-20 10:34:58 +04:00
|
|
|
bool naclSetInterfaces(::PP_Instance, const ::PPB_Instance*, const ::PPB_Graphics3D*, PostSwapBuffersFn);
|
2013-08-11 09:15:59 +04:00
|
|
|
|
2013-01-14 03:35:06 +04:00
|
|
|
} // namespace bgfx
|
|
|
|
|
2013-04-19 08:16:09 +04:00
|
|
|
#elif BX_PLATFORM_OSX
|
2013-01-14 03:35:06 +04:00
|
|
|
namespace bgfx
|
|
|
|
{
|
2013-08-11 09:15:59 +04:00
|
|
|
///
|
2013-04-19 10:32:12 +04:00
|
|
|
void osxSetNSWindow(void* _window);
|
2013-08-11 09:15:59 +04:00
|
|
|
|
2013-01-14 03:35:06 +04:00
|
|
|
} // namespace bgfx
|
|
|
|
|
2013-04-19 08:16:09 +04:00
|
|
|
#elif BX_PLATFORM_WINDOWS
|
|
|
|
# include <windows.h>
|
2013-01-16 08:37:07 +04:00
|
|
|
|
|
|
|
namespace bgfx
|
|
|
|
{
|
2013-08-11 09:15:59 +04:00
|
|
|
///
|
2013-04-19 10:32:12 +04:00
|
|
|
void winSetHwnd(::HWND _window);
|
2013-08-11 09:15:59 +04:00
|
|
|
|
2013-01-16 08:37:07 +04:00
|
|
|
} // namespace bgfx
|
|
|
|
|
2013-01-14 03:35:06 +04:00
|
|
|
#endif // BX_PLATFORM_
|
|
|
|
|
2013-08-11 10:22:40 +04:00
|
|
|
#if defined(_SDL_H)
|
2013-08-11 10:30:57 +04:00
|
|
|
// If SDL.h is included before bgfxplatform.h we can enable SDL window
|
|
|
|
// interop convenience code.
|
2013-08-11 10:22:40 +04:00
|
|
|
|
2013-08-13 07:47:41 +04:00
|
|
|
# include <SDL2/SDL_syswm.h>
|
2013-08-11 09:15:59 +04:00
|
|
|
|
|
|
|
namespace bgfx
|
|
|
|
{
|
|
|
|
///
|
|
|
|
inline bool sdlSetWindow(SDL_Window* _window)
|
|
|
|
{
|
|
|
|
SDL_SysWMinfo wmi;
|
|
|
|
SDL_VERSION(&wmi.version);
|
2014-01-25 09:49:15 +04:00
|
|
|
if (!SDL_GetWindowWMInfo(_window, &wmi) )
|
2013-08-11 09:15:59 +04:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-08-11 10:22:40 +04:00
|
|
|
# if BX_PLATFORM_LINUX
|
2013-08-11 09:15:59 +04:00
|
|
|
x11SetDisplayWindow(wmi.info.x11.display, wmi.info.x11.window);
|
2013-08-11 10:22:40 +04:00
|
|
|
# elif BX_PLATFORM_OSX
|
2013-08-11 09:15:59 +04:00
|
|
|
osxSetNSWindow(wmi.info.cocoa.window);
|
2013-08-11 10:22:40 +04:00
|
|
|
# elif BX_PLATFORM_WINDOWS
|
2013-08-11 09:15:59 +04:00
|
|
|
winSetHwnd(wmi.info.win.window);
|
2013-08-11 10:22:40 +04:00
|
|
|
# endif // BX_PLATFORM_
|
2013-08-11 09:15:59 +04:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2013-08-13 07:47:41 +04:00
|
|
|
|
2013-08-11 09:15:59 +04:00
|
|
|
} // namespace bgfx
|
2013-08-11 10:22:40 +04:00
|
|
|
|
|
|
|
#elif defined(_glfw3_h_)
|
2013-08-11 10:30:57 +04:00
|
|
|
// If GLFW/glfw3.h is included before bgfxplatform.h we can enable GLFW3
|
|
|
|
// window interop convenience code.
|
2013-08-11 10:22:40 +04:00
|
|
|
|
|
|
|
# if BX_PLATFORM_LINUX
|
|
|
|
# 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)
|
|
|
|
{
|
|
|
|
# if BX_PLATFORM_LINUX
|
|
|
|
::Display* display = glfwGetX11Display();
|
|
|
|
::Window window = glfwGetX11Window(_window);
|
|
|
|
x11SetDisplayWindow(display, window);
|
|
|
|
# elif BX_PLATFORM_OSX
|
|
|
|
void* id = glfwGetCocoaWindow(_window);
|
|
|
|
osxSetNSWindow(id);
|
|
|
|
# elif BX_PLATFORM_WINDOWS
|
|
|
|
HWND hwnd = glfwGetWin32Window(_window);
|
|
|
|
winSetHwnd(hwnd);
|
|
|
|
# endif BX_PLATFORM_WINDOWS
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace bgfx
|
|
|
|
|
|
|
|
#endif // defined(_SDL_H)
|
2013-08-11 09:15:59 +04:00
|
|
|
|
2013-11-14 09:54:36 +04:00
|
|
|
#endif // BGFX_PLATFORM_H_HEADER_GUARD
|