Fixed parallel canvas shading

This commit is contained in:
Michaël Lemaire 2014-08-18 16:25:44 +02:00
parent b5ee4c432f
commit 9c2d545e6a
2 changed files with 14 additions and 5 deletions

View file

@ -16,8 +16,8 @@ int CanvasPixelShader::processParallelUnit(int unit)
{
// Locate the chunk we work on
int prev_sub_chunk_size = chunk_size * 2;
int chunk_x = unit % chunks_x;
int chunk_y = unit / chunks_x;
int chunk_x = unit / chunks_y;
int chunk_y = unit % chunks_y;
int base_x = chunk_x * chunk_size;
int base_y = chunk_y * chunk_size;
int limit_x = portion->getWidth() - base_x;
@ -26,11 +26,12 @@ int CanvasPixelShader::processParallelUnit(int unit)
limit_x = (limit_x > chunk_size) ? chunk_size : limit_x;
limit_y = (limit_y > chunk_size) ? chunk_size : limit_y;
// Iterate on sub-chunks
for (int x = 0; x < limit_x; x += sub_chunk_size)
{
for (int y = 0; y < limit_y; y += sub_chunk_size)
{
if (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)
{
// Resolve the pixel color
const CanvasPixel &pixel = portion->at(base_x + x, base_y + y);
@ -42,7 +43,15 @@ int CanvasPixelShader::processParallelUnit(int unit)
const Rasterizer &rasterizer = renderer.getRasterizer(fragment.getClient());
composite.mask(rasterizer.shadeFragment(fragment));
}
portion->setColor(base_x + x, base_y + y, composite);
// Fill the square area
for (int fx = 0; fx + x < limit_x and fx < sub_chunk_size; fx++)
{
for (int fy = 0; fy + y < limit_y and fy < sub_chunk_size; fy++)
{
portion->setColor(base_x + x + fx, base_y + y + fy, composite);
}
}
}
}
}

View file

@ -66,8 +66,8 @@ protected:
if (unit >= 0)
{
work->worker->processParallelUnit(unit);
work->returnThread(this);
unit = -1;
work->returnThread(this);
}
}
}