From 9a47a870df619656e9092f2f77622e84e640307a Mon Sep 17 00:00:00 2001 From: "therealmogminer@gmail.com" Date: Thu, 18 Feb 2016 15:57:34 +0100 Subject: First take on render API reorg, nw --- src/osd/modules/render/bgfx/effect.cpp | 44 ++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/osd/modules/render/bgfx/effect.cpp (limited to 'src/osd/modules/render/bgfx/effect.cpp') diff --git a/src/osd/modules/render/bgfx/effect.cpp b/src/osd/modules/render/bgfx/effect.cpp new file mode 100644 index 00000000000..76092fd13f9 --- /dev/null +++ b/src/osd/modules/render/bgfx/effect.cpp @@ -0,0 +1,44 @@ +#include "effect.h" + +bgfx_effect::bgfx_effect(uint64_t state, bgfx::ShaderHandle vertex_shader, bgfx::ShaderHandle fragment_shader, std::vector uniforms) + : m_state(state) +{ + m_program_handle = bgfx::createProgram(vertex_shader, fragment_shader, false); + + for (int i = 0; i < uniforms.size(); i++) + { + m_uniforms[uniforms[i]->name()] = uniforms[i]; + } +} + +bgfx_effect::~bgfx_effect() +{ + for (std::pair uniform : m_uniforms) + { + delete uniform.second; + } + m_uniforms.clear(); + bgfx::destroyProgram(m_program_handle); +} + +void bgfx_effect::submit(int view) +{ + for (std::pair uniform_pair : m_uniforms) + { + (uniform_pair.second)->upload(); + } + bgfx::setState(m_state); + bgfx::submit(view, m_program_handle); +} + +bgfx_uniform* bgfx_effect::uniform(std::string name) +{ + std::map::iterator iter = m_uniforms.find(name); + + if (iter != m_uniforms.end()) + { + return iter->second; + } + + return nullptr; +} \ No newline at end of file -- cgit v1.2.3-70-g09d2