BsMacOSGLSupport.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2017 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "MacOS/BsMacOSGLSupport.h"
  4. #include "MacOS/BsMacOSContext.h"
  5. #include "MacOS/BsMacOSRenderWindow.h"
  6. #include "BsMacOSVideoModeInfo.h"
  7. #include "BsGLRenderAPI.h"
  8. #include <dlfcn.h>
  9. namespace bs::ct
  10. {
  11. SPtr<bs::RenderWindow> MacOSGLSupport::newWindow(
  12. RENDER_WINDOW_DESC& desc,
  13. UINT32 windowId,
  14. SPtr<bs::RenderWindow> parentWindow)
  15. {
  16. bs::MacOSRenderWindow* window = new (bs_alloc<bs::MacOSRenderWindow>()) bs::MacOSRenderWindow(desc, windowId, *this);
  17. return SPtr<bs::RenderWindow>(window, &bs::CoreObject::_delete<bs::MacOSRenderWindow, GenAlloc>);
  18. }
  19. SPtr<RenderWindow> MacOSGLSupport::newWindowCore(RENDER_WINDOW_DESC& desc, UINT32 windowId)
  20. {
  21. MacOSRenderWindow* window = new (bs_alloc<MacOSRenderWindow>()) MacOSRenderWindow(desc, windowId, *this);
  22. return bs_shared_ptr<MacOSRenderWindow>(window);
  23. }
  24. void MacOSGLSupport::start()
  25. {
  26. // Do nothing
  27. }
  28. void MacOSGLSupport::stop()
  29. {
  30. // Do nothing
  31. }
  32. SPtr<MacOSContext> MacOSGLSupport::createContext(bool depthStencil, UINT32 msaaCount)
  33. {
  34. GLRenderAPI* rapi = static_cast<GLRenderAPI*>(RenderAPI::instancePtr());
  35. // If RenderAPI has initialized a context use that, otherwise we create our own
  36. if (!rapi->_isContextInitialized())
  37. return bs_shared_ptr_new<MacOSContext>(depthStencil, msaaCount);
  38. else
  39. {
  40. SPtr<GLContext> context = rapi->_getMainContext();
  41. return std::static_pointer_cast<MacOSContext>(context);
  42. }
  43. }
  44. void* MacOSGLSupport::getProcAddress(const String& procname)
  45. {
  46. static void* image = nullptr;
  47. if (!image)
  48. image = dlopen("/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL", RTLD_LAZY);
  49. if(!image)
  50. return nullptr;
  51. return dlsym(image, (const char*)procname.c_str());
  52. }
  53. SPtr<VideoModeInfo> MacOSGLSupport::getVideoModeInfo() const
  54. {
  55. return bs_shared_ptr_new<MacOSVideoModeInfo>();
  56. }
  57. }