blob: 6b6c2bb2fe49a84e62405e547d2ff898ac028c9e (
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
52
|
#include <mbgl/programs/program_parameters.hpp>
#include <mbgl/util/string.hpp>
namespace mbgl {
ProgramParameters::ProgramParameters(const float pixelRatio,
const bool overdraw,
optional<std::string> cacheDir_)
: defines([&] {
std::string result;
result.reserve(32);
result += "#define DEVICE_PIXEL_RATIO ";
result += util::toString(pixelRatio, true);
result += '\n';
if (overdraw) {
result += "#define OVERDRAW_INSPECTOR\n";
}
return result;
}()),
cacheDir(std::move(cacheDir_)) {
}
const std::string& ProgramParameters::getDefines() const {
return defines;
}
optional<std::string> ProgramParameters::cachePath(const char* name) const {
if (!cacheDir) {
return {};
} else {
std::string result;
result.reserve(cacheDir->length() + 64);
result += *cacheDir;
result += "/com.mapbox.gl.shader.";
result += name;
result += '.';
result += util::toHex(std::hash<std::string>()(defines));
result += ".pbf";
return result;
}
}
ProgramParameters ProgramParameters::withAdditionalDefines(const std::vector<std::string>& additionalDefines) const {
ProgramParameters result(*this);
for (const auto& define : additionalDefines) {
result.defines += define;
result.defines += "\n";
}
return result;
}
} // namespace mbgl
|