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
11 changed files
with
297 additions
and
19 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
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,60 @@ | ||
#include <mbgl/renderer/tile_mask_repository.hpp> | ||
#include <mbgl/util/constants.hpp> | ||
|
||
namespace mbgl { | ||
|
||
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; | ||
} | ||
return it->second; | ||
} | ||
|
||
void TileMaskRepository::clear() { | ||
drawables.clear(); | ||
} | ||
|
||
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,29 @@ | ||
#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: | ||
const Drawable<gl::Triangles, RasterLayoutVertex, RasterAttributes>& | ||
getDrawable(gl::Context&, const TileMask&); | ||
|
||
void clear(); | ||
|
||
static IndexedPrimitives<gl::Triangles, RasterLayoutVertex, RasterAttributes> | ||
getPrimitives(const TileMask&); | ||
|
||
private: | ||
std::map<TileMask, const Drawable<gl::Triangles, RasterLayoutVertex, RasterAttributes>> drawables; | ||
}; | ||
|
||
} // namespace mbgl |
Oops, something went wrong.