Photon Editor Library 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
OpenglObjectManager.h
Go to the documentation of this file.
1#pragma once
2
9
10#include <Utility/Concurrent/TAtomicQuasiQueue.h>
11#include <Utility/TFunction.h>
12#include <Common/primitive_type.h>
13
14#include <vector>
15
16namespace ph::editor::ghi
17{
18
19class OpenglContext;
20
22{
23 using CreateOperation = TFunction<void(), 64>;
24
26
29 inline void create() const
30 {
31 op();
32 }
33};
34
36{
37 using ManipulateOperation = TFunction<void(), 64>;
38
40
43 inline void manipulate() const
44 {
45 op();
46 }
47};
48
50{
51 using DeleteOperation = TFunction<bool(), 32>;
52
54 uint32 numRetries = 0;
55
60 inline bool tryDelete() const
61 {
62 return op();
63 }
64};
65
67{
68public:
71
72 TextureHandle createTexture(const TextureDesc& desc) override;
73
75 const FramebufferDesc& desc) override;
76
78 std::string name,
79 EShadingStage shadingStage,
80 std::string shaderSource) override;
81
83 std::string name,
84 const ShaderSetInfo& shaders) override;
85
87 std::size_t numVertices,
88 const VertexGroupFormatInfo& format,
89 EStorageUsage usage) override;
90
92 std::size_t numIndices,
93 EStorageElement indexType,
94 EStorageUsage usage) override;
95
97 TSpanView<VertexStorageHandle> vertexStorages,
98 const MeshVertexLayoutInfo& layout,
99 IndexStorageHandle indexStorage) override;
100
101 void uploadPixelData(
102 TextureHandle handle,
103 TSpanView<std::byte> pixelData,
104 EPixelFormat pixelFormat,
105 EPixelComponent pixelComponent) override;
106
107 void removeTexture(TextureHandle handle) override;
108 void removeFramebuffer(FramebufferHandle handle) override;
109 void removeShader(ShaderHandle handle) override;
110 void removeShaderProgram(ShaderProgramHandle handle) override;
111 void removeVertexStorage(VertexStorageHandle handle) override;
112 void removeIndexStorage(IndexStorageHandle handle) override;
113 void removeMesh(MeshHandle handle) override;
114
115 void onGHILoad() override;
116 void onGHIUnload() override;
117 void beginFrameUpdate(const GHIThreadUpdateContext& ctx) override;
118 void endFrameUpdate(const GHIThreadUpdateContext& ctx) override;
119
120public:
121 template<typename OpenglObjType, CWeakHandle HandleType>
123
126
127private:
128 void deleteAllObjects();
129 void deleteAllTextures();
130
131 OpenglContext& m_ctx;
132 TAtomicQuasiQueue<OpenglObjectCreator> m_creationQueue;
133 TAtomicQuasiQueue<OpenglObjectManipulator> m_manipulationQueue;
134 TAtomicQuasiQueue<OpenglObjectDeleter> m_deletionQueue;
135 std::vector<OpenglObjectDeleter> m_failedDeleterCache;
136};
137
138}// end namespace ph::editor::ghi
Definition GHIThreadUpdateContext.h:11
Item pool for simple types. This item pool is designed to minimize execution time and memory footprin...
Definition TTrivialItemPool.h:50
Definition ghi_infos.h:124
Manages the creation and deletion of graphics-related resource objects. All create<XXX>() and delete<...
Definition GraphicsObjectManager.h:26
Definition OpenglContext.h:14
Definition OpenglObjectManager.h:67
TextureHandle createTexture(const TextureDesc &desc) override
Definition OpenglObjectManager.cpp:30
OpenglObjectManager(OpenglContext &ctx)
Definition OpenglObjectManager.cpp:14
void removeShader(ShaderHandle handle) override
Definition OpenglObjectManager.cpp:146
void beginFrameUpdate(const GHIThreadUpdateContext &ctx) override
Called by GHI thread when a frame begins.
Definition OpenglObjectManager.cpp:217
void removeIndexStorage(IndexStorageHandle handle) override
Definition OpenglObjectManager.cpp:155
VertexStorageHandle createVertexStorage(std::size_t numVertices, const VertexGroupFormatInfo &format, EStorageUsage usage) override
Definition OpenglObjectManager.cpp:69
void removeShaderProgram(ShaderProgramHandle handle) override
Definition OpenglObjectManager.cpp:149
MeshHandle createMesh(TSpanView< VertexStorageHandle > vertexStorages, const MeshVertexLayoutInfo &layout, IndexStorageHandle indexStorage) override
Definition OpenglObjectManager.cpp:85
void removeVertexStorage(VertexStorageHandle handle) override
Definition OpenglObjectManager.cpp:152
void removeMesh(MeshHandle handle) override
Definition OpenglObjectManager.cpp:158
void endFrameUpdate(const GHIThreadUpdateContext &ctx) override
Called by GHI thread when a frame ends.
Definition OpenglObjectManager.cpp:235
ShaderProgramHandle createShaderProgram(std::string name, const ShaderSetInfo &shaders) override
Definition OpenglObjectManager.cpp:62
void removeFramebuffer(FramebufferHandle handle) override
Definition OpenglObjectManager.cpp:143
void onGHIUnload() override
Called by GHI thread before GHI is unloaded.
Definition OpenglObjectManager.cpp:186
FramebufferHandle createFramebuffer(const FramebufferDesc &desc) override
Definition OpenglObjectManager.cpp:48
void uploadPixelData(TextureHandle handle, TSpanView< std::byte > pixelData, EPixelFormat pixelFormat, EPixelComponent pixelComponent) override
Definition OpenglObjectManager.cpp:93
IndexStorageHandle createIndexStorage(std::size_t numIndices, EStorageElement indexType, EStorageUsage usage) override
Definition OpenglObjectManager.cpp:77
ShaderHandle createShader(std::string name, EShadingStage shadingStage, std::string shaderSource) override
Definition OpenglObjectManager.cpp:54
void removeTexture(TextureHandle handle) override
Definition OpenglObjectManager.cpp:118
TPool< OpenglTexture, TextureHandle > textures
Definition OpenglObjectManager.h:124
TPool< OpenglFramebuffer, FramebufferHandle > framebuffers
Definition OpenglObjectManager.h:125
void onGHILoad() override
Called by GHI thread after GHI is loaded.
Definition OpenglObjectManager.cpp:183
Definition ghi_infos.h:46
Definition ghi_infos.h:101
Definition PlatformDisplay.h:13
EPixelFormat
Definition ghi_enums.h:31
EStorageElement
Definition ghi_enums.h:70
EShadingStage
Definition ghi_enums.h:104
EStorageUsage
Definition ghi_enums.h:86
EPixelComponent
Definition ghi_enums.h:42
Definition OpenglObjectManager.h:22
TFunction< void(), 64 > CreateOperation
Definition OpenglObjectManager.h:23
CreateOperation op
Definition OpenglObjectManager.h:25
void create() const
Run the create operation.
Definition OpenglObjectManager.h:29
Definition OpenglObjectManager.h:50
TFunction< bool(), 32 > DeleteOperation
Definition OpenglObjectManager.h:51
bool tryDelete() const
Run the delete operation.
Definition OpenglObjectManager.h:60
DeleteOperation op
Definition OpenglObjectManager.h:53
uint32 numRetries
Definition OpenglObjectManager.h:54
Definition OpenglObjectManager.h:36
void manipulate() const
Run the manipulate operation.
Definition OpenglObjectManager.h:43
TFunction< void(), 64 > ManipulateOperation
Definition OpenglObjectManager.h:37
ManipulateOperation op
Definition OpenglObjectManager.h:39