2
0

bgfxplatform.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. namespace bgfx
  43. {
  44. ///
  45. void x11SetDisplayWindow(void* _display, uint32_t _window);
  46. } // namespace bgfx
  47. #elif BX_PLATFORM_NACL
  48. # include <ppapi/c/ppb_graphics_3d.h>
  49. # include <ppapi/c/ppb_instance.h>
  50. namespace bgfx
  51. {
  52. typedef void (*PostSwapBuffersFn)(uint32_t _width, uint32_t _height);
  53. ///
  54. bool naclSetInterfaces(::PP_Instance, const ::PPB_Instance*, const ::PPB_Graphics3D*, PostSwapBuffersFn);
  55. } // namespace bgfx
  56. #elif BX_PLATFORM_OSX
  57. namespace bgfx
  58. {
  59. ///
  60. void osxSetNSWindow(void* _window);
  61. } // namespace bgfx
  62. #elif BX_PLATFORM_WINDOWS
  63. # include <windows.h>
  64. namespace bgfx
  65. {
  66. ///
  67. void winSetHwnd(::HWND _window);
  68. } // namespace bgfx
  69. #elif BX_PLATFORM_WINRT
  70. # include <Unknwn.h>
  71. namespace bgfx
  72. {
  73. ///
  74. void winrtSetWindow(IUnknown* _window);
  75. } // namespace bgfx
  76. #endif // BX_PLATFORM_
  77. #if defined(_SDL_H)
  78. // If SDL.h is included before bgfxplatform.h we can enable SDL window
  79. // interop convenience code.
  80. # include <SDL2/SDL_syswm.h>
  81. namespace bgfx
  82. {
  83. ///
  84. inline bool sdlSetWindow(SDL_Window* _window)
  85. {
  86. SDL_SysWMinfo wmi;
  87. SDL_VERSION(&wmi.version);
  88. if (!SDL_GetWindowWMInfo(_window, &wmi) )
  89. {
  90. return false;
  91. }
  92. # if BX_PLATFORM_LINUX || BX_PLATFORM_FREEBSD
  93. x11SetDisplayWindow(wmi.info.x11.display, wmi.info.x11.window);
  94. # elif BX_PLATFORM_OSX
  95. osxSetNSWindow(wmi.info.cocoa.window);
  96. # elif BX_PLATFORM_WINDOWS
  97. winSetHwnd(wmi.info.win.window);
  98. # endif // BX_PLATFORM_
  99. return true;
  100. }
  101. } // namespace bgfx
  102. #elif defined(_glfw3_h_)
  103. // If GLFW/glfw3.h is included before bgfxplatform.h we can enable GLFW3
  104. // window interop convenience code.
  105. # if BX_PLATFORM_LINUX || BX_PLATFORM_FREEBSD
  106. # define GLFW_EXPOSE_NATIVE_X11
  107. # define GLFW_EXPOSE_NATIVE_GLX
  108. # elif BX_PLATFORM_OSX
  109. # define GLFW_EXPOSE_NATIVE_COCOA
  110. # define GLFW_EXPOSE_NATIVE_NSGL
  111. # elif BX_PLATFORM_WINDOWS
  112. # define GLFW_EXPOSE_NATIVE_WIN32
  113. # define GLFW_EXPOSE_NATIVE_WGL
  114. # endif //
  115. # include <GLFW/glfw3native.h>
  116. namespace bgfx
  117. {
  118. inline void glfwSetWindow(GLFWwindow* _window)
  119. {
  120. # if BX_PLATFORM_LINUX || BX_PLATFORM_FREEBSD
  121. ::Display* display = glfwGetX11Display();
  122. ::Window window = glfwGetX11Window(_window);
  123. x11SetDisplayWindow(display, window);
  124. # elif BX_PLATFORM_OSX
  125. void* id = glfwGetCocoaWindow(_window);
  126. osxSetNSWindow(id);
  127. # elif BX_PLATFORM_WINDOWS
  128. HWND hwnd = glfwGetWin32Window(_window);
  129. winSetHwnd(hwnd);
  130. # endif BX_PLATFORM_WINDOWS
  131. }
  132. } // namespace bgfx
  133. #endif // defined(_SDL_H)
  134. #endif // BGFX_PLATFORM_H_HEADER_GUARD