blob: e6b4d9156ee8c5c1410c8005bdd9795ff6084925 (
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
|
#include <mbgl/gl/extension.hpp>
#include <mbgl/gl/gl.hpp>
#include <mutex>
#include <string>
#include <vector>
#include <cstring>
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] {
if (const char* extensions =
reinterpret_cast<const char*>(MBGL_CHECK_ERROR(glGetString(GL_EXTENSIONS)))) {
for (auto fn : detail::extensionFunctions()) {
for (auto probe : fn.second) {
if (strstr(extensions, probe.first) != nullptr) {
*fn.first = getProcAddress(probe.second);
break;
}
}
}
}
});
}
} // namespace gl
} // namespace mbgl
|