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

Commit

Permalink
[core] do not call glStencilFunc when we're not clipping
Browse files Browse the repository at this point in the history
  • Loading branch information
kkaefer committed Apr 6, 2016
1 parent 3a36079 commit e7ac0f6
Show file tree
Hide file tree
Showing 14 changed files with 35 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/mbgl/renderer/bucket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class Bucket : private util::noncopyable {

virtual bool hasData() const = 0;

virtual bool needsClipping() const = 0;

inline bool needsUpload() const {
return !uploaded;
}
Expand Down
4 changes: 4 additions & 0 deletions src/mbgl/renderer/circle_bucket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ bool CircleBucket::hasData() const {
return !triangleGroups_.empty();
}

bool CircleBucket::needsClipping() const {
return true;
}

void CircleBucket::addGeometry(const GeometryCollection& geometryCollection) {
for (auto& circle : geometryCollection) {
for(auto & geometry : circle) {
Expand Down
1 change: 1 addition & 0 deletions src/mbgl/renderer/circle_bucket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class CircleBucket : public Bucket {
void render(Painter&, const StyleLayer&, const TileID&, const mat4&) override;

bool hasData() const override;
bool needsClipping() const override;
void addGeometry(const GeometryCollection&);

void drawCircles(CircleShader&, gl::GLObjectStore&);
Expand Down
4 changes: 4 additions & 0 deletions src/mbgl/renderer/fill_bucket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ bool FillBucket::hasData() const {
return !triangleGroups.empty() || !lineGroups.empty();
}

bool FillBucket::needsClipping() const {
return true;
}

void FillBucket::drawElements(PlainShader& shader, gl::GLObjectStore& glObjectStore) {
GLbyte* vertex_index = BUFFER_OFFSET(0);
GLbyte* elements_index = BUFFER_OFFSET(0);
Expand Down
1 change: 1 addition & 0 deletions src/mbgl/renderer/fill_bucket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class FillBucket : public Bucket {
void upload(gl::GLObjectStore&) override;
void render(Painter&, const StyleLayer&, const TileID&, const mat4&) override;
bool hasData() const override;
bool needsClipping() const override;

void addGeometry(const GeometryCollection&);
void tessellate();
Expand Down
4 changes: 4 additions & 0 deletions src/mbgl/renderer/line_bucket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,10 @@ bool LineBucket::hasData() const {
return !triangleGroups.empty();
}

bool LineBucket::needsClipping() const {
return true;
}

void LineBucket::drawLines(LineShader& shader, gl::GLObjectStore& glObjectStore) {
GLbyte* vertex_index = BUFFER_OFFSET(0);
GLbyte* elements_index = BUFFER_OFFSET(0);
Expand Down
1 change: 1 addition & 0 deletions src/mbgl/renderer/line_bucket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class LineBucket : public Bucket {
void upload(gl::GLObjectStore&) override;
void render(Painter&, const StyleLayer&, const TileID&, const mat4&) override;
bool hasData() const override;
bool needsClipping() const override;

void addGeometry(const GeometryCollection&);
void addGeometry(const GeometryCoordinates& line);
Expand Down
10 changes: 6 additions & 4 deletions src/mbgl/renderer/painter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ bool Painter::needsAnimation() const {
return frameHistory.needsAnimation(util::DEFAULT_FADE_DURATION);
}

void Painter::prepareTile(const Tile& tile) {
const GLint ref = (GLint)tile.clip.reference.to_ulong();
const GLuint mask = (GLuint)tile.clip.mask.to_ulong();
void Painter::setClipping(const ClipID& clip) {
const GLint ref = (GLint)clip.reference.to_ulong();
const GLuint mask = (GLuint)clip.mask.to_ulong();
config.stencilFunc = { GL_EQUAL, ref, mask };
}

Expand Down Expand Up @@ -249,7 +249,9 @@ void Painter::renderPass(RenderPass pass_,
config.setDirty();
} else {
MBGL_DEBUG_GROUP(layer.id + " - " + std::string(item.tile->id));
prepareTile(*item.tile);
if (item.bucket->needsClipping()) {
setClipping(item.tile->clip);
}
item.bucket->render(*this, layer, item.tile->id, item.tile->matrix);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/mbgl/renderer/painter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class Painter : private util::noncopyable {
Iterator it, Iterator end,
GLsizei i, int8_t increment);

void prepareTile(const Tile& tile);
void setClipping(const ClipID&);

template <typename BucketProperties, typename StyleProperties>
void renderSDF(SymbolBucket &bucket,
Expand Down
2 changes: 1 addition & 1 deletion src/mbgl/renderer/painter_debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ void Painter::renderTileDebug(const Tile& tile) {
MBGL_DEBUG_GROUP(std::string { "debug " } + std::string(tile.id));
assert(tile.data);
if (data.getDebug() != MapDebugOptions::NoDebug) {
prepareTile(tile);
setClipping(tile.clip);
if (data.getDebug() & (MapDebugOptions::Timestamps | MapDebugOptions::ParseStatus)) {
renderDebugText(*tile.data, tile.matrix);
}
Expand Down
4 changes: 4 additions & 0 deletions src/mbgl/renderer/raster_bucket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,7 @@ void RasterBucket::drawRaster(RasterShader& shader, StaticVertexBuffer &vertices
bool RasterBucket::hasData() const {
return raster.isLoaded();
}

bool RasterBucket::needsClipping() const {
return false;
}
1 change: 1 addition & 0 deletions src/mbgl/renderer/raster_bucket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class RasterBucket : public Bucket {
void upload(gl::GLObjectStore&) override;
void render(Painter&, const StyleLayer&, const TileID&, const mat4&) override;
bool hasData() const override;
bool needsClipping() const override;

void setImage(PremultipliedImage);

Expand Down
4 changes: 4 additions & 0 deletions src/mbgl/renderer/symbol_bucket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ bool SymbolBucket::hasIconData() const { return renderData && !renderData->icon.

bool SymbolBucket::hasCollisionBoxData() const { return renderData && !renderData->collisionBox.groups.empty(); }

bool SymbolBucket::needsClipping() const {
return mode == MapMode::Still;
}

void SymbolBucket::parseFeatures(const GeometryTileLayer& layer,
const FilterExpression& filter) {
const bool has_text = !layout.text.field.value.empty() && !layout.text.font.value.empty();
Expand Down
1 change: 1 addition & 0 deletions src/mbgl/renderer/symbol_bucket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class SymbolBucket : public Bucket {
bool hasTextData() const;
bool hasIconData() const;
bool hasCollisionBoxData() const;
bool needsClipping() const override;

void addFeatures(uintptr_t tileUID,
SpriteAtlas&,
Expand Down

0 comments on commit e7ac0f6

Please sign in to comment.