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.
|
|
|
|
*/
|
2015-11-09 21:30:46 +00:00
|
|
|
class SOFTWARESHARED_EXPORT SoftwareCanvasRenderer : public SoftwareRenderer {
|
|
|
|
public:
|
2015-08-18 20:29:18 +00:00
|
|
|
SoftwareCanvasRenderer(Scenery *scenery);
|
2014-06-12 15:45:59 +00:00
|
|
|
virtual ~SoftwareCanvasRenderer();
|
2014-06-05 15:12:49 +00:00
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
inline const Canvas *getCanvas() const {
|
|
|
|
return canvas;
|
|
|
|
}
|
|
|
|
inline RenderProgress *getProgressHelper() const {
|
|
|
|
return progress;
|
|
|
|
}
|
|
|
|
inline bool isFinished() const {
|
|
|
|
return finished;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Rasterizer *getSkyRasterizer() const {
|
|
|
|
return rasterizers[0];
|
|
|
|
}
|
|
|
|
inline Rasterizer *getWaterRasterizer() const {
|
|
|
|
return rasterizers[1];
|
|
|
|
}
|
|
|
|
inline Rasterizer *getTerrainRasterizer() const {
|
|
|
|
return rasterizers[2];
|
|
|
|
}
|
2015-10-08 22:55:36 +00:00
|
|
|
|
2015-09-10 17:33:52 +00:00
|
|
|
virtual void setQuality(double factor) override;
|
|
|
|
|
2015-09-13 16:58:11 +00:00
|
|
|
/**
|
|
|
|
* Clear the rasterizers list, and put a single one.
|
|
|
|
*
|
|
|
|
* The renderer takes ownership of the rasterizer.
|
|
|
|
*/
|
|
|
|
void setSoloRasterizer(Rasterizer *rasterizer);
|
|
|
|
|
2015-08-23 18:22:37 +00:00
|
|
|
/**
|
|
|
|
* Get the global rendering progress (0.0-1.0).
|
|
|
|
*/
|
|
|
|
double getProgress() const;
|
|
|
|
|
2014-08-20 12:23:35 +00:00
|
|
|
/**
|
|
|
|
* Set the renderer configuration.
|
|
|
|
*/
|
|
|
|
void setConfig(const RenderConfig &config);
|
|
|
|
|
2015-09-10 17:33:52 +00:00
|
|
|
/**
|
|
|
|
* Enable or disable the post processing.
|
|
|
|
*/
|
|
|
|
void enablePostprocess(bool enabled);
|
|
|
|
|
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.
|
|
|
|
*/
|
2015-11-09 21:30:46 +00:00
|
|
|
void setSize(int width, int height, int samples = 1);
|
2014-06-05 15:12:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @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;
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
protected:
|
2014-06-05 15:12:49 +00:00
|
|
|
/**
|
|
|
|
* @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
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
private:
|
2015-08-23 18:22:37 +00:00
|
|
|
RenderProgress *progress;
|
2014-08-20 13:58:37 +00:00
|
|
|
|
2014-08-19 07:18:55 +00:00
|
|
|
Canvas *canvas;
|
2014-08-21 10:36:28 +00:00
|
|
|
int samples;
|
2015-11-09 21:30:46 +00:00
|
|
|
std::vector<Rasterizer *> rasterizers;
|
2014-06-05 15:12:49 +00:00
|
|
|
bool started;
|
2014-09-09 15:56:52 +00:00
|
|
|
bool finished;
|
2014-08-19 12:20:37 +00:00
|
|
|
bool interrupted;
|
2014-08-19 07:18:55 +00:00
|
|
|
|
2015-09-10 17:33:52 +00:00
|
|
|
bool postprocess_enabled;
|
|
|
|
|
2014-08-19 07:18:55 +00:00
|
|
|
ParallelWork *current_work;
|
2014-06-05 15:12:49 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // SOFTWARECANVASRENDERER_H
|