blob: ee94e8ecfdba3d91d6b7b7e5cbcff07e823befc7 (
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
|
#include <mbgl/gl/extension.hpp>
#include <mbgl/gl/gl.hpp>
#include <mutex>
#include <string>
#include <vector>
namespace mbgl {
namespace gl {
namespace detail {
using Probes = std::vector<ExtensionFunctionBase::Probe>;
using ExtensionFunctions = std::vector<std::pair<glProc*, Probes>>;
ExtensionFunctions& extensionFunctions() {
static ExtensionFunctions functions;
return functions;
}
ExtensionFunctionBase::ExtensionFunctionBase(std::initializer_list<Probe> probes) {
extensionFunctions().emplace_back(&ptr, probes);
}
} // namespace detail
static std::once_flag initializeExtensionsOnce;
void InitializeExtensions(glProc (*getProcAddress)(const char*)) {
std::call_once(initializeExtensionsOnce, [getProcAddress] {
const char* extensionsPtr =
reinterpret_cast<const char*>(MBGL_CHECK_ERROR(glGetString(GL_EXTENSIONS)));
if (!extensionsPtr)
return;
const std::string extensions = extensionsPtr;
for (auto fn : detail::extensionFunctions()) {
for (auto probe : fn.second) {
if (extensions.find(probe.first) != std::string::npos) {
*fn.first = getProcAddress(probe.second);
break;
}
}
}
});
}
} // namespace gl
} // namespace mbgl
|