BsMacOSGLSupport.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. void MacOSGLSupport::start()
  20. {
  21. // Do nothing
  22. }
  23. void MacOSGLSupport::stop()
  24. {
  25. // Do nothing
  26. }
  27. SPtr<MacOSContext> MacOSGLSupport::createContext(bool depthStencil, UINT32 msaaCount)
  28. {
  29. GLRenderAPI* rapi = static_cast<GLRenderAPI*>(RenderAPI::instancePtr());
  30. // If RenderAPI has initialized a context use that, otherwise we create our own
  31. if (!rapi->_isContextInitialized())
  32. return bs_shared_ptr_new<MacOSContext>(depthStencil, msaaCount);
  33. else
  34. {
  35. SPtr<GLContext> context = rapi->_getMainContext();
  36. return std::static_pointer_cast<MacOSContext>(context);
  37. }
  38. }
  39. void* MacOSGLSupport::getProcAddress(const String& procname)
  40. {
  41. static void* image = nullptr;
  42. if (!image)
  43. image = dlopen("/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL", RTLD_LAZY);
  44. if(!image)
  45. return nullptr;
  46. return dlsym(image, (const char*)procname.c_str());
  47. }
  48. SPtr<VideoModeInfo> MacOSGLSupport::getVideoModeInfo() const
  49. {
  50. return bs_shared_ptr_new<MacOSVideoModeInfo>();
  51. }
  52. }