|
15 | 15 | #include "resource/File.h"
|
16 | 16 | #include <stb/stb_image.h>
|
17 | 17 | #include "window/gui/Fonts.h"
|
| 18 | +#include "window/gui/resource/GuiTextureFactory.h" |
18 | 19 |
|
19 | 20 | #ifdef __WIIU__
|
20 | 21 | #include <gx2/registers.h> // GX2SetViewport / GX2SetScissor
|
@@ -150,6 +151,10 @@ void Gui::Init(GuiWindowInitData windowImpl) {
|
150 | 151 | GetGuiWindow("Console")->Init();
|
151 | 152 | GetGameOverlay()->Init();
|
152 | 153 |
|
| 154 | + Context::GetInstance()->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory( |
| 155 | + std::make_shared<ResourceFactoryBinaryGuiTextureV0>(), RESOURCE_FORMAT_BINARY, "GuiTexture", |
| 156 | + static_cast<uint32_t>(RESOURCE_TYPE_GUI_TEXTURE), 0); |
| 157 | + |
153 | 158 | ImGuiWMInit();
|
154 | 159 | ImGuiBackendInit();
|
155 | 160 | #ifdef __SWITCH__
|
@@ -230,38 +235,22 @@ void Gui::ImGuiBackendInit() {
|
230 | 235 | }
|
231 | 236 |
|
232 | 237 | void Gui::LoadTextureFromRawImage(const std::string& name, const std::string& path) {
|
233 |
| - const auto res = Context::GetInstance()->GetResourceManager()->GetArchiveManager()->LoadFileRaw(path); |
234 |
| - |
235 |
| - if (!res) { |
236 |
| - SPDLOG_ERROR("Failed to load resource"); |
237 |
| - return; |
238 |
| - } |
239 |
| - if (!res->Buffer || res->Buffer->empty()) { |
240 |
| - SPDLOG_ERROR("Buffer is null or empty"); |
241 |
| - return; |
242 |
| - } |
243 |
| - |
244 |
| - GuiTexture asset; |
245 |
| - asset.Width = 0; |
246 |
| - asset.Height = 0; |
247 |
| - uint8_t* imgData = stbi_load_from_memory(reinterpret_cast<const stbi_uc*>(res->Buffer->data()), res->Buffer->size(), |
248 |
| - &asset.Width, &asset.Height, nullptr, 4); |
249 |
| - |
250 |
| - if (imgData == nullptr) { |
251 |
| - SPDLOG_ERROR("Error loading imgui texture {}", stbi_failure_reason()); |
252 |
| - return; |
253 |
| - } |
| 238 | + auto initData = std::make_shared<ResourceInitData>(); |
| 239 | + initData->Format = RESOURCE_FORMAT_BINARY; |
| 240 | + initData->Type = static_cast<uint32_t>(RESOURCE_TYPE_GUI_TEXTURE); |
| 241 | + initData->ResourceVersion = 0; |
| 242 | + auto guiTexture = std::static_pointer_cast<GuiTexture>( |
| 243 | + Context::GetInstance()->GetResourceManager()->LoadResource(path, false, initData)); |
254 | 244 |
|
255 | 245 | GfxRenderingAPI* api = gfx_get_current_rendering_api();
|
256 | 246 |
|
257 | 247 | // TODO: Nothing ever unloads the texture from Fast3D here.
|
258 |
| - asset.RendererTextureId = api->new_texture(); |
259 |
| - api->select_texture(0, asset.RendererTextureId); |
| 248 | + guiTexture->Metadata.RendererTextureId = api->new_texture(); |
| 249 | + api->select_texture(0, guiTexture->Metadata.RendererTextureId); |
260 | 250 | api->set_sampler_parameters(0, false, 0, 0);
|
261 |
| - api->upload_texture(imgData, asset.Width, asset.Height); |
| 251 | + api->upload_texture(guiTexture->Data, guiTexture->Metadata.Width, guiTexture->Metadata.Height); |
262 | 252 |
|
263 |
| - mGuiTextures[name] = asset; |
264 |
| - stbi_image_free(imgData); |
| 253 | + mGuiTextures[name] = guiTexture->Metadata; |
265 | 254 | }
|
266 | 255 |
|
267 | 256 | bool Gui::SupportsViewports() {
|
@@ -831,7 +820,7 @@ void Gui::LoadGuiTexture(const std::string& name, const std::string& path, const
|
831 | 820 | texBuffer[pixel * 4 + 3] *= tint.w;
|
832 | 821 | }
|
833 | 822 |
|
834 |
| - GuiTexture asset; |
| 823 | + GuiTextureMetadata asset; |
835 | 824 | asset.RendererTextureId = api->new_texture();
|
836 | 825 | asset.Width = res->Width;
|
837 | 826 | asset.Height = res->Height;
|
|
0 commit comments