bgfxplatform.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. * Copyright 2011-2013 Branimir Karadzic. All rights reserved.
  3. * License: http://www.opensource.org/licenses/BSD-2-Clause
  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/bx.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. Proper use requires
  25. /// changes inside lib.
  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_LINUX
  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. void naclSetIntefraces(::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. #endif // BX_PLATFORM_
  71. #if defined(_SDL_H)
  72. // If SDL.h is included before bgfxplatform.h we can enable SDL window
  73. // interop convenience code.
  74. # include <SDL2/SDL_syswm.h>
  75. namespace bgfx
  76. {
  77. ///
  78. inline bool sdlSetWindow(SDL_Window* _window)
  79. {
  80. SDL_SysWMinfo wmi;
  81. SDL_VERSION(&wmi.version);
  82. if (-1 == SDL_GetWindowWMInfo(_window, &wmi) )
  83. {
  84. return false;
  85. }
  86. # if BX_PLATFORM_LINUX
  87. x11SetDisplayWindow(wmi.info.x11.display, wmi.info.x11.window);
  88. # elif BX_PLATFORM_OSX
  89. osxSetNSWindow(wmi.info.cocoa.window);
  90. # elif BX_PLATFORM_WINDOWS
  91. winSetHwnd(wmi.info.win.window);
  92. # endif // BX_PLATFORM_
  93. return true;
  94. }
  95. } // namespace bgfx
  96. #elif defined(_glfw3_h_)
  97. // If GLFW/glfw3.h is included before bgfxplatform.h we can enable GLFW3
  98. // window interop convenience code.
  99. # if BX_PLATFORM_LINUX
  100. # define GLFW_EXPOSE_NATIVE_X11
  101. # define GLFW_EXPOSE_NATIVE_GLX
  102. # elif BX_PLATFORM_OSX
  103. # define GLFW_EXPOSE_NATIVE_COCOA
  104. # define GLFW_EXPOSE_NATIVE_NSGL
  105. # elif BX_PLATFORM_WINDOWS
  106. # define GLFW_EXPOSE_NATIVE_WIN32
  107. # define GLFW_EXPOSE_NATIVE_WGL
  108. # endif //
  109. # include <GLFW/glfw3native.h>
  110. namespace bgfx
  111. {
  112. inline void glfwSetWindow(GLFWwindow* _window)
  113. {
  114. # if BX_PLATFORM_LINUX
  115. ::Display* display = glfwGetX11Display();
  116. ::Window window = glfwGetX11Window(_window);
  117. x11SetDisplayWindow(display, window);
  118. # elif BX_PLATFORM_OSX
  119. void* id = glfwGetCocoaWindow(_window);
  120. osxSetNSWindow(id);
  121. # elif BX_PLATFORM_WINDOWS
  122. HWND hwnd = glfwGetWin32Window(_window);
  123. winSetHwnd(hwnd);
  124. # endif BX_PLATFORM_WINDOWS
  125. }
  126. } // namespace bgfx
  127. #endif // defined(_SDL_H)
  128. #endif // BGFX_PLATFORM_H_HEADER_GUARD