bgfxplatform.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. * Copyright 2011-2015 Branimir Karadzic. All rights reserved.
  3. * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE
  4. */
  5. #ifndef BGFX_PLATFORM_H_HEADER_GUARD
  6. #define BGFX_PLATFORM_H_HEADER_GUARD
  7. // NOTICE:
  8. // This header file contains platform specific interfaces. It is only
  9. // necessary to use this header in conjunction with creating windows.
  10. #include <bx/platform.h>
  11. namespace bgfx
  12. {
  13. struct RenderFrame
  14. {
  15. enum Enum
  16. {
  17. NoContext,
  18. Render,
  19. Exiting,
  20. Count
  21. };
  22. };
  23. /// WARNING: This call should be only used on platforms that don't
  24. /// allow creating separate rendering thread. If it is called before
  25. /// to bgfx::init, render thread won't be created by bgfx::init call.
  26. RenderFrame::Enum renderFrame();
  27. }
  28. #if BX_PLATFORM_ANDROID
  29. # include <android/native_window.h>
  30. namespace bgfx
  31. {
  32. ///
  33. void androidSetWindow(::ANativeWindow* _window);
  34. } // namespace bgfx
  35. #elif BX_PLATFORM_IOS
  36. namespace bgfx
  37. {
  38. ///
  39. void iosSetEaglLayer(void* _layer);
  40. } // namespace bgfx
  41. #elif BX_PLATFORM_FREEBSD || BX_PLATFORM_LINUX || BX_PLATFORM_RPI
  42. # include <X11/Xlib.h>
  43. namespace bgfx
  44. {
  45. ///
  46. void x11SetDisplayWindow(::Display* _display, ::Window _window);
  47. } // namespace bgfx
  48. #elif BX_PLATFORM_NACL
  49. # include <ppapi/c/ppb_graphics_3d.h>
  50. # include <ppapi/c/ppb_instance.h>
  51. namespace bgfx
  52. {
  53. typedef void (*PostSwapBuffersFn)(uint32_t _width, uint32_t _height);
  54. ///
  55. bool naclSetInterfaces(::PP_Instance, const ::PPB_Instance*, const ::PPB_Graphics3D*, PostSwapBuffersFn);
  56. } // namespace bgfx
  57. #elif BX_PLATFORM_OSX
  58. namespace bgfx
  59. {
  60. ///
  61. void osxSetNSWindow(void* _window);
  62. } // namespace bgfx
  63. #elif BX_PLATFORM_WINDOWS
  64. # include <windows.h>
  65. namespace bgfx
  66. {
  67. ///
  68. void winSetHwnd(::HWND _window);
  69. } // namespace bgfx
  70. #elif BX_PLATFORM_WINRT
  71. # include <Unknwn.h>
  72. namespace bgfx
  73. {
  74. ///
  75. void winrtSetWindow(IUnknown* _window);
  76. } // namespace bgfx
  77. #endif // BX_PLATFORM_
  78. #if defined(_SDL_H)
  79. // If SDL.h is included before bgfxplatform.h we can enable SDL window
  80. // interop convenience code.
  81. # include <SDL2/SDL_syswm.h>
  82. namespace bgfx
  83. {
  84. ///
  85. inline bool sdlSetWindow(SDL_Window* _window)
  86. {
  87. SDL_SysWMinfo wmi;
  88. SDL_VERSION(&wmi.version);
  89. if (!SDL_GetWindowWMInfo(_window, &wmi) )
  90. {
  91. return false;
  92. }
  93. # if BX_PLATFORM_LINUX || BX_PLATFORM_FREEBSD
  94. x11SetDisplayWindow(wmi.info.x11.display, wmi.info.x11.window);
  95. # elif BX_PLATFORM_OSX
  96. osxSetNSWindow(wmi.info.cocoa.window);
  97. # elif BX_PLATFORM_WINDOWS
  98. winSetHwnd(wmi.info.win.window);
  99. # endif // BX_PLATFORM_
  100. return true;
  101. }
  102. } // namespace bgfx
  103. #elif defined(_glfw3_h_)
  104. // If GLFW/glfw3.h is included before bgfxplatform.h we can enable GLFW3
  105. // window interop convenience code.
  106. # if BX_PLATFORM_LINUX || BX_PLATFORM_FREEBSD
  107. # define GLFW_EXPOSE_NATIVE_X11
  108. # define GLFW_EXPOSE_NATIVE_GLX
  109. # elif BX_PLATFORM_OSX
  110. # define GLFW_EXPOSE_NATIVE_COCOA
  111. # define GLFW_EXPOSE_NATIVE_NSGL
  112. # elif BX_PLATFORM_WINDOWS
  113. # define GLFW_EXPOSE_NATIVE_WIN32
  114. # define GLFW_EXPOSE_NATIVE_WGL
  115. # endif //
  116. # include <GLFW/glfw3native.h>
  117. namespace bgfx
  118. {
  119. inline void glfwSetWindow(GLFWwindow* _window)
  120. {
  121. # if BX_PLATFORM_LINUX || BX_PLATFORM_FREEBSD
  122. ::Display* display = glfwGetX11Display();
  123. ::Window window = glfwGetX11Window(_window);
  124. x11SetDisplayWindow(display, window);
  125. # elif BX_PLATFORM_OSX
  126. void* id = glfwGetCocoaWindow(_window);
  127. osxSetNSWindow(id);
  128. # elif BX_PLATFORM_WINDOWS
  129. HWND hwnd = glfwGetWin32Window(_window);
  130. winSetHwnd(hwnd);
  131. # endif BX_PLATFORM_WINDOWS
  132. }
  133. } // namespace bgfx
  134. #endif // defined(_SDL_H)
  135. #endif // BGFX_PLATFORM_H_HEADER_GUARD