2014-06-05 15:12:49 +00:00
|
|
|
#ifndef SOFTWARECANVASRENDERER_H
|
|
|
|
#define SOFTWARECANVASRENDERER_H
|
|
|
|
|
|
|
|
#include "software_global.h"
|
|
|
|
|
2014-06-12 15:45:59 +00:00
|
|
|
#include "SoftwareRenderer.h"
|
|
|
|
|
2014-06-05 15:12:49 +00:00
|
|
|
namespace paysages {
|
|
|
|
namespace software {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Software rendering inside a Canvas surface.
|
|
|
|
*
|
|
|
|
* This class launches the rasterization process into canvas portions and
|
|
|
|
* redirects post processing to the software renderer.
|
|
|
|
*
|
|
|
|
* It tries to keep a canvas portion rasterized ahead of the post processing.
|
|
|
|
*/
|
2014-06-12 15:45:59 +00:00
|
|
|
class SOFTWARESHARED_EXPORT SoftwareCanvasRenderer: public SoftwareRenderer
|
2014-06-05 15:12:49 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
SoftwareCanvasRenderer();
|
2014-06-12 15:45:59 +00:00
|
|
|
virtual ~SoftwareCanvasRenderer();
|
2014-06-05 15:12:49 +00:00
|
|
|
|
|
|
|
inline const Canvas *getCanvas() const {return canvas;}
|
2014-08-20 13:58:37 +00:00
|
|
|
inline double getProgress() const {return progress;}
|
2014-06-05 15:12:49 +00:00
|
|
|
|
2014-08-20 12:23:35 +00:00
|
|
|
/**
|
|
|
|
* Set the renderer configuration.
|
|
|
|
*/
|
|
|
|
void setConfig(const RenderConfig &config);
|
|
|
|
|
2014-06-05 15:12:49 +00:00
|
|
|
/**
|
|
|
|
* @brief Set the rendering size in pixels.
|
|
|
|
*
|
|
|
|
* Set 'samples' to something bigger than 1 to allow for the multi-sampling of pixels.
|
|
|
|
*/
|
|
|
|
void setSize(int width, int height, int samples=1);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Start the two-pass render process.
|
|
|
|
*/
|
|
|
|
void render();
|
|
|
|
|
2014-08-19 12:20:37 +00:00
|
|
|
/**
|
|
|
|
* @brief Interrupt the render process.
|
|
|
|
*/
|
|
|
|
void interrupt();
|
2014-08-19 07:18:55 +00:00
|
|
|
|
2014-08-18 10:17:16 +00:00
|
|
|
/**
|
|
|
|
* Get a rasterizer by its client id.
|
|
|
|
*/
|
|
|
|
const Rasterizer &getRasterizer(int client_id) const;
|
|
|
|
|
2014-08-21 10:36:28 +00:00
|
|
|
/**
|
|
|
|
* Save the rendered canvas to a picture file on disk.
|
|
|
|
*
|
|
|
|
* Returns true if the save was successful.
|
|
|
|
*/
|
|
|
|
bool saveToDisk(const std::string &filepath) const;
|
|
|
|
|
2014-06-05 15:12:49 +00:00
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* @brief Rasterize the scenery into a canvas portion.
|
|
|
|
*/
|
2014-08-20 13:58:37 +00:00
|
|
|
void rasterize(CanvasPortion *portion);
|
2014-06-05 15:12:49 +00:00
|
|
|
|
|
|
|
/**
|
2014-08-19 07:18:55 +00:00
|
|
|
* @brief Apply pixel shader to fragments stored in the CanvasPortion.
|
2014-06-05 15:12:49 +00:00
|
|
|
*/
|
2014-08-20 13:58:37 +00:00
|
|
|
void applyPixelShader(CanvasPortion *portion);
|
2014-06-05 15:12:49 +00:00
|
|
|
|
|
|
|
private:
|
2014-08-20 13:58:37 +00:00
|
|
|
double progress;
|
|
|
|
double progress_segment;
|
|
|
|
|
2014-08-19 07:18:55 +00:00
|
|
|
Canvas *canvas;
|
2014-08-21 10:36:28 +00:00
|
|
|
int samples;
|
2014-06-12 15:45:59 +00:00
|
|
|
std::vector<Rasterizer*> rasterizers;
|
2014-06-05 15:12:49 +00:00
|
|
|
bool started;
|
2014-08-19 12:20:37 +00:00
|
|
|
bool interrupted;
|
2014-08-19 07:18:55 +00:00
|
|
|
|
|
|
|
ParallelWork *current_work;
|
2014-06-05 15:12:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // SOFTWARECANVASRENDERER_H
|