diff --git a/include/gui_node/gui_engine.hpp b/include/gui_node/gui_engine.hpp index bd2ea5f..64c6c46 100644 --- a/include/gui_node/gui_engine.hpp +++ b/include/gui_node/gui_engine.hpp @@ -334,10 +334,13 @@ class TextureLoader * Updates the texture with provided image data. * * @param image_data Vector of the image data. + * @param width Width of the image. + * @param height Height of the image. + * @param channels Number of channels in the image. * * @return bool True if the texture was updated successfully. */ - bool updateTexture(std::vector image_data); + bool updateTexture(std::vector image_data, int width, int height, int channels); }; /** diff --git a/src/gui_engine.cpp b/src/gui_engine.cpp index eef88ac..07f06e1 100644 --- a/src/gui_engine.cpp +++ b/src/gui_engine.cpp @@ -1408,9 +1408,25 @@ bool TextureLoader::recordCommandBuffer(VkCommandPoolSharedPtr command_pool, con return checkVulkanResult(result, node->get_logger(), "Failed to wait for device to become idle!"); } -bool TextureLoader::updateTexture(std::vector image_data) +bool TextureLoader::updateTexture(std::vector image_data, int width, int height, int channels) { this->image_data = image_data; + + // Recreate image if size or channels constraints are not met + if (this->width != width || this->height != height || this->channels != channels) + { + this->width = width; + this->height = height; + this->channels = channels; + VkResult result = vkDeviceWaitIdle(*gui_engine->getDevice().get()); + checkVulkanResult(result, node->get_logger(), "Failed to wait for device to become idle!"); + createImage(); + createImageView(); + descriptor_set = + ImGui_ImplVulkan_AddTexture(*sampler.get(), *image_view.get(), VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); + createUploadBuffer(); + } + return uploadToBuffer() && recordCommandBuffer(gui_engine->getCommandPool(), gui_engine->getGraphicsQueue()); } diff --git a/src/widget/widget_video.cpp b/src/widget/widget_video.cpp index fa82259..785312c 100644 --- a/src/widget/widget_video.cpp +++ b/src/widget/widget_video.cpp @@ -94,7 +94,7 @@ bool BaseVideoWidget::updateTexture(const std::vector &buffer, in std::shared_ptr texture_loader = gui_engine->getTexture(ros_data_name); if (buffer != last_image_data) { - if (!texture_loader->updateTexture(buffer)) + if (!texture_loader->updateTexture(buffer, width, height, channels)) { return false; }