Photon Editor Library 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
OfflineRenderer.h
Go to the documentation of this file.
1#pragma once
2
6
7#include <Common/primitive_type.h>
8#include <Utility/Concurrent/TSPSCExecutor.h>
9#include <DataIO/FileSystem/Path.h>
10#include <Utility/Concurrent/TSynchronized.h>
11#include <Utility/Concurrent/TRelaxedAtomic.h>
12#include <Frame/TFrame.h>
13#include <Math/Geometry/TAABB2D.h>
14
15#include <functional>
16#include <atomic>
17#include <thread>
18
19namespace ph { class Engine; }
20namespace ph { class Renderer; }
21namespace ph::editor { class RenderConfig; }
22
23namespace ph::editor::render
24{
25
27{
28public:
30 ~OfflineRenderer() override;
31
32 void render(RenderConfig config);
33
38
44
45 bool tryGetRenderPeek(OfflineRenderPeek* peek, bool shouldUpdateInput = false);
46
47 void setupGHI(GHIThreadCaller& caller) override;
48 void cleanupGHI(GHIThreadCaller& caller) override;
49 void update(const RenderThreadUpdateContext& ctx) override;
50 void createGHICommands(GHIThreadCaller& caller) override;
51
52private:
53 using EngineWork = std::function<void(void)>;
54
55 struct FrameData
56 {
57 HdrRgbFrame frame;
58 math::TAABB2D<int32> updatedRegion = math::TAABB2D<int32>::makeEmpty();
59 };
60
61 bool tryUploadFrameData(GHIThreadCaller& caller);
62 void renderSingleStaticImageOnEngineThread(RenderConfig config);
63
67 void setRenderStage(EOfflineRenderStage stage);
68
69 std::jthread makeStatsRequestThread(Renderer* renderer, uint32 minPeriodMs);
70 std::jthread makePeekFrameThread(Renderer* renderer, uint32 minPeriodMs);
71
72 TSPSCExecutor<EngineWork> m_engineThread;
73 TRelaxedAtomic<EOfflineRenderStage> m_renderStage;
74 TSynchronized<OfflineRenderStats> m_syncedRenderStats;
75 TSynchronized<OfflineRenderPeek> m_syncedRenderPeek;
76 OfflineRenderPeek::Input m_cachedRenderPeekInput;
77 TSynchronized<FrameData> m_synchedFrameData;
78 std::atomic_flag m_requestCompletedFrameDataUpload;
79 std::atomic_flag m_requestRenderStats;
80 std::atomic_flag m_requestRenderPeek;
81};
82
84{
85 return m_renderStage.relaxedRead();
86}
87
88inline void OfflineRenderer::setRenderStage(EOfflineRenderStage stage)
89{
90 m_renderStage.relaxedWrite(stage);
91}
92
93}// end namespace ph::editor::render
Thin wrapper for GHI thread interactions from another thread. Mainly to hide unrelated GHI interface ...
Definition GHIThreadCaller.h:16
Definition RenderConfig.h:13
Definition RenderThreadUpdateContext.h:11
Information about the rendered frame. For frame data exchange between the renderer and outside world.
Definition OfflineRenderPeek.h:18
Information about the rendering process. For gathering general information from the renderer.
Definition OfflineRenderStats.h:27
Definition OfflineRenderer.h:27
bool tryGetRenderPeek(OfflineRenderPeek *peek, bool shouldUpdateInput=false)
Definition OfflineRenderer.cpp:118
bool tryGetRenderStats(OfflineRenderStats *stats)
Make an attempt to retrieve render statistics from the render engine.
Definition OfflineRenderer.cpp:96
OfflineRenderer()
Definition OfflineRenderer.cpp:37
void update(const RenderThreadUpdateContext &ctx) override
Definition OfflineRenderer.cpp:275
void render(RenderConfig config)
Definition OfflineRenderer.cpp:55
void cleanupGHI(GHIThreadCaller &caller) override
Definition OfflineRenderer.cpp:272
EOfflineRenderStage getRenderStage() const
Definition OfflineRenderer.h:83
void createGHICommands(GHIThreadCaller &caller) override
Definition OfflineRenderer.cpp:288
~OfflineRenderer() override
Definition OfflineRenderer.cpp:52
void setupGHI(GHIThreadCaller &caller) override
Definition OfflineRenderer.cpp:269
Definition SceneRenderer.h:11
Definition DesignerObject.h:19
EOfflineRenderStage
Definition OfflineRenderStats.h:13
Definition ph_editor.h:10
Definition ph_editor.h:5
Definition OfflineRenderPeek.h:21