summaryrefslogtreecommitdiff
path: root/Source/Core/VideoCommon/GraphicsModSystem/Runtime/Actions/CustomPipelineAction.cpp
blob: 35c8ce0a2599fa80552724bdfbade81c950bdadf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright 2022 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#include "VideoCommon/GraphicsModSystem/Runtime/Actions/CustomPipelineAction.h"

#include "Common/JsonUtil.h"
#include "Common/Logging/Log.h"
#include "Core/System.h"

#include "VideoCommon/Resources/CustomResourceManager.h"

std::unique_ptr<CustomPipelineAction>
CustomPipelineAction::Create(std::shared_ptr<VideoCommon::CustomAssetLibrary> library)
{
  return std::make_unique<CustomPipelineAction>(std::move(library));
}

std::unique_ptr<CustomPipelineAction>
CustomPipelineAction::Create(const picojson::value& json_data,
                             std::shared_ptr<VideoCommon::CustomAssetLibrary> library)
{
  auto material_asset = ReadStringFromJson(json_data.get<picojson::object>(), "material_asset");

  if (!material_asset)
  {
    ERROR_LOG_FMT(VIDEO,
                  "Failed to load custom pipeline action, 'material_asset' does not have a value");
    return nullptr;
  }

  return std::make_unique<CustomPipelineAction>(std::move(library), std::move(*material_asset));
}

CustomPipelineAction::CustomPipelineAction(std::shared_ptr<VideoCommon::CustomAssetLibrary> library)
    : m_library(std::move(library))
{
}

CustomPipelineAction::CustomPipelineAction(std::shared_ptr<VideoCommon::CustomAssetLibrary> library,
                                           std::string material_asset)
    : m_library(std::move(library)), m_material_asset(std::move(material_asset))
{
}

void CustomPipelineAction::OnDrawStarted(GraphicsModActionData::DrawStarted*)
{
  // TODO
}

void CustomPipelineAction::AfterEFB(GraphicsModActionData::PostEFB* post_efb)
{
  if (!post_efb) [[unlikely]]
    return;

  if (m_material_asset.empty())
    return;

  auto& resource_manager = Core::System::GetInstance().GetCustomResourceManager();
  post_efb->material =
      resource_manager.GetPostProcessingMaterialFromAsset(m_material_asset, m_library);
}