Photon Editor Library 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
ImguiImageLibrary.h
Go to the documentation of this file.
1#pragma once
2
9
11
12#include <Common/assertion.h>
13#include <Common/Container/TStdUnorderedStringMap.h>
14#include <Utility/utility.h>
15#include <Math/TVector2.h>
16#include <Math/TVector4.h>
17#include <DataIO/FileSystem/Path.h>
18
19#include <memory>
20#include <array>
21#include <cstddef>
22#include <string>
23#include <string_view>
24#include <vector>
25
26namespace ph::editor::render { class Scene; }
27
28namespace ph::editor
29{
30
31class Editor;
32class RenderThreadCaller;
33
36enum class EImguiImage
37{
38 Warning = 0,
39 Folder,
40 File,
41 Image,
42
44 SIZE
45};
46
52{
53public:
56
57 void initialize(Editor* editor);
58 void terminate();
59
60 void imguiImage(
61 EImguiImage targetImage,
62 const math::Vector2F& sizePx,
63 const math::Vector4F& tintColorRGBA = math::Vector4F(1, 1, 1, 1),
64 const math::Vector4F& borderColorRGBA = math::Vector4F(0, 0, 0, 0)) const;
65
66 void imguiImage(
67 std::string_view imageName,
68 const math::Vector2F& sizePx,
69 const math::Vector4F& tintColorRGBA = math::Vector4F(1, 1, 1, 1),
70 const math::Vector4F& borderColorRGBA = math::Vector4F(0, 0, 0, 0)) const;
71
73 const char* strId,
74 EImguiImage targetImage,
75 const math::Vector2F& sizePx,
76 const math::Vector4F& backgroundColorRGBA = math::Vector4F(0, 0, 0, 0),
77 const math::Vector4F& tintColorRGBA = math::Vector4F(1, 1, 1, 1));
78
80 const char* strId,
81 std::string_view imageName,
82 const math::Vector2F& sizePx,
83 const math::Vector4F& backgroundColorRGBA = math::Vector4F(0, 0, 0, 0),
84 const math::Vector4F& tintColorRGBA = math::Vector4F(1, 1, 1, 1));
85
86 ImTextureID get(std::string_view imageName) const;
87 ImTextureID get(EImguiImage targetImage) const;
88
93 bool has(std::string_view imageName) const;
94
98 math::Vector2UI getSizePx(std::string_view imageName) const;
99 ghi::ESizedPixelFormat getFormat(std::string_view imageName) const;
100 render::TextureHandle getHandle(std::string_view imageName) const;
101 ghi::TextureHandle getGraphicsHandle(std::string_view imageName) const;
103
104 /*void imguiDrawImageButton(
105 std::string_view
106 EImguiImage targetImage,
107 const math::Vector2F& sizePx,
108 const math::Vector4F& tintColorRGBA = math::Vector4F(1, 1, 1, 1),
109 const math::Vector4F& borderColorRGBA = math::Vector4F(0, 0, 0, 0));*/
110
111 void loadImage(EImguiImage targetImage, const Path& filePath);
112
113 void loadImage(
114 std::string_view imageName,
115 const Path& filePath,
116 math::Vector2UI sizePx = {0, 0},
118
119 void loadImage(
120 std::string_view imageName,
121 math::Vector2UI sizePx,
123
124 void unloadImage(std::string_view imageName);
125
127
131
132 Editor& getEditor();
133
134 // TODO: wrapper for image & image drawing (with button?)
135
136private:
137 struct Entry
138 {
140 ghi::TextureHandle gHandle;
141 ImTextureID textureID = nullptr;
142 math::Vector2UI sizePx = {0, 0};
144 };
145
146 struct Loader
147 {
148 std::string entryName;
149 int entryIdx = -1;
150 Path fileToLoad;
151 math::Vector2UI sizePx = {0, 0};
153 };
154
155 struct NativeHandleRetriever
156 {
157 std::string entryName;
158 int entryIdx = -1;
161 bool isFinished = false;
162 };
163
164 auto getEntry(std::string_view name) const -> const Entry*;
165
166 static ImTextureID getTextureIDFromNativeHandle(ghi::TextureNativeHandle nativeHandle);
167
168 Editor* m_editor;
169 std::vector<Loader> m_loaders;
170 std::vector<NativeHandleRetriever> m_retrievers;
171 std::vector<render::TextureHandle> m_unloadingTextures;
172 TStdUnorderedStringMap<Entry> m_namedEntries;
173 std::array<Entry, enum_size<EImguiImage>()> m_builtinEntries;
174};
175
176inline math::Vector2UI ImguiImageLibrary::getSizePx(std::string_view name) const
177{
178 const Entry* entry = getEntry(name);
179 return entry ? entry->sizePx : math::Vector2UI{0, 0};
180}
181
182inline ghi::ESizedPixelFormat ImguiImageLibrary::getFormat(std::string_view name) const
183{
184 const Entry* entry = getEntry(name);
185 return entry ? entry->format : ghi::ESizedPixelFormat::Empty;
186}
187
188inline render::TextureHandle ImguiImageLibrary::getHandle(std::string_view name) const
189{
190 const Entry* entry = getEntry(name);
191 return entry ? entry->handle : render::TextureHandle{};
192}
193
195{
196 const Entry* entry = getEntry(name);
197 return entry ? entry->gHandle : ghi::TextureHandle{};
198}
199
201{
202 PH_ASSERT(m_editor);
203 return *m_editor;
204}
205
206inline ImTextureID ImguiImageLibrary::get(std::string_view imageName) const
207{
208 auto iter = m_namedEntries.find(imageName);
209 return iter != m_namedEntries.end() ? iter->second.textureID : nullptr;
210}
211
212inline ImTextureID ImguiImageLibrary::get(EImguiImage targetImage) const
213{
214 PH_ASSERT_LT(static_cast<std::size_t>(targetImage), m_builtinEntries.size());
215 return m_builtinEntries[static_cast<std::size_t>(targetImage)].textureID;
216}
217
218inline bool ImguiImageLibrary::has(std::string_view imageName) const
219{
220 return getEntry(imageName) != nullptr;
221}
222
223inline auto ImguiImageLibrary::getEntry(std::string_view imageName) const
224-> const Entry*
225{
226 auto iter = m_namedEntries.find(imageName);
227 return iter != m_namedEntries.end() ? &(iter->second) : nullptr;
228}
229
230}// end namespace ph::editor
Definition Editor.h:45
Definition ImguiImageLibrary.h:52
void initialize(Editor *editor)
Definition ImguiImageLibrary.cpp:33
void unloadImage(std::string_view imageName)
Definition ImguiImageLibrary.cpp:153
bool imguiImageButton(const char *strId, EImguiImage targetImage, const math::Vector2F &sizePx, const math::Vector4F &backgroundColorRGBA=math::Vector4F(0, 0, 0, 0), const math::Vector4F &tintColorRGBA=math::Vector4F(1, 1, 1, 1))
Definition ImguiImageLibrary.cpp:62
void terminate()
Definition ImguiImageLibrary.cpp:39
void createRenderCommands(RenderThreadCaller &caller, render::Scene &scene)
Definition ImguiImageLibrary.cpp:190
void cleanupTextures(RenderThreadCaller &caller, render::Scene &scene)
Unload all named and builtin images.
Definition ImguiImageLibrary.cpp:357
render::TextureHandle getHandle(std::string_view imageName) const
Definition ImguiImageLibrary.h:188
ImguiImageLibrary()
Definition ImguiImageLibrary.cpp:22
void loadImage(EImguiImage targetImage, const Path &filePath)
Definition ImguiImageLibrary.cpp:84
void imguiImage(EImguiImage targetImage, const math::Vector2F &sizePx, const math::Vector4F &tintColorRGBA=math::Vector4F(1, 1, 1, 1), const math::Vector4F &borderColorRGBA=math::Vector4F(0, 0, 0, 0)) const
Definition ImguiImageLibrary.cpp:42
ghi::ESizedPixelFormat getFormat(std::string_view imageName) const
Definition ImguiImageLibrary.h:182
math::Vector2UI getSizePx(std::string_view imageName) const
Get information of a named image.
Definition ImguiImageLibrary.h:176
Editor & getEditor()
Definition ImguiImageLibrary.h:200
ImTextureID get(std::string_view imageName) const
Definition ImguiImageLibrary.h:206
ghi::TextureHandle getGraphicsHandle(std::string_view imageName) const
Definition ImguiImageLibrary.h:194
bool has(std::string_view imageName) const
Whether the library has the image. If true is returned, does not mean get(imageName) will necessary r...
Definition ImguiImageLibrary.h:218
Thin wrapper for render thread interactions from another thread. Mainly to hide unrelated render thre...
Definition RenderThreadCaller.h:16
A scene for the editor renderer only.
Definition Scene.h:34
ESizedPixelFormat
Combined pixel layout and component type information. Unless stated explicitly, the characters RGB do...
Definition ghi_enums.h:19
std::variant< std::monostate, uint64 > TextureNativeHandle
Definition ghi_fwd.h:52
TQuery< GraphicsContext, Performer > TQueryOf
Definition query_basics.h:15
Definition DesignerObject.h:19
TQuery< System, Performer > TQueryOf
Definition query_basics.h:15
Definition ph_editor.h:10
@ File
Definition ImguiEditorPanel.h:13
EImguiImage
Built-in images.
Definition ImguiImageLibrary.h:37