diff options
Diffstat (limited to 'platform/darwin')
-rw-r--r-- | platform/darwin/src/headless_backend_cgl.cpp | 41 | ||||
-rw-r--r-- | platform/darwin/src/headless_backend_eagl.mm | 40 |
2 files changed, 42 insertions, 39 deletions
diff --git a/platform/darwin/src/headless_backend_cgl.cpp b/platform/darwin/src/headless_backend_cgl.cpp index 6e19213f52..46a5beb870 100644 --- a/platform/darwin/src/headless_backend_cgl.cpp +++ b/platform/darwin/src/headless_backend_cgl.cpp @@ -65,8 +65,9 @@ public: CGLPixelFormatObj pixelFormat = nullptr; }; -struct CGLImpl : public HeadlessBackend::Impl { - CGLImpl() { +class CGLBackendImpl : public HeadlessBackend::Impl { +public: + CGLBackendImpl() { CGLError error = CGLCreateContext(cglDisplay->pixelFormat, nullptr, &glContext); if (error != kCGLNoError) { throw std::runtime_error(std::string("Error creating GL context object:") + @@ -80,10 +81,24 @@ struct CGLImpl : public HeadlessBackend::Impl { } } - ~CGLImpl() final { + ~CGLBackendImpl() final { CGLDestroyContext(glContext); } + gl::ProcAddress getExtensionFunctionPointer(const char* name) final { + static CFBundleRef framework = CFBundleGetBundleWithIdentifier(CFSTR("com.apple.opengl")); + if (!framework) { + throw std::runtime_error("Failed to load OpenGL framework."); + } + + CFStringRef str = + CFStringCreateWithCString(kCFAllocatorDefault, name, kCFStringEncodingASCII); + void* symbol = CFBundleGetFunctionPointerForName(framework, str); + CFRelease(str); + + return reinterpret_cast<gl::ProcAddress>(symbol); + } + void activateContext() final { CGLError error = CGLSetCurrentContext(glContext); if (error != kCGLNoError) { @@ -105,23 +120,9 @@ private: CGLContextObj glContext = nullptr; }; -gl::ProcAddress HeadlessBackend::initializeExtension(const char* name) { - assert(hasContext()); - static CFBundleRef framework = CFBundleGetBundleWithIdentifier(CFSTR("com.apple.opengl")); - if (!framework) { - throw std::runtime_error("Failed to load OpenGL framework."); - } - - CFStringRef str = CFStringCreateWithCString(kCFAllocatorDefault, name, kCFStringEncodingASCII); - void* symbol = CFBundleGetFunctionPointerForName(framework, str); - CFRelease(str); - - return reinterpret_cast<gl::ProcAddress>(symbol); -} - -void HeadlessBackend::createContext() { - assert(!hasContext()); - impl = std::make_unique<CGLImpl>(); +void HeadlessBackend::createImpl() { + assert(!impl); + impl = std::make_unique<CGLBackendImpl>(); } } // namespace mbgl diff --git a/platform/darwin/src/headless_backend_eagl.mm b/platform/darwin/src/headless_backend_eagl.mm index 6bf5787f60..050fa62c78 100644 --- a/platform/darwin/src/headless_backend_eagl.mm +++ b/platform/darwin/src/headless_backend_eagl.mm @@ -6,8 +6,9 @@ namespace mbgl { -struct EAGLImpl : public HeadlessBackend::Impl { - EAGLImpl() { +class EAGLBackendImpl : public HeadlessBackend::Impl { +public: + EAGLBackendImpl() { glContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; if (glContext == nil) { throw std::runtime_error("Error creating GL context object"); @@ -16,7 +17,21 @@ struct EAGLImpl : public HeadlessBackend::Impl { } // Required for ARC to deallocate correctly. - ~EAGLImpl() final = default; + ~EAGLBackendImpl() final = default; + + gl::ProcAddress getExtensionFunctionPointer(const char* name) final { + static CFBundleRef framework = CFBundleGetBundleWithIdentifier(CFSTR("com.apple.opengles")); + if (!framework) { + throw std::runtime_error("Failed to load OpenGL framework."); + } + + CFStringRef str = + CFStringCreateWithCString(kCFAllocatorDefault, name, kCFStringEncodingASCII); + void* symbol = CFBundleGetFunctionPointerForName(framework, str); + CFRelease(str); + + return reinterpret_cast<gl::ProcAddress>(symbol); + } void activateContext() final { [EAGLContext setCurrentContext:glContext]; @@ -30,22 +45,9 @@ private: EAGLContext* glContext = nullptr; }; -gl::ProcAddress HeadlessBackend::initializeExtension(const char* name) { - static CFBundleRef framework = CFBundleGetBundleWithIdentifier(CFSTR("com.apple.opengles")); - if (!framework) { - throw std::runtime_error("Failed to load OpenGL framework."); - } - - CFStringRef str = CFStringCreateWithCString(kCFAllocatorDefault, name, kCFStringEncodingASCII); - void* symbol = CFBundleGetFunctionPointerForName(framework, str); - CFRelease(str); - - return reinterpret_cast<gl::ProcAddress>(symbol); -} - -void HeadlessBackend::createContext() { - assert(!hasContext()); - impl = std::make_unique<EAGLImpl>(); +void HeadlessBackend::createImpl() { + assert(!impl); + impl = std::make_unique<EAGLBackendImpl>(); } } // namespace mbgl |