[core] update native for line property function shaders changes (#6658)
* [core] update shaders for line property functions update deps, define device pixel ratio for all shaders [core] create ShaderParameter struct to store pixel ratio and overdraw param repair rebase errs update shaders to include pixel ratio make sure collision_box never overdraws update test suite, move shaders to Painter::render so the correct pixel ratio is applied move shader compiling back to the Painter constructor rebase from shader --> program refactor re-factor parameters for collisionBox and debug programs remove unused vars from line-program, move blur math to shader update core files remove unecessary files update shaders PR, remove comments bump test suite sha fix formatting, incorporate feedback refactor program.hpp * [core] remove line transformations that were moved to the shaders, bump shader sha * [core] shorten ProgramParameter instantiation * [core] bump shader+test suite shas
This commit is contained in:
@@ -160,6 +160,7 @@ set(MBGL_CORE_FILES
|
||||
src/mbgl/programs/line_program.cpp
|
||||
src/mbgl/programs/line_program.hpp
|
||||
src/mbgl/programs/program.hpp
|
||||
src/mbgl/programs/program_parameters.hpp
|
||||
src/mbgl/programs/programs.hpp
|
||||
src/mbgl/programs/raster_program.cpp
|
||||
src/mbgl/programs/raster_program.hpp
|
||||
|
||||
@@ -22,9 +22,9 @@
|
||||
"ejs": "^2.4.1",
|
||||
"express": "^4.11.1",
|
||||
"lodash": "^4.16.4",
|
||||
"mapbox-gl-shaders": "mapbox/mapbox-gl-shaders#ec891ce5360e488d81f60991f95d2038b83c4e3c",
|
||||
"mapbox-gl-shaders": "mapbox/mapbox-gl-shaders#597115a1e1bd982944b068f8accde34eada74fc2",
|
||||
"mapbox-gl-style-spec": "mapbox/mapbox-gl-style-spec#7f62a4fc9f21e619824d68abbc4b03cbc1685572",
|
||||
"mapbox-gl-test-suite": "mapbox/mapbox-gl-test-suite#7f9f6837dd8e7c595d684680c69da0880e07d7eb",
|
||||
"mapbox-gl-test-suite": "mapbox/mapbox-gl-test-suite#bd5c7a34702634bf670ef9ea03251eda8b36944a",
|
||||
"mkdirp": "^0.5.1",
|
||||
"node-cmake": "^1.2.1",
|
||||
"request": "^2.72.0",
|
||||
|
||||
@@ -292,7 +292,7 @@ void Map::Impl::update() {
|
||||
|
||||
void Map::Impl::render(View& view) {
|
||||
if (!painter) {
|
||||
painter = std::make_unique<Painter>(backend.getContext(), transform.getState());
|
||||
painter = std::make_unique<Painter>(backend.getContext(), transform.getState(), pixelRatio);
|
||||
}
|
||||
|
||||
FrameData frameData { timePoint,
|
||||
|
||||
@@ -11,7 +11,6 @@ namespace mbgl {
|
||||
namespace uniforms {
|
||||
MBGL_DEFINE_UNIFORM_SCALAR(float, u_radius);
|
||||
MBGL_DEFINE_UNIFORM_SCALAR(bool, u_scale_with_map);
|
||||
MBGL_DEFINE_UNIFORM_SCALAR(float, u_devicepixelratio);
|
||||
} // namespace uniforms
|
||||
|
||||
using CircleAttributes = gl::Attributes<
|
||||
@@ -28,8 +27,7 @@ class CircleProgram : public Program<
|
||||
uniforms::u_radius,
|
||||
uniforms::u_blur,
|
||||
uniforms::u_scale_with_map,
|
||||
uniforms::u_extrude_scale,
|
||||
uniforms::u_devicepixelratio>>
|
||||
uniforms::u_extrude_scale>>
|
||||
{
|
||||
public:
|
||||
using Program::Program;
|
||||
|
||||
@@ -12,13 +12,9 @@ static_assert(sizeof(LineAttributes::Vertex) == 8, "expected LineVertex size");
|
||||
|
||||
template <class Values, class...Args>
|
||||
Values makeValues(const style::LinePaintProperties& properties,
|
||||
float pixelRatio,
|
||||
const RenderTile& tile,
|
||||
const TransformState& state,
|
||||
Args&&... args) {
|
||||
// the distance over which the line edge fades out.
|
||||
// Retina devices need a smaller distance to avoid aliasing.
|
||||
float antialiasing = 1.0 / pixelRatio;
|
||||
|
||||
mat2 antialiasingMatrix;
|
||||
matrix::identity(antialiasingMatrix);
|
||||
@@ -35,11 +31,10 @@ Values makeValues(const style::LinePaintProperties& properties,
|
||||
properties.lineTranslateAnchor.value,
|
||||
state) },
|
||||
uniforms::u_opacity::Value{ properties.lineOpacity.value },
|
||||
uniforms::u_linewidth::Value{ properties.lineWidth.value / 2 },
|
||||
uniforms::u_gapwidth::Value{ properties.lineGapWidth.value / 2 },
|
||||
uniforms::u_blur::Value{ properties.lineBlur.value + antialiasing },
|
||||
uniforms::u_offset::Value{ -properties.lineOffset.value },
|
||||
uniforms::u_antialiasing::Value{ antialiasing / 2 },
|
||||
uniforms::u_width::Value{ properties.lineWidth.value },
|
||||
uniforms::u_gapwidth::Value{ properties.lineGapWidth.value },
|
||||
uniforms::u_blur::Value{ properties.lineBlur.value },
|
||||
uniforms::u_offset::Value{ properties.lineOffset.value },
|
||||
uniforms::u_antialiasingmatrix::Value{ antialiasingMatrix },
|
||||
uniforms::u_ratio::Value{ 1.0f / tile.id.pixelsToTileUnits(1.0, state.getZoom()) },
|
||||
uniforms::u_extra::Value{ (topedgelength + x) / topedgelength - 1.0f },
|
||||
@@ -49,12 +44,10 @@ Values makeValues(const style::LinePaintProperties& properties,
|
||||
|
||||
LineProgram::UniformValues
|
||||
LineProgram::uniformValues(const style::LinePaintProperties& properties,
|
||||
float pixelRatio,
|
||||
const RenderTile& tile,
|
||||
const TransformState& state) {
|
||||
return makeValues<LineProgram::UniformValues>(
|
||||
properties,
|
||||
pixelRatio,
|
||||
tile,
|
||||
state,
|
||||
uniforms::u_color::Value{ properties.lineColor.value }
|
||||
@@ -85,7 +78,6 @@ LineSDFProgram::uniformValues(const style::LinePaintProperties& properties,
|
||||
|
||||
return makeValues<LineSDFProgram::UniformValues>(
|
||||
properties,
|
||||
pixelRatio,
|
||||
tile,
|
||||
state,
|
||||
uniforms::u_color::Value{ properties.lineColor.value },
|
||||
@@ -101,7 +93,6 @@ LineSDFProgram::uniformValues(const style::LinePaintProperties& properties,
|
||||
|
||||
LinePatternProgram::UniformValues
|
||||
LinePatternProgram::uniformValues(const style::LinePaintProperties& properties,
|
||||
float pixelRatio,
|
||||
const RenderTile& tile,
|
||||
const TransformState& state,
|
||||
const SpriteAtlasPosition& posA,
|
||||
@@ -118,7 +109,6 @@ LinePatternProgram::uniformValues(const style::LinePaintProperties& properties,
|
||||
|
||||
return makeValues<LinePatternProgram::UniformValues>(
|
||||
properties,
|
||||
pixelRatio,
|
||||
tile,
|
||||
state,
|
||||
uniforms::u_pattern_tl_a::Value{ posA.tl },
|
||||
|
||||
@@ -23,9 +23,8 @@ class SpriteAtlasPosition;
|
||||
|
||||
namespace uniforms {
|
||||
MBGL_DEFINE_UNIFORM_SCALAR(float, u_ratio);
|
||||
MBGL_DEFINE_UNIFORM_SCALAR(float, u_linewidth);
|
||||
MBGL_DEFINE_UNIFORM_SCALAR(float, u_width);
|
||||
MBGL_DEFINE_UNIFORM_SCALAR(float, u_gapwidth);
|
||||
MBGL_DEFINE_UNIFORM_SCALAR(float, u_antialiasing);
|
||||
MBGL_DEFINE_UNIFORM_SCALAR(float, u_extra);
|
||||
MBGL_DEFINE_UNIFORM_SCALAR(float, u_offset);
|
||||
MBGL_DEFINE_UNIFORM_SCALAR(float, u_tex_y_a);
|
||||
@@ -93,11 +92,10 @@ class LineProgram : public Program<
|
||||
gl::Uniforms<
|
||||
uniforms::u_matrix,
|
||||
uniforms::u_opacity,
|
||||
uniforms::u_linewidth,
|
||||
uniforms::u_width,
|
||||
uniforms::u_gapwidth,
|
||||
uniforms::u_blur,
|
||||
uniforms::u_offset,
|
||||
uniforms::u_antialiasing,
|
||||
uniforms::u_antialiasingmatrix,
|
||||
uniforms::u_ratio,
|
||||
uniforms::u_extra,
|
||||
@@ -107,7 +105,6 @@ public:
|
||||
using Program::Program;
|
||||
|
||||
static UniformValues uniformValues(const style::LinePaintProperties&,
|
||||
float pixelRatio,
|
||||
const RenderTile&,
|
||||
const TransformState&);
|
||||
};
|
||||
@@ -119,11 +116,10 @@ class LinePatternProgram : public Program<
|
||||
gl::Uniforms<
|
||||
uniforms::u_matrix,
|
||||
uniforms::u_opacity,
|
||||
uniforms::u_linewidth,
|
||||
uniforms::u_width,
|
||||
uniforms::u_gapwidth,
|
||||
uniforms::u_blur,
|
||||
uniforms::u_offset,
|
||||
uniforms::u_antialiasing,
|
||||
uniforms::u_antialiasingmatrix,
|
||||
uniforms::u_ratio,
|
||||
uniforms::u_extra,
|
||||
@@ -140,7 +136,6 @@ public:
|
||||
using Program::Program;
|
||||
|
||||
static UniformValues uniformValues(const style::LinePaintProperties&,
|
||||
float pixelRatio,
|
||||
const RenderTile&,
|
||||
const TransformState&,
|
||||
const SpriteAtlasPosition& posA,
|
||||
@@ -154,11 +149,10 @@ class LineSDFProgram : public Program<
|
||||
gl::Uniforms<
|
||||
uniforms::u_matrix,
|
||||
uniforms::u_opacity,
|
||||
uniforms::u_linewidth,
|
||||
uniforms::u_width,
|
||||
uniforms::u_gapwidth,
|
||||
uniforms::u_blur,
|
||||
uniforms::u_offset,
|
||||
uniforms::u_antialiasing,
|
||||
uniforms::u_antialiasingmatrix,
|
||||
uniforms::u_ratio,
|
||||
uniforms::u_extra,
|
||||
|
||||
@@ -1,33 +1,38 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/gl/program.hpp>
|
||||
#include <mbgl/programs/program_parameters.hpp>
|
||||
|
||||
#include <cassert>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
enum class ProgramDefines : bool {
|
||||
None = false,
|
||||
Overdraw = true,
|
||||
};
|
||||
|
||||
template <class Shaders, class Primitive, class Attributes, class Uniforms>
|
||||
class Program : public gl::Program<Primitive, Attributes, Uniforms> {
|
||||
public:
|
||||
using ParentType = gl::Program<Primitive, Attributes, Uniforms>;
|
||||
|
||||
Program(gl::Context& context, ProgramDefines defines)
|
||||
: ParentType(context, Shaders::vertexSource, fragmentSource(defines))
|
||||
Program(gl::Context& context, const ProgramParameters& programParameters)
|
||||
: ParentType(context, vertexSource(programParameters), fragmentSource(programParameters))
|
||||
{}
|
||||
|
||||
static std::string fragmentSource(ProgramDefines defines) {
|
||||
std::string fragment = Shaders::fragmentSource;
|
||||
if (defines == ProgramDefines::Overdraw) {
|
||||
assert(fragment.find("#ifdef OVERDRAW_INSPECTOR") != std::string::npos);
|
||||
fragment.replace(fragment.find_first_of('\n'), 1, "\n#define OVERDRAW_INSPECTOR\n");
|
||||
}
|
||||
return fragment;
|
||||
|
||||
static std::string pixelRatioDefine(const ProgramParameters& parameters) {
|
||||
return std::string("#define DEVICE_PIXEL_RATIO ") + std::to_string(parameters.pixelRatio) + "\n";
|
||||
}
|
||||
|
||||
static std::string fragmentSource(const ProgramParameters& parameters) {
|
||||
std::string source = pixelRatioDefine(parameters) + 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::vertexSource;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
16
src/mbgl/programs/program_parameters.hpp
Normal file
16
src/mbgl/programs/program_parameters.hpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
class ProgramParameters {
|
||||
public:
|
||||
ProgramParameters(float pixelRatio_ = 1.0, bool overdraw_ = false)
|
||||
: pixelRatio(pixelRatio_),
|
||||
overdraw(overdraw_) {}
|
||||
|
||||
float pixelRatio;
|
||||
bool overdraw;
|
||||
};
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -7,26 +7,27 @@
|
||||
#include <mbgl/programs/symbol_program.hpp>
|
||||
#include <mbgl/programs/debug_program.hpp>
|
||||
#include <mbgl/programs/collision_box_program.hpp>
|
||||
#include <mbgl/programs/program_parameters.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
class Programs {
|
||||
public:
|
||||
Programs(gl::Context& context, ProgramDefines defines = ProgramDefines::None)
|
||||
: circle(context, defines),
|
||||
fill(context, defines),
|
||||
fillPattern(context, defines),
|
||||
fillOutline(context, defines),
|
||||
fillOutlinePattern(context, defines),
|
||||
line(context, defines),
|
||||
lineSDF(context, defines),
|
||||
linePattern(context, defines),
|
||||
raster(context, defines),
|
||||
symbolIcon(context, defines),
|
||||
symbolIconSDF(context, defines),
|
||||
symbolGlyph(context, defines),
|
||||
debug(context, ProgramDefines::None),
|
||||
collisionBox(context, ProgramDefines::None) {
|
||||
Programs(gl::Context& context, const ProgramParameters& programParameters)
|
||||
: circle(context, programParameters),
|
||||
fill(context, programParameters),
|
||||
fillPattern(context, programParameters),
|
||||
fillOutline(context, programParameters),
|
||||
fillOutlinePattern(context, programParameters),
|
||||
line(context, programParameters),
|
||||
lineSDF(context, programParameters),
|
||||
linePattern(context, programParameters),
|
||||
raster(context, programParameters),
|
||||
symbolIcon(context, programParameters),
|
||||
symbolIconSDF(context, programParameters),
|
||||
symbolGlyph(context, programParameters),
|
||||
debug(context, ProgramParameters(programParameters.pixelRatio, false)),
|
||||
collisionBox(context, ProgramParameters(programParameters.pixelRatio, false)) {
|
||||
}
|
||||
|
||||
CircleProgram circle;
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include <mbgl/geometry/line_atlas.hpp>
|
||||
#include <mbgl/text/glyph_atlas.hpp>
|
||||
|
||||
#include <mbgl/programs/program_parameters.hpp>
|
||||
#include <mbgl/programs/programs.hpp>
|
||||
|
||||
#include <mbgl/algorithm/generate_clip_ids.hpp>
|
||||
@@ -73,7 +74,7 @@ static gl::VertexVector<RasterVertex, gl::TriangleStrip> rasterTriangleStrip() {
|
||||
return result;
|
||||
}
|
||||
|
||||
Painter::Painter(gl::Context& context_, const TransformState& state_)
|
||||
Painter::Painter(gl::Context& context_, const TransformState& state_, float pixelRatio)
|
||||
: context(context_),
|
||||
state(state_),
|
||||
tileTriangleVertexBuffer(context.createVertexBuffer(tileTriangles())),
|
||||
@@ -86,9 +87,12 @@ Painter::Painter(gl::Context& context_, const TransformState& state_)
|
||||
gl::debugging::enable();
|
||||
#endif
|
||||
|
||||
programs = std::make_unique<Programs>(context);
|
||||
ProgramParameters programParameters{ pixelRatio, false };
|
||||
programs = std::make_unique<Programs>(context, programParameters);
|
||||
#ifndef NDEBUG
|
||||
overdrawPrograms = std::make_unique<Programs>(context, ProgramDefines::Overdraw);
|
||||
|
||||
ProgramParameters programParametersOverdraw{ pixelRatio, true };
|
||||
overdrawPrograms = std::make_unique<Programs>(context, programParametersOverdraw);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
#include <mbgl/gl/context.hpp>
|
||||
#include <mbgl/programs/debug_program.hpp>
|
||||
#include <mbgl/programs/program_parameters.hpp>
|
||||
#include <mbgl/programs/fill_program.hpp>
|
||||
#include <mbgl/programs/raster_program.hpp>
|
||||
|
||||
@@ -67,7 +68,7 @@ struct FrameData {
|
||||
|
||||
class Painter : private util::noncopyable {
|
||||
public:
|
||||
Painter(gl::Context&, const TransformState&);
|
||||
Painter(gl::Context&, const TransformState&, float pixelRatio);
|
||||
~Painter();
|
||||
|
||||
void render(const style::Style&,
|
||||
|
||||
@@ -45,8 +45,7 @@ void Painter::renderCircle(PaintParameters& parameters,
|
||||
pixelsToGLUnits[0] * state.getAltitude(),
|
||||
pixelsToGLUnits[1] * state.getAltitude()
|
||||
}}
|
||||
: pixelsToGLUnits },
|
||||
uniforms::u_devicepixelratio::Value{ frame.pixelRatio },
|
||||
: pixelsToGLUnits }
|
||||
},
|
||||
*bucket.vertexBuffer,
|
||||
*bucket.indexBuffer,
|
||||
|
||||
@@ -70,7 +70,6 @@ void Painter::renderLine(PaintParameters& parameters,
|
||||
draw(parameters.programs.linePattern,
|
||||
LinePatternProgram::uniformValues(
|
||||
properties,
|
||||
frame.pixelRatio,
|
||||
tile,
|
||||
state,
|
||||
*posA,
|
||||
@@ -80,7 +79,6 @@ void Painter::renderLine(PaintParameters& parameters,
|
||||
draw(parameters.programs.line,
|
||||
LineProgram::uniformValues(
|
||||
properties,
|
||||
frame.pixelRatio,
|
||||
tile,
|
||||
state));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user