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

Commit

Permalink
[core] draw clipping masks from ClipIDGenerator rather than Sources
Browse files Browse the repository at this point in the history
  • Loading branch information
kkaefer committed Feb 10, 2016
1 parent a5c9103 commit 4edb2bc
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 27 deletions.
8 changes: 0 additions & 8 deletions src/mbgl/map/source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,6 @@ void Source::updateMatrices(const mat4 &projMatrix, const TransformState &transf
}
}

void Source::drawClippingMasks(Painter &painter) {
for (const auto& pair : tiles) {
Tile &tile = *pair.second;
MBGL_DEBUG_GROUP(std::string { "mask: " } + std::string(tile.id));
painter.drawClippingMask(tile.matrix, tile.clip);
}
}

void Source::finishRender(Painter &painter) {
for (const auto& pair : tiles) {
Tile &tile = *pair.second;
Expand Down
1 change: 0 additions & 1 deletion src/mbgl/map/source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ class Source : private util::noncopyable {
bool update(const StyleUpdateParameters&);

void updateMatrices(const mat4 &projMatrix, const TransformState &transform);
void drawClippingMasks(Painter &painter);
void finishRender(Painter &painter);

std::forward_list<Tile *> getLoadedTiles() const;
Expand Down
2 changes: 1 addition & 1 deletion src/mbgl/renderer/painter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ void Painter::render(const Style& style, const FrameData& frame_, SpriteAtlas& a
source->updateMatrices(projMatrix, state);
}

drawClippingMasks(sources);
drawClippingMasks(generator.getStencils());
}

frameHistory.record(data.getAnimationTime(), state.getZoom());
Expand Down
3 changes: 1 addition & 2 deletions src/mbgl/renderer/painter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ class Painter : private util::noncopyable {
float contrastFactor(float contrast);
std::array<float, 3> spinWeights(float spin_value);

void drawClippingMasks(const std::set<Source*>&);
void drawClippingMask(const mat4& matrix, const ClipID& clip);
void drawClippingMasks(const std::map<TileID, ClipID>&);

bool needsAnimation() const;

Expand Down
33 changes: 18 additions & 15 deletions src/mbgl/renderer/painter_clipping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,34 @@

using namespace mbgl;

void Painter::drawClippingMasks(const std::set<Source*>& sources) {

void Painter::drawClippingMasks(const std::map<TileID, ClipID>& stencils) {
MBGL_DEBUG_GROUP("clipping masks");

mat4 matrix;
const GLuint mask = 0b11111111;

config.program = plainShader->program;
config.stencilOp.reset();
config.stencilTest = GL_TRUE;
config.depthFunc.reset();
config.depthTest = GL_TRUE;
config.depthTest = GL_FALSE;
config.depthMask = GL_FALSE;
config.colorMask = { GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE };
config.depthRange = { 1.0f, 1.0f };
config.stencilMask = mask;

coveringPlainArray.bind(*plainShader, tileStencilBuffer, BUFFER_OFFSET_0);

for (const auto& source : sources) {
source->drawClippingMasks(*this);
}
}
for (const auto& stencil : stencils) {
const auto& id = stencil.first;
const auto& clip = stencil.second;

void Painter::drawClippingMask(const mat4& matrix, const ClipID &clip) {
plainShader->u_matrix = matrix;
MBGL_DEBUG_GROUP(std::string{ "mask: " } + std::string(id));
state.matrixFor(matrix, id, id.z);
matrix::multiply(matrix, projMatrix, matrix);
plainShader->u_matrix = matrix;

const GLint ref = (GLint)(clip.reference.to_ulong());
const GLuint mask = (GLuint)(clip.mask.to_ulong());
config.stencilFunc = { GL_ALWAYS, ref, mask };
config.stencilMask = mask;
MBGL_CHECK_ERROR(glDrawArrays(GL_TRIANGLES, 0, (GLsizei)tileStencilBuffer.index()));
const GLint ref = (GLint)(clip.reference.to_ulong());
config.stencilFunc = { GL_ALWAYS, ref, mask };
MBGL_CHECK_ERROR(glDrawArrays(GL_TRIANGLES, 0, (GLsizei)tileStencilBuffer.index()));
}
}

0 comments on commit 4edb2bc

Please sign in to comment.