From 733bae981f4f9bf2b9c9785b0fc95b3813ca3c4a Mon Sep 17 00:00:00 2001 From: iwubcode Date: Fri, 28 Feb 2025 00:23:31 -0600 Subject: [PATCH] VideoCommon: add render target asset --- .../VideoCommon/Assets/RenderTargetAsset.cpp | 43 +++++++++++++++++++ .../VideoCommon/Assets/RenderTargetAsset.h | 31 +++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 Source/Core/VideoCommon/Assets/RenderTargetAsset.cpp create mode 100644 Source/Core/VideoCommon/Assets/RenderTargetAsset.h diff --git a/Source/Core/VideoCommon/Assets/RenderTargetAsset.cpp b/Source/Core/VideoCommon/Assets/RenderTargetAsset.cpp new file mode 100644 index 0000000000..149af22ba3 --- /dev/null +++ b/Source/Core/VideoCommon/Assets/RenderTargetAsset.cpp @@ -0,0 +1,43 @@ +// Copyright 2025 Dolphin Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "VideoCommon/Assets/RenderTargetAsset.h" + +#include "Common/EnumUtils.h" +#include "Common/JsonUtil.h" +#include "Common/Logging/Log.h" + +namespace VideoCommon +{ +bool RenderTargetData::FromJson(const CustomAssetLibrary::AssetID& asset_id, + const picojson::object& json, RenderTargetData* data) +{ + data->m_texture_format = AbstractTextureFormat::RGBA8; + // TODO: parse format + return true; +} + +void RenderTargetData::ToJson(picojson::object* obj, const RenderTargetData& data) +{ + if (!obj) [[unlikely]] + return; + + auto& json_obj = *obj; + json_obj.emplace("format", static_cast(data.m_texture_format)); +} + +CustomAssetLibrary::LoadInfo +RenderTargetAsset::LoadImpl(const CustomAssetLibrary::AssetID& asset_id) +{ + auto potential_data = std::make_shared(); + const auto loaded_info = m_owning_library->LoadRenderTarget(asset_id, potential_data.get()); + if (loaded_info.m_bytes_loaded == 0) + return {}; + { + std::lock_guard lk(m_data_lock); + m_loaded = true; + m_data = std::move(potential_data); + } + return loaded_info; +} +} // namespace VideoCommon diff --git a/Source/Core/VideoCommon/Assets/RenderTargetAsset.h b/Source/Core/VideoCommon/Assets/RenderTargetAsset.h new file mode 100644 index 0000000000..94a28e354b --- /dev/null +++ b/Source/Core/VideoCommon/Assets/RenderTargetAsset.h @@ -0,0 +1,31 @@ +// Copyright 2025 Dolphin Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include + +#include "VideoCommon/Assets/CustomAsset.h" +#include "VideoCommon/RenderState.h" +#include "VideoCommon/TextureConfig.h" + +namespace VideoCommon +{ +struct RenderTargetData +{ + static bool FromJson(const CustomAssetLibrary::AssetID& asset_id, const picojson::object& json, + RenderTargetData* data); + static void ToJson(picojson::object* obj, const RenderTargetData& data); + AbstractTextureFormat m_texture_format; + SamplerState m_sampler; +}; + +class RenderTargetAsset final : public CustomLoadableAsset +{ +public: + using CustomLoadableAsset::CustomLoadableAsset; + +private: + CustomAssetLibrary::LoadInfo LoadImpl(const CustomAssetLibrary::AssetID& asset_id) override; +}; +} // namespace VideoCommon