Merge branch 'master' of github.com:mapbox/mapbox-gl-native

This commit is contained in:
Justin R. Miller
2014-07-15 18:48:10 -07:00
13 changed files with 110 additions and 32 deletions

View File

@@ -52,6 +52,7 @@ private:
private:
Map ↦
std::string url;
std::string body;
std::string image;
std::atomic<bool> loaded;

View File

@@ -32,6 +32,7 @@ enum class Event : uint8_t {
ParseTile,
Render,
HttpRequest,
Sprite,
};
LLMR_DEFINE_ENUM_CLASS(EventClass, Event, {
@@ -42,6 +43,7 @@ LLMR_DEFINE_ENUM_CLASS(EventClass, Event, {
{ Event::ParseTile, "ParseTile" },
{ Event::Render, "Render" },
{ Event::HttpRequest, "HttpRequest" },
{ Event::Sprite, "Sprite" },
{ Event(-1), "Unknown" },
});

View File

@@ -128,9 +128,7 @@ Rect<SpriteAtlas::dimension> SpriteAtlas::allocateImage(size_t width, size_t hei
Rect<SpriteAtlas::dimension> SpriteAtlas::getIcon(const int size, const std::string &name) {
std::lock_guard<std::mutex> lock(mtx);
const std::string id = name + "-" + std::to_string(size);
auto rect_it = images.find(id);
auto rect_it = images.find(name);
if (rect_it != images.end()) {
return rect_it->second;
}
@@ -143,7 +141,7 @@ Rect<SpriteAtlas::dimension> SpriteAtlas::getIcon(const int size, const std::str
return rect;
}
images.emplace(id, rect);
images.emplace(name, rect);
allocate();
@@ -158,7 +156,7 @@ Rect<SpriteAtlas::dimension> SpriteAtlas::getIcon(const int size, const std::str
1.0f / size / pixelRatio
);
uninitialized.emplace(id);
uninitialized.emplace(name);
dirty = true;
@@ -251,11 +249,13 @@ void SpriteAtlas::update(const Sprite &sprite) {
}
void SpriteAtlas::bind(bool linear) {
bool first = false;
if (!texture) {
glGenTextures(1, &texture);
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);
first = true;
} else {
glBindTexture(GL_TEXTURE_2D, texture);
}
@@ -270,20 +270,34 @@ void SpriteAtlas::bind(bool linear) {
if (dirty) {
std::lock_guard<std::mutex> lock(mtx);
allocate();
glTexImage2D(
GL_TEXTURE_2D, // GLenum target
0, // GLint level
GL_RGBA, // GLint internalformat
width * pixelRatio, // GLsizei width
height * pixelRatio, // GLsizei height
0, // GLint border
GL_RGBA, // GLenum format
GL_UNSIGNED_BYTE, // GLenum type
data // const GLvoid * data
);
if (first) {
glTexImage2D(
GL_TEXTURE_2D, // GLenum target
0, // GLint level
GL_RGBA, // GLint internalformat
width * pixelRatio, // GLsizei width
height * pixelRatio, // GLsizei height
0, // GLint border
GL_RGBA, // GLenum format
GL_UNSIGNED_BYTE, // GLenum type
data // const GLvoid * data
);
} else {
glTexSubImage2D(GL_TEXTURE_2D, // GLenum target
0, // GLint level
0, // GLint xoffset
0, // GLint yoffset
width * pixelRatio, // GLsizei width
height * pixelRatio, // GLsizei height
GL_RGBA, // GLenum format
GL_UNSIGNED_BYTE, // GLenum type
data // const GLvoid *pixels
);
}
#if defined(DEBUG)
// platform::show_color_debug_image("Sprite Atlas", data, width, height, width * pixelRatio, height * pixelRatio);
// platform::show_color_debug_image("Sprite Atlas", reinterpret_cast<char *>(data), width, height, width * pixelRatio, height * pixelRatio);
#endif
dirty = false;
}
@@ -291,6 +305,10 @@ void SpriteAtlas::bind(bool linear) {
SpriteAtlas::~SpriteAtlas() {
std::lock_guard<std::mutex> lock(mtx);
glDeleteTextures(1, &texture);
texture = 0;
if (data) {
free(data);
data = nullptr;

View File

@@ -97,6 +97,7 @@ void Map::run() {
// If the map rendering wasn't started asynchronously, we perform one render
// *after* all events have been processed.
if (!async) {
prepare();
render();
}
}

View File

@@ -1,6 +1,7 @@
#include <llmr/map/sprite.hpp>
#include <llmr/map/map.hpp>
#include <llmr/util/raster.hpp>
#include <llmr/platform/log.hpp>
#include <string>
#include <llmr/platform/platform.hpp>
@@ -27,6 +28,8 @@ Sprite::Sprite(Map &map, float pixelRatio)
}
void Sprite::load(const std::string& base_url) {
loaded = false;
url = base_url;
std::shared_ptr<Sprite> sprite = shared_from_this();
std::string suffix = (pixelRatio > 1 ? "@2x" : "");
@@ -53,12 +56,12 @@ void Sprite::load(const std::string& base_url) {
}
void Sprite::complete(std::shared_ptr<Sprite> &sprite) {
if (sprite->raster && sprite->pos.size()) {
const bool raster = bool(sprite->raster);
const bool json = bool(sprite->pos.size());
if (raster && json && !sprite->loaded) {
sprite->loaded = true;
sprite->map.update();
#if defined(DEBUG)
fprintf(stderr, "sprite loaded\n");
#endif
Log::Info(Event::Sprite, "loaded %s", sprite->url.c_str());
}
}

View File

@@ -23,7 +23,7 @@ void Painter::renderIcon(IconBucket& bucket, std::shared_ptr<StyleLayer> layer_d
useProgram(iconShader->program);
iconShader->setMatrix(matrix);
// TODO: update
// iconShader->setColor(color);
iconShader->setColor({{ 1, 1, 1, 1 }});
iconShader->setImage(0);
iconShader->setRatio(map.getState().getPixelRatio());
iconShader->setDimension({{

View File

@@ -61,11 +61,11 @@ bool FilterComparison::Instance::compare(const std::forward_list<Value> &propert
switch (op) {
case Operator::Equal:
for (const Value &property_value : property_values) {
if (!includes(property_value, util::relaxed_equal)) {
return false;
if (includes(property_value, util::relaxed_equal)) {
return true;
}
}
return true;
return false;
case Operator::NotEqual:
for (const Value &property_value : property_values) {
if (includes(property_value, util::relaxed_equal)) {

View File

@@ -15,7 +15,7 @@ void write_file(const std::string &filename, const std::string &data) {
fwrite(data.data(), sizeof(std::string::value_type), data.size(), fd);
fclose(fd);
} else {
fprintf(stderr, "Failed to open file\n");
throw std::runtime_error(std::string("Failed to open file ") + filename);
}
}
@@ -26,7 +26,7 @@ std::string read_file(const std::string &filename) {
data << file.rdbuf();
return data.str();
} else {
throw std::runtime_error("Cannot read file " + filename);
throw std::runtime_error(std::string("Cannot read file ") + filename);
}
}

View File

@@ -24,6 +24,7 @@ std::vector<FixtureLogBackend::LogMessage> FixtureLogBackend::unchecked() const
for (const LogMessage &msg : messages) {
if (!msg.checked) {
unchecked.push_back(msg);
msg.checked = true;
}
}
return unchecked;
@@ -37,10 +38,10 @@ std::vector<FixtureLogBackend::LogMessage> FixtureLogBackend::unchecked() const
}
::std::ostream& operator<<(::std::ostream& os, const FixtureLogBackend::LogMessage& message) {
os << "[\"" << message.severity.get() << "\", \"" << message.event.get();
if (message.code) os << "\", " << message.code.get();
if (message.msg) os << ", \"" << message.msg.get();
return os << "\"]" << std::endl;
os << "[\"" << message.severity.get() << "\", \"" << message.event.get() << "\"";
if (message.code) os << ", " << message.code.get();
if (message.msg) os << ", \"" << message.msg.get() << "\"";
return os << "]" << std::endl;
}
}

View File

@@ -2,6 +2,7 @@
#define LLMR_TEST_FIXTURE_LOG
#include <llmr/platform/log.hpp>
#include <llmr/util/noncopyable.hpp>
#include <boost/optional.hpp>
@@ -10,7 +11,7 @@
namespace llmr {
class FixtureLogBackend : public LogBackend {
class FixtureLogBackend : public LogBackend, private util::noncopyable {
public:
struct LogMessage {
inline LogMessage(EventSeverity severity, Event event, int64_t code, const std::string &msg)

18
test/fixtures/styles/icons.info.json vendored Normal file
View File

@@ -0,0 +1,18 @@
{
"default": {
"zoom": 14,
"center": [52.499167, 13.418056],
"height": 256,
"log": [
[1, "INFO", "HttpRequest", 200, "sprites/outdoors.json"],
[1, "INFO", "HttpRequest", 200, "sprites/outdoors.png"],
[1, "INFO", "HttpRequest", 200, "tiles/14-8803-5375.vector.pbf"],
[1, "INFO", "HttpRequest", 200, "tiles/14-8802-5375.vector.pbf"],
[1, "INFO", "HttpRequest", 200, "tiles/14-8803-5374.vector.pbf"],
[1, "INFO", "HttpRequest", 200, "tiles/14-8802-5374.vector.pbf"],
[6, "INFO", "HttpRequest"],
[1, "INFO", "Sprite", "loaded sprites/outdoors"]
]
}
}

33
test/fixtures/styles/icons.style.json vendored Normal file
View File

@@ -0,0 +1,33 @@
{
"version": 3,
"sources": {
"mapbox": {
"type": "vector",
"url": "tiles/{z}-{x}-{y}.vector.pbf",
"tileSize": 512,
"maxZoom": 14
}
},
"sprite": "sprites/outdoors",
"layers": [
{
"id": "background",
"type": "background",
"style": {
"background-color": "green"
}
},
{
"id": "poi",
"source": "mapbox",
"source-layer": "poi_label",
"type": "icon",
"filter": { "maki": "restaurant" },
"render": {
"icon-image": "{maki}-12",
"icon-size": 12,
"icon-allow-overlap": true
}
}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB