This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[core] generate masks for raster tiles to avoid painting over children
- Loading branch information
Showing
12 changed files
with
332 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule mapbox-gl-js
updated
6 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#include <mbgl/renderer/tile_mask_repository.hpp> | ||
#include <mbgl/util/constants.hpp> | ||
|
||
namespace mbgl { | ||
|
||
void TileMaskRepository::mark() { | ||
// Mark all drawables as stale. | ||
for (auto& pair : drawables) { | ||
pair.second.stale = true; | ||
} | ||
} | ||
|
||
void TileMaskRepository::sweep() { | ||
// Delete all drawables that are still marked stale. | ||
for (auto it = drawables.begin(); it != drawables.end();) { | ||
if (it->second.stale) { | ||
drawables.erase(it++); | ||
} else { | ||
++it; | ||
} | ||
} | ||
} | ||
|
||
const Drawable<gl::Triangles, RasterLayoutVertex, RasterAttributes>& | ||
TileMaskRepository::getDrawable(gl::Context& context, const TileMask& mask) { | ||
auto it = drawables.find(mask); | ||
if (it == drawables.end()) { | ||
it = drawables | ||
.emplace(std::piecewise_construct, std::forward_as_tuple(mask), | ||
std::forward_as_tuple(context, getPrimitives(mask))) | ||
.first; | ||
} else { | ||
it->second.stale = false; | ||
} | ||
return it->second.drawable; | ||
} | ||
|
||
IndexedPrimitives<gl::Triangles, RasterLayoutVertex, RasterAttributes> | ||
TileMaskRepository::getPrimitives(const TileMask& mask) { | ||
IndexedPrimitives<gl::Triangles, RasterLayoutVertex, RasterAttributes> primitives; | ||
|
||
for (const auto& id : mask) { | ||
// Create a quad for every masked tile. | ||
const int32_t vertexExtent = util::EXTENT >> id.z; | ||
const int32_t textureExtent = 32768 >> id.z; | ||
|
||
const Point<int16_t> tlVertex = { static_cast<int16_t>(id.x * vertexExtent), | ||
static_cast<int16_t>(id.y * vertexExtent) }; | ||
const Point<int16_t> brVertex = { static_cast<int16_t>(tlVertex.x + vertexExtent), | ||
static_cast<int16_t>(tlVertex.y + vertexExtent) }; | ||
const Point<uint16_t> tlTexture = { static_cast<uint16_t>(id.x * textureExtent), | ||
static_cast<uint16_t>(id.y * textureExtent) }; | ||
const Point<uint16_t> brTexture = { static_cast<uint16_t>(tlTexture.x + textureExtent), | ||
static_cast<uint16_t>(tlTexture.y + textureExtent) }; | ||
|
||
primitives.add( | ||
{ | ||
RasterProgram::layoutVertex({ tlVertex.x, tlVertex.y }, | ||
{ tlTexture.x, tlTexture.y }), | ||
RasterProgram::layoutVertex({ brVertex.x, tlVertex.y }, | ||
{ brTexture.x, tlTexture.y }), | ||
RasterProgram::layoutVertex({ tlVertex.x, brVertex.y }, | ||
{ tlTexture.x, brTexture.y }), | ||
RasterProgram::layoutVertex({ brVertex.x, brVertex.y }, | ||
{ brTexture.x, brTexture.y }), | ||
}, | ||
{ | ||
{{ 0, 1, 2 }}, | ||
{{ 1, 2, 3 }}, | ||
}); | ||
} | ||
|
||
return primitives; | ||
} | ||
|
||
} // namespace mbgl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#pragma once | ||
|
||
#include <mbgl/renderer/tile_mask.hpp> | ||
#include <mbgl/renderer/indexed_primitives.hpp> | ||
#include <mbgl/renderer/drawable.hpp> | ||
#include <mbgl/gl/draw_mode.hpp> | ||
#include <mbgl/programs/raster_program.hpp> | ||
|
||
namespace mbgl { | ||
|
||
namespace gl { | ||
class Context; | ||
} // namespace gl | ||
|
||
class TileMaskRepository { | ||
public: | ||
// Call this function at the beginning of a frame to mark all drawables as "stale". | ||
void mark(); | ||
|
||
// Delete all drawables that are still marked stale. Call this function at the end of a frame | ||
// during the cleanup phase. | ||
void sweep(); | ||
|
||
// Obtains a drawable with the specified mask. Creates a new drawable if it doesn't exist, or | ||
// marks the existing as not "stale". | ||
const Drawable<gl::Triangles, RasterLayoutVertex, RasterAttributes>& | ||
getDrawable(gl::Context&, const TileMask&); | ||
|
||
static IndexedPrimitives<gl::Triangles, RasterLayoutVertex, RasterAttributes> | ||
getPrimitives(const TileMask&); | ||
|
||
private: | ||
struct Entry { | ||
template <class... Args> | ||
Entry(Args&&... args) : drawable(std::forward<Args>(args)...) {} | ||
const Drawable<gl::Triangles, RasterLayoutVertex, RasterAttributes> drawable; | ||
bool stale = false; | ||
}; | ||
std::map<TileMask, Entry> drawables; | ||
}; | ||
|
||
} // namespace mbgl |
Oops, something went wrong.