diff options
Diffstat (limited to 'src/osd/modules/render/bgfx/effect.cpp')
-rw-r--r-- | src/osd/modules/render/bgfx/effect.cpp | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/src/osd/modules/render/bgfx/effect.cpp b/src/osd/modules/render/bgfx/effect.cpp index fb3d7d933ba..18b43cca9bf 100644 --- a/src/osd/modules/render/bgfx/effect.cpp +++ b/src/osd/modules/render/bgfx/effect.cpp @@ -11,52 +11,52 @@ #include "uniform.h" #include "modules/osdmodule.h" +#include "osdcore.h" -bgfx_effect::bgfx_effect(uint64_t state, bgfx::ShaderHandle vertex_shader, bgfx::ShaderHandle fragment_shader, std::vector<bgfx_uniform*> uniforms) - : m_state(state) +#include <utility> + + +bgfx_effect::bgfx_effect(std::string &&name, uint64_t state, bgfx::ShaderHandle vertex_shader, bgfx::ShaderHandle fragment_shader, std::vector<std::unique_ptr<bgfx_uniform> > &uniforms) + : m_name(std::move(name)) + , m_state(state) { m_program_handle = bgfx::createProgram(vertex_shader, fragment_shader, false); - for (int i = 0; i < uniforms.size(); i++) + for (auto &uniform : uniforms) { - if (m_uniforms[uniforms[i]->name()] != nullptr) + const auto existing = m_uniforms.find(uniform->name()); + if (existing != m_uniforms.end()) { - osd_printf_verbose("Uniform %s appears to be duplicated in one or more effects, please double-check the effect JSON files.\n", uniforms[i]->name().c_str()); - delete uniforms[i]; + osd_printf_verbose("Uniform %s appears to be duplicated in one or more effects, please double-check the effect JSON files.\n", uniform->name()); + uniform.reset(); continue; } - m_uniforms[uniforms[i]->name()] = uniforms[i]; + uniform->create(); + m_uniforms.emplace(uniform->name(), std::move(uniform)); } } bgfx_effect::~bgfx_effect() { - for (std::pair<std::string, bgfx_uniform*> uniform : m_uniforms) - { - delete uniform.second; - } m_uniforms.clear(); bgfx::destroy(m_program_handle); } void bgfx_effect::submit(int view, uint64_t blend) { - for (std::pair<std::string, bgfx_uniform*> uniform_pair : m_uniforms) + for (auto &[name, uniform] : m_uniforms) { - (uniform_pair.second)->upload(); + uniform->upload(); } - bgfx::setState(m_state | blend); + + const uint64_t final_state = (blend != ~0ULL) ? ((m_state & ~BGFX_STATE_BLEND_MASK) | blend) : m_state; + + bgfx::setState(final_state); bgfx::submit(view, m_program_handle); } -bgfx_uniform* bgfx_effect::uniform(std::string name) +bgfx_uniform* bgfx_effect::uniform(const std::string &name) { - std::map<std::string, bgfx_uniform*>::iterator iter = m_uniforms.find(name); - - if (iter != m_uniforms.end()) - { - return iter->second; - } - - return nullptr; + const auto iter = m_uniforms.find(name); + return (iter != m_uniforms.end()) ? iter->second.get() : nullptr; } |