fixes #70: raster tile rendering as toggleable mode from vector
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
#ifndef LLMR_MAP_COVERAGE
|
||||
#define LLMR_MAP_COVERAGE
|
||||
|
||||
#include <llmr/util/vec.hpp>
|
||||
#include <llmr/map/tile.hpp>
|
||||
|
||||
#include <forward_list>
|
||||
|
||||
namespace llmr {
|
||||
|
||||
std::forward_list<Tile::ID> covering_tiles(int32_t zoom, const box& points);
|
||||
std::forward_list<Tile::ID> covering_tiles(int32_t zoom, const box& points, const bool use_raster = false, const bool use_retina = false);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <llmr/style/style.hpp>
|
||||
#include <llmr/renderer/painter.hpp>
|
||||
#include <llmr/util/noncopyable.hpp>
|
||||
#include <llmr/util/texturepool.hpp>
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
@@ -23,9 +24,9 @@ public:
|
||||
/* setup */
|
||||
void setup(float pixelRatio = 1);
|
||||
void loadStyle(const uint8_t *const data, uint32_t bytes);
|
||||
void loadSprite(const std::string& url);
|
||||
void loadSettings();
|
||||
void resize(uint32_t width, uint32_t height, uint32_t fb_width, uint32_t fb_height);
|
||||
void toggleRaster();
|
||||
|
||||
/* callback */
|
||||
bool render();
|
||||
@@ -68,12 +69,12 @@ private:
|
||||
TileData::State addTile(const Tile::ID& id);
|
||||
TileData::State hasTile(const Tile::ID& id);
|
||||
|
||||
|
||||
void update();
|
||||
|
||||
private:
|
||||
Settings& settings;
|
||||
Transform transform;
|
||||
Texturepool texturepool;
|
||||
Style style;
|
||||
Painter painter;
|
||||
|
||||
@@ -82,6 +83,8 @@ private:
|
||||
|
||||
float pixel_ratio;
|
||||
|
||||
bool use_raster = false;
|
||||
|
||||
std::forward_list<Tile> tiles;
|
||||
std::forward_list<std::weak_ptr<TileData>> tile_data;
|
||||
};
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
namespace llmr {
|
||||
|
||||
class Style;
|
||||
class Raster;
|
||||
class Bucket;
|
||||
class LayerDescription;
|
||||
class BucketDescription;
|
||||
@@ -52,7 +53,7 @@ public:
|
||||
};
|
||||
|
||||
public:
|
||||
TileData(Tile::ID id, const Style& style);
|
||||
TileData(Tile::ID id, const Style& style, const bool use_raster = false, const bool use_retina = false);
|
||||
~TileData();
|
||||
|
||||
// Start loading the tile.
|
||||
@@ -72,7 +73,10 @@ public:
|
||||
|
||||
public:
|
||||
const Tile::ID id;
|
||||
const bool use_raster;
|
||||
const bool use_retina;
|
||||
std::atomic<State> state;
|
||||
std::shared_ptr<Raster> raster;
|
||||
|
||||
// Holds the actual geometries in this tile.
|
||||
DebugFontBuffer debugFontBuffer;
|
||||
|
||||
@@ -7,8 +7,11 @@
|
||||
|
||||
namespace llmr {
|
||||
|
||||
extern const char *kTileURL;
|
||||
extern const char *kTileVectorURL;
|
||||
extern const char *kTileRasterURL;
|
||||
extern const char *kSpriteURL;
|
||||
extern const int32_t kTileVectorMaxZoom;
|
||||
extern const int32_t kTileRasterMaxZoom;
|
||||
|
||||
namespace platform {
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#include <llmr/shader/line_shader.hpp>
|
||||
#include <llmr/shader/linejoin_shader.hpp>
|
||||
#include <llmr/shader/point_shader.hpp>
|
||||
|
||||
#include <llmr/shader/raster_shader.hpp>
|
||||
|
||||
namespace llmr {
|
||||
|
||||
@@ -42,10 +42,11 @@ public:
|
||||
void resize(int width, int height);
|
||||
|
||||
void prepareClippingMask();
|
||||
void drawClippingMask(const mat4& matrix, uint8_t clip_id);
|
||||
void drawClippingMask(const mat4& matrix, uint8_t clip_id, bool opaque = true);
|
||||
void finishClippingMask();
|
||||
private:
|
||||
void setupShaders();
|
||||
void renderRaster(const std::shared_ptr<TileData>& tile);
|
||||
void renderLayers(const std::shared_ptr<TileData>& tile, const std::vector<LayerDescription>& layers);
|
||||
void renderLayer(const std::shared_ptr<TileData>& tile_data, const LayerDescription& layer_desc);
|
||||
void renderDebug(const std::shared_ptr<TileData>& tile);
|
||||
@@ -80,6 +81,7 @@ private:
|
||||
std::unique_ptr<LinejoinShader> linejoinShader;
|
||||
std::unique_ptr<PatternShader> patternShader;
|
||||
std::unique_ptr<PointShader> pointShader;
|
||||
std::unique_ptr<RasterShader> rasterShader;
|
||||
|
||||
// Set up the stencil quad we're using to generate the stencil mask.
|
||||
VertexBuffer tileStencilBuffer = {
|
||||
@@ -96,6 +98,7 @@ private:
|
||||
|
||||
VertexArrayObject coveringPlainArray;
|
||||
VertexArrayObject coveringPatternArray;
|
||||
VertexArrayObject coveringRasterArray;
|
||||
|
||||
// Set up the tile boundary lines we're using to draw the tile outlines.
|
||||
VertexBuffer tileBorderBuffer = {
|
||||
|
||||
28
include/llmr/shader/raster_shader.hpp
Normal file
28
include/llmr/shader/raster_shader.hpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#ifndef LLMR_RENDERER_SHADER_RASTER
|
||||
#define LLMR_RENDERER_SHADER_RASTER
|
||||
|
||||
#include <llmr/shader/shader.hpp>
|
||||
|
||||
namespace llmr {
|
||||
|
||||
class RasterShader : public Shader {
|
||||
public:
|
||||
RasterShader();
|
||||
|
||||
void bind(char *offset);
|
||||
|
||||
void setImage(int32_t image);
|
||||
void setOpacity(float opacity);
|
||||
|
||||
private:
|
||||
int32_t a_pos = -1;
|
||||
|
||||
int32_t image = -1;
|
||||
int32_t u_image = -1;
|
||||
float opacity = 0.0f;
|
||||
float u_opacity = 0.0f;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -17,6 +17,7 @@ enum {
|
||||
PATTERN_SHADER,
|
||||
PLAIN_SHADER,
|
||||
POINT_SHADER,
|
||||
RASTER_SHADER,
|
||||
SHADER_COUNT
|
||||
};
|
||||
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
#ifndef LLMR_STYLE_SPRITE
|
||||
#define LLMR_STYLE_SPRITE
|
||||
|
||||
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <mutex>
|
||||
#include <memory>
|
||||
|
||||
#include <llmr/util/raster.hpp>
|
||||
#include <llmr/util/vec.hpp>
|
||||
|
||||
namespace llmr {
|
||||
@@ -34,27 +33,24 @@ public:
|
||||
|
||||
class Sprite : public std::enable_shared_from_this<Sprite> {
|
||||
public:
|
||||
~Sprite();
|
||||
Sprite();
|
||||
|
||||
void load(const std::string& base_url, float pixelRatio = 1);
|
||||
void bind(bool linear = false);
|
||||
|
||||
ImagePosition getPosition(const std::string& name, bool repeating = false);
|
||||
|
||||
operator bool() const;
|
||||
|
||||
public:
|
||||
std::shared_ptr<Raster> raster;
|
||||
|
||||
private:
|
||||
void parseJSON(const std::string& data);
|
||||
void loadImage(const std::string& data);
|
||||
|
||||
private:
|
||||
mutable std::mutex mtx;
|
||||
bool loaded = false;
|
||||
uint32_t filter = 0;
|
||||
uint32_t texture = 0;
|
||||
std::map<std::string, SpritePosition> pos;
|
||||
uint32_t width = 0, height = 0;
|
||||
char *img = nullptr;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
72
include/llmr/util/raster.hpp
Normal file
72
include/llmr/util/raster.hpp
Normal file
@@ -0,0 +1,72 @@
|
||||
#ifndef LLMR_UTIL_RASTER
|
||||
#define LLMR_UTIL_RASTER
|
||||
|
||||
#include <llmr/util/animation.hpp>
|
||||
#include <llmr/util/texturepool.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <mutex>
|
||||
|
||||
namespace llmr {
|
||||
|
||||
class Raster : public std::enable_shared_from_this<Raster> {
|
||||
|
||||
public:
|
||||
~Raster();
|
||||
|
||||
// load image data
|
||||
void load(const std::string& data);
|
||||
|
||||
// set shared texture pool
|
||||
void setTexturepool(Texturepool* texturepool);
|
||||
|
||||
// bind current texture
|
||||
void bind(bool linear = false);
|
||||
|
||||
// loaded status
|
||||
operator bool() const;
|
||||
|
||||
// animations
|
||||
void beginFadeInAnimation();
|
||||
bool needsAnimation() const;
|
||||
void updateAnimations();
|
||||
|
||||
public:
|
||||
// loaded image dimensions
|
||||
uint32_t width = 0, height = 0;
|
||||
|
||||
// has been uploaded to texture
|
||||
bool textured = false;
|
||||
|
||||
// the uploaded texture
|
||||
uint32_t texture = 0;
|
||||
|
||||
// texture opacity
|
||||
double opacity = 0;
|
||||
|
||||
private:
|
||||
// load raw pixels
|
||||
void loadImage(const std::string& data);
|
||||
|
||||
private:
|
||||
mutable std::mutex mtx;
|
||||
|
||||
// raw pixels have been loaded
|
||||
bool loaded = false;
|
||||
|
||||
// shared texture pool
|
||||
Texturepool* texturepool = nullptr;
|
||||
|
||||
// min/mag filter
|
||||
uint32_t filter = 0;
|
||||
|
||||
// the raw pixels
|
||||
char *img = nullptr;
|
||||
|
||||
// fade in animation
|
||||
std::shared_ptr<util::animation> fade_animation = nullptr;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
25
include/llmr/util/texturepool.hpp
Normal file
25
include/llmr/util/texturepool.hpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#ifndef LLMR_UTIL_TEXTUREPOOL
|
||||
#define LLMR_UTIL_TEXTUREPOOL
|
||||
|
||||
#include <llmr/util/noncopyable.hpp>
|
||||
#include <llmr/platform/gl.hpp>
|
||||
|
||||
#include <set>
|
||||
#include <mutex>
|
||||
|
||||
namespace llmr {
|
||||
|
||||
class Texturepool : private util::noncopyable {
|
||||
|
||||
public:
|
||||
GLuint getTextureID();
|
||||
void removeTextureID(GLuint texture_id);
|
||||
void clearTextureIDs();
|
||||
|
||||
private:
|
||||
std::set<GLuint> texture_ids;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user