From 090fb5f5f19b0f407466071c0aab15d1004ea5c7 Mon Sep 17 00:00:00 2001 From: Dario Date: Wed, 29 Jan 2025 17:07:22 -0300 Subject: [PATCH] Use RT64's texture laoding instead. --- CMakeLists.txt | 2 ++ src/ui/ui_renderer.cpp | 39 +++++++++++++++++++++------------------ 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a857232..b356ceb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,6 +39,8 @@ endif() set(RT64_STATIC TRUE) set(RT64_SDL_WINDOW_VULKAN TRUE) +add_compile_definitions(HLSL_CPU) + add_subdirectory(${CMAKE_SOURCE_DIR}/lib/rt64 ${CMAKE_BINARY_DIR}/rt64) # set(BUILD_SHARED_LIBS_SAVED "${BUILD_SHARED_LIBS}") diff --git a/src/ui/ui_renderer.cpp b/src/ui/ui_renderer.cpp index 4918e8f..2cd0e0a 100644 --- a/src/ui/ui_renderer.cpp +++ b/src/ui/ui_renderer.cpp @@ -8,10 +8,9 @@ #include -#include "stb/stb_image.h" - #include "rt64_render_hooks.h" #include "rt64_render_interface_builders.h" +#include "rt64_texture_cache.h" #include "RmlUi/Core/RenderInterfaceCompatibility.h" @@ -404,25 +403,29 @@ public: return true; } - constexpr uint32_t PNG_MAGIC = 0x474E5089; - uint32_t magicNumber = *reinterpret_cast(it->second.data()); - if (magicNumber == PNG_MAGIC) { - int width, height; - stbi_uc *stbi_data = stbi_load_from_memory((const stbi_uc *)(it->second.data()), it->second.size(), &width, &height, nullptr, 4); - if (stbi_data == nullptr) { - return false; - } + // TODO: This data copy can be avoided when RT64::TextureCache::loadTextureFromBytes's function is updated to only take a pointer and size as the input. + std::vector data_copy(it->second.data(), it->second.data() + it->second.size()); + std::unique_ptr texture_buffer; + copy_command_list_->begin(); + RT64::Texture *texture = RT64::TextureCache::loadTextureFromBytes(device_, copy_command_list_.get(), data_copy, texture_buffer); + copy_command_list_->end(); + copy_command_queue_->executeCommandLists(copy_command_list_.get(), copy_command_fence_.get()); + copy_command_queue_->waitForCommandFence(copy_command_fence_.get()); - texture_dimensions.x = width; - texture_dimensions.y = height; - - bool texture_generated = GenerateTexture(texture_handle, stbi_data, texture_dimensions); - stbi_image_free(stbi_data); - return texture_generated; - } - else { + if (texture == nullptr) { return false; } + + texture_handle = texture_count_++; + texture_dimensions.x = texture->width; + texture_dimensions.y = texture->height; + + std::unique_ptr set = texture_set_builder_->create(device_); + set->setTexture(gTexture_descriptor_index, texture->texture.get(), RT64::RenderTextureLayout::SHADER_READ); + textures_.emplace(texture_handle, TextureHandle{ std::move(texture->texture), std::move(set), false }); + delete texture; + + return true; } bool GenerateTexture(Rml::TextureHandle& texture_handle, const Rml::byte* source, const Rml::Vector2i& source_dimensions) override {