better allocator defaults
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
'CLANG_CXX_LANGUAGE_STANDARD':'c++11',
|
||||
'GCC_VERSION': 'com.apple.compilers.llvm.clang.1_0',
|
||||
},
|
||||
'cppflags':['-std=c++11'],
|
||||
'cxxflags':['-std=c++11'],
|
||||
'configurations': {
|
||||
'Debug': {
|
||||
'cflags': [ '-g', '-O0', '-I<(boost_root)/include' ],
|
||||
|
||||
@@ -28,6 +28,12 @@ struct Coordinate;
|
||||
struct pbf;
|
||||
|
||||
class FillBucket : public Bucket {
|
||||
|
||||
static void *alloc(void *data, unsigned int size);
|
||||
static void *realloc(void *data, void *ptr, unsigned int size);
|
||||
static void free(void *userData, void *ptr);
|
||||
|
||||
|
||||
typedef ElementGroup<PlainShader> triangle_group_type;
|
||||
typedef ElementGroup<OutlineShader> line_group_type;
|
||||
public:
|
||||
@@ -52,6 +58,7 @@ public:
|
||||
const BucketGeometryDescription geom_desc;
|
||||
|
||||
private:
|
||||
TESSalloc *allocator;
|
||||
TESStesselator *tesselator;
|
||||
|
||||
std::shared_ptr<FillVertexBuffer> vertexBuffer;
|
||||
@@ -66,10 +73,11 @@ private:
|
||||
std::vector<triangle_group_type> triangleGroups;
|
||||
std::vector<line_group_type> lineGroups;
|
||||
|
||||
std::vector<TESSreal> line;
|
||||
bool hasVertices = false;
|
||||
|
||||
static const int vertexSize = 2;
|
||||
static const int stride = sizeof(TESSreal) * vertexSize;
|
||||
static const int stride = sizeof(TESSreal) *vertexSize;
|
||||
static const int vertices_per_group = 3;
|
||||
};
|
||||
|
||||
|
||||
@@ -173,7 +173,7 @@ std::shared_ptr<Bucket> Tile::createBucket(const VectorTile& tile, const BucketD
|
||||
std::shared_ptr<Bucket> Tile::createFillBucket(const VectorTileLayer& layer, const BucketDescription& bucket_desc) {
|
||||
std::shared_ptr<FillBucket> bucket = std::make_shared<FillBucket>(fillVertexBuffer, triangleElementsBuffer, lineElementsBuffer, bucket_desc);
|
||||
|
||||
auto init_start = std::chrono::high_resolution_clock::now();
|
||||
// auto init_start = std::chrono::high_resolution_clock::now();
|
||||
|
||||
FilteredVectorTileLayer filtered_layer(layer, bucket_desc);
|
||||
for (pbf feature : filtered_layer) {
|
||||
@@ -181,16 +181,17 @@ std::shared_ptr<Bucket> Tile::createFillBucket(const VectorTileLayer& layer, con
|
||||
pbf geometry_pbf = feature.message();
|
||||
if (geometry_pbf) {
|
||||
bucket->addGeometry(geometry_pbf);
|
||||
bucket->tessellate();
|
||||
}
|
||||
}
|
||||
}
|
||||
auto init_end = std::chrono::high_resolution_clock::now();
|
||||
auto init = (double)std::chrono::duration_cast<std::chrono::microseconds>(init_end - init_start).count() / 1000.0;
|
||||
|
||||
auto tess_start = std::chrono::high_resolution_clock::now();
|
||||
bucket->tessellate();
|
||||
auto tess_end = std::chrono::high_resolution_clock::now();
|
||||
auto tess = (double)std::chrono::duration_cast<std::chrono::microseconds>(tess_end - tess_start).count() / 1000.0;
|
||||
// auto init_end = std::chrono::high_resolution_clock::now();
|
||||
// auto init = (double)std::chrono::duration_cast<std::chrono::microseconds>(init_end - init_start).count() / 1000.0;
|
||||
|
||||
// auto tess_start = std::chrono::high_resolution_clock::now();
|
||||
// auto tess_end = std::chrono::high_resolution_clock::now();
|
||||
// auto tess = (double)std::chrono::duration_cast<std::chrono::microseconds>(tess_end - tess_start).count() / 1000.0;
|
||||
|
||||
|
||||
// fprintf(stderr, "%s/%s init: %f tess: %f\n", bucket_desc.source_layer.c_str(), bucket_desc.source_field.c_str(), init, tess);
|
||||
|
||||
@@ -10,48 +10,44 @@
|
||||
#include <llmr/platform/gl.hpp>
|
||||
|
||||
|
||||
|
||||
void *customHeapAlloc(void *userData, unsigned int size) {
|
||||
// fprintf(stderr, "malloc %d\n", size);
|
||||
return malloc(size);
|
||||
}
|
||||
|
||||
void *customHeapRealloc(void *userData, void *ptr, unsigned int size) {
|
||||
// fprintf(stderr, "realloc %p %d\n", ptr, size);
|
||||
return realloc(ptr, size);
|
||||
}
|
||||
|
||||
void customHeapFree(void *userData, void *ptr) {
|
||||
// fprintf(stderr, "free %p\n", ptr);
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
static TESSalloc defaultAlloc = {
|
||||
&customHeapAlloc,
|
||||
&customHeapRealloc,
|
||||
&customHeapFree,
|
||||
nullptr, // userData
|
||||
512, // meshEdgeBucketSize
|
||||
512, // meshVertexBucketSize
|
||||
256, // meshFaceBucketSize
|
||||
512, // dictNodeBucketSize
|
||||
256, // regionBucketSize
|
||||
128, // extraVertices allocated for the priority queue.
|
||||
};
|
||||
|
||||
|
||||
#include <cassert>
|
||||
|
||||
struct geometry_too_long_exception : std::exception {};
|
||||
|
||||
using namespace llmr;
|
||||
|
||||
|
||||
|
||||
void *FillBucket::alloc(void *, unsigned int size) {
|
||||
return ::malloc(size);
|
||||
}
|
||||
|
||||
void *FillBucket::realloc(void *, void *ptr, unsigned int size) {
|
||||
return ::realloc(ptr, size);
|
||||
}
|
||||
|
||||
void FillBucket::free(void *, void *ptr) {
|
||||
::free(ptr);
|
||||
}
|
||||
|
||||
FillBucket::FillBucket(const std::shared_ptr<FillVertexBuffer>& vertexBuffer,
|
||||
const std::shared_ptr<TriangleElementsBuffer>& triangleElementsBuffer,
|
||||
const std::shared_ptr<LineElementsBuffer>& lineElementsBuffer,
|
||||
const BucketDescription& bucket_desc)
|
||||
: geom_desc(bucket_desc.geometry),
|
||||
tesselator(tessNewTess(&defaultAlloc)),
|
||||
allocator(new TESSalloc {
|
||||
&alloc,
|
||||
&realloc,
|
||||
&free,
|
||||
nullptr, // userData
|
||||
64, // meshEdgeBucketSize
|
||||
64, // meshVertexBucketSize
|
||||
32, // meshFaceBucketSize
|
||||
64, // dictNodeBucketSize
|
||||
8, // regionBucketSize
|
||||
128, // extraVertices allocated for the priority queue.
|
||||
}),
|
||||
tesselator(tessNewTess(allocator)),
|
||||
vertexBuffer(vertexBuffer),
|
||||
triangleElementsBuffer(triangleElementsBuffer),
|
||||
lineElementsBuffer(lineElementsBuffer),
|
||||
@@ -65,38 +61,32 @@ FillBucket::~FillBucket() {
|
||||
if (tesselator) {
|
||||
tessDeleteTess(tesselator);
|
||||
}
|
||||
if (allocator) {
|
||||
delete allocator;
|
||||
}
|
||||
}
|
||||
|
||||
void FillBucket::addGeometry(pbf& geom) {
|
||||
std::vector<Coordinate> line;
|
||||
Geometry::command cmd;
|
||||
|
||||
std::vector<TESSreal> line2;
|
||||
|
||||
Coordinate coord;
|
||||
Geometry geometry(geom);
|
||||
int32_t x, y;
|
||||
while ((cmd = geometry.next(x, y)) != Geometry::end) {
|
||||
if (cmd == Geometry::move_to) {
|
||||
if (line.size()) {
|
||||
// addGeometry(line);
|
||||
tessAddContour(tesselator, vertexSize, line.data(), stride, line.size() / vertexSize);
|
||||
line.clear();
|
||||
}
|
||||
if (line2.size()) {
|
||||
tessAddContour(tesselator, vertexSize, line2.data(), stride, line2.size() / vertexSize);
|
||||
line2.clear();
|
||||
hasVertices = true;
|
||||
}
|
||||
}
|
||||
line.emplace_back(x, y);
|
||||
line2.push_back(x);
|
||||
line2.push_back(y);
|
||||
line.push_back(x);
|
||||
line.push_back(y);
|
||||
}
|
||||
|
||||
if (line.size()) {
|
||||
// addGeometry(line);
|
||||
}
|
||||
if (line2.size()) {
|
||||
tessAddContour(tesselator, vertexSize, line2.data(), stride, line2.size() / vertexSize);
|
||||
tessAddContour(tesselator, vertexSize, line.data(), stride, line.size() / vertexSize);
|
||||
line.clear();
|
||||
hasVertices = true;
|
||||
}
|
||||
}
|
||||
@@ -135,9 +125,9 @@ void FillBucket::tessellate() {
|
||||
}
|
||||
|
||||
// Add vertices and create reverse index mapping for drawing the outline.
|
||||
std::map<TESSindex, int> contour_vertices;
|
||||
// std::map<TESSindex, int> contour_vertices;
|
||||
for (int i = 0; i < vertex_count; ++i) {
|
||||
contour_vertices[vertex_indices[i]] = i;
|
||||
// contour_vertices[vertex_indices[i]] = i;
|
||||
vertexBuffer->add(vertices[i * 2], vertices[i * 2 + 1]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user