Calculate clip IDs with a huffman prefix tree

This changes the clip IDs from sequential to a huffman prefix tree, meaning that
parent tiles share the same prefix with child tiles (but are shorter). This allows
us to use the same checkerboard pattern to draw all tiles.

TODO:
- make sure we're not overflowing the 8 bit limit of the stencil buffer
- draw all checkerboard fields at the same time, with one draw call
- fix raster drawing (fading, clipping)

refs #132
This commit is contained in:
Konstantin Käfer
2014-05-09 18:10:28 +02:00
parent 70a7ba81f3
commit 0bfd7b0f43
32 changed files with 1129 additions and 290 deletions

View File

@@ -4,6 +4,8 @@
using namespace llmr;
#include <iostream>
Tile::Tile(const ID& id)
: id(id) {
}
@@ -31,14 +33,19 @@ std::forward_list<Tile::ID> Tile::ID::children(int32_t child_z) const {
return children;
}
void Tile::ID::normalize() {
Tile::ID Tile::ID::normalized() const {
int32_t dim = pow(2, z);
while (x < 0) x += dim;
while (x >= dim) x -= dim;
int32_t nx = x, ny = y;
while (nx < 0) nx += dim;
while (nx >= dim) nx -= dim;
return ID { z, nx, ny };
}
Tile::ID Tile::ID::normalized() const {
ID pos(z, x, y);
pos.normalize();
return pos;
bool Tile::ID::isChildOf(const Tile::ID &parent) const {
if (parent.z >= z || parent.w != w) {
return false;
}
int32_t scale = pow(2, z - parent.z);
return parent.x == ((x < 0 ? x - scale + 1 : x) / scale) &&
parent.y == y / scale;
}