blob: f2c7d8c2fbb29acd3ead2975e59a22b575d3fe6d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
#include <mbgl/gl/headless_backend.hpp>
#include <OpenGLES/EAGL.h>
#include <stdexcept>
namespace mbgl {
namespace gl {
class EAGLBackendImpl : public HeadlessBackend::Impl {
public:
EAGLBackendImpl() {
glContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
if (glContext == nil) {
throw std::runtime_error("Error creating GL context object");
}
glContext.multiThreaded = YES;
}
// Required for ARC to deallocate correctly.
~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.");
}
return reinterpret_cast<gl::ProcAddress>(CFBundleGetFunctionPointerForName(
framework, (__bridge CFStringRef)[NSString stringWithUTF8String:name]));
}
void activateContext() final {
[EAGLContext setCurrentContext:glContext];
}
void deactivateContext() final {
[EAGLContext setCurrentContext:nil];
}
private:
EAGLContext* glContext = nullptr;
};
void HeadlessBackend::createImpl() {
assert(!impl);
impl = std::make_unique<EAGLBackendImpl>();
}
} // namespace gl
} // namespace mbgl
|