diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2014-01-28 11:47:21 +0100 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2014-01-28 11:47:21 +0100 |
commit | edf2a532af23cba7a22c1de1494d0f811f57c105 (patch) | |
tree | 9c5ce72a83710558a1320417648f9851ab29e4ef /src | |
parent | a6434168b357e8d880b2282336addc0c06205b8f (diff) | |
download | qtlocation-mapboxgl-edf2a532af23cba7a22c1de1494d0f811f57c105.tar.gz |
add LineBuffer and change DebugFontBuffer naming
Diffstat (limited to 'src')
-rw-r--r-- | src/CMakeLists.txt | 4 | ||||
-rw-r--r-- | src/geometry/debug_font_buffer.cpp | 17 | ||||
-rw-r--r-- | src/geometry/line_buffer.cpp | 45 | ||||
-rw-r--r-- | src/geometry/linevertexbuffer.cpp | 43 | ||||
-rw-r--r-- | src/map/tile.cpp | 6 | ||||
-rw-r--r-- | src/renderer/painter.cpp | 6 |
6 files changed, 61 insertions, 60 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 14a3e88125..45b861ebbd 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,7 +1,7 @@ SET(llmr_SOURCES geometry/debug_font_buffer.cpp - geometry/linevertexbuffer.cpp geometry/fill_buffer.cpp + geometry/line_buffer.cpp map/map.cpp map/tile.cpp map/transform.cpp @@ -24,8 +24,8 @@ SET(llmr_SOURCES SET(llmr_HEADERS ../include/llmr/geometry/debug_font_buffer.hpp - ../include/llmr/geometry/linevertexbuffer.hpp ../include/llmr/geometry/fill_buffer.hpp + ../include/llmr/geometry/line_buffer.hpp ../include/llmr/llmr.hpp ../include/llmr/map/map.hpp ../include/llmr/map/tile.hpp diff --git a/src/geometry/debug_font_buffer.cpp b/src/geometry/debug_font_buffer.cpp index a383ca5734..b88a7e404e 100644 --- a/src/geometry/debug_font_buffer.cpp +++ b/src/geometry/debug_font_buffer.cpp @@ -6,20 +6,20 @@ using namespace llmr; -debug_font_buffer::debug_font_buffer() +DebugFontBuffer::DebugFontBuffer() : buffer(0), dirty(true) { } -debug_font_buffer::~debug_font_buffer() { +DebugFontBuffer::~DebugFontBuffer() { if (buffer != 0) { glDeleteBuffers(1, &buffer); buffer = 0; } } -void debug_font_buffer::addText(const char *text, double left, double baseline, double scale) { +void DebugFontBuffer::addText(const char *text, double left, double baseline, double scale) { int32_t length = strlen(text); for (int32_t i = 0; i < length; i++) { if (text[i] < 32 || text[i] > 127) { @@ -52,24 +52,23 @@ void debug_font_buffer::addText(const char *text, double left, double baseline, dirty = true; } -void debug_font_buffer::clear() { +void DebugFontBuffer::clear() { array.clear(); dirty = true; } -uint32_t debug_font_buffer::length() { +uint32_t DebugFontBuffer::length() { // We store 2 coordinates per vertex return array.size() / 2; } -void debug_font_buffer::bind() { +void DebugFontBuffer::bind() { if (buffer == 0) { glGenBuffers(1, &buffer); - glBindBuffer(GL_ARRAY_BUFFER, buffer); - } else { - glBindBuffer(GL_ARRAY_BUFFER, buffer); } + glBindBuffer(GL_ARRAY_BUFFER, buffer); + if (dirty) { glBufferData(GL_ARRAY_BUFFER, array.size() * sizeof(uint16_t), array.data(), GL_STATIC_DRAW); dirty = false; diff --git a/src/geometry/line_buffer.cpp b/src/geometry/line_buffer.cpp new file mode 100644 index 0000000000..0c9d815a38 --- /dev/null +++ b/src/geometry/line_buffer.cpp @@ -0,0 +1,45 @@ +#include <llmr/geometry/line_buffer.hpp> +#include <llmr/platform/gl.hpp> +// #include <cmath> + +using namespace llmr; + +LineBuffer::~LineBuffer() { + if (buffer != 0) { + glDeleteBuffers(1, &buffer); + buffer = 0; + } +} + +uint32_t LineBuffer::length() const { + // We store 2 coordinates per vertex + 1 linesofar + 1 extrude coord pair == 4 (== 8 bytes) + return array.size() / 4; +} + +void LineBuffer::add(int16_t x, int16_t y, float ex, float ey, int8_t tx, int8_t ty, int32_t linesofar) { + array.push_back((x * 2) | tx); + array.push_back((y * 2) | ty); + array.push_back(linesofar); + array.push_back( + ((int16_t)round(extrudeScale * ex) << 8) | + ((int16_t)round(extrudeScale * ey) & 0xFF) + ); + if (!dirty) dirty = true; +}; + +void LineBuffer::addDegenerate() { + add(16383, 16383, 0, 0, 1, 1, 0); +} + +void LineBuffer::bind() { + if (buffer == 0) { + glGenBuffers(1, &buffer); + } + + glBindBuffer(GL_ARRAY_BUFFER, buffer); + + if (dirty) { + glBufferData(GL_ARRAY_BUFFER, array.size() * sizeof(int16_t), array.data(), GL_STATIC_DRAW); + dirty = false; + } +} diff --git a/src/geometry/linevertexbuffer.cpp b/src/geometry/linevertexbuffer.cpp deleted file mode 100644 index 3c8521bc39..0000000000 --- a/src/geometry/linevertexbuffer.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include <llmr/geometry/linevertexbuffer.hpp> -#include <llmr/platform/gl.hpp> - -#include <cstdio> - -using namespace llmr; - -linevertexbuffer::linevertexbuffer() - : buffer(0) { -} - -linevertexbuffer::~linevertexbuffer() { - if (buffer != 0) { - glDeleteBuffers(1, &buffer); - buffer = 0; - } -} - -void linevertexbuffer::addDegenerate() { - array.push_back(32767); - array.push_back(0); -} - -void linevertexbuffer::addCoordinate(int16_t x, int16_t y) { - array.push_back(x); - array.push_back(y); -} - -uint32_t linevertexbuffer::length() { - // We store 2 coordinates per vertex - return array.size() / 2; -} - -void linevertexbuffer::bind() { - if (buffer == 0) { - glGenBuffers(1, &buffer); - // fprintf(stderr, "new buffer id: %d\n", buffer); - glBindBuffer(GL_ARRAY_BUFFER, buffer); - glBufferData(GL_ARRAY_BUFFER, array.size() * sizeof(uint16_t), array.data(), GL_STATIC_DRAW); - } else { - glBindBuffer(GL_ARRAY_BUFFER, buffer); - } -} diff --git a/src/map/tile.cpp b/src/map/tile.cpp index e8a0c1979a..57823d9939 100644 --- a/src/map/tile.cpp +++ b/src/map/tile.cpp @@ -44,9 +44,9 @@ std::forward_list<Tile::ID> Tile::children(const ID& id, int32_t z) { Tile::Tile(ID id, const Style& style) : id(id), state(initial), - lineVertex(std::make_shared<linevertexbuffer>()), - debugFontVertex(std::make_shared<debug_font_buffer>()), + debugFontBuffer(std::make_shared<DebugFontBuffer>()), fillBuffer(std::make_shared<FillBuffer>()), + lineBuffer(std::make_shared<LineBuffer>()), data(0), bytes(0), style(style) { @@ -54,7 +54,7 @@ Tile::Tile(ID id, const Style& style) // Initialize tile debug coordinates char coord[32]; snprintf(coord, sizeof(coord), "%d/%d/%d", id.z, id.x, id.y); - debugFontVertex->addText(coord, 50, 200, 5); + debugFontBuffer->addText(coord, 50, 200, 5); } Tile::~Tile() { diff --git a/src/renderer/painter.cpp b/src/renderer/painter.cpp index 84e8f95946..853ae5558d 100644 --- a/src/renderer/painter.cpp +++ b/src/renderer/painter.cpp @@ -344,14 +344,14 @@ void Painter::renderDebug(const Tile::Ptr& tile) { // draw debug info switchShader(lineShader); glUniformMatrix4fv(lineShader->u_matrix, 1, GL_FALSE, matrix); - tile->debugFontVertex->bind(); + tile->debugFontBuffer->bind(); glVertexAttribPointer(lineShader->a_pos, 2, GL_SHORT, GL_FALSE, 0, BUFFER_OFFSET(0)); glUniform4f(lineShader->u_color, 1.0f, 1.0f, 1.0f, 1.0f); glLineWidth(4.0f); - glDrawArrays(GL_LINES, 0, tile->debugFontVertex->length()); + glDrawArrays(GL_LINES, 0, tile->debugFontBuffer->length()); glUniform4f(lineShader->u_color, 0.0f, 0.0f, 0.0f, 1.0f); glLineWidth(2.0f); - glDrawArrays(GL_LINES, 0, tile->debugFontVertex->length()); + glDrawArrays(GL_LINES, 0, tile->debugFontBuffer->length()); // Revert blending mode to blend to the back. glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_ONE); |