Eliminate Map::getTexturepool()

This commit is contained in:
John Firebaugh
2014-11-25 13:36:07 -08:00
parent 3aa15306f6
commit 576533b18c
14 changed files with 57 additions and 30 deletions

View File

@@ -128,7 +128,6 @@ public:
inline const TransformState &getState() const { return state; }
inline util::ptr<Style> getStyle() const { return style; }
util::ptr<Sprite> getSprite();
inline util::ptr<Texturepool> getTexturepool() { return texturepool; }
inline timestamp getAnimationTime() const { return animationTime; }
inline timestamp getTime() const { return animationTime; }
void updateTiles();

View File

@@ -11,12 +11,13 @@ class Map;
class Painter;
class SourceInfo;
class StyleLayer;
class Texturepool;
class RasterTileData : public TileData {
friend class TileParser;
public:
RasterTileData(Tile::ID const& id, Map &map, const util::ptr<SourceInfo> &source);
RasterTileData(Tile::ID const& id, Map &map, Texturepool&, const util::ptr<SourceInfo> &source);
~RasterTileData();
virtual void parse();

View File

@@ -22,6 +22,7 @@ class GlyphAtlas;
class GlyphStore;
class SpriteAtlas;
class FileSource;
class Texturepool;
class Painter;
class StyleLayer;
class TransformState;
@@ -32,7 +33,10 @@ public:
Source(const util::ptr<SourceInfo>& info);
void load(Map&, FileSource&);
bool update(Map&, uv::worker&, GlyphAtlas&, GlyphStore&, SpriteAtlas&, FileSource&);
bool update(Map&, uv::worker&,
GlyphAtlas&, GlyphStore&,
SpriteAtlas&,
Texturepool&, FileSource&);
void updateMatrices(const mat4 &projMatrix, const TransformState &transform);
void drawClippingMasks(Painter &painter);
@@ -51,9 +55,17 @@ private:
int32_t coveringZoomLevel(const TransformState&) const;
std::forward_list<Tile::ID> coveringTiles(const TransformState&) const;
bool updateTiles(Map&, uv::worker&, GlyphAtlas&, GlyphStore&, SpriteAtlas&, FileSource&);
bool updateTiles(Map&, uv::worker&,
GlyphAtlas&, GlyphStore&,
SpriteAtlas&,
Texturepool&, FileSource&);
TileData::State addTile(Map&, uv::worker&,
GlyphAtlas&, GlyphStore&,
SpriteAtlas&,
FileSource&, Texturepool&,
const Tile::ID&);
TileData::State addTile(Map&, uv::worker&, GlyphAtlas&, GlyphStore&, SpriteAtlas&, FileSource&, const Tile::ID&);
TileData::State hasTile(const Tile::ID& id);
double getZoom(const TransformState &state) const;

View File

@@ -28,6 +28,7 @@ class StyleBucketSymbol;
class StyleLayerGroup;
class VectorTileData;
class Collision;
class Texturepool;
class TileParser : private util::noncopyable
{
@@ -37,7 +38,8 @@ public:
GlyphAtlas & glyphAtlas,
GlyphStore & glyphStore,
SpriteAtlas & spriteAtlas,
const util::ptr<Sprite> &sprite);
const util::ptr<Sprite> &sprite,
Texturepool& texturepool);
~TileParser();
public:
@@ -49,7 +51,7 @@ private:
std::unique_ptr<Bucket> createBucket(util::ptr<StyleBucket> bucket_desc);
std::unique_ptr<Bucket> createFillBucket(const VectorTileLayer& layer, const FilterExpression &filter, const StyleBucketFill &fill);
std::unique_ptr<Bucket> createRasterBucket(const util::ptr<Texturepool> &texturepool, const StyleBucketRaster &raster);
std::unique_ptr<Bucket> createRasterBucket(Texturepool& texturepool, const StyleBucketRaster &raster);
std::unique_ptr<Bucket> createLineBucket(const VectorTileLayer& layer, const FilterExpression &filter, const StyleBucketLine &line);
std::unique_ptr<Bucket> createSymbolBucket(const VectorTileLayer& layer, const FilterExpression &filter, const StyleBucketSymbol &symbol);
@@ -65,7 +67,7 @@ private:
GlyphStore & glyphStore;
SpriteAtlas & spriteAtlas;
util::ptr<Sprite> sprite;
util::ptr<Texturepool> texturePool;
Texturepool& texturePool;
std::unique_ptr<Collision> collision;
};

View File

