From 9d276f3b0f0e5f1b5089a6cd727927361e6634ac Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Mon, 5 Jun 2017 12:15:27 -0700 Subject: [core] Dynamic program compilation for data-driven properties --- src/mbgl/gl/program.hpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src/mbgl/gl') diff --git a/src/mbgl/gl/program.hpp b/src/mbgl/gl/program.hpp index c36543839c..47ad39de7c 100644 --- a/src/mbgl/gl/program.hpp +++ b/src/mbgl/gl/program.hpp @@ -50,7 +50,8 @@ public: const char* vertexSource_, const char* fragmentSource_) { #if MBGL_HAS_BINARY_PROGRAMS - if (!programParameters.cacheDir.empty() && context.supportsProgramBinaries()) { + optional cachePath = programParameters.cachePath(name); + if (cachePath && context.supportsProgramBinaries()) { const std::string vertexSource = shaders::vertexSource(programParameters, vertexSource_); const std::string fragmentSource = @@ -58,10 +59,8 @@ public: const std::string identifier = shaders::programIdentifier(vertexSource, fragmentSource_); - const std::string cachePath = programParameters.cachePath(name); - try { - if (auto cachedBinaryProgram = util::readFile(cachePath)) { + if (auto cachedBinaryProgram = util::readFile(*cachePath)) { const BinaryProgram binaryProgram(std::move(*cachedBinaryProgram)); if (binaryProgram.identifier() == identifier) { return Program { context, binaryProgram }; @@ -82,8 +81,8 @@ public: try { if (const auto binaryProgram = result.template get(context, identifier)) { - util::write_file(cachePath, binaryProgram->serialize()); - Log::Warning(Event::OpenGL, "Caching program in: %s", cachePath.c_str()); + util::write_file(*cachePath, binaryProgram->serialize()); + Log::Warning(Event::OpenGL, "Caching program in: %s", (*cachePath).c_str()); } } catch (std::runtime_error& error) { Log::Warning(Event::OpenGL, "Failed to cache program: %s", error.what()); -- cgit v1.2.1