Photon Editor Library 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
GHIThread.h
Go to the documentation of this file.
1#pragma once
2
5
6#include <Common/primitive_type.h>
7#include <Utility/Timer.h>
8
9#include <memory>
10#include <atomic>
11#include <thread>
12
13namespace ph::editor::ghi { class GraphicsContext; }
14
15namespace ph::editor
16{
17
18class GHIThread final : public TUnbufferedFrameWorkerThread<void(ghi::GraphicsContext&)>
19{
20public:
22
23 GHIThread();
24 ~GHIThread() override;
25
26 void onAsyncWorkerStart() override;
27 void onAsyncWorkerStop() override;
28 void onAsyncProcessWork(const Work& work) override;
29 void onBeginFrame() override;
30 void onEndFrame() override;
31
33
37 float32 getFrameTimeMs() const;
38
42 bool isOnGHIThread() const;
43
44private:
45 void switchContext(ghi::GraphicsContext* newCtx);
46
47 // Fields that are accessed on GHI thread
49 std::unique_ptr<ghi::GraphicsContext> m_nullCtx;
50 GHIThreadUpdateContext m_updateCtx;
51 Timer m_frameTimer;
52
53 std::atomic<float32> m_frameTimeMs;
54};
55
56inline float32 GHIThread::getFrameTimeMs() const
57{
58 return m_frameTimeMs.load(std::memory_order_relaxed);
59}
60
61inline bool GHIThread::isOnGHIThread() const
62{
63 return std::this_thread::get_id() == getWorkerThreadId();
64}
65
66}// end namespace ph::editor
Definition GHIThread.h:19
void onAsyncProcessWork(const Work &work) override
Definition GHIThread.cpp:47
void onBeginFrame() override
Definition GHIThread.cpp:54
void onAsyncWorkerStop() override
Definition GHIThread.cpp:40
float32 getFrameTimeMs() const
Definition GHIThread.h:56
bool isOnGHIThread() const
Definition GHIThread.h:61
void onEndFrame() override
Definition GHIThread.cpp:70
void addContextSwitchWork(ghi::GraphicsContext *newCtx)
Definition GHIThread.cpp:87
GHIThread()
Definition GHIThread.cpp:17
~GHIThread() override
Definition GHIThread.cpp:26
void onAsyncWorkerStart() override
Definition GHIThread.cpp:32
Definition GHIThreadUpdateContext.h:11
Definition TUnbufferedFrameWorkerThread.h:30
Definition GraphicsContext.h:24
Definition PlatformDisplay.h:13
Definition ph_editor.h:10