Restored correct terrain tessellation

This commit is contained in:
Michaël Lemaire 2014-01-02 15:08:00 +01:00 committed by Michael Lemaire
parent 67ae34ddbd
commit 1db49afaed
4 changed files with 14 additions and 16 deletions

View file

@ -229,7 +229,7 @@ Vector3 CameraDefinition::unproject(const Vector3 &point) const
return unprojector.transform(tpoint); return unprojector.transform(tpoint);
} }
bool CameraDefinition::isBoxInView(const Vector3 &center, double xsize, double ysize, double zsize) const int CameraDefinition::isBoxInView(const Vector3 &center, double xsize, double ysize, double zsize) const
{ {
BoundingBox box; BoundingBox box;
@ -239,7 +239,7 @@ bool CameraDefinition::isBoxInView(const Vector3 &center, double xsize, double y
return isUnprojectedBoxInView(box); return isUnprojectedBoxInView(box);
} }
bool CameraDefinition::isUnprojectedBoxInView(const BoundingBox &box) const int CameraDefinition::isUnprojectedBoxInView(const BoundingBox &box) const
{ {
BoundingBox projected; BoundingBox projected;
@ -255,18 +255,18 @@ bool CameraDefinition::isUnprojectedBoxInView(const BoundingBox &box) const
return isProjectedBoxInView(projected); 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) 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 dx = box.xmax - box.xmin;
double dy = box.ymax - box.ymin; double dy = box.ymax - box.ymin;
return (int)ceil(dx) * (int)ceil(dy) > 0; return (int)ceil(dx) * (int)ceil(dy);
} }
else else
{ {
return false; return 0;
} }
} }

View file

@ -60,9 +60,9 @@ public:
void setRenderSize(int width, int height); void setRenderSize(int width, int height);
Vector3 project(const Vector3 &point) const; Vector3 project(const Vector3 &point) const;
Vector3 unproject(const Vector3 &point) const; Vector3 unproject(const Vector3 &point) const;
bool isBoxInView(const Vector3 &center, double xsize, double ysize, double zsize) const; int isBoxInView(const Vector3 &center, double xsize, double ysize, double zsize) const;
bool isUnprojectedBoxInView(const BoundingBox &box) const; int isUnprojectedBoxInView(const BoundingBox &box) const;
bool isProjectedBoxInView(const BoundingBox &box) const; int isProjectedBoxInView(const BoundingBox &box) const;
bool transitionToAnother(const CameraDefinition *wanted, double factor); bool transitionToAnother(const CameraDefinition *wanted, double factor);

View file

@ -117,7 +117,7 @@ static void _getChunk(SoftwareRenderer* renderer, TerrainRasterizer::TerrainChun
int coverage = renderer->render_camera->isUnprojectedBoxInView(box); int coverage = renderer->render_camera->isUnprojectedBoxInView(box);
if (coverage > 0) 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) if (chunk->detail_hint > 5 * renderer->render_quality)
{ {
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 radius_int, radius_ext;
double base_chunk_size, chunk_size; 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_factor = 1;
chunk_count = 2; chunk_count = 2;
@ -219,7 +219,7 @@ int TerrainRasterizer::processChunk(TerrainChunkInfo* chunk, double progress)
info->rasterizer = this; info->rasterizer = this;
info->chunk = *chunk; info->chunk = *chunk;
if (!((ParallelQueue*)renderer->customData[0])->addJob(_parallelJobCallback, info)) if (!queue->addJob(_parallelJobCallback, info))
{ {
delete info; delete info;
} }
@ -230,14 +230,11 @@ int TerrainRasterizer::processChunk(TerrainChunkInfo* chunk, double progress)
void TerrainRasterizer::renderSurface() void TerrainRasterizer::renderSurface()
{ {
ParallelQueue queue; queue = new ParallelQueue();
/* TODO Do not use custom data, it could already be used by another module */
renderer->customData[0] = &queue;
renderer->render_progress = 0.0; renderer->render_progress = 0.0;
getTessellationInfo(0); getTessellationInfo(0);
renderer->render_progress = 0.05; renderer->render_progress = 0.05;
queue.wait(); queue->wait();
} }

View file

@ -49,6 +49,7 @@ public:
private: private:
SoftwareRenderer* renderer; SoftwareRenderer* renderer;
ParallelQueue* queue;
}; };
} }