1 #include <mbgl/programs/program_parameters.hpp> 2 3 #include <iomanip> 4 #include <sstream> 5 6 namespace mbgl { 7 ProgramParameters(const float pixelRatio,const bool overdraw,optional<std::string> cacheDir_)8ProgramParameters::ProgramParameters(const float pixelRatio, 9 const bool overdraw, 10 optional<std::string> cacheDir_) 11 : defines([&] { 12 std::ostringstream ss; 13 ss.imbue(std::locale("C")); 14 ss.setf(std::ios_base::showpoint); 15 ss << "#define DEVICE_PIXEL_RATIO " << pixelRatio << std::endl; 16 if (overdraw) { 17 ss << "#define OVERDRAW_INSPECTOR" << std::endl; 18 } 19 return ss.str(); 20 }()), 21 cacheDir(std::move(cacheDir_)) { 22 } 23 getDefines() const24const std::string& ProgramParameters::getDefines() const { 25 return defines; 26 } 27 cachePath(const char * name) const28optional<std::string> ProgramParameters::cachePath(const char* name) const { 29 if (!cacheDir) { 30 return {}; 31 } else { 32 std::ostringstream ss; 33 ss << *cacheDir << "/com.mapbox.gl.shader." << name << "." << std::setfill('0') 34 << std::setw(sizeof(size_t) * 2) << std::hex << std::hash<std::string>()(defines) << ".pbf"; 35 return ss.str(); 36 } 37 } 38 withAdditionalDefines(const std::vector<std::string> & additionalDefines) const39ProgramParameters ProgramParameters::withAdditionalDefines(const std::vector<std::string>& additionalDefines) const { 40 ProgramParameters result(*this); 41 for (const auto& define : additionalDefines) { 42 result.defines += define; 43 result.defines += "\n"; 44 } 45 return result; 46 } 47 48 } // namespace mbgl 49