Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
Renderer.h
Go to the documentation of this file.
1#pragma once
2
9#include "Frame/frame_fwd.h"
15#include "Frame/Viewport.h"
16#include "Utility/Timer.h"
17#include "Utility/TSpan.h"
18
19#include <Common/assertion.h>
20#include <Common/primitive_type.h>
21
22#include <cstddef>
23#include <vector>
24#include <mutex>
25#include <memory>
26#include <atomic>
27#include <deque>
28#include <string>
29
30namespace ph { class CoreCookedUnit; }
31namespace ph { class VisualWorld; }
32
33namespace ph
34{
35
36class RenderWorker;
37
39{
40public:
41 Renderer(Viewport viewport, uint32 numWorkers);
42
43 virtual ~Renderer();
44
48 virtual void doUpdate(const CoreCookedUnit& cooked, const VisualWorld& world) = 0;
49
52 virtual void doRender() = 0;
53
56 virtual void retrieveFrame(std::size_t layerIndex, HdrRgbFrame& out_frame) = 0;
57
66 virtual std::size_t asyncPollUpdatedRegions(TSpan<RenderRegionStatus> out_regions) = 0;
67
73
79
84 virtual void asyncPeekFrame(
85 std::size_t layerIndex,
86 const Region& region,
87 HdrRgbFrame& out_frame) = 0;
88
94
97 void update(const CoreCookedUnit& cooked, const VisualWorld& world);
98
101 void render();
102
105 void setNumWorkers(uint32 numWorkers);
106
107 uint32 numWorkers() const;
108 uint32 getRenderWidthPx() const;
109 uint32 getRenderHeightPx() const;
110
116
122
126 const Viewport& getViewport() const;
127
128 bool asyncIsUpdating() const;
129 bool asyncIsRendering() const;
130
140 TSpan<RenderRegionStatus> out_regions,
141 std::size_t mergeSize);
142
143private:
144 Viewport m_viewport;
145 uint32 m_numWorkers;
146
147 std::vector<RenderWorker> m_workers;
148
149 std::atomic_bool m_isUpdating;
150 std::atomic_bool m_isRendering;
151};
152
153// In-header Implementations:
154
155inline uint32 Renderer::numWorkers() const
156{
157 return m_numWorkers;
158}
159
160inline uint32 Renderer::getRenderWidthPx() const
161{
162 return m_viewport.getBaseSizePx().x();
163}
164
165inline uint32 Renderer::getRenderHeightPx() const
166{
167 return m_viewport.getBaseSizePx().y();
168}
169
171{
172 return m_viewport.getWindowPx();
173}
174
176{
177 return m_viewport.getCroppedRegionPx();
178}
179
180inline const Viewport& Renderer::getViewport() const
181{
182 return m_viewport;
183}
184
185inline bool Renderer::asyncIsUpdating() const
186{
187 return m_isUpdating.load(std::memory_order_relaxed);
188}
189
190inline bool Renderer::asyncIsRendering() const
191{
192 return m_isRendering.load(std::memory_order_relaxed);
193}
194
195}// end namespace ph
Definition CoreCookedUnit.h:19
Meta information for data related to ongoing render operation.
Definition RenderObservationInfo.h:15
Definition RenderProgress.h:12
Definition RenderStats.h:12
Definition Renderer.h:39
virtual RenderStats asyncQueryRenderStats()=0
Get general information of the ongoing rendering process. More information can be provided by the imp...
virtual RenderObservationInfo getObservationInfo() const =0
Get information about available transient outputs of an ongoing render operation. This information wi...
math::TAABB2D< int64 > getCropWindowPx() const
The region to work on. The user may specify a window to confine all operations to this region....
Definition Renderer.h:170
Renderer(Viewport viewport, uint32 numWorkers)
Definition Renderer.cpp:26
virtual void doUpdate(const CoreCookedUnit &cooked, const VisualWorld &world)=0
Perform necessary updates for rendering. No asynchronous operation is allowed during update.
virtual void asyncPeekFrame(std::size_t layerIndex, const Region &region, HdrRgbFrame &out_frame)=0
Get the intermediate render result. This method is similar to retrieveFrame(), except that correctnes...
uint32 getRenderHeightPx() const
Definition Renderer.h:165
virtual RenderProgress asyncQueryRenderProgress()=0
Get progress of the ongoing rendering process. Implementation is advised to provide this information ...
const Viewport & getViewport() const
Descriptions regarding dimensions for the rendered frame. Viewport is set on ctor and stayed constant...
Definition Renderer.h:180
bool asyncIsUpdating() const
Definition Renderer.h:185
uint32 getRenderWidthPx() const
Definition Renderer.h:160
virtual std::size_t asyncPollUpdatedRegions(TSpan< RenderRegionStatus > out_regions)=0
Get the rendering regions that have been updated. Status of a region will always transition to ERegio...
math::TAABB2D< int64 > getRenderRegionPx() const
The region that is going to be rendered. The difference between render region and crop window is that...
Definition Renderer.h:175
virtual ~Renderer()
void setNumWorkers(uint32 numWorkers)
Set number of workers for the renderer.
Definition Renderer.cpp:72
void render()
Start rendering.
Definition Renderer.cpp:56
void update(const CoreCookedUnit &cooked, const VisualWorld &world)
Start updating.
Definition Renderer.cpp:36
uint32 numWorkers() const
Definition Renderer.h:155
virtual void retrieveFrame(std::size_t layerIndex, HdrRgbFrame &out_frame)=0
Get the rendered result.
std::size_t asyncPollMergedUpdatedRegions(TSpan< RenderRegionStatus > out_regions, std::size_t mergeSize)
Get the rendering region that has been updated. This variant polls for combined regions....
Definition Renderer.cpp:83
bool asyncIsRendering() const
Definition Renderer.h:190
virtual void doRender()=0
Perform rendering.
Definition Viewport.h:16
const math::TVector2< uint32 > & getBaseSizePx() const
The full size of this viewport.
Definition Viewport.h:70
const math::TAABB2D< int64 > & getWindowPx() const
The window that limits the viewing area of this viewport.
Definition Viewport.h:75
math::TAABB2D< int64 > getCroppedRegionPx() const
The viewing area of this viewport. The difference between cropped region and window is that cropped r...
Definition Viewport.h:80
A virtual world for image synthesis.
Definition VisualWorld.h:34
T & x()
Definition TVector2.ipp:38
T & y()
Definition TVector2.ipp:44
The root for all renderer implementations.
Definition EEngineProject.h:6
std::span< T, EXTENT > TSpan
A contiguous sequence of objects of type T. Effectively the same as std::span.
Definition TSpan.h:12