diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2017-03-09 07:53:02 -0800 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2017-03-09 10:32:34 -0800 |
commit | d5c2920104ea733b8ed417d2b9bdbade61b049cd (patch) | |
tree | b3ca9606f83c348c2b5cbb471ca32cd9af564f73 /src | |
parent | af75736857213ff99145769883770d4b276a644a (diff) | |
download | qtlocation-mapboxgl-d5c2920104ea733b8ed417d2b9bdbade61b049cd.tar.gz |
[core] Extract and de-templatize several Program static methods
Diffstat (limited to 'src')
-rw-r--r-- | src/mbgl/programs/program.hpp | 31 | ||||
-rw-r--r-- | src/mbgl/shaders/shaders.cpp | 33 | ||||
-rw-r--r-- | src/mbgl/shaders/shaders.hpp | 15 |
3 files changed, 52 insertions, 27 deletions
diff --git a/src/mbgl/programs/program.hpp b/src/mbgl/programs/program.hpp index ffad767c3a..8437e3a651 100644 --- a/src/mbgl/programs/program.hpp +++ b/src/mbgl/programs/program.hpp @@ -1,13 +1,9 @@ #pragma once #include <mbgl/gl/program.hpp> -#include <mbgl/programs/program_parameters.hpp> #include <mbgl/programs/attributes.hpp> #include <mbgl/style/paint_property.hpp> -#include <mbgl/shaders/preludes.hpp> - -#include <sstream> -#include <cassert> +#include <mbgl/shaders/shaders.hpp> namespace mbgl { @@ -34,30 +30,11 @@ public: ProgramType program; Program(gl::Context& context, const ProgramParameters& programParameters) - : program(context, vertexSource(programParameters), fragmentSource(programParameters)) + : program(context, + shaders::vertexSource(programParameters, Shaders::vertexSource), + shaders::fragmentSource(programParameters, Shaders::fragmentSource)) {} - 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"; - } - - static std::string fragmentSource(const ProgramParameters& parameters) { - std::string source = pixelRatioDefine(parameters) + shaders::fragmentPrelude + Shaders::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; - } - - static std::string vertexSource(const ProgramParameters& parameters) { - return pixelRatioDefine(parameters) + shaders::vertexPrelude + Shaders::vertexSource; - } - template <class DrawMode> void draw(gl::Context& context, DrawMode drawMode, 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 |