Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[core] Remove MapData dependency from Painter
Browse files Browse the repository at this point in the history
  • Loading branch information
jfirebaugh committed Apr 15, 2016
1 parent ed489e7 commit 9d18d65
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 35 deletions.
27 changes: 15 additions & 12 deletions src/mbgl/map/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class Map::Impl : public Style::Observer {
Map::StillImageCallback callback;
size_t sourceCacheSize;
TransformState transformState;
FrameData frameData;
TimePoint timePoint;
bool loading = false;
};

Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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() ?
Expand Down Expand Up @@ -202,24 +196,24 @@ 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);
updateFlags |= Update::Classes;
}

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,
Expand All @@ -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());
Expand Down
7 changes: 3 additions & 4 deletions src/mbgl/renderer/painter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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();
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/mbgl/renderer/painter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

namespace mbgl {

class MapData;
class Style;
class StyleLayer;
class Tile;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -152,7 +155,6 @@ class Painter : private util::noncopyable {
return identity;
}();

MapData& data;
TransformState& state;
gl::GLObjectStore& glObjectStore;

Expand Down
4 changes: 2 additions & 2 deletions src/mbgl/renderer/painter_circle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();

Expand Down
16 changes: 8 additions & 8 deletions src/mbgl/renderer/painter_debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -31,16 +31,16 @@ 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();
plainShader->u_matrix = 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
Expand All @@ -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();
Expand All @@ -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()));
}
4 changes: 2 additions & 2 deletions src/mbgl/renderer/painter_line.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/mbgl/renderer/painter_symbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 9d18d65

Please sign in to comment.