[core] Extract and de-templatize several Program static methods

This commit is contained in:
John Firebaugh
2017-03-09 07:53:02 -08:00
parent af75736857
commit d5c2920104
4 changed files with 54 additions and 27 deletions

View File

@@ -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,