summaryrefslogtreecommitdiffstatshomepage
path: root/src/osd/modules/render/bgfx/effectmanager.cpp
diff options
context:
space:
mode:
author MooglyGuy <MooglyGuy@users.noreply.github.com>2022-03-16 03:32:33 +0100
committer GitHub <noreply@github.com>2022-03-15 22:32:33 -0400
commit92ece92fedb15efa82a12901bc343b46a0f06905 (patch)
treedc16d467c041bb86470b409111d156ef803b73d3 /src/osd/modules/render/bgfx/effectmanager.cpp
parent8d267ad2c7d3e757bf47d05ce816e060e37de401 (diff)
Updated BGFX fixes; verified as working on Linux and Windows. (#9420)
* -bgfx: Improved stability when encountering missing files, and improved multi-window stability. [Ryan Holtz] * -osd: Added video-init fallback functionality to other OSDs. [Ryan Holtz] * -bgfx: Fixed issues from the previous batch of changes. [Ryan Holtz] * -osdwindow: Remove no-longer-needed addition of post_create(). [Ryan Holtz]
Diffstat (limited to 'src/osd/modules/render/bgfx/effectmanager.cpp')
-rw-r--r--src/osd/modules/render/bgfx/effectmanager.cpp96
1 files changed, 59 insertions, 37 deletions
diff --git a/src/osd/modules/render/bgfx/effectmanager.cpp b/src/osd/modules/render/bgfx/effectmanager.cpp
index 6462ae75f72..98bc9a72097 100644
--- a/src/osd/modules/render/bgfx/effectmanager.cpp
+++ b/src/osd/modules/render/bgfx/effectmanager.cpp
@@ -23,68 +23,79 @@
#include "effectreader.h"
#include "effect.h"
-using namespace rapidjson;
-
-effect_manager::~effect_manager()
-{
- for (std::pair<std::string, bgfx_effect*> effect : m_effects)
- {
- delete effect.second;
- }
- m_effects.clear();
-}
-
-bgfx_effect* effect_manager::effect(std::string name)
-{
- std::map<std::string, bgfx_effect*>::iterator iter = m_effects.find(name);
- if (iter != m_effects.end())
- {
- return iter->second;
- }
-
- return load_effect(name);
-}
-
-bgfx_effect* effect_manager::load_effect(std::string name)
+static bool prepare_effect_document(std::string &name, osd_options &options, rapidjson::Document &document)
{
std::string full_name = name;
- if (full_name.length() < 5 || (full_name.compare(full_name.length() - 5, 5, ".json") != 0)) {
+ if (full_name.length() < 5 || (full_name.compare(full_name.length() - 5, 5, ".json") != 0))
+ {
full_name = full_name + ".json";
}
+
std::string path;
- osd_subst_env(path, util::string_format("%s" PATH_SEPARATOR "effects" PATH_SEPARATOR, m_options.bgfx_path()));
+ osd_subst_env(path, util::string_format("%s" PATH_SEPARATOR "effects" PATH_SEPARATOR, options.bgfx_path()));
path += full_name;
bx::FileReader reader;
if (!bx::open(&reader, path.c_str()))
{
- printf("Unable to open effect file %s\n", path.c_str());
- return nullptr;
+ osd_printf_error("Unable to open effect file %s\n", path.c_str());
+ return false;
}
int32_t size (bx::getSize(&reader));
-
char* data = new char[size + 1];
bx::read(&reader, reinterpret_cast<void*>(data), size);
bx::close(&reader);
data[size] = 0;
- Document document;
- document.Parse<kParseCommentsFlag>(data);
+ document.Parse<rapidjson::kParseCommentsFlag>(data);
delete [] data;
- if (document.HasParseError()) {
- std::string error(GetParseError_En(document.GetParseError()));
- printf("Unable to parse effect %s. Errors returned:\n", path.c_str());
- printf("%s\n", error.c_str());
+ if (document.HasParseError())
+ {
+ std::string error(rapidjson::GetParseError_En(document.GetParseError()));
+ osd_printf_error("Unable to parse effect %s. Errors returned:\n", path.c_str());
+ osd_printf_error("%s\n", error.c_str());
+ return false;
+ }
+
+ return true;
+}
+
+effect_manager::~effect_manager()
+{
+ for (std::pair<std::string, bgfx_effect*> effect : m_effects)
+ {
+ delete effect.second;
+ }
+ m_effects.clear();
+}
+
+bgfx_effect* effect_manager::get_or_load_effect(osd_options &options, std::string name)
+{
+ std::map<std::string, bgfx_effect*>::iterator iter = m_effects.find(name);
+ if (iter != m_effects.end())
+ {
+ return iter->second;
+ }
+
+ return load_effect(options, name);
+}
+
+bgfx_effect* effect_manager::load_effect(osd_options &options, std::string name)
+{
+ rapidjson::Document document;
+ if (!prepare_effect_document(name, options, document))
+ {
return nullptr;
}
- bgfx_effect* effect = effect_reader::read_from_value(document, "Effect '" + name + "': ", m_shaders);
+ bgfx_effect* effect = effect_reader::read_from_value(document, "Effect '" + name + "': ", options, m_shaders);
- if (effect == nullptr) {
- printf("Unable to load effect %s\n", path.c_str());
+ if (effect == nullptr)
+ {
+ osd_printf_error("Unable to load effect %s\n", name.c_str());
return nullptr;
}
@@ -92,3 +103,14 @@ bgfx_effect* effect_manager::load_effect(std::string name)
return effect;
}
+
+bool effect_manager::validate_effect(osd_options &options, std::string name)
+{
+ rapidjson::Document document;
+ if (!prepare_effect_document(name, options, document))
+ {
+ return false;
+ }
+
+ return effect_reader::validate_value(document, "Effect '" + name + "': ", options);
+}
t'>| * Fixed another warning, a full compile now completes with GCC 13.1. [R. Belmont] arbee2023-04-291-0/+1 | * Support GCC 13.1 / Fedora 38 [R. Belmont] arbee2023-04-291-0/+9 | * -Lua engine: run everything in coroutines. (#11019) Vas Crabb2023-03-251-1/+1 | | | | | | | | | * This lets you use emu.wait(...) directly without mucking around creating coroutines. * Allow emu.wait to accept an attotime argument. * Added a couple more wait helper functions. -emu/profiler.h: Actually use scope-based profiling helpers. * This makes the comment at the top of emu/profile.h less dishonest, and makes it easier to write exception-safe code. * Got rid of some do { ... } while (0) loops that only existed so break could be used like a goto. * Removed local copy of SDL source and update Android build support. (#10899) Miodrag Milanović2023-02-271-37/+2 | | | | | | | | | * Removed SDL2 source. * Updated gradle. * Updated SDL2 Java support glue code. * Increased minimum supported Android API version to 24. * Updated required asset files for Android app. * Added proper tag for Android logging. * Added SDL2 hint to make BGFX work on Android. * Use EQUIVALENT_ARRAY to avoid issues with std::size on member arrays, enable ↵ Vas Crabb2023-02-011-0/+1 | | | | warnings for VLAs in C++. * Fail earlier in the build process if SOURCES= specifies no files containing ↵ Vas Crabb2022-07-071-2/+12 | | | | system definitions * genie: Explicitly set LinkSupportCircularDependencies for NetBSD. (#10020)