Skip to content

Commit

Permalink
VideoCommon: add graphics mod callback interface for when a texture i…
Browse files Browse the repository at this point in the history
…s created
  • Loading branch information
iwubcode committed Jun 21, 2023
1 parent 5ad2d86 commit 1d767c3
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,16 @@ std::optional<GraphicsTargetConfig> DeserializeTargetFromConfig(const picojson::
target.m_texture_info_string = texture_info.value();
return target;
}
else if (type == "create_texture")
{
std::optional<std::string> texture_info = ExtractTextureFilenameForConfig(obj);
if (!texture_info.has_value())
return std::nullopt;

CreateTextureTarget target;
target.m_texture_info_string = texture_info.value();
return target;
}
else if (type == "efb")
{
return DeserializeFBTargetFromConfig<EFBTarget>(obj, EFB_DUMP_PREFIX);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ struct LoadTextureTarget final : public TextureTarget
{
};

struct CreateTextureTarget final : public TextureTarget
{
};

struct FBTarget
{
u32 m_height = 0;
Expand All @@ -47,8 +51,9 @@ struct ProjectionTarget
ProjectionType m_projection_type = ProjectionType::Perspective;
};

using GraphicsTargetConfig = std::variant<DrawStartedTextureTarget, LoadTextureTarget, EFBTarget,
XFBTarget, ProjectionTarget>;
using GraphicsTargetConfig =
std::variant<DrawStartedTextureTarget, LoadTextureTarget, CreateTextureTarget, EFBTarget,
XFBTarget, ProjectionTarget>;

std::optional<GraphicsTargetConfig> DeserializeTargetFromConfig(const picojson::object& obj);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ class GraphicsModAction
virtual void OnProjection(GraphicsModActionData::Projection*) {}
virtual void OnProjectionAndTexture(GraphicsModActionData::Projection*) {}
virtual void OnTextureLoad(GraphicsModActionData::TextureLoad*) {}
virtual void OnTextureCreate(GraphicsModActionData::TextureCreate*) {}
virtual void OnFrameEnd() {}
};
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,7 @@ struct TextureLoad
{
std::string_view texture_name;
};
struct TextureCreate
{
};
} // namespace GraphicsModActionData
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ class GraphicsModManager::DecoratedAction final : public GraphicsModAction
return;
m_action_impl->OnTextureLoad(texture_load);
}
void OnTextureCreate(GraphicsModActionData::TextureCreate* texture_create) override
{
if (!m_mod.m_enabled)
return;
m_action_impl->OnTextureCreate(texture_create);
}
void OnFrameEnd() override
{
if (!m_mod.m_enabled)
Expand Down Expand Up @@ -143,6 +149,18 @@ GraphicsModManager::GetTextureLoadActions(const std::string& texture_name) const
return m_default;
}

const std::vector<GraphicsModAction*>&
GraphicsModManager::GetTextureCreateActions(const std::string& texture_name) const
{
if (const auto it = m_create_texture_target_to_actions.find(texture_name);
it != m_create_texture_target_to_actions.end())
{
return it->second;
}

return m_default;
}

const std::vector<GraphicsModAction*>& GraphicsModManager::GetEFBActions(const FBInfo& efb) const
{
if (const auto it = m_efb_target_to_actions.find(efb); it != m_efb_target_to_actions.end())
Expand Down Expand Up @@ -223,6 +241,10 @@ void GraphicsModManager::Load(const GraphicsModGroupConfig& config)
m_load_texture_target_to_actions[the_target.m_texture_info_string].push_back(
m_actions.back().get());
},
[&](const CreateTextureTarget& the_target) {
m_create_texture_target_to_actions[the_target.m_texture_info_string].push_back(
m_actions.back().get());
},
[&](const EFBTarget& the_target) {
FBInfo info;
info.m_height = the_target.m_height;
Expand Down Expand Up @@ -315,6 +337,7 @@ void GraphicsModManager::Reset()
m_projection_texture_target_to_actions.clear();
m_draw_started_target_to_actions.clear();
m_load_texture_target_to_actions.clear();
m_create_texture_target_to_actions.clear();
m_efb_target_to_actions.clear();
m_xfb_target_to_actions.clear();
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class GraphicsModManager
GetDrawStartedActions(const std::string& texture_name) const;
const std::vector<GraphicsModAction*>&
GetTextureLoadActions(const std::string& texture_name) const;
const std::vector<GraphicsModAction*>&
GetTextureCreateActions(const std::string& texture_name) const;
const std::vector<GraphicsModAction*>& GetEFBActions(const FBInfo& efb) const;
const std::vector<GraphicsModAction*>& GetXFBActions(const FBInfo& xfb) const;

Expand All @@ -49,6 +51,8 @@ class GraphicsModManager
m_projection_texture_target_to_actions;
std::unordered_map<std::string, std::vector<GraphicsModAction*>> m_draw_started_target_to_actions;
std::unordered_map<std::string, std::vector<GraphicsModAction*>> m_load_texture_target_to_actions;
std::unordered_map<std::string, std::vector<GraphicsModAction*>>
m_create_texture_target_to_actions;
std::unordered_map<FBInfo, std::vector<GraphicsModAction*>, FBInfoHasher> m_efb_target_to_actions;
std::unordered_map<FBInfo, std::vector<GraphicsModAction*>, FBInfoHasher> m_xfb_target_to_actions;

Expand Down

0 comments on commit 1d767c3

Please sign in to comment.