2014-06-05 15:12:49 +00:00
|
|
|
#ifndef RASTERIZER_H
|
|
|
|
#define RASTERIZER_H
|
|
|
|
|
|
|
|
#include "software_global.h"
|
|
|
|
|
|
|
|
namespace paysages {
|
|
|
|
namespace software {
|
|
|
|
|
2015-10-15 22:51:46 +00:00
|
|
|
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;
|
2015-10-15 22:51:46 +00:00
|
|
|
|
2014-06-12 15:45:59 +00:00
|
|
|
typedef struct ScanPoint ScanPoint;
|
|
|
|
typedef struct RenderScanlines RenderScanlines;
|
|
|
|
|
2014-06-05 15:12:49 +00:00
|
|
|
/**
|
|
|
|
* @brief Base abstract class for scenery pieces that can be rasterized to polygons.
|
|
|
|
*/
|
|
|
|
class SOFTWARESHARED_EXPORT Rasterizer
|
|
|
|
{
|
|
|
|
public:
|
2015-08-23 18:22:37 +00:00
|
|
|
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;}
|
2015-10-08 17:20:44 +00:00
|
|
|
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);
|
|
|
|
|
2015-10-08 17:20:44 +00:00
|
|
|
/**
|
|
|
|
* Set the edge length under which to stop auto-cutting triangles near the camera.
|
|
|
|
*/
|
|
|
|
void setAutoCutLimit(double limit);
|
|
|
|
|
2015-08-23 18:22:37 +00:00
|
|
|
/**
|
|
|
|
* Abstract method to prepare for the rasterization process, and return the estimated progress count.
|
|
|
|
*/
|
|
|
|
virtual int prepareRasterization() = 0;
|
2015-10-15 22:51:46 +00:00
|
|
|
|
2015-08-23 18:22:37 +00:00
|
|
|
/**
|
|
|
|
* Abstract method to effectively do the rasterization on a canvas.
|
|
|
|
*/
|
2015-10-08 17:20:44 +00:00
|
|
|
virtual void rasterizeToCanvas(CanvasPortion *canvas) = 0;
|
2014-06-12 15:45:59 +00:00
|
|
|
|
2015-10-15 22:51:46 +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);
|
2015-10-08 17:20:44 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2015-10-08 17:20:44 +00:00
|
|
|
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;
|
2015-08-23 18:22:37 +00:00
|
|
|
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);
|
2015-10-08 17:20:44 +00:00
|
|
|
|
|
|
|
int triangle_count;
|
|
|
|
double auto_cut_limit;
|
2015-10-15 22:51:46 +00:00
|
|
|
bool backface_culling;
|
2014-06-05 15:12:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // RASTERIZER_H
|