summaryrefslogtreecommitdiff
path: root/src/mbgl/shaders
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2017-03-09 07:53:02 -0800
committerJohn Firebaugh <john.firebaugh@gmail.com>2017-03-09 10:32:34 -0800
commitd5c2920104ea733b8ed417d2b9bdbade61b049cd (patch)
treeb3ca9606f83c348c2b5cbb471ca32cd9af564f73 /src/mbgl/shaders
parentaf75736857213ff99145769883770d4b276a644a (diff)
downloadqtlocation-mapboxgl-d5c2920104ea733b8ed417d2b9bdbade61b049cd.tar.gz
[core] Extract and de-templatize several Program static methods
Diffstat (limited to 'src/mbgl/shaders')
-rw-r--r--src/mbgl/shaders/shaders.cpp33
-rw-r--r--src/mbgl/shaders/shaders.hpp15
2 files changed, 48 insertions, 0 deletions
diff --git a/src/mbgl/shaders/shaders.cpp b/src/mbgl/shaders/shaders.cpp
new file mode 100644
index 0000000000..f7f5b4d44f
--- /dev/null
+++ b/src/mbgl/shaders/shaders.cpp
@@ -0,0 +1,33 @@
+#include <mbgl/shaders/shaders.hpp>
+#include <mbgl/shaders/preludes.hpp>
+#include <mbgl/programs/program_parameters.hpp>
+
+#include <cassert>
+#include <sstream>
+
+namespace mbgl {
+namespace shaders {
+
+static std::string pixelRatioDefine(const ProgramParameters& parameters) {
+ std::ostringstream pixelRatioSS;
+ pixelRatioSS.imbue(std::locale("C"));
+ pixelRatioSS.setf(std::ios_base::showpoint);
+ pixelRatioSS << parameters.pixelRatio;
+ return std::string("#define DEVICE_PIXEL_RATIO ") + pixelRatioSS.str() + "\n";
+}
+
+std::string fragmentSource(const ProgramParameters& parameters, const char* fragmentSource) {
+ std::string source = pixelRatioDefine(parameters) + fragmentPrelude + fragmentSource;
+ if (parameters.overdraw) {
+ assert(source.find("#ifdef OVERDRAW_INSPECTOR") != std::string::npos);
+ source.replace(source.find_first_of('\n'), 1, "\n#define OVERDRAW_INSPECTOR\n");
+ }
+ return source;
+}
+
+std::string vertexSource(const ProgramParameters& parameters, const char* vertexSource) {
+ return pixelRatioDefine(parameters) + vertexPrelude + vertexSource;
+}
+
+} // namespace shaders
+} // namespace mbgl
diff --git a/src/mbgl/shaders/shaders.hpp b/src/mbgl/shaders/shaders.hpp
new file mode 100644
index 0000000000..e2912c5688
--- /dev/null
+++ b/src/mbgl/shaders/shaders.hpp
@@ -0,0 +1,15 @@
+#pragma once
+
+#include <string>
+
+namespace mbgl {
+
+class ProgramParameters;
+
+namespace shaders {
+
+std::string fragmentSource(const ProgramParameters&, const char* fragmentSource);
+std::string vertexSource(const ProgramParameters&, const char* vertexSource);
+
+} // namespace shaders
+} // namespace mbgl