summaryrefslogtreecommitdiff
path: root/src/mbgl/programs/program_parameters.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl/programs/program_parameters.cpp')
-rw-r--r--src/mbgl/programs/program_parameters.cpp30
1 files changed, 23 insertions, 7 deletions
diff --git a/src/mbgl/programs/program_parameters.cpp b/src/mbgl/programs/program_parameters.cpp
index f9f680ac1e..e76ec4be71 100644
--- a/src/mbgl/programs/program_parameters.cpp
+++ b/src/mbgl/programs/program_parameters.cpp
@@ -7,7 +7,7 @@ namespace mbgl {
ProgramParameters::ProgramParameters(const float pixelRatio,
const bool overdraw,
- std::string cacheDir_)
+ optional<std::string> cacheDir_)
: defines([&] {
std::ostringstream ss;
ss.imbue(std::locale("C"));
@@ -18,15 +18,31 @@ ProgramParameters::ProgramParameters(const float pixelRatio,
}
return ss.str();
}()),
- hash(std::hash<std::string>()(defines)),
cacheDir(std::move(cacheDir_)) {
}
-std::string ProgramParameters::cachePath(const char* name) const {
- std::ostringstream ss;
- ss << cacheDir << "/com.mapbox.gl.shader." << name << "." << std::setfill('0')
- << std::setw(sizeof(size_t) * 2) << std::hex << hash << ".pbf";
- return ss.str();
+const std::string& ProgramParameters::getDefines() const {
+ return defines;
+}
+
+optional<std::string> ProgramParameters::cachePath(const char* name) const {
+ if (!cacheDir) {
+ return {};
+ } else {
+ std::ostringstream ss;
+ ss << *cacheDir << "/com.mapbox.gl.shader." << name << "." << std::setfill('0')
+ << std::setw(sizeof(size_t) * 2) << std::hex << std::hash<std::string>()(defines) << ".pbf";
+ return ss.str();
+ }
+}
+
+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