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);
}
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;
@ -239,7 +239,7 @@ bool CameraDefinition::isBoxInView(const Vector3 &center, 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;
}
}

View file

@ -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 &center, double xsize, double ysize, double zsize) const;
bool isUnprojectedBoxInView(const BoundingBox &box) const;
bool isProjectedBoxInView(const BoundingBox &box) const;
int isBoxInView(const Vector3 &center, 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);

View file

@ -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();
}

View file

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