From 1db49afaed2f551f7f4ac5854c54163492dfe788 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Thu, 2 Jan 2014 15:08:00 +0100 Subject: [PATCH] Restored correct terrain tessellation --- src/definition/CameraDefinition.cpp | 10 +++++----- src/definition/CameraDefinition.h | 6 +++--- src/render/software/TerrainRasterizer.cpp | 13 +++++-------- src/render/software/TerrainRasterizer.h | 1 + 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/definition/CameraDefinition.cpp b/src/definition/CameraDefinition.cpp index f350676..5fcfce6 100644 --- a/src/definition/CameraDefinition.cpp +++ b/src/definition/CameraDefinition.cpp @@ -229,7 +229,7 @@ Vector3 CameraDefinition::unproject(const Vector3 &point) const return unprojector.transform(tpoint); } -bool CameraDefinition::isBoxInView(const Vector3 ¢er, double xsize, double ysize, double zsize) const +int CameraDefinition::isBoxInView(const Vector3 ¢er, double xsize, double ysize, double zsize) const { BoundingBox box; @@ -239,7 +239,7 @@ bool CameraDefinition::isBoxInView(const Vector3 ¢er, double xsize, double y return isUnprojectedBoxInView(box); } -bool CameraDefinition::isUnprojectedBoxInView(const BoundingBox &box) const +int CameraDefinition::isUnprojectedBoxInView(const BoundingBox &box) const { BoundingBox projected; @@ -255,18 +255,18 @@ bool CameraDefinition::isUnprojectedBoxInView(const BoundingBox &box) const return isProjectedBoxInView(projected); } -bool CameraDefinition::isProjectedBoxInView(const BoundingBox &box) const +int CameraDefinition::isProjectedBoxInView(const BoundingBox &box) const { if (box.xmin <= width && box.xmax >= 0.0 && box.ymin <= height && box.ymax >= 0.0 && box.zmax >= perspective.znear) { double dx = box.xmax - box.xmin; double dy = box.ymax - box.ymin; - return (int)ceil(dx) * (int)ceil(dy) > 0; + return (int)ceil(dx) * (int)ceil(dy); } else { - return false; + return 0; } } diff --git a/src/definition/CameraDefinition.h b/src/definition/CameraDefinition.h index 6d4b6b2..e8b3364 100644 --- a/src/definition/CameraDefinition.h +++ b/src/definition/CameraDefinition.h @@ -60,9 +60,9 @@ public: void setRenderSize(int width, int height); Vector3 project(const Vector3 &point) const; Vector3 unproject(const Vector3 &point) const; - bool isBoxInView(const Vector3 ¢er, double xsize, double ysize, double zsize) const; - bool isUnprojectedBoxInView(const BoundingBox &box) const; - bool isProjectedBoxInView(const BoundingBox &box) const; + int isBoxInView(const Vector3 ¢er, double xsize, double ysize, double zsize) const; + int isUnprojectedBoxInView(const BoundingBox &box) const; + int isProjectedBoxInView(const BoundingBox &box) const; bool transitionToAnother(const CameraDefinition *wanted, double factor); diff --git a/src/render/software/TerrainRasterizer.cpp b/src/render/software/TerrainRasterizer.cpp index d05892d..cf53310 100644 --- a/src/render/software/TerrainRasterizer.cpp +++ b/src/render/software/TerrainRasterizer.cpp @@ -117,7 +117,7 @@ static void _getChunk(SoftwareRenderer* renderer, TerrainRasterizer::TerrainChun int coverage = renderer->render_camera->isUnprojectedBoxInView(box); if (coverage > 0) { - chunk->detail_hint = (int)ceil(sqrt((double)coverage) / (double)(25 - renderer->render_quality)); + chunk->detail_hint = (int)ceil(sqrt((double)coverage) / (double)(25 - 2 * renderer->render_quality)); if (chunk->detail_hint > 5 * renderer->render_quality) { chunk->detail_hint = 5 * renderer->render_quality; @@ -139,7 +139,7 @@ void TerrainRasterizer::getTessellationInfo(int displaced) double radius_int, radius_ext; double base_chunk_size, chunk_size; - base_chunk_size = 8.0 / (double)(renderer->render_quality * renderer->render_quality); + base_chunk_size = 5.0 / (double)renderer->render_quality; chunk_factor = 1; chunk_count = 2; @@ -219,7 +219,7 @@ int TerrainRasterizer::processChunk(TerrainChunkInfo* chunk, double progress) info->rasterizer = this; info->chunk = *chunk; - if (!((ParallelQueue*)renderer->customData[0])->addJob(_parallelJobCallback, info)) + if (!queue->addJob(_parallelJobCallback, info)) { delete info; } @@ -230,14 +230,11 @@ int TerrainRasterizer::processChunk(TerrainChunkInfo* chunk, double progress) void TerrainRasterizer::renderSurface() { - ParallelQueue queue; - - /* TODO Do not use custom data, it could already be used by another module */ - renderer->customData[0] = &queue; + queue = new ParallelQueue(); renderer->render_progress = 0.0; getTessellationInfo(0); renderer->render_progress = 0.05; - queue.wait(); + queue->wait(); } diff --git a/src/render/software/TerrainRasterizer.h b/src/render/software/TerrainRasterizer.h index 6f7dca7..47b559e 100644 --- a/src/render/software/TerrainRasterizer.h +++ b/src/render/software/TerrainRasterizer.h @@ -49,6 +49,7 @@ public: private: SoftwareRenderer* renderer; + ParallelQueue* queue; }; }