From 2e36bd2ca1674f39059350c08c71c2f87a2b28f0 Mon Sep 17 00:00:00 2001 From: Georg Hagen Date: Thu, 20 Nov 2025 17:05:11 +0100 Subject: [PATCH] Add texture image support for imgui --- .../UI/ImGuiExtensions/ImGuiTextureImage.cpp | 23 +++++++++++++++++++ .../UI/ImGuiExtensions/ImGuiTextureImage.hpp | 17 ++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 openVulkanoCpp/Scene/UI/ImGuiExtensions/ImGuiTextureImage.cpp create mode 100644 openVulkanoCpp/Scene/UI/ImGuiExtensions/ImGuiTextureImage.hpp diff --git a/openVulkanoCpp/Scene/UI/ImGuiExtensions/ImGuiTextureImage.cpp b/openVulkanoCpp/Scene/UI/ImGuiExtensions/ImGuiTextureImage.cpp new file mode 100644 index 0000000..568d79b --- /dev/null +++ b/openVulkanoCpp/Scene/UI/ImGuiExtensions/ImGuiTextureImage.cpp @@ -0,0 +1,23 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +#include "ImGuiTextureImage.hpp" +#include "Vulkan/Scene/VulkanTexture.hpp" + +namespace ImGui +{ + void TextureImage(const OpenVulkano::Scene::Texture& texture, ImVec2 size, const ImVec2& uv0, const ImVec2& uv1, const ImVec4& tintColor, const ImVec4& borderColor) + { + OpenVulkano::Vulkan::VulkanTexture* renderTexture = texture.GetRenderResource(); + if (!renderTexture) + { + renderTexture = OpenVulkano::Vulkan::ResourceManager::INSTANCE->PrepareTexture(const_cast(&texture)); + } + if (size.x < 0) size.x = texture.resolution.x; + if (size.y < 0) size.y = texture.resolution.y; + Image(renderTexture->m_descriptorSet, size, uv0, uv1, tintColor, borderColor); + } +} diff --git a/openVulkanoCpp/Scene/UI/ImGuiExtensions/ImGuiTextureImage.hpp b/openVulkanoCpp/Scene/UI/ImGuiExtensions/ImGuiTextureImage.hpp new file mode 100644 index 0000000..0069a20 --- /dev/null +++ b/openVulkanoCpp/Scene/UI/ImGuiExtensions/ImGuiTextureImage.hpp @@ -0,0 +1,17 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +#pragma once + +#include "Scene/Texture.hpp" +#include + +namespace ImGui +{ + void TextureImage(const OpenVulkano::Scene::Texture& texture, ImVec2 size = ImVec2(-1, -1), + const ImVec2& uv0 = ImVec2(0, 0), const ImVec2& uv1 = ImVec2(1, 1), + const ImVec4& tintColor = ImVec4(1, 1, 1, 1), const ImVec4& borderColor = ImVec4(0, 0, 0, 0)); +}