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

Commit

Permalink
fixes #70: raster tile rendering as toggleable mode from vector
Browse files Browse the repository at this point in the history
  • Loading branch information
incanus committed Mar 18, 2014
1 parent bdfa761 commit 00a3245
Show file tree
Hide file tree
Showing 24 changed files with 604 additions and 196 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,9 @@ This is automatically taken care of as a build phase if you are using the Xcode

## Desktop

- Press 'R' to reset the transform
- Press 'X' to reset the transform
- Press 'N' to reset north
- Press 'R' to toggle raster
- Press Tab to toggle debug information
- Press Esc to quit

Expand All @@ -130,3 +131,4 @@ This is automatically taken care of as a build phase if you are using the Xcode
- Long-press to reset north
- Two-finger long press to reset the transform
- Three-finger long press to toggle debug information
- Four-finger long press to toggle raster
4 changes: 2 additions & 2 deletions include/llmr/map/coverage.hpp
Original file line number Diff line number Diff line change
@@ -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);

}

Expand Down
7 changes: 5 additions & 2 deletions include/llmr/map/map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -23,9 +24,9 @@ class Map : private util::noncopyable {
/* 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();
Expand Down Expand Up @@ -68,12 +69,12 @@ class Map : private util::noncopyable {
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;

Expand All @@ -82,6 +83,8 @@ class Map : private util::noncopyable {

float pixel_ratio;

bool use_raster = false;

std::forward_list<Tile> tiles;
std::forward_list<std::weak_ptr<TileData>> tile_data;
};
Expand Down
6 changes: 5 additions & 1 deletion include/llmr/map/tile_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
namespace llmr {

class Style;
class Raster;
class Bucket;
class LayerDescription;
class BucketDescription;
Expand Down Expand Up @@ -52,7 +53,7 @@ class TileData : public std::enable_shared_from_this<TileData>,
};

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.
Expand All @@ -72,7 +73,10 @@ class TileData : public std::enable_shared_from_this<TileData>,

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;
Expand Down
5 changes: 4 additions & 1 deletion include/llmr/platform/platform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
7 changes: 5 additions & 2 deletions include/llmr/renderer/painter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -42,10 +42,11 @@ class Painter : private util::noncopyable {
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);
Expand Down Expand Up @@ -80,6 +81,7 @@ class Painter : private util::noncopyable {
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 = {
Expand All @@ -96,6 +98,7 @@ class Painter : private util::noncopyable {

VertexArrayObject coveringPlainArray;
VertexArrayObject coveringPatternArray;
VertexArrayObject coveringRasterArray;

// Set up the tile boundary lines we're using to draw the tile outlines.
VertexBuffer tileBorderBuffer = {
Expand Down
28 changes: 28 additions & 0 deletions include/llmr/shader/raster_shader.hpp
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions include/llmr/shader/shaders.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ enum {
PATTERN_SHADER,
PLAIN_SHADER,
POINT_SHADER,
RASTER_SHADER,
SHADER_COUNT
};

Expand Down
14 changes: 5 additions & 9 deletions include/llmr/style/sprite.hpp
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -34,27 +33,24 @@ class ImagePosition {

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;
};

}
Expand Down
72 changes: 72 additions & 0 deletions include/llmr/util/raster.hpp
Original file line number Diff line number Diff line change
@@ -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 changes: 25 additions & 0 deletions include/llmr/util/texturepool.hpp
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions ios/MBXViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ - (void)viewDidLoad
threeFingerLongPress.numberOfTouchesRequired = 3;
[self.view addGestureRecognizer:threeFingerLongPress];

UILongPressGestureRecognizer *fourFingerLongPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleFourFingerLongPressGesture:)];
fourFingerLongPress.numberOfTouchesRequired = 4;
[self.view addGestureRecognizer:fourFingerLongPress];

if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
UILongPressGestureRecognizer *quickZoom = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleQuickZoomGesture:)];
Expand Down Expand Up @@ -360,6 +364,16 @@ - (void)handleThreeFingerLongPressGesture:(UILongPressGestureRecognizer *)threeF
[self updateRender];
}

- (void)handleFourFingerLongPressGesture:(UILongPressGestureRecognizer *)fourFingerLongPress
{
mapView->map.cancelAnimations();

if (fourFingerLongPress.state == UIGestureRecognizerStateBegan)
mapView->map.toggleRaster();

[self updateRender];
}

- (void)handleQuickZoomGesture:(UILongPressGestureRecognizer *)quickZoom
{
mapView->map.cancelAnimations();
Expand Down
Loading

0 comments on commit 00a3245

Please sign in to comment.