paysages3d/src/render/software/CanvasPortion.cpp

72 lines
1.3 KiB
C++
Raw Normal View History

#include "CanvasPortion.h"
2014-06-10 13:13:16 +00:00
#include <cassert>
#include "CanvasPixel.h"
2014-06-12 15:45:59 +00:00
#include "CanvasPreview.h"
2014-06-10 13:13:16 +00:00
#define CHECK_COORDINATES() assert(x >= 0); \
assert(x < width); \
assert(y >= 0); \
assert(y < height)
2014-06-12 15:45:59 +00:00
CanvasPortion::CanvasPortion(CanvasPreview* preview):
preview(preview)
{
2014-06-10 13:13:16 +00:00
width = 1;
height = 1;
pixels = new CanvasPixel[1];
}
CanvasPortion::~CanvasPortion()
{
delete[] pixels;
}
int CanvasPortion::getFragmentCount(int x, int y) const
{
CHECK_COORDINATES();
return pixels[y * width + x].getFragmentCount();
}
const CanvasFragment *CanvasPortion::getFrontFragment(int x, int y) const
{
CHECK_COORDINATES();
return pixels[y * width + x].getFrontFragment();
}
void CanvasPortion::clear()
{
int n = width * height;
for (int i = 0; i < n; i++)
{
pixels[i].reset();
}
}
void CanvasPortion::setSize(int width, int height)
{
this->width = width;
this->height = height;
2014-06-10 13:13:16 +00:00
delete[] pixels;
pixels = new CanvasPixel[width * height];
}
void CanvasPortion::pushFragment(int x, int y, const CanvasFragment &fragment)
{
CHECK_COORDINATES();
CanvasPixel &pixel = pixels[y * width + x];
2014-06-12 15:45:59 +00:00
Color old_color = pixel.getComposite();
2014-06-10 13:13:16 +00:00
pixel.pushFragment(fragment);
2014-06-12 15:45:59 +00:00
if (preview)
{
preview->pushPixel(x, y, old_color, pixel.getComposite());
}
}