Rasterizers now use their own interrupt system

This commit is contained in:
Michaël Lemaire 2014-08-19 11:44:54 +02:00
parent 915f43503e
commit 0c48fb075f
9 changed files with 22 additions and 17 deletions

View file

@ -12,7 +12,7 @@ CanvasPixelShader::CanvasPixelShader(const SoftwareCanvasRenderer &renderer, Can
{ {
} }
int CanvasPixelShader::processParallelUnit(int unit) void CanvasPixelShader::processParallelUnit(int unit)
{ {
// Locate the chunk we work on // Locate the chunk we work on
int prev_sub_chunk_size = chunk_size * 2; int prev_sub_chunk_size = chunk_size * 2;
@ -33,7 +33,7 @@ int CanvasPixelShader::processParallelUnit(int unit)
{ {
if (interrupted) if (interrupted)
{ {
return 0; return;
} }
if (sub_chunk_size == chunk_size or x % prev_sub_chunk_size != 0 or y % prev_sub_chunk_size != 0) if (sub_chunk_size == chunk_size or x % prev_sub_chunk_size != 0 or y % prev_sub_chunk_size != 0)
@ -60,6 +60,4 @@ int CanvasPixelShader::processParallelUnit(int unit)
} }
} }
} }
return 0;
} }

View file

@ -20,7 +20,7 @@ class CanvasPixelShader: public ParallelWorker
public: public:
CanvasPixelShader(const SoftwareCanvasRenderer &renderer, CanvasPortion *portion, int chunk_size, int sub_chunk_size, int chunks_x, int chunks_y); CanvasPixelShader(const SoftwareCanvasRenderer &renderer, CanvasPortion *portion, int chunk_size, int sub_chunk_size, int chunks_x, int chunks_y);
virtual int processParallelUnit(int unit) override; virtual void processParallelUnit(int unit) override;
private: private:
const SoftwareCanvasRenderer &renderer; const SoftwareCanvasRenderer &renderer;

View file

@ -34,7 +34,7 @@ void SkyRasterizer::rasterizeToCanvas(CanvasPortion* canvas)
for (j = 0; j < res_j; j++) for (j = 0; j < res_j; j++)
{ {
if (!renderer->addRenderProgress(0.0)) if (interrupted)
{ {
return; return;
} }

View file

@ -86,6 +86,10 @@ void SoftwareCanvasRenderer::interrupt()
{ {
current_work->interrupt(); current_work->interrupt();
} }
for (auto &rasterizer:getRasterizers())
{
rasterizer->interrupt();
}
} }
const std::vector<Rasterizer *> &SoftwareCanvasRenderer::getRasterizers() const const std::vector<Rasterizer *> &SoftwareCanvasRenderer::getRasterizers() const

View file

@ -152,25 +152,29 @@ void TerrainRasterizer::getTessellationInfo(CanvasPortion* canvas, int displaced
for (i = 0; i < chunk_count - 1; i++) for (i = 0; i < chunk_count - 1; i++)
{ {
_getChunk(renderer, &chunk, cx - radius_ext + chunk_size * i, cz - radius_ext, chunk_size, displaced); _getChunk(renderer, &chunk, cx - radius_ext + chunk_size * i, cz - radius_ext, chunk_size, displaced);
if (!processChunk(canvas, &chunk, progress)) processChunk(canvas, &chunk, progress);
if (interrupted)
{ {
return; return;
} }
_getChunk(renderer, &chunk, cx + radius_int, cz - radius_ext + chunk_size * i, chunk_size, displaced); _getChunk(renderer, &chunk, cx + radius_int, cz - radius_ext + chunk_size * i, chunk_size, displaced);
if (!processChunk(canvas, &chunk, progress)) processChunk(canvas, &chunk, progress);
if (interrupted)
{ {
return; return;
} }
_getChunk(renderer, &chunk, cx + radius_int - chunk_size * i, cz + radius_int, chunk_size, displaced); _getChunk(renderer, &chunk, cx + radius_int - chunk_size * i, cz + radius_int, chunk_size, displaced);
if (!processChunk(canvas, &chunk, progress)) processChunk(canvas, &chunk, progress);
if (interrupted)
{ {
return; return;
} }
_getChunk(renderer, &chunk, cx - radius_ext, cz + radius_int - chunk_size * i, chunk_size, displaced); _getChunk(renderer, &chunk, cx - radius_ext, cz + radius_int - chunk_size * i, chunk_size, displaced);
if (!processChunk(canvas, &chunk, progress)) processChunk(canvas, &chunk, progress);
if (interrupted)
{ {
return; return;
} }
@ -188,12 +192,11 @@ void TerrainRasterizer::getTessellationInfo(CanvasPortion* canvas, int displaced
} }
} }
int TerrainRasterizer::processChunk(CanvasPortion* canvas, TerrainChunkInfo* chunk, double progress) void TerrainRasterizer::processChunk(CanvasPortion* canvas, TerrainChunkInfo* chunk, double progress)
{ {
tessellateChunk(canvas, chunk, chunk->detail_hint); tessellateChunk(canvas, chunk, chunk->detail_hint);
renderer->render_progress = 0.05 * progress; renderer->render_progress = 0.05 * progress;
return !renderer->render_interrupt;
} }
void TerrainRasterizer::rasterizeToCanvas(CanvasPortion *canvas) void TerrainRasterizer::rasterizeToCanvas(CanvasPortion *canvas)

View file

@ -27,7 +27,7 @@ public:
/** /**
* Method called for each chunk tessellated by getTessellationInfo. * Method called for each chunk tessellated by getTessellationInfo.
*/ */
int processChunk(CanvasPortion* canvas, TerrainChunkInfo* chunk, double progress); void processChunk(CanvasPortion* canvas, TerrainChunkInfo* chunk, double progress);
/** /**
* Tessellate the terrain, calling processChunk for each chunk. * Tessellate the terrain, calling processChunk for each chunk.

View file

@ -55,7 +55,7 @@ void WaterRasterizer::rasterizeToCanvas(CanvasPortion *canvas)
while (radius_int < 20000.0) while (radius_int < 20000.0)
{ {
if (!renderer->addRenderProgress(0.0)) if (interrupted)
{ {
return; return;
} }

View file

@ -18,9 +18,9 @@ public:
{ {
} }
virtual int processParallelUnit(int unit) virtual void processParallelUnit(int unit)
{ {
return func(work, unit, data); func(work, unit, data);
} }
private: private:

View file

@ -20,7 +20,7 @@ public:
* *
* This method will be called from any thread in the thread pool used by the ParallelWork. * This method will be called from any thread in the thread pool used by the ParallelWork.
*/ */
virtual int processParallelUnit(int unit) = 0; virtual void processParallelUnit(int unit) = 0;
/** /**
* Method to reimplement to know when to interrupt the processing of units. * Method to reimplement to know when to interrupt the processing of units.