paysages3d/src/render/software/Rasterizer.h

98 lines
3.3 KiB
C
Raw Normal View History

#ifndef RASTERIZER_H
#define RASTERIZER_H
#include "software_global.h"
namespace paysages {
namespace software {
const int RASTERIZER_CLIENT_SKY = 0;
const int RASTERIZER_CLIENT_WATER = 1;
const int RASTERIZER_CLIENT_TERRAIN = 2;
2015-10-18 15:26:19 +00:00
const int RASTERIZER_CLIENT_VEGETATION = 3;
2014-06-12 15:45:59 +00:00
typedef struct ScanPoint ScanPoint;
typedef struct RenderScanlines RenderScanlines;
/**
* @brief Base abstract class for scenery pieces that can be rasterized to polygons.
*/
class SOFTWARESHARED_EXPORT Rasterizer
{
public:
Rasterizer(SoftwareRenderer *renderer, RenderProgress *progress, int client_id, const Color &color);
2014-06-12 15:45:59 +00:00
virtual ~Rasterizer();
inline SoftwareRenderer *getRenderer() const {return renderer;}
inline int getTriangleCount() const {return triangle_count;}
2014-06-12 15:45:59 +00:00
2015-09-10 17:33:52 +00:00
/**
* Set the rasterization quality factor.
*/
virtual void setQuality(double factor);
/**
* Set the edge length under which to stop auto-cutting triangles near the camera.
*/
void setAutoCutLimit(double limit);
/**
* Abstract method to prepare for the rasterization process, and return the estimated progress count.
*/
virtual int prepareRasterization() = 0;
/**
* Abstract method to effectively do the rasterization on a canvas.
*/
virtual void rasterizeToCanvas(CanvasPortion *canvas) = 0;
2014-06-12 15:45:59 +00:00
/**
* Abstract method to render a fragment stored on a canvas, to a color.
*/
virtual Color shadeFragment(const CanvasFragment &fragment, const CanvasFragment *previous) const = 0;
/**
* Ask for an interrupt in rasterization process.
*/
virtual void interrupt();
void setColor(const Color &color);
void setBackFaceCulling(bool cull);
/**
* Reset the internal triangle counter to 0.
*/
void resetTriangleCount();
2014-06-12 15:45:59 +00:00
void pushTriangle(CanvasPortion *canvas, const Vector3 &v1, const Vector3 &v2, const Vector3 &v3);
void pushDisplacedTriangle(CanvasPortion *canvas, const Vector3 &v1, const Vector3 &v2, const Vector3 &v3, const Vector3 &ov1, const Vector3 &ov2, const Vector3 &ov3);
void pushQuad(CanvasPortion *canvas, const Vector3 &v1, const Vector3 &v2, const Vector3 &v3, const Vector3 &v4);
2014-06-12 15:45:59 +00:00
void pushDisplacedQuad(CanvasPortion *canvas, const Vector3 &v1, const Vector3 &v2, const Vector3 &v3, const Vector3 &v4, const Vector3 &ov1, const Vector3 &ov2, const Vector3 &ov3, const Vector3 &ov4);
protected:
bool pushProjectedTriangle(CanvasPortion *canvas, const Vector3 &pixel1, const Vector3 &pixel2, const Vector3 &pixel3, const Vector3 &location1, const Vector3 &location2, const Vector3 &location3);
2014-08-16 11:34:55 +00:00
Color* color;
2014-06-12 15:45:59 +00:00
SoftwareRenderer *renderer;
RenderProgress *progress;
2014-06-12 15:45:59 +00:00
int client_id;
2014-08-19 07:18:55 +00:00
bool interrupted;
2014-06-12 15:45:59 +00:00
private:
void scanGetDiff(ScanPoint *v1, ScanPoint *v2, ScanPoint *result);
void scanInterpolate(CameraDefinition *camera, ScanPoint *v1, ScanPoint *diff, double value, ScanPoint *result);
void pushScanPoint(CanvasPortion *canvas, RenderScanlines *scanlines, ScanPoint *point);
void pushScanLineEdge(CanvasPortion *canvas, RenderScanlines *scanlines, ScanPoint *point1, ScanPoint *point2);
void renderScanLines(CanvasPortion *canvas, RenderScanlines *scanlines);
int triangle_count;
double auto_cut_limit;
bool backface_culling;
};
}
}
#endif // RASTERIZER_H