@@ -24,6 +24,7 @@ class TileParser;
class GlyphAtlas;
class GlyphStore;
class SpriteAtlas;
class Texturepool;
class VectorTileData : public TileData {
friend class TileParser;
@@ -32,6 +33,7 @@ public:
VectorTileData(Tile::ID const&, Map&,
GlyphAtlas&, GlyphStore&,
SpriteAtlas&,
Texturepool&,
const util::ptr<SourceInfo>&);
~VectorTileData();
@@ -57,6 +59,7 @@ protected:
GlyphAtlas& glyphAtlas;
GlyphStore& glyphStore;
SpriteAtlas& spriteAtlas;
Texturepool& texturepool;
public:
const float depth;

View File

@@ -16,7 +16,7 @@ class VertexArrayObject;
class RasterBucket : public Bucket {
public:
RasterBucket(const util::ptr<Texturepool> &texturepool, const StyleBucketRaster& properties);
RasterBucket(Texturepool&, const StyleBucketRaster&);
virtual void render(Painter& painter, util::ptr<StyleLayer> layer_desc, const Tile::ID& id, const mat4 &matrix);
virtual bool hasData() const;
@@ -31,8 +31,6 @@ public:
void drawRaster(RasterShader& shader, StaticVertexBuffer &vertices, VertexArrayObject &array, GLuint texture);
Raster raster;
private:
};
}

View File

