summaryrefslogtreecommitdiff
path: root/src/mbgl/programs/program_parameters.cpp
blob: e692b74e0e35b0258dd80f3ddf68dd1a51c66978 (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
#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;
    }
}

} // namespace mbgl