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

Support using maki as a value for image property #196

Merged
merged 7 commits into from
May 19, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
182 changes: 6 additions & 176 deletions bin/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -452,116 +452,13 @@ module.exports = {
"feature_type": "point",
"type": "text"
},
"poi_airport": {
"poi": {
"source": "mapbox streets",
"layer": "poi_label",
"field": "maki",
"value": "airport",
"size": {
"x": 12,
"y": 12
},
"type": "point"
},
"poi_rail": {
"source": "mapbox streets",
"layer": "poi_label",
"field": "maki",
"value": "rail",
"size": {
"x": 12,
"y": 12
},
"type": "point"
},
"poi_fire_station": {
"source": "mapbox streets",
"layer": "poi_label",
"field": "maki",
"value": "fire-station",
"size": {
"x": 12,
"y": 12
},
"type": "point"
},
"poi_bus": {
"source": "mapbox streets",
"layer": "poi_label",
"field": "maki",
"value": "bus",
"size": {
"x": 12,
"y": 12
},
"type": "point"
},
"poi_restaurant": {
"source": "mapbox streets",
"layer": "poi_label",
"field": "maki",
"value": "restaurant",
"size": {
"x": 12,
"y": 12
},
"type": "point"
},
"poi_park": {
"source": "mapbox streets",
"layer": "poi_label",
"field": "maki",
"value": "park",
"size": {
"x": 12,
"y": 12
},
"type": "point"
},
"poi_playground": {
"source": "mapbox streets",
"layer": "poi_label",
"field": "maki",
"value": "playground",
"size": {
"x": 12,
"y": 12
},
"type": "point"
},
"poi_hospital": {
"source": "mapbox streets",
"layer": "poi_label",
"field": "maki",
"value": "hospital",
"size": {
"x": 12,
"y": 12
},
"icon": "maki",
"size": 12,
"type": "point"
},
"poi_cafe": {
"source": "mapbox streets",
"layer": "poi_label",
"field": "maki",
"value": "cafe",
"size": {
"x": 12,
"y": 12
},
"type": "point"
},
"poi_beer": {
"source": "mapbox streets",
"layer": "poi_label",
"field": "maki",
"value": "beer",
"size": {
"x": 12,
"y": 12
},
"type": "point"
}
},
"constants": {
"land": "#f8f4f0",
Expand Down Expand Up @@ -801,42 +698,12 @@ module.exports = {
}, {
"name": "road_label",
"bucket": "road_label"
}, {
"name": "poi_label",
"bucket": "poi_label"
}, {
"name": "water_label",
"bucket": "water_label"
}, {
"name": "poi_airport",
"bucket": "poi_airport"
}, {
"name": "poi_rail",
"bucket": "poi_rail"
}, {
"name": "poi_bus",
"bucket": "poi_bus"
}, {
"name": "poi_fire_station",
"bucket": "poi_fire_station"
}, {
"name": "poi_restaurant",
"bucket": "poi_restaurant"
}, {
"name": "poi_park",
"bucket": "poi_park"
}, {
"name": "poi_hospital",
"bucket": "poi_hospital"
}, {
"name": "poi_playground",
"bucket": "poi_playground"
}, {
"name": "poi_cafe",
"bucket": "poi_cafe"
}, {
"name": "poi_beer",
"bucket": "poi_beer"
"name": "poi",
"bucket": "poi"
}],
"classes": [{
"name": "default",
Expand Down Expand Up @@ -2010,45 +1877,8 @@ module.exports = {
0.75
],
},
"poi_airport": {
"color": "maki",
"image": "airport-12",
},
"poi_restaurant": {
"color": "maki",
"image": "restaurant-12",
},
"poi_bus": {
"color": "maki",
"image": "bus-12",
},
"poi_rail": {
"color": "maki",
"image": "rail-12",
},
"poi_fire_station": {
"color": "maki",
"image": "fire-station-12",
},
"poi_park": {
"color": "maki",
"image": "park-12",
},
"poi_hospital": {
"color": "maki",
"image": "hospital-12",
},
"poi_playground": {
"color": "maki",
"image": "playground-12",
},
"poi_cafe": {
"color": "maki",
"image": "cafe-12",
},
"poi_beer": {
"poi": {
"color": "maki",
"image": "beer-12",
},
"satellite": {
"type": "raster",
Expand Down
34 changes: 34 additions & 0 deletions common/glfw_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ namespace platform {
double elapsed() { return glfwGetTime(); }

void show_debug_image(std::string name, const char *data, size_t width, size_t height) {
glfwInit();

static GLFWwindow *debug_window = nullptr;
if (!debug_window) {
debug_window = glfwCreateWindow(width, height, name.c_str(), nullptr, nullptr);
Expand Down Expand Up @@ -231,5 +233,37 @@ void show_debug_image(std::string name, const char *data, size_t width, size_t h
glfwMakeContextCurrent(current_window);
}


void show_color_debug_image(std::string name, const char *data, size_t logical_width, size_t logical_height, size_t width, size_t height) {
glfwInit();

static GLFWwindow *debug_window = nullptr;
if (!debug_window) {
debug_window = glfwCreateWindow(logical_width, logical_height, name.c_str(), nullptr, nullptr);
if (!debug_window) {
glfwTerminate();
fprintf(stderr, "Failed to initialize window\n");
exit(1);
}
}

GLFWwindow *current_window = glfwGetCurrentContext();

glfwSetWindowSize(debug_window, logical_width, logical_height);
glfwMakeContextCurrent(debug_window);

int fb_width, fb_height;
glfwGetFramebufferSize(debug_window, &fb_width, &fb_height);
float x_scale = (float)fb_width / (float)width;
float y_scale = (float)fb_height / (float)height;

glPixelZoom(x_scale, -y_scale);
glRasterPos2f(-1.0f, 1.0f);
glDrawPixels(width, height, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, data);
glfwSwapBuffers(debug_window);

glfwMakeContextCurrent(current_window);
}

}
}
44 changes: 32 additions & 12 deletions include/llmr/geometry/buffer.hpp
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
#ifndef LLMR_GEOMETRY_BUFFER
#define LLMR_GEOMETRY_BUFFER

#include <cstdlib>
#include <cassert>
#include <llmr/platform/gl.hpp>
#include <llmr/util/noncopyable.hpp>

#include <cstdlib>
#include <cassert>
#include <stdexcept>

namespace llmr {

template <
size_t item_size,
int bufferType = GL_ARRAY_BUFFER,
size_t defaultLength = 8192
size_t defaultLength = 8192,
bool retainAfterUpload = false
>
class Buffer : private util::noncopyable {
public:
~Buffer() {
if (array) {
free(array);
array = nullptr;
}
cleanup();
if (buffer != 0) {
glDeleteBuffers(1, &buffer);
buffer = 0;
Expand All @@ -33,19 +33,28 @@ class Buffer : private util::noncopyable {
}

// Transfers this buffer to the GPU and binds the buffer to the GL context.
void bind() {
void bind(bool force = false) {
if (buffer == 0) {
glGenBuffers(1, &buffer);
glBindBuffer(bufferType, buffer);
force = true;
}
glBindBuffer(bufferType, buffer);
if (force) {
assert("Buffer was already deleted" && array != nullptr);
glBufferData(bufferType, pos, array, GL_STATIC_DRAW);
if (!retainAfterUpload) {
cleanup();
}
}
}

void cleanup() {
if (array) {
free(array);
array = nullptr;
} else {
glBindBuffer(bufferType, buffer);
}
}


protected:
// increase the buffer size by at least /required/ bytes.
inline void *addElement() {
Expand All @@ -59,6 +68,17 @@ class Buffer : private util::noncopyable {
return static_cast<char *>(array) + (pos - itemSize);
}

// Get a pointer to the item at a given index.
inline void *getElement(size_t index) {
assert("Buffer was deleted" && array != nullptr);

if (index * itemSize >= pos) {
throw new std::runtime_error("Can't get element after array bounds");
} else {
return static_cast<char *>(array) + (index * itemSize);
}
}

public:
static const size_t itemSize = item_size;

Expand Down
5 changes: 3 additions & 2 deletions include/llmr/geometry/icon_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
namespace llmr {

class IconVertexBuffer : public Buffer<
4 // 2 coordinates per vertex (== 4 bytes)
4 + // int16 x/y coordinates per vertex (== 4 bytes)
4 // uint16 x/y coordinates of icon in sprite (== 4 bytes)
> {
public:
typedef int16_t vertex_type;

void add(vertex_type x, vertex_type y);
void add(vertex_type x, vertex_type y, uint16_t tx, uint16_t ty);
};

}
Expand Down
Loading