@@ -17,7 +17,7 @@ namespace mbgl {
class Raster : public std::enable_shared_from_this<Raster> {
public:
Raster(const util::ptr<Texturepool> &texturepool);
Raster(Texturepool&);
~Raster();
// load image data
@@ -57,7 +57,7 @@ private:
bool loaded = false;
// shared texture pool
util::ptr<Texturepool> texturepool;
Texturepool& texturepool;
// min/mag filter
uint32_t filter = 0;

View File

@@ -642,7 +642,7 @@ void Map::updateSources(const util::ptr<StyleLayerGroup> &group) {
void Map::updateTiles() {
for (const util::ptr<StyleSource> &source : getActiveSources()) {
source->source->update(*this, getWorker(), glyphAtlas, *glyphStore, spriteAtlas, *fileSource);
source->source->update(*this, getWorker(), glyphAtlas, *glyphStore, spriteAtlas, *texturepool, *fileSource);
}
}

View File

@@ -5,9 +5,9 @@
using namespace mbgl;
RasterTileData::RasterTileData(Tile::ID const& id_, Map &map_, const util::ptr<SourceInfo> &source_)
RasterTileData::RasterTileData(Tile::ID const& id_, Map &map_, Texturepool& texturepool, const util::ptr<SourceInfo> &source_)
: TileData(id_, map_, source_),
bucket(map.getTexturepool(), properties) {
bucket(texturepool, properties) {
}
RasterTileData::~RasterTileData() {

View File

@@ -63,9 +63,10 @@ void Source::load(Map& map, FileSource& fileSource) {
bool Source::update(Map& map, uv::worker& worker,
GlyphAtlas& glyphAtlas, GlyphStore& glyphStore,
SpriteAtlas& spriteAtlas, FileSource& fileSource) {
SpriteAtlas& spriteAtlas,
Texturepool& texturepool, FileSource& fileSource) {
if (loaded && map.getTime() > updated) {
return updateTiles(map, worker, glyphAtlas, glyphStore, spriteAtlas, fileSource);
return updateTiles(map, worker, glyphAtlas, glyphStore, spriteAtlas, texturepool, fileSource);
} else {
return false;
}
@@ -164,7 +165,8 @@ TileData::State Source::hasTile(const Tile::ID& id) {
TileData::State Source::addTile(Map& map, uv::worker& worker,
GlyphAtlas& glyphAtlas, GlyphStore& glyphStore,
SpriteAtlas& spriteAtlas,
FileSource& fileSource, const Tile::ID& id) {
FileSource& fileSource, Texturepool& texturepool,
const Tile::ID& id) {
const TileData::State state = hasTile(id);
if (state != TileData::State::invalid) {
@@ -192,9 +194,9 @@ TileData::State Source::addTile(Map& map, uv::worker& worker,
if (!new_tile.data) {
// If we don't find working tile data, we're just going to load it.
if (info->type == SourceType::Vector) {
new_tile.data = std::make_shared<VectorTileData>(normalized_id, map, glyphAtlas, glyphStore, spriteAtlas, info);
new_tile.data = std::make_shared<VectorTileData>(normalized_id, map, glyphAtlas, glyphStore, spriteAtlas, texturepool, info);
} else if (info->type == SourceType::Raster) {
new_tile.data = std::make_shared<RasterTileData>(normalized_id, map, info);
new_tile.data = std::make_shared<RasterTileData>(normalized_id, map, texturepool, info);
} else {
throw std::runtime_error("source type not implemented");
}
@@ -288,7 +290,8 @@ bool Source::findLoadedParent(const Tile::ID& id, int32_t minCoveringZoom, std::
bool Source::updateTiles(Map& map, uv::worker& worker,
GlyphAtlas& glyphAtlas, GlyphStore& glyphStore,
SpriteAtlas& spriteAtlas, FileSource& fileSource) {
SpriteAtlas& spriteAtlas,
Texturepool& texturepool, FileSource& fileSource) {
bool changed = false;
int32_t zoom = std::floor(getZoom(map.getState()));
@@ -305,7 +308,11 @@ bool Source::updateTiles(Map& map, uv::worker& worker,
// Add existing child/parent tiles if the actual tile is not yet loaded
for (const Tile::ID& id : required) {
const TileData::State state = addTile(map, worker, glyphAtlas, glyphStore, spriteAtlas, fileSource, id);
const TileData::State state = addTile(map, worker,
glyphAtlas, glyphStore,
spriteAtlas,
fileSource, texturepool,
id);
if (state != TileData::State::parsed) {
// The tile we require is not yet loaded. Try to find a parent or

View File

@@ -34,7 +34,8 @@ TileParser::TileParser(const std::string &data, VectorTileData &tile_,
GlyphAtlas & glyphAtlas_,
GlyphStore & glyphStore_,
SpriteAtlas & spriteAtlas_,
const util::ptr<Sprite> &sprite_)
const util::ptr<Sprite> &sprite_,
Texturepool& texturePool_)
: vector_data(pbf((const uint8_t *)data.data(), data.size())),
tile(tile_),
style(style_),
@@ -42,6 +43,7 @@ TileParser::TileParser(const std::string &data, VectorTileData &tile_,
glyphStore(glyphStore_),
spriteAtlas(spriteAtlas_),
sprite(sprite_),
texturePool(texturePool_),
collision(std::make_unique<Collision>(tile.id.z, 4096, tile.source->tile_size, tile.depth)) {
assert(&tile != nullptr);
assert(style);
@@ -153,7 +155,7 @@ std::unique_ptr<Bucket> TileParser::createFillBucket(const VectorTileLayer& laye
return obsolete() ? nullptr : std::move(bucket);
}
std::unique_ptr<Bucket> TileParser::createRasterBucket(const util::ptr<Texturepool> &texturepool, const StyleBucketRaster &raster) {
std::unique_ptr<Bucket> TileParser::createRasterBucket(Texturepool& texturepool, const StyleBucketRaster &raster) {
std::unique_ptr<RasterBucket> bucket = std::make_unique<RasterBucket>(texturepool, raster);
return obsolete() ? nullptr : std::move(bucket);
}

View File

@@ -11,11 +11,13 @@ using namespace mbgl;
VectorTileData::VectorTileData(Tile::ID const& id_, Map &map_,
GlyphAtlas& glyphAtlas_, GlyphStore& glyphStore_,
SpriteAtlas& spriteAtlas_,
Texturepool& texturepool_,
const util::ptr<SourceInfo> &source_)
: TileData(id_, map_, source_),
glyphAtlas(glyphAtlas_),
glyphStore(glyphStore_),
spriteAtlas(spriteAtlas_),
texturepool(texturepool_),
depth(id.z >= source->max_zoom ? map.getMaxZoom() - id.z : 1) {
}
@@ -35,7 +37,8 @@ void VectorTileData::parse() {
// is going to be discarded afterwards.
TileParser parser(data, *this, map.getStyle(),
glyphAtlas, glyphStore,
spriteAtlas, map.getSprite());
spriteAtlas, map.getSprite(),
texturepool);
parser.parse();
} catch (const std::exception& ex) {
#if defined(DEBUG)

View File

@@ -3,7 +3,7 @@
using namespace mbgl;
RasterBucket::RasterBucket(const util::ptr<Texturepool> &texturepool, const StyleBucketRaster& properties_)
RasterBucket::RasterBucket(Texturepool& texturepool, const StyleBucketRaster& properties_)
: properties(properties_),
texture(properties_),
raster(texturepool) {

View File

@@ -11,13 +11,13 @@
using namespace mbgl;
Raster::Raster(const util::ptr<Texturepool> &texturepool_)
Raster::Raster(Texturepool& texturepool_)
: texturepool(texturepool_)
{}
Raster::~Raster() {
if (textured) {
texturepool->removeTextureID(texture);
texturepool.removeTextureID(texture);
}
}
@@ -46,7 +46,7 @@ void Raster::bind(bool linear) {
}
if (img && !textured) {
texture = texturepool->getTextureID();
texture = texturepool.getTextureID();
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);