@@ -239,13 +239,51 @@ void Gui::LoadTextureFromRawImage(const std::string& name, const std::string& pa
239
239
initData->Format = RESOURCE_FORMAT_BINARY;
240
240
initData->Type = static_cast <uint32_t >(RESOURCE_TYPE_GUI_TEXTURE);
241
241
initData->ResourceVersion = 0 ;
242
- auto guiTextureResource = std::static_pointer_cast<GuiTextureResource>( Context::GetInstance ()->GetResourceManager ()->LoadResource ( path, false , initData) );
242
+ const auto res = Context::GetInstance ()->GetResourceManager ()->GetArchiveManager ()-> LoadFile ( path, initData);
243
243
244
- if (guiTextureResource == nullptr ) {
244
+ if (!res) {
245
+ SPDLOG_ERROR (" Failed to load resource" );
245
246
return ;
246
247
}
248
+ if (!res->Buffer || res->Buffer ->empty ()) {
249
+ SPDLOG_ERROR (" Buffer is null or empty" );
250
+ return ;
251
+ }
252
+
253
+ GuiTexture asset;
254
+ asset.Width = 0 ;
255
+ asset.Height = 0 ;
256
+ uint8_t * imgData = stbi_load_from_memory (reinterpret_cast <const stbi_uc*>(res->Buffer ->data ()), res->Buffer ->size (),
257
+ &asset.Width , &asset.Height , nullptr , 4 );
258
+
259
+
260
+ if (imgData == nullptr ) {
261
+ SPDLOG_ERROR (" Error loading imgui texture {}" , stbi_failure_reason ());
262
+ return ;
263
+ }
264
+
265
+ GfxRenderingAPI* api = gfx_get_current_rendering_api ();
266
+
267
+ // TODO: Nothing ever unloads the texture from Fast3D here.
268
+ asset.RendererTextureId = api->new_texture ();
269
+ api->select_texture (0 , asset.RendererTextureId );
270
+ api->set_sampler_parameters (0 , false , 0 , 0 );
271
+ api->upload_texture (imgData, asset.Width , asset.Height );
272
+
273
+ mGuiTextures [name] = asset;
274
+ stbi_image_free (imgData);
275
+
276
+ // auto initData = std::make_shared<ResourceInitData>();
277
+ // initData->Format = RESOURCE_FORMAT_BINARY;
278
+ // initData->Type = static_cast<uint32_t>(RESOURCE_TYPE_GUI_TEXTURE);
279
+ // initData->ResourceVersion = 0;
280
+ // auto guiTextureResource = std::static_pointer_cast<GuiTextureResource>(Context::GetInstance()->GetResourceManager()->LoadResource(path, false, initData));
281
+
282
+ // if (guiTextureResource == nullptr) {
283
+ // return;
284
+ // }
247
285
248
- mGuiTextures [name] = guiTextureResource->GuiTextureData ;
286
+ // mGuiTextures[name] = guiTextureResource->GuiTextureData;
249
287
}
250
288
251
289
bool Gui::SupportsViewports () {
0 commit comments