Merge branch 'master' into tessellation
Conflicts: include/llmr/renderer/fill_bucket.hpp src/renderer/fill_bucket.cpp src/renderer/painter.cpp
This commit is contained in:
19
include/llmr/geometry/point_buffer.hpp
Normal file
19
include/llmr/geometry/point_buffer.hpp
Normal file
@@ -0,0 +1,19 @@
|
||||
#ifndef LLMR_GEOMETRY_POINT_BUFFER
|
||||
#define LLMR_GEOMETRY_POINT_BUFFER
|
||||
|
||||
#include "buffer.hpp"
|
||||
|
||||
namespace llmr {
|
||||
|
||||
class PointVertexBuffer : public Buffer<
|
||||
4 // 2 coordinates per vertex (== 4 bytes)
|
||||
> {
|
||||
public:
|
||||
typedef int16_t vertex_type;
|
||||
|
||||
void add(vertex_type x, vertex_type y);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -2,6 +2,7 @@
|
||||
#define LLMR_GEOMETRY_VERTEX_BUFFER
|
||||
|
||||
#include <vector>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <cmath>
|
||||
|
||||
@@ -17,7 +18,7 @@ public:
|
||||
* Returns the number of elements in this buffer. This is not the number of
|
||||
* bytes, but rather the number of coordinates with associated information.
|
||||
*/
|
||||
uint32_t index() const;
|
||||
size_t index() const;
|
||||
|
||||
/*
|
||||
* Transfers this buffer to the GPU and binds the buffer to the GL context.
|
||||
|
||||
@@ -20,7 +20,7 @@ public:
|
||||
~Map();
|
||||
|
||||
/* setup */
|
||||
void setup();
|
||||
void setup(float pixelRatio = 1);
|
||||
void loadStyle(const uint8_t *const data, uint32_t bytes);
|
||||
void loadSprite(const std::string& url);
|
||||
void loadSettings();
|
||||
@@ -29,13 +29,13 @@ public:
|
||||
/* callback */
|
||||
bool render();
|
||||
void cancelAnimations();
|
||||
void tileLoaded(std::shared_ptr<Tile> tile);
|
||||
void tileFailed(std::shared_ptr<Tile> tile);
|
||||
|
||||
/* position */
|
||||
void moveBy(double dx, double dy, double duration = 0);
|
||||
void setLonLat(double lon, double lat, double duration = 0);
|
||||
void getLonLat(double &lon, double &lat) const;
|
||||
void startPanning();
|
||||
void stopPanning();
|
||||
void resetPosition();
|
||||
|
||||
/* scale */
|
||||
@@ -47,12 +47,16 @@ public:
|
||||
void setLonLatZoom(double lon, double lat, double zoom, double duration = 0);
|
||||
void getLonLatZoom(double &lon, double &lat, double &zoom) const;
|
||||
void resetZoom();
|
||||
void startScaling();
|
||||
void stopScaling();
|
||||
|
||||
/* rotation */
|
||||
void rotateBy(double cx, double cy, double sx, double sy, double ex, double ey, double duration = 0);
|
||||
void setAngle(double angle, double cx = -1, double cy = -1, double duration = 0);
|
||||
double getAngle() const;
|
||||
void resetNorth();
|
||||
void startRotating();
|
||||
void stopRotating();
|
||||
|
||||
void toggleDebug();
|
||||
|
||||
@@ -75,6 +79,8 @@ private:
|
||||
int32_t min_zoom;
|
||||
int32_t max_zoom;
|
||||
|
||||
float pixel_ratio;
|
||||
|
||||
std::forward_list<std::shared_ptr<Tile>> tiles;
|
||||
std::forward_list<std::shared_ptr<Tile>> historic_tiles;
|
||||
};
|
||||
|
||||
@@ -23,6 +23,7 @@ class VectorTile;
|
||||
class VectorTileLayer;
|
||||
class FillVertexBuffer;
|
||||
class LineVertexBuffer;
|
||||
class PointVertexBuffer;
|
||||
class TriangleElementsBuffer;
|
||||
class LineElementsBuffer;
|
||||
class PointElementsBuffer;
|
||||
@@ -59,6 +60,7 @@ public:
|
||||
std::shared_ptr<Bucket> createBucket(const VectorTile& tile, const BucketDescription& bucket_desc);
|
||||
std::shared_ptr<Bucket> createFillBucket(const VectorTileLayer& layer, const BucketDescription& bucket_desc);
|
||||
std::shared_ptr<Bucket> createLineBucket(const VectorTileLayer& layer, const BucketDescription& bucket_desc);
|
||||
std::shared_ptr<Bucket> createPointBucket(const VectorTileLayer& layer, const BucketDescription& bucket_desc);
|
||||
|
||||
void cancel();
|
||||
|
||||
@@ -77,6 +79,7 @@ public:
|
||||
|
||||
std::shared_ptr<FillVertexBuffer> fillVertexBuffer;
|
||||
std::shared_ptr<LineVertexBuffer> lineVertexBuffer;
|
||||
std::shared_ptr<PointVertexBuffer> pointVertexBuffer;
|
||||
|
||||
std::shared_ptr<TriangleElementsBuffer> triangleElementsBuffer;
|
||||
std::shared_ptr<LineElementsBuffer> lineElementsBuffer;
|
||||
|
||||
@@ -42,6 +42,14 @@ public:
|
||||
void getLonLat(double& lon, double& lat) const;
|
||||
void getLonLatZoom(double& lon, double& lat, double& zoom) const;
|
||||
|
||||
// Animations
|
||||
void startPanning();
|
||||
void stopPanning();
|
||||
void startRotating();
|
||||
void stopRotating();
|
||||
void startScaling();
|
||||
void stopScaling();
|
||||
|
||||
// Temporary
|
||||
void mapCornersToBox(uint32_t z, box& b) const;
|
||||
|
||||
@@ -61,6 +69,10 @@ public:
|
||||
|
||||
float pixelRatio = 1;
|
||||
|
||||
bool rotating = false;
|
||||
bool scaling = false;
|
||||
bool panning = false;
|
||||
|
||||
private:
|
||||
double x = 0, y = 0; // pixel values of the map center in the current scale
|
||||
double angle = 0;
|
||||
@@ -72,7 +84,10 @@ private:
|
||||
// cache values for spherical mercator math
|
||||
double zc, Bc, Cc;
|
||||
|
||||
std::forward_list<util::animation> animations;
|
||||
std::forward_list<std::shared_ptr<util::animation>> animations;
|
||||
std::shared_ptr<util::animation> scale_timeout;
|
||||
std::shared_ptr<util::animation> rotate_timeout;
|
||||
std::shared_ptr<util::animation> pan_timeout;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
#ifndef LLMR_RENDERER_GL
|
||||
#define LLMR_RENDERER_GL
|
||||
|
||||
#ifdef EMSCRIPTEN
|
||||
#include <GLES2/gl2.h>
|
||||
#elif __APPLE__
|
||||
#if __APPLE__
|
||||
#include "TargetConditionals.h"
|
||||
#if TARGET_OS_IPHONE
|
||||
#include <OpenGLES/ES2/gl.h>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include <string>
|
||||
|
||||
#define kTileURL "http://a.gl-api-us-east-1.tilestream.net/v3/mapbox.mapbox-streets-v4/%d/%d/%d.gl.pbf"
|
||||
#define kSpriteURL "http://mapbox-kkaefer.s3.amazonaws.com/static/sprite"
|
||||
#define kSpriteURL "https://dl.dropboxusercontent.com/u/575564/sprite"
|
||||
|
||||
namespace llmr {
|
||||
|
||||
@@ -14,16 +14,16 @@ class Tile;
|
||||
|
||||
namespace platform {
|
||||
|
||||
// Restarts painting. This could for example trigger the event loop of the
|
||||
// controlling application.
|
||||
void restart(void *obj);
|
||||
// Restarts painting. This could for example trigger the event loop of the controlling application.
|
||||
void restart();
|
||||
|
||||
struct Response {
|
||||
int16_t code = -1;
|
||||
std::string body;
|
||||
};
|
||||
|
||||
void request_http(std::string url, std::function<void(Response&)> func, std::function<void()> cb);
|
||||
// Makes an HTTP request of a URL on a background thread, calls a function with the results on the same thread, and finally calls a callback function on the main thread.
|
||||
void request_http(std::string url, std::function<void(Response&)> background_function, std::function<void()> foreground_callback);
|
||||
|
||||
// Returns a relative timestamp in seconds. This value must be monotonic.
|
||||
double time();
|
||||
|
||||
@@ -68,10 +68,11 @@ private:
|
||||
std::shared_ptr<LineElementsBuffer> lineElementsBuffer;
|
||||
|
||||
// hold information on where the vertices are located in the FillBuffer
|
||||
const uint32_t vertex_start;
|
||||
const uint32_t triangle_elements_start;
|
||||
const uint32_t line_elements_start;
|
||||
const size_t vertex_start;
|
||||
const size_t triangle_elements_start;
|
||||
const size_t line_elements_start;
|
||||
VertexArrayObject array;
|
||||
|
||||
std::vector<triangle_group_type> triangleGroups;
|
||||
std::vector<line_group_type> lineGroups;
|
||||
|
||||
|
||||
@@ -47,9 +47,9 @@ private:
|
||||
std::shared_ptr<TriangleElementsBuffer> triangleElementsBuffer;
|
||||
std::shared_ptr<PointElementsBuffer> pointElementsBuffer;
|
||||
|
||||
const uint32_t vertex_start;
|
||||
const uint32_t triangle_elements_start;
|
||||
const uint32_t point_elements_start;
|
||||
const size_t vertex_start;
|
||||
const size_t triangle_elements_start;
|
||||
const size_t point_elements_start;
|
||||
|
||||
std::vector<triangle_group_type> triangleGroups;
|
||||
std::vector<point_group_type> pointGroups;
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <llmr/renderer/shader-pattern.hpp>
|
||||
#include <llmr/renderer/shader-line.hpp>
|
||||
#include <llmr/renderer/shader-linejoin.hpp>
|
||||
#include <llmr/renderer/shader-point.hpp>
|
||||
|
||||
|
||||
namespace llmr {
|
||||
@@ -23,6 +24,7 @@ class Tile;
|
||||
|
||||
class FillBucket;
|
||||
class LineBucket;
|
||||
class PointBucket;
|
||||
|
||||
class Painter : private util::noncopyable {
|
||||
public:
|
||||
@@ -36,6 +38,7 @@ public:
|
||||
void renderBackground();
|
||||
void renderFill(FillBucket& bucket, const std::string& layer_name, const Tile::ID& id);
|
||||
void renderLine(LineBucket& bucket, const std::string& layer_name, const Tile::ID& id);
|
||||
void renderPoint(PointBucket& bucket, const std::string& layer_name, const Tile::ID& id);
|
||||
|
||||
private:
|
||||
void setupShaders();
|
||||
@@ -63,6 +66,7 @@ private:
|
||||
std::unique_ptr<LineShader> lineShader;
|
||||
std::unique_ptr<LinejoinShader> linejoinShader;
|
||||
std::unique_ptr<PatternShader> patternShader;
|
||||
std::unique_ptr<PointShader> pointShader;
|
||||
|
||||
// Set up the stencil quad we're using to generate the stencil mask.
|
||||
VertexBuffer tileStencilBuffer = {
|
||||
|
||||
51
include/llmr/renderer/point_bucket.hpp
Normal file
51
include/llmr/renderer/point_bucket.hpp
Normal file
@@ -0,0 +1,51 @@
|
||||
#ifndef LLMR_RENDERER_POINTBUCKET
|
||||
#define LLMR_RENDERER_POINTBUCKET
|
||||
|
||||
#include <llmr/renderer/bucket.hpp>
|
||||
#include <llmr/style/bucket_description.hpp>
|
||||
#include <llmr/geometry/elements_buffer.hpp>
|
||||
#include <llmr/geometry/point_buffer.hpp>
|
||||
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
#ifndef BUFFER_OFFSET
|
||||
#define BUFFER_OFFSET(i) ((char *)nullptr + (i))
|
||||
#endif
|
||||
|
||||
namespace llmr {
|
||||
|
||||
class Style;
|
||||
class PointVertexBuffer;
|
||||
class BucketDescription;
|
||||
class PointShader;
|
||||
struct Coordinate;
|
||||
struct pbf;
|
||||
|
||||
class PointBucket : public Bucket {
|
||||
public:
|
||||
PointBucket(const std::shared_ptr<PointVertexBuffer>& vertexBuffer,
|
||||
const BucketDescription& bucket_desc);
|
||||
|
||||
virtual void render(Painter& painter, const std::string& layer_name, const Tile::ID& id);
|
||||
|
||||
void addGeometry(pbf& data);
|
||||
|
||||
bool hasPoints() const;
|
||||
|
||||
void drawPoints(PointShader& shader);
|
||||
|
||||
public:
|
||||
const BucketGeometryDescription geometry;
|
||||
|
||||
private:
|
||||
std::shared_ptr<PointVertexBuffer> vertexBuffer;
|
||||
VertexArrayObject<PointShader> array;
|
||||
|
||||
const size_t vertex_start;
|
||||
size_t vertex_end = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
41
include/llmr/renderer/shader-point.hpp
Normal file
41
include/llmr/renderer/shader-point.hpp
Normal file
@@ -0,0 +1,41 @@
|
||||
#ifndef LLMR_RENDERER_SHADER_POINT
|
||||
#define LLMR_RENDERER_SHADER_POINT
|
||||
|
||||
#include "shader.hpp"
|
||||
|
||||
namespace llmr {
|
||||
|
||||
class PointShader : public Shader {
|
||||
public:
|
||||
PointShader();
|
||||
|
||||
void bind(char *offset);
|
||||
|
||||
void setImage(int32_t image);
|
||||
void setColor(const std::array<float, 4>& color);
|
||||
void setPointTopLeft(const std::array<float, 2>& point_tl);
|
||||
void setPointBottomRight(const std::array<float, 2>& point_br);
|
||||
void setSize(float size);
|
||||
|
||||
private:
|
||||
int32_t a_pos = -1;
|
||||
|
||||
int32_t image = -1;
|
||||
int32_t u_image = -1;
|
||||
|
||||
std::array<float, 4> color = {};
|
||||
int32_t u_color = -1;
|
||||
|
||||
std::array<float, 2> point_tl = {};
|
||||
int32_t u_point_tl = -1;
|
||||
|
||||
std::array<float, 2> point_br = {};
|
||||
int32_t u_point_br = -1;
|
||||
|
||||
float size = 0;
|
||||
int32_t u_size = -1;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -16,6 +16,7 @@ enum {
|
||||
OUTLINE_SHADER,
|
||||
PATTERN_SHADER,
|
||||
PLAIN_SHADER,
|
||||
POINT_SHADER,
|
||||
SHADER_COUNT
|
||||
};
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ class ClassDescription {
|
||||
public:
|
||||
std::map<std::string, FillClass> fill;
|
||||
std::map<std::string, LineClass> line;
|
||||
std::map<std::string, PointClass> point;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -60,8 +60,22 @@ struct FunctionProperty {
|
||||
inline T operator()(float z) const { return function(z, values); }
|
||||
};
|
||||
|
||||
struct PointClass {
|
||||
FunctionProperty<bool> hidden;
|
||||
FunctionProperty<float> size;
|
||||
Color color = {{ 0, 0, 0, 1 }};
|
||||
FunctionProperty<float> opacity = 1;
|
||||
std::string image;
|
||||
};
|
||||
|
||||
struct PointProperties {
|
||||
bool hidden = false;
|
||||
float size = 0;
|
||||
Color color = {{ 0, 0, 0, 1 }};
|
||||
float opacity = 1.0;
|
||||
std::string image;
|
||||
};
|
||||
|
||||
// LineClass is the information we parse from the stylesheet
|
||||
struct LineClass {
|
||||
FunctionProperty<bool> hidden;
|
||||
FunctionProperty<float> width;
|
||||
@@ -70,7 +84,6 @@ struct LineClass {
|
||||
FunctionProperty<float> opacity = 1;
|
||||
};
|
||||
|
||||
// LineProperties is the one we resolve this to.
|
||||
struct LineProperties {
|
||||
bool hidden = false;
|
||||
float width = 0;
|
||||
@@ -79,9 +92,6 @@ struct LineProperties {
|
||||
float opacity = 1.0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
struct FillClass {
|
||||
FunctionProperty<bool> hidden;
|
||||
Winding winding = Winding::NonZero;
|
||||
|
||||
@@ -34,7 +34,9 @@ public:
|
||||
|
||||
class Sprite : public std::enable_shared_from_this<Sprite> {
|
||||
public:
|
||||
void load(const std::string& base_url);
|
||||
~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);
|
||||
@@ -52,7 +54,7 @@ private:
|
||||
uint32_t texture = 0;
|
||||
std::map<std::string, SpritePosition> pos;
|
||||
uint32_t width = 0, height = 0;
|
||||
std::string img;
|
||||
char *img = nullptr;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ public:
|
||||
Style();
|
||||
|
||||
void reset();
|
||||
void load(const uint8_t *const data, uint32_t bytes);
|
||||
void load(const uint8_t *const data, size_t bytes);
|
||||
|
||||
// This is commented out because it is not fully implemented yet. For now,
|
||||
// we keep using the protobuf stylesheet format
|
||||
@@ -36,6 +36,7 @@ private:
|
||||
static std::pair<std::string, ClassDescription> parseClass(pbf data);
|
||||
static std::pair<std::string, FillClass> parseFillClass(pbf data);
|
||||
static std::pair<std::string, LineClass> parseLineClass(pbf data);
|
||||
static std::pair<std::string, PointClass> parsePointClass(pbf data);
|
||||
template <typename T> static FunctionProperty<T> parseProperty(pbf data);
|
||||
static Color parseColor(pbf& data);
|
||||
|
||||
@@ -53,6 +54,7 @@ public:
|
||||
struct {
|
||||
std::map<std::string, FillProperties> fills;
|
||||
std::map<std::string, LineProperties> lines;
|
||||
std::map<std::string, PointProperties> points;
|
||||
} computed;
|
||||
};
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define LLMR_UTIL_ANIMATION
|
||||
|
||||
#include <llmr/util/noncopyable.hpp>
|
||||
#include <llmr/platform/platform.hpp>
|
||||
|
||||
namespace llmr {
|
||||
namespace util {
|
||||
@@ -12,14 +13,51 @@ public:
|
||||
running,
|
||||
complete
|
||||
};
|
||||
animation(double duration)
|
||||
: start(platform::time()),
|
||||
duration(duration) {}
|
||||
|
||||
animation(double from, double to, double &value, double duration);
|
||||
double progress() const {
|
||||
return (platform::time() - start) / duration;
|
||||
}
|
||||
|
||||
virtual state update() const = 0;
|
||||
virtual ~animation();
|
||||
|
||||
protected:
|
||||
const double start, duration;
|
||||
};
|
||||
|
||||
class ease_animation : public animation {
|
||||
public:
|
||||
ease_animation(double from, double to, double& value, double duration);
|
||||
state update() const;
|
||||
|
||||
private:
|
||||
const double start, duration;
|
||||
const double from, to;
|
||||
double &value;
|
||||
double& value;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class timeout : public animation {
|
||||
public:
|
||||
timeout(T final_value, T& value, double duration)
|
||||
: animation(duration),
|
||||
final_value(final_value),
|
||||
value(value) {}
|
||||
|
||||
state update() const {
|
||||
if (progress() >= 1) {
|
||||
value = final_value;
|
||||
return complete;
|
||||
} else {
|
||||
return running;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
const T final_value;
|
||||
T& value;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ struct pbf {
|
||||
struct unknown_field_type_exception : exception {};
|
||||
struct end_of_buffer_exception : exception {};
|
||||
|
||||
inline pbf(const unsigned char *data, uint32_t length);
|
||||
inline pbf(const unsigned char *data, size_t length);
|
||||
inline pbf();
|
||||
|
||||
inline operator bool() const;
|
||||
@@ -49,7 +49,7 @@ struct pbf {
|
||||
uint32_t tag = 0;
|
||||
};
|
||||
|
||||
pbf::pbf(const unsigned char *data, uint32_t length)
|
||||
pbf::pbf(const unsigned char *data, size_t length)
|
||||
: data(data),
|
||||
end(data + length),
|
||||
value(0),
|
||||
|
||||
Reference in New Issue
Block a user