Plasma Engine  2.0
Loading...
Searching...
No Matches
RenderWorld.h
1#pragma once
2
3#include <Core/ResourceManager/ResourceHandle.h>
4#include <RendererCore/Pipeline/Declarations.h>
5
7
9{
10 enum class Type
11 {
12 BeginExtraction,
13 BeforeViewExtraction,
14 AfterViewExtraction,
15 EndExtraction
16 };
17
18 Type m_Type;
19 plView* m_pView = nullptr;
20 plUInt64 m_uiFrameCounter = 0;
21};
22
24{
25 enum class Type
26 {
27 BeginRender,
28 BeforePipelineExecution,
29 AfterPipelineExecution,
30 EndRender,
31 };
32
33 Type m_Type;
34 plRenderPipeline* m_pPipeline = nullptr;
35 const plRenderViewContext* m_pRenderViewContext = nullptr;
36 plUInt64 m_uiFrameCounter = 0;
37};
38
39class PL_RENDERERCORE_DLL plRenderWorld
40{
41public:
42 static plViewHandle CreateView(const char* szName, plView*& out_pView);
43 static void DeleteView(const plViewHandle& hView);
44
45 static bool TryGetView(const plViewHandle& hView, plView*& out_pView);
46
48 static plView* GetViewByUsageHint(plCameraUsageHint::Enum usageHint, plCameraUsageHint::Enum alternativeUsageHint = plCameraUsageHint::None, const plWorld* pWorld = nullptr);
49
50 static void AddMainView(const plViewHandle& hView);
51 static void RemoveMainView(const plViewHandle& hView);
52 static void ClearMainViews();
53 static plArrayPtr<plViewHandle> GetMainViews();
54
55 static void CacheRenderData(const plView& view, const plGameObjectHandle& hOwnerObject, const plComponentHandle& hOwnerComponent, plUInt16 uiComponentVersion, plArrayPtr<plInternal::RenderDataCacheEntry> cacheEntries);
56
57 static void DeleteAllCachedRenderData();
58 static void DeleteCachedRenderData(const plGameObjectHandle& hOwnerObject, const plComponentHandle& hOwnerComponent);
59 static void DeleteCachedRenderDataForObject(const plGameObject* pOwnerObject);
60 static void DeleteCachedRenderDataForObjectRecursive(const plGameObject* pOwnerObject);
61 static void ResetRenderDataCache(plView& ref_view);
62 static plArrayPtr<const plInternal::RenderDataCacheEntry> GetCachedRenderData(const plView& view, const plGameObjectHandle& hOwner, plUInt16 uiComponentVersion);
63
64 static void AddViewToRender(const plViewHandle& hView);
65
66 static void ExtractMainViews();
67
68 static void Render(plRenderContext* pRenderContext);
69
70 static void BeginFrame();
71 static void EndFrame();
72
73 static plEvent<plView*, plMutex> s_ViewCreatedEvent;
74 static plEvent<plView*, plMutex> s_ViewDeletedEvent;
75
76 static const plEvent<const plRenderWorldExtractionEvent&, plMutex>& GetExtractionEvent() { return s_ExtractionEvent; }
77 static const plEvent<const plRenderWorldRenderEvent&, plMutex>& GetRenderEvent() { return s_RenderEvent; }
78
79 static bool GetUseMultithreadedRendering();
80
82 PL_ALWAYS_INLINE static void ResetFrameCounter() { s_uiFrameCounter = 0; }
83
84 PL_ALWAYS_INLINE static plUInt64 GetFrameCounter() { return s_uiFrameCounter; }
85
86 PL_FORCE_INLINE static plUInt32 GetDataIndexForExtraction() { return GetUseMultithreadedRendering() ? (s_uiFrameCounter & 1) : 0; }
87
88 PL_FORCE_INLINE static plUInt32 GetDataIndexForRendering() { return GetUseMultithreadedRendering() ? ((s_uiFrameCounter + 1) & 1) : 0; }
89
90 static bool IsRenderingThread();
91
94public:
96 {
97 plRenderPipelineResourceHandle m_hRenderPipeline;
98 };
99
100 static void BeginModifyCameraConfigs();
101 static void EndModifyCameraConfigs();
102 static void ClearCameraConfigs();
103 static void SetCameraConfig(const char* szName, const CameraConfig& config);
104 static const CameraConfig* FindCameraConfig(const char* szName);
105
106 static plEvent<void*> s_CameraConfigsModifiedEvent;
107
108private:
109 static bool s_bModifyingCameraConfigs;
110 static plMap<plString, CameraConfig> s_CameraConfigs;
111
113
114private:
115 PL_MAKE_SUBSYSTEM_STARTUP_FRIEND(RendererCore, RenderWorld);
116 friend class plView;
117 friend class plRenderPipeline;
118
119 static void DeleteCachedRenderDataInternal(const plGameObjectHandle& hOwnerObject);
120 static void ClearRenderDataCache();
121 static void UpdateRenderDataCache();
122
123 static void AddRenderPipelineToRebuild(plRenderPipeline* pRenderPipeline, const plViewHandle& hView);
124 static void RebuildPipelines();
125
126 static void OnEngineStartup();
127 static void OnEngineShutdown();
128
131 static plUInt64 s_uiFrameCounter;
132};
This class encapsulates an array and it's size. It is recommended to use this class instead of plain ...
Definition ArrayPtr.h:37
Definition Event.h:177
This class represents an object inside the world.
Definition GameObject.h:32
Definition Map.h:408
Definition RenderContext.h:30
Definition RenderPipeline.h:20
Definition RenderWorld.h:40
static PL_ALWAYS_INLINE void ResetFrameCounter()
Resets the frame counter to zero. Only for test purposes !
Definition RenderWorld.h:82
Definition Declarations.h:64
Encapsulates a view on the given world through the given camera and rendered with the specified Rende...
Definition View.h:21
A world encapsulates a scene graph of game objects and various component managers and their component...
Definition World.h:22
Enum
Definition Declarations.h:85
@ None
No hint, camera may not be used, at all.
Definition Declarations.h:86
A handle to a component.
Definition Declarations.h:138
A handle to a game object.
Definition Declarations.h:76
Definition Declarations.h:51
Definition RenderWorld.h:96
Definition RenderWorld.h:9
Definition RenderWorld.h:24