[core] Remove MapData dependency from Painter
This commit is contained in:
@@ -68,7 +68,7 @@ public:
|
||||
Map::StillImageCallback callback;
|
||||
size_t sourceCacheSize;
|
||||
TransformState transformState;
|
||||
FrameData frameData;
|
||||
TimePoint timePoint;
|
||||
bool loading = false;
|
||||
};
|
||||
|
||||
@@ -132,9 +132,6 @@ void Map::renderStill(StillImageCallback callback) {
|
||||
}
|
||||
|
||||
impl->callback = callback;
|
||||
impl->transformState = impl->transform.getState();
|
||||
impl->frameData = FrameData{ impl->view.getFramebufferSize(), Clock::now() };
|
||||
|
||||
impl->updateFlags |= Update::RenderStill;
|
||||
impl->asyncUpdate.send();
|
||||
}
|
||||
@@ -163,9 +160,6 @@ void Map::render() {
|
||||
|
||||
const Update flags = impl->transform.updateTransitions(Clock::now());
|
||||
|
||||
impl->transformState = impl->transform.getState();
|
||||
impl->frameData = FrameData { impl->view.getFramebufferSize(), Clock::now() };
|
||||
|
||||
impl->render();
|
||||
|
||||
impl->view.notifyMapChange(isFullyLoaded() ?
|
||||
@@ -202,7 +196,7 @@ void Map::Impl::update() {
|
||||
// This time point is used to:
|
||||
// - Calculate style property transitions;
|
||||
// - Hint style sources to notify when all its tiles are loaded;
|
||||
frameData.timePoint = Clock::now();
|
||||
timePoint = Clock::now();
|
||||
|
||||
if (style->loaded && updateFlags & Update::Annotations) {
|
||||
data.getAnnotationManager()->updateStyle(*style);
|
||||
@@ -210,16 +204,16 @@ void Map::Impl::update() {
|
||||
}
|
||||
|
||||
if (updateFlags & Update::Classes) {
|
||||
style->cascade(frameData.timePoint, data.mode);
|
||||
style->cascade(timePoint, data.mode);
|
||||
}
|
||||
|
||||
if (updateFlags & Update::Classes || updateFlags & Update::RecalculateStyle) {
|
||||
style->recalculate(transformState.getZoom(), frameData.timePoint, data.mode);
|
||||
style->recalculate(transformState.getZoom(), timePoint, data.mode);
|
||||
}
|
||||
|
||||
StyleUpdateParameters parameters(data.pixelRatio,
|
||||
data.getDebug(),
|
||||
frameData.timePoint,
|
||||
timePoint,
|
||||
transformState,
|
||||
style->workers,
|
||||
fileSource,
|
||||
@@ -243,10 +237,19 @@ void Map::Impl::update() {
|
||||
}
|
||||
|
||||
void Map::Impl::render() {
|
||||
transformState = transform.getState();
|
||||
|
||||
if (!painter) {
|
||||
painter = std::make_unique<Painter>(data, transformState, glObjectStore);
|
||||
painter = std::make_unique<Painter>(transformState, glObjectStore);
|
||||
}
|
||||
|
||||
FrameData frameData { view.getFramebufferSize(),
|
||||
timePoint,
|
||||
data.pixelRatio,
|
||||
data.mode,
|
||||
data.contextMode,
|
||||
data.getDebug() };
|
||||
|
||||
painter->render(*style,
|
||||
frameData,
|
||||
data.getAnnotationManager()->getSpriteAtlas());
|
||||
|
||||
@@ -43,9 +43,8 @@
|
||||
|
||||
using namespace mbgl;
|
||||
|
||||
Painter::Painter(MapData& data_, TransformState& state_, gl::GLObjectStore& glObjectStore_)
|
||||
: data(data_),
|
||||
state(state_),
|
||||
Painter::Painter(TransformState& state_, gl::GLObjectStore& glObjectStore_)
|
||||
: state(state_),
|
||||
glObjectStore(glObjectStore_) {
|
||||
gl::debugging::enable();
|
||||
|
||||
@@ -201,7 +200,7 @@ void Painter::render(const Style& style, const FrameData& frame_, SpriteAtlas& a
|
||||
MBGL_CHECK_ERROR(VertexArrayObject::Unbind());
|
||||
}
|
||||
|
||||
if (data.contextMode == GLContextMode::Shared) {
|
||||
if (frame.contextMode == GLContextMode::Shared) {
|
||||
config.setDirty();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
class MapData;
|
||||
class Style;
|
||||
class StyleLayer;
|
||||
class Tile;
|
||||
@@ -76,11 +75,15 @@ class GLObjectStore;
|
||||
struct FrameData {
|
||||
std::array<uint16_t, 2> framebufferSize;
|
||||
TimePoint timePoint;
|
||||
float pixelRatio;
|
||||
MapMode mapMode;
|
||||
GLContextMode contextMode;
|
||||
MapDebugOptions debugOptions;
|
||||
};
|
||||
|
||||
class Painter : private util::noncopyable {
|
||||
public:
|
||||
Painter(MapData&, TransformState&, gl::GLObjectStore&);
|
||||
Painter(TransformState&, gl::GLObjectStore&);
|
||||
~Painter();
|
||||
|
||||
void render(const Style& style,
|
||||
@@ -152,7 +155,6 @@ private:
|
||||
return identity;
|
||||
}();
|
||||
|
||||
MapData& data;
|
||||
TransformState& state;
|
||||
gl::GLObjectStore& glObjectStore;
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ void Painter::renderCircle(CircleBucket& bucket,
|
||||
// Abort early.
|
||||
if (pass == RenderPass::Opaque) return;
|
||||
|
||||
config.stencilTest = data.mode == MapMode::Still ? GL_TRUE : GL_FALSE;
|
||||
config.stencilTest = frame.mapMode == MapMode::Still ? GL_TRUE : GL_FALSE;
|
||||
config.depthFunc.reset();
|
||||
config.depthTest = GL_TRUE;
|
||||
config.depthMask = GL_FALSE;
|
||||
@@ -36,7 +36,7 @@ void Painter::renderCircle(CircleBucket& bucket,
|
||||
// a faux-antialiasing for the circle. since blur is a ratio of the circle's
|
||||
// size and the intent is to keep the blur at roughly 1px, the two
|
||||
// are inversely related.
|
||||
float antialiasing = 1 / data.pixelRatio / properties.radius;
|
||||
float antialiasing = 1 / frame.pixelRatio / properties.radius;
|
||||
|
||||
config.program = circleShader->getID();
|
||||
|
||||
|
||||
@@ -12,12 +12,12 @@ using namespace mbgl;
|
||||
void Painter::renderTileDebug(const Tile& tile) {
|
||||
MBGL_DEBUG_GROUP(std::string { "debug " } + std::string(tile.id));
|
||||
assert(tile.data);
|
||||
if (data.getDebug() != MapDebugOptions::NoDebug) {
|
||||
if (frame.debugOptions != MapDebugOptions::NoDebug) {
|
||||
setClipping(tile.clip);
|
||||
if (data.getDebug() & (MapDebugOptions::Timestamps | MapDebugOptions::ParseStatus)) {
|
||||
if (frame.debugOptions & (MapDebugOptions::Timestamps | MapDebugOptions::ParseStatus)) {
|
||||
renderDebugText(*tile.data, tile.matrix);
|
||||
}
|
||||
if (data.getDebug() & MapDebugOptions::TileBorders) {
|
||||
if (frame.debugOptions & MapDebugOptions::TileBorders) {
|
||||
renderDebugFrame(tile.matrix);
|
||||
}
|
||||
}
|
||||
@@ -31,8 +31,8 @@ void Painter::renderDebugText(TileData& tileData, const mat4 &matrix) {
|
||||
if (!tileData.debugBucket || tileData.debugBucket->state != tileData.getState()
|
||||
|| !(tileData.debugBucket->modified == tileData.modified)
|
||||
|| !(tileData.debugBucket->expires == tileData.expires)
|
||||
|| tileData.debugBucket->debugMode != data.getDebug()) {
|
||||
tileData.debugBucket = std::make_unique<DebugBucket>(tileData.id, tileData.getState(), tileData.modified, tileData.expires, data.getDebug());
|
||||
|| tileData.debugBucket->debugMode != frame.debugOptions) {
|
||||
tileData.debugBucket = std::make_unique<DebugBucket>(tileData.id, tileData.getState(), tileData.modified, tileData.expires, frame.debugOptions);
|
||||
}
|
||||
|
||||
config.program = plainShader->getID();
|
||||
@@ -40,7 +40,7 @@ void Painter::renderDebugText(TileData& tileData, const mat4 &matrix) {
|
||||
|
||||
// Draw white outline
|
||||
plainShader->u_color = {{ 1.0f, 1.0f, 1.0f, 1.0f }};
|
||||
config.lineWidth = 4.0f * data.pixelRatio;
|
||||
config.lineWidth = 4.0f * frame.pixelRatio;
|
||||
tileData.debugBucket->drawLines(*plainShader, glObjectStore);
|
||||
|
||||
#ifndef GL_ES_VERSION_2_0
|
||||
@@ -51,7 +51,7 @@ void Painter::renderDebugText(TileData& tileData, const mat4 &matrix) {
|
||||
|
||||
// Draw black text.
|
||||
plainShader->u_color = {{ 0.0f, 0.0f, 0.0f, 1.0f }};
|
||||
config.lineWidth = 2.0f * data.pixelRatio;
|
||||
config.lineWidth = 2.0f * frame.pixelRatio;
|
||||
tileData.debugBucket->drawLines(*plainShader, glObjectStore);
|
||||
|
||||
config.depthFunc.reset();
|
||||
@@ -74,6 +74,6 @@ void Painter::renderDebugFrame(const mat4 &matrix) {
|
||||
// draw tile outline
|
||||
tileBorderArray.bind(*plainShader, tileBorderBuffer, BUFFER_OFFSET_0, glObjectStore);
|
||||
plainShader->u_color = {{ 1.0f, 0.0f, 0.0f, 1.0f }};
|
||||
config.lineWidth = 4.0f * data.pixelRatio;
|
||||
config.lineWidth = 4.0f * frame.pixelRatio;
|
||||
MBGL_CHECK_ERROR(glDrawArrays(GL_LINE_STRIP, 0, (GLsizei)tileBorderBuffer.index()));
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ void Painter::renderLine(LineBucket& bucket, const LineLayer& layer, const TileI
|
||||
|
||||
// the distance over which the line edge fades out.
|
||||
// Retina devices need a smaller distance to avoid aliasing.
|
||||
float antialiasing = 1.0 / data.pixelRatio;
|
||||
float antialiasing = 1.0 / frame.pixelRatio;
|
||||
|
||||
float blur = properties.blur + antialiasing;
|
||||
float edgeWidth = properties.width / 2.0;
|
||||
@@ -94,7 +94,7 @@ void Painter::renderLine(LineBucket& bucket, const LineLayer& layer, const TileI
|
||||
linesdfShader->u_tex_y_a = posA.y;
|
||||
linesdfShader->u_patternscale_b = {{ scaleXB, scaleYB }};
|
||||
linesdfShader->u_tex_y_b = posB.y;
|
||||
linesdfShader->u_sdfgamma = lineAtlas->width / (std::min(widthA, widthB) * 256.0 * data.pixelRatio) / 2;
|
||||
linesdfShader->u_sdfgamma = lineAtlas->width / (std::min(widthA, widthB) * 256.0 * frame.pixelRatio) / 2;
|
||||
linesdfShader->u_mix = properties.dasharray.value.t;
|
||||
linesdfShader->u_extra = extra;
|
||||
linesdfShader->u_offset = -properties.offset;
|
||||
|
||||
@@ -61,7 +61,7 @@ void Painter::renderSDF(SymbolBucket &bucket,
|
||||
|
||||
sdfShader.u_zoom = (state.getZoom() - zoomAdjust) * 10; // current zoom level
|
||||
|
||||
if (data.mode == MapMode::Continuous) {
|
||||
if (frame.mapMode == MapMode::Continuous) {
|
||||
FadeProperties f = frameHistory.getFadeProperties(frame.timePoint, util::DEFAULT_FADE_DURATION);
|
||||
sdfShader.u_fadedist = f.fadedist * 10;
|
||||
sdfShader.u_minfadezoom = std::floor(f.minfadezoom * 10);
|
||||
@@ -76,7 +76,7 @@ void Painter::renderSDF(SymbolBucket &bucket,
|
||||
|
||||
// The default gamma value has to be adjust for the current pixelratio so that we're not
|
||||
// drawing blurry font on retina screens.
|
||||
const float gamma = 0.105 * sdfFontSize / fontSize / data.pixelRatio;
|
||||
const float gamma = 0.105 * sdfFontSize / fontSize / frame.pixelRatio;
|
||||
|
||||
const float sdfPx = 8.0f;
|
||||
const float blurOffset = 1.19f;
|
||||
@@ -138,7 +138,7 @@ void Painter::renderSymbol(SymbolBucket& bucket, const SymbolLayer& layer, const
|
||||
config.depthMask = GL_FALSE;
|
||||
|
||||
// TODO remove the `true ||` when #1673 is implemented
|
||||
const bool drawAcrossEdges = (data.mode == MapMode::Continuous) && (true || !(layout.text.allowOverlap || layout.icon.allowOverlap ||
|
||||
const bool drawAcrossEdges = (frame.mapMode == MapMode::Continuous) && (true || !(layout.text.allowOverlap || layout.icon.allowOverlap ||
|
||||
layout.text.ignorePlacement || layout.icon.ignorePlacement));
|
||||
|
||||
// Disable the stencil test so that labels aren't clipped to tile boundaries.
|
||||
@@ -172,7 +172,7 @@ void Painter::renderSymbol(SymbolBucket& bucket, const SymbolLayer& layer, const
|
||||
const float fontScale = fontSize / 1.0f;
|
||||
|
||||
SpriteAtlas* activeSpriteAtlas = layer.spriteAtlas;
|
||||
const bool iconScaled = fontScale != 1 || data.pixelRatio != activeSpriteAtlas->getPixelRatio() || bucket.iconsNeedLinear;
|
||||
const bool iconScaled = fontScale != 1 || frame.pixelRatio != activeSpriteAtlas->getPixelRatio() || bucket.iconsNeedLinear;
|
||||
const bool iconTransformed = layout.icon.rotationAlignment == RotationAlignmentType::Map || angleOffset != 0 || state.getPitch() != 0;
|
||||
config.activeTexture = GL_TEXTURE0;
|
||||
activeSpriteAtlas->bind(sdf || state.isChanging() || iconScaled || iconTransformed, glObjectStore);
|
||||
|
||||
Reference in New Issue
Block a user