Photon Editor Library 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
RenderThread.h
Go to the documentation of this file.
1#pragma once
2
4#include "editor_lib_config.h"
6
7#include <Common/primitive_type.h>
8#include <Utility/Timer.h>
9
10#include <memory>
11#include <atomic>
12
13namespace ph::editor::render { class System; }
14namespace ph::editor::ghi { class GraphicsContext; }
15
16namespace ph::editor
17{
18
19class GHIThread;
20
22 public TFrameWorkerThread<
23 config::NUM_RENDER_THREAD_BUFFERED_FRAMES,
24 void(render::System&)>
25{
26public:
29 void(render::System&)>;
30
32 ~RenderThread() override;
33
34 void onAsyncProcessWork(const Work& work) override;
35 void onAsyncWorkerStart() override;
36 void onAsyncWorkerStop() override;
37 void onBeginFrame() override;
38 void onEndFrame() override;
39
43 float32 getFrameTimeMs() const;
44
48 float32 getGHIFrameTimeMs() const;
49
53 std::thread::id getGHIWorkerThreadId() const;
54
59
60private:
63 void beforeFirstRenderWorkInFrame();
64
67 void afterLastRenderWorkInFrame();
68
69 // Context should be set before thread start and cannot be changed. See `setGraphicsContext()`.
70 ghi::GraphicsContext* m_graphicsCtx;
71
72 // Fields that are accessed on render thread
73 std::unique_ptr<render::System> m_system;
74 GHIThread m_ghiThread;
75 Timer m_frameTimer;
76
77 std::atomic<float32> m_frameTimeMs;
78};
79
80inline float32 RenderThread::getFrameTimeMs() const
81{
82 return m_frameTimeMs.load(std::memory_order_relaxed);
83}
84
85inline float32 RenderThread::getGHIFrameTimeMs() const
86{
87 return m_ghiThread.getFrameTimeMs();
88}
89
90inline std::thread::id RenderThread::getGHIWorkerThreadId() const
91{
92 return m_ghiThread.getWorkerThreadId();
93}
94
95}// end namespace ph::editor
Definition GHIThread.h:19
float32 getFrameTimeMs() const
Definition GHIThread.h:56
Definition RenderThread.h:25
float32 getFrameTimeMs() const
Definition RenderThread.h:80
void onAsyncWorkerStop() override
Definition RenderThread.cpp:71
~RenderThread() override
Definition RenderThread.cpp:31
void onEndFrame() override
Definition RenderThread.cpp:178
void setGraphicsContext(ghi::GraphicsContext *graphicsCtx)
Set a graphics context which is persistent throughout the worker thread's lifespan....
Definition RenderThread.cpp:259
void onBeginFrame() override
Definition RenderThread.cpp:116
void onAsyncProcessWork(const Work &work) override
Definition RenderThread.cpp:34
float32 getGHIFrameTimeMs() const
Definition RenderThread.h:85
void onAsyncWorkerStart() override
Definition RenderThread.cpp:41
RenderThread()
Definition RenderThread.cpp:20
std::thread::id getGHIWorkerThreadId() const
Definition RenderThread.h:90
Definition TFrameWorkerThread.h:55
Definition GraphicsContext.h:24
Definition System.h:26
constexpr std::size_t NUM_RENDER_THREAD_BUFFERED_FRAMES
Definition editor_lib_config.h:10
Definition PlatformDisplay.h:13
Definition DesignerObject.h:19
Definition ph_editor.h:10