|
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,39 +235,22 @@ void Gui::ImGuiBackendInit() {
|
230 | 235 | }
|
231 | 236 |
|
232 | 237 | void Gui::LoadTextureFromRawImage(const std::string& name, const std::string& path) {
|
233 |
| - // GuiTexture (put in Gui) |
234 |
| - const auto res = Context::GetInstance()->GetResourceManager()->GetArchiveManager()->LoadFileRaw(path); |
235 |
| - |
236 |
| - if (!res) { |
237 |
| - SPDLOG_ERROR("Failed to load resource"); |
238 |
| - return; |
239 |
| - } |
240 |
| - if (!res->Buffer || res->Buffer->empty()) { |
241 |
| - SPDLOG_ERROR("Buffer is null or empty"); |
242 |
| - return; |
243 |
| - } |
244 |
| - |
245 |
| - GuiTexture asset; |
246 |
| - asset.Width = 0; |
247 |
| - asset.Height = 0; |
248 |
| - uint8_t* imgData = stbi_load_from_memory(reinterpret_cast<const stbi_uc*>(res->Buffer->data()), res->Buffer->size(), |
249 |
| - &asset.Width, &asset.Height, nullptr, 4); |
250 |
| - |
251 |
| - if (imgData == nullptr) { |
252 |
| - SPDLOG_ERROR("Error loading imgui texture {}", stbi_failure_reason()); |
253 |
| - return; |
254 |
| - } |
| 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)); |
255 | 244 |
|
256 | 245 | GfxRenderingAPI* api = gfx_get_current_rendering_api();
|
257 | 246 |
|
258 | 247 | // TODO: Nothing ever unloads the texture from Fast3D here.
|
259 |
| - asset.RendererTextureId = api->new_texture(); |
260 |
| - api->select_texture(0, asset.RendererTextureId); |
| 248 | + guiTexture->Metadata.RendererTextureId = api->new_texture(); |
| 249 | + api->select_texture(0, guiTexture->Metadata.RendererTextureId); |
261 | 250 | api->set_sampler_parameters(0, false, 0, 0);
|
262 |
| - api->upload_texture(imgData, asset.Width, asset.Height); |
| 251 | + api->upload_texture(guiTexture->Data, guiTexture->Metadata.Width, guiTexture->Metadata.Height); |
263 | 252 |
|
264 |
| - mGuiTextures[name] = asset; |
265 |
| - stbi_image_free(imgData); |
| 253 | + mGuiTextures[name] = guiTexture->Metadata; |
266 | 254 | }
|
267 | 255 |
|
268 | 256 | bool Gui::SupportsViewports() {
|
@@ -832,7 +820,7 @@ void Gui::LoadGuiTexture(const std::string& name, const std::string& path, const
|
832 | 820 | texBuffer[pixel * 4 + 3] *= tint.w;
|
833 | 821 | }
|
834 | 822 |
|
835 |
| - GuiTexture asset; |
| 823 | + GuiTextureMetadata asset; |
836 | 824 | asset.RendererTextureId = api->new_texture();
|
837 | 825 | asset.Width = res->Width;
|
838 | 826 | asset.Height = res->Height;
|
|
0 commit comments