From 8b8d855a204de61441e5dfe7c42f1633a740e947 Mon Sep 17 00:00:00 2001 From: iwubcode Date: Fri, 28 Feb 2025 00:00:15 -0600 Subject: [PATCH] VideoCommon: add graphics mod editor control for render target assets --- .../Controls/RenderTargetControl.cpp | 159 ++++++++++++++++++ .../Controls/RenderTargetControl.h | 32 ++++ 2 files changed, 191 insertions(+) create mode 100644 Source/Core/VideoCommon/GraphicsModEditor/Controls/RenderTargetControl.cpp create mode 100644 Source/Core/VideoCommon/GraphicsModEditor/Controls/RenderTargetControl.h diff --git a/Source/Core/VideoCommon/GraphicsModEditor/Controls/RenderTargetControl.cpp b/Source/Core/VideoCommon/GraphicsModEditor/Controls/RenderTargetControl.cpp new file mode 100644 index 0000000000..8b829d4043 --- /dev/null +++ b/Source/Core/VideoCommon/GraphicsModEditor/Controls/RenderTargetControl.cpp @@ -0,0 +1,159 @@ +// Copyright 2025 Dolphin Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "VideoCommon/GraphicsModEditor/Controls/RenderTargetControl.h" + +#include + +#include + +#include "Common/StringUtil.h" +#include "VideoCommon/Assets/TextureAsset.h" +#include "VideoCommon/GraphicsModEditor/EditorEvents.h" + +namespace GraphicsModEditor::Controls +{ +RenderTargetControl::RenderTargetControl(EditorState& state) : m_state(state) +{ +} +void RenderTargetControl::DrawImGui(const VideoCommon::CustomAssetLibrary::AssetID& asset_id, + VideoCommon::RenderTargetData* render_target_data, + const std::filesystem::path& path, + VideoCommon::CustomAssetLibrary::TimeType* last_data_write, + AbstractTexture* texture_preview) +{ + if (ImGui::BeginTable("TextureForm", 2)) + { + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + ImGui::Text("ID"); + ImGui::TableNextColumn(); + ImGui::Text("%s", asset_id.c_str()); + + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + ImGui::Text("Name"); + ImGui::TableNextColumn(); + ImGui::TextWrapped("%s", PathToString(path.stem()).c_str()); + + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + ImGui::Text("Format"); + ImGui::TableNextColumn(); + ImGui::Text("RGBA8"); + + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + ImGui::Text("Min Filter Mode"); + ImGui::TableNextColumn(); + if (ImGui::BeginCombo("##MinFilterMode", + fmt::to_string(render_target_data->m_sampler.tm0.min_filter).c_str())) + { + for (auto e = FilterMode::Near; e <= FilterMode::Linear; + e = static_cast(static_cast(e) + 1)) + { + const bool is_selected = render_target_data->m_sampler.tm0.min_filter == e; + if (ImGui::Selectable(fmt::to_string(e).c_str(), is_selected)) + { + render_target_data->m_sampler.tm0.min_filter = e; + *last_data_write = std::chrono::system_clock::now(); + GraphicsModEditor::EditorEvents::AssetReloadEvent::Trigger(asset_id); + } + } + ImGui::EndCombo(); + } + + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + ImGui::Text("Mag Filter Mode"); + ImGui::TableNextColumn(); + if (ImGui::BeginCombo("##MagFilterMode", + fmt::to_string(render_target_data->m_sampler.tm0.mag_filter).c_str())) + { + for (auto e = FilterMode::Near; e <= FilterMode::Linear; + e = static_cast(static_cast(e) + 1)) + { + const bool is_selected = render_target_data->m_sampler.tm0.mag_filter == e; + if (ImGui::Selectable(fmt::to_string(e).c_str(), is_selected)) + { + render_target_data->m_sampler.tm0.mag_filter = e; + *last_data_write = std::chrono::system_clock::now(); + GraphicsModEditor::EditorEvents::AssetReloadEvent::Trigger(asset_id); + } + } + ImGui::EndCombo(); + } + + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + ImGui::Text("Mip Filter Mode"); + ImGui::TableNextColumn(); + if (ImGui::BeginCombo("##MipFilterMode", + fmt::to_string(render_target_data->m_sampler.tm0.mipmap_filter).c_str())) + { + for (auto e = FilterMode::Near; e <= FilterMode::Linear; + e = static_cast(static_cast(e) + 1)) + { + const bool is_selected = render_target_data->m_sampler.tm0.mipmap_filter == e; + if (ImGui::Selectable(fmt::to_string(e).c_str(), is_selected)) + { + render_target_data->m_sampler.tm0.mipmap_filter = e; + *last_data_write = std::chrono::system_clock::now(); + GraphicsModEditor::EditorEvents::AssetReloadEvent::Trigger(asset_id); + } + } + ImGui::EndCombo(); + } + + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + ImGui::Text("U Wrap Mode"); + ImGui::TableNextColumn(); + if (ImGui::BeginCombo("##UWrapMode", + fmt::to_string(render_target_data->m_sampler.tm0.wrap_u).c_str())) + { + for (auto e = WrapMode::Clamp; e <= WrapMode::Mirror; + e = static_cast(static_cast(e) + 1)) + { + const bool is_selected = render_target_data->m_sampler.tm0.wrap_u == e; + if (ImGui::Selectable(fmt::to_string(e).c_str(), is_selected)) + { + render_target_data->m_sampler.tm0.wrap_u = e; + *last_data_write = std::chrono::system_clock::now(); + GraphicsModEditor::EditorEvents::AssetReloadEvent::Trigger(asset_id); + } + } + ImGui::EndCombo(); + } + + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + ImGui::Text("V Wrap Mode"); + ImGui::TableNextColumn(); + if (ImGui::BeginCombo("##VWrapMode", + fmt::to_string(render_target_data->m_sampler.tm0.wrap_v).c_str())) + { + for (auto e = WrapMode::Clamp; e <= WrapMode::Mirror; + e = static_cast(static_cast(e) + 1)) + { + const bool is_selected = render_target_data->m_sampler.tm0.wrap_v == e; + if (ImGui::Selectable(fmt::to_string(e).c_str(), is_selected)) + { + render_target_data->m_sampler.tm0.wrap_v = e; + *last_data_write = std::chrono::system_clock::now(); + GraphicsModEditor::EditorEvents::AssetReloadEvent::Trigger(asset_id); + } + } + ImGui::EndCombo(); + } + ImGui::EndTable(); + + if (texture_preview) + { + const auto ratio = texture_preview->GetWidth() / texture_preview->GetHeight(); + ImGui::Image(*texture_preview, ImVec2{ImGui::GetContentRegionAvail().x, + ImGui::GetContentRegionAvail().x * ratio}); + } + } +} +} // namespace GraphicsModEditor::Controls diff --git a/Source/Core/VideoCommon/GraphicsModEditor/Controls/RenderTargetControl.h b/Source/Core/VideoCommon/GraphicsModEditor/Controls/RenderTargetControl.h new file mode 100644 index 0000000000..dcbe2c0e8d --- /dev/null +++ b/Source/Core/VideoCommon/GraphicsModEditor/Controls/RenderTargetControl.h @@ -0,0 +1,32 @@ +// Copyright 2025 Dolphin Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include + +#include "VideoCommon/Assets/CustomAsset.h" +#include "VideoCommon/GraphicsModEditor/EditorState.h" + +namespace VideoCommon +{ +class AbstractTexture; +struct RenderTargetData; +} // namespace VideoCommon + +namespace GraphicsModEditor::Controls +{ +class RenderTargetControl +{ +public: + explicit RenderTargetControl(EditorState& state); + void DrawImGui(const VideoCommon::CustomAssetLibrary::AssetID& asset_id, + VideoCommon::RenderTargetData* render_target_data, + const std::filesystem::path& path, + VideoCommon::CustomAssetLibrary::TimeType* last_data_write, + AbstractTexture* texture_preview); + +private: + EditorState& m_state; +}; +} // namespace GraphicsModEditor::Controls