1 /**
2  * Mandelbulber v2, a 3D fractal generator       ,=#MKNmMMKmmßMNWy,
3  *                                             ,B" ]L,,p%%%,,,§;, "K
4  * Copyright (C) 2014-21 Mandelbulber Team     §R-==%w["'~5]m%=L.=~5N
5  *                                        ,=mm=§M ]=4 yJKA"/-Nsaj  "Bw,==,,
6  * This file is part of Mandelbulber.    §R.r= jw",M  Km .mM  FW ",§=ß., ,TN
7  *                                     ,4R =%["w[N=7]J '"5=],""]]M,w,-; T=]M
8  * Mandelbulber is free software:     §R.ß~-Q/M=,=5"v"]=Qf,'§"M= =,M.§ Rz]M"Kw
9  * you can redistribute it and/or     §w "xDY.J ' -"m=====WeC=\ ""%""y=%"]"" §
10  * modify it under the terms of the    "§M=M =D=4"N #"%==A%p M§ M6  R' #"=~.4M
11  * GNU General Public License as        §W =, ][T"]C  §  § '§ e===~ U  !§[Z ]N
12  * published by the                    4M",,Jm=,"=e~  §  §  j]]""N  BmM"py=ßM
13  * Free Software Foundation,          ]§ T,M=& 'YmMMpM9MMM%=w=,,=MT]M m§;'§,
14  * either version 3 of the License,    TWw [.j"5=~N[=§%=%W,T ]R,"=="Y[LFT ]N
15  * or (at your option)                   TW=,-#"%=;[  =Q:["V""  ],,M.m == ]N
16  * any later version.                      J§"mr"] ,=,," =="""J]= M"M"]==ß"
17  *                                          §= "=C=4 §"eM "=B:m|4"]#F,§~
18  * Mandelbulber is distributed in            "9w=,,]w em%wJ '"~" ,=,,ß"
19  * the hope that it will be useful,                 . "K=  ,=RMMMßM"""
20  * but WITHOUT ANY WARRANTY;                            .'''
21  * without even the implied warranty
22  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
23  *
24  * See the GNU General Public License for more details.
25  * You should have received a copy of the GNU General Public License
26  * along with Mandelbulber. If not, see <http://www.gnu.org/licenses/>.
27  *
28  * ###########################################################################
29  *
30  * Authors: Krzysztof Marczak (buddhi1980@gmail.com)
31  *
32  * cRenderJob class - prepare and coordinate rendering of single or multiple images (animation)
33  */
34 
35 #ifndef MANDELBULBER2_SRC_RENDER_JOB_HPP_
36 #define MANDELBULBER2_SRC_RENDER_JOB_HPP_
37 
38 #ifndef _USE_MATH_DEFINES
39 #define _USE_MATH_DEFINES
40 #endif
41 
42 #include <memory>
43 
44 #include <QObject>
45 
46 #include "camera_target.hpp"
47 #include "fractal_container.hpp"
48 #include "parameters.hpp"
49 #include "region.hpp"
50 #include "rendered_tile_data.hpp"
51 #include "statistics.h"
52 
53 // forward declarations
54 class cImage;
55 struct sRenderData;
56 class cRenderingConfiguration;
57 struct sImageOptional;
58 class cNineFractals;
59 class cRenderer;
60 class cProgressText;
61 struct sParamRender;
62 
63 class cRenderJob : public QObject
64 {
65 	Q_OBJECT
66 public:
67 	cRenderJob(const std::shared_ptr<cParameterContainer> _params,
68 		const std::shared_ptr<cFractalContainer> _fractal, std::shared_ptr<cImage> _image,
69 		bool *_stopRequest, QWidget *_qWidget = nullptr);
70 	~cRenderJob() override;
71 	// QWidget *parent is needed to connect signals for refreshing progress and status bar.
72 	// If _parent is not nullptr then parent has to have slot slotUpdateProgressAndStatus()
73 
74 	enum enumMode
75 	{
76 		still,
77 		keyframeAnim,
78 		flightAnim,
79 		flightAnimRecord
80 	};
81 
82 	bool Init(enumMode _mode, const cRenderingConfiguration &config);
83 	bool Execute();
GetImagePtr() const84 	std::shared_ptr<cImage> GetImagePtr() const { return image; }
GetNumberOfCPUs() const85 	int GetNumberOfCPUs() const { return totalNumberOfCPUs; }
UseSizeFromImage(bool modeInput)86 	void UseSizeFromImage(bool modeInput) { useSizeFromImage = modeInput; }
87 	void ChangeCameraTargetPosition(cCameraTarget &cameraTarget) const;
88 
89 	void UpdateParameters(const std::shared_ptr<cParameterContainer> _params,
90 		const std::shared_ptr<cFractalContainer> _fractal);
91 	void UpdateConfig(const cRenderingConfiguration &config) const;
GetRunningJobCount()92 	static int GetRunningJobCount() { return runningJobs; }
93 	cStatistics GetStatistics() const;
94 
95 public slots:
96 	void slotExecute();
97 
98 private:
99 	bool InitImage(int w, int h, const sImageOptional &optional);
100 	void PrepareData();
101 	void ReduceDetail() const;
102 	QStringList CreateListOfUsedTextures() const;
103 	int GetNumberOfRepeatsOfStereoLoop(bool *twoPassStereo);
104 	void SetupStereoEyes(int repeat, bool twoPassStereo);
105 	void InitNetRender();
106 	void InitStatistics(const cNineFractals *fractals);
107 	void ConnectUpdateSinalsSlots(const cRenderer *renderer);
108 	void ConnectNetRenderSignalsSlots(const cRenderer *renderer);
109 
110 #ifdef USE_OPENCL
111 	bool RenderFractalWithOpenCl(std::shared_ptr<sParamRender> params,
112 		std::shared_ptr<cNineFractals> fractals, cProgressText *progressText);
113 	void RenderSSAOWithOpenCl(std::shared_ptr<sParamRender> params, const cRegion<int> &region,
114 		cProgressText *progressText, bool *result);
115 	void RenderDOFWithOpenCl(std::shared_ptr<sParamRender> params, bool *result);
116 	void RenderPostFiltersWithOpenCl(std::shared_ptr<sParamRender> params, const cRegion<int> &region,
117 		cProgressText *progressText, bool *result);
118 #endif
119 
120 	void LoadTextures(int frameNo, const cRenderingConfiguration &config);
121 
122 	bool hasQWidget;
123 	bool inProgress;
124 	bool ready;
125 	bool useSizeFromImage;
126 	std::shared_ptr<cImage> image;
127 	std::shared_ptr<cFractalContainer> fractalContainer;
128 	std::shared_ptr<cParameterContainer> paramsContainer;
129 
130 	enumMode mode;
131 	int height;
132 	int totalNumberOfCPUs;
133 	int width;
134 	QWidget *imageWidget;
135 	std::shared_ptr<sRenderData> renderData;
136 	bool *stopRequest;
137 	bool canUseNetRender;
138 
139 	static int id; // global identifier of actual rendering job
140 	static int runningJobs;
141 
142 signals:
143 	void finished();
144 	void fullyRendered(const QString &text, const QString &progressText);
145 	void fullyRenderedTime(double timeSeconds);
146 	void updateProgressAndStatus(const QString &text, const QString &progressText, double progress);
147 	void updateStatistics(cStatistics statistics);
148 	void updateImage();
149 	void sendRenderedTilesList(QList<sRenderedTileData>);
150 	void SendNetRenderJob(std::shared_ptr<const cParameterContainer> settings,
151 		std::shared_ptr<const cFractalContainer> fractal, QStringList listOfTextures);
152 	void SendNetRenderSetup(int clientIndex, QList<int> startingPositions);
153 	void SetMinimumWidgetSize(int width, int height);
154 	void signalTotalRenderTime(double seconds);
155 };
156 
157 #endif /* MANDELBULBER2_SRC_RENDER_JOB_HPP_ */
158