diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2014-03-11 15:46:55 +0100 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2014-03-14 11:36:10 +0100 |
commit | 117078270d4f3d4491746e4ac8c054731ddd2a86 (patch) | |
tree | c3853f119e4a46c419b7fcdf168b2eaaadc09505 /src/geometry/text_buffer.cpp | |
parent | a37dcedc419a6eefc333b6219f2220feca5cae0a (diff) | |
download | qtlocation-mapboxgl-117078270d4f3d4491746e4ac8c054731ddd2a86.tar.gz |
add text buffer code
Diffstat (limited to 'src/geometry/text_buffer.cpp')
-rw-r--r-- | src/geometry/text_buffer.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/geometry/text_buffer.cpp b/src/geometry/text_buffer.cpp new file mode 100644 index 0000000000..92580cdc32 --- /dev/null +++ b/src/geometry/text_buffer.cpp @@ -0,0 +1,33 @@ +#include <llmr/geometry/text_buffer.hpp> +#include <llmr/platform/gl.hpp> +#include <llmr/util/math.hpp> + +#include <cmath> + +using namespace llmr; + +const double TextVertexBuffer::angleFactor = 128 / M_PI; + + +size_t TextVertexBuffer::add(const GlyphPosition& pos) { + size_t idx = index(); + void *data = addElement(); + + int16_t *shorts = static_cast<int16_t *>(data); + shorts[0] = pos.x; + shorts[1] = pos.y; + shorts[2] = round(pos.ox * 64); // use 1/64 pixels for placement + shorts[3] = round(pos.oy * 64); + + uint8_t *ubytes = static_cast<uint8_t *>(data); + ubytes[8] = pos.tx / 4; + ubytes[9] = pos.ty / 4; + ubytes[10] = pos.labelminzoom * 10; + ubytes[11] = pos.minzoom * 10; // 1/10 zoom levels: z16 == 160. + ubytes[12] = fmin(pos.maxzoom, 25) * 10; // 1/10 zoom levels: z16 == 160. + ubytes[13] = (int16_t)round(pos.angle * angleFactor) % 256; + ubytes[14] = util::max((int16_t)round(pos.rangefrom * angleFactor), (int16_t)0) % 256; + ubytes[15] = util::min((int16_t)round(pos.rangeto * angleFactor), (int16_t)255) % 256; + + return idx; +} |