summaryrefslogtreecommitdiffstatshomepage
path: root/src/osd/modules/render/bgfx/effect.cpp
diff options
context:
space:
mode:
author therealmogminer@gmail.com <therealmogminer@gmail.com>2016-02-18 15:57:34 +0100
committer therealmogminer@gmail.com <therealmogminer@gmail.com>2016-02-21 03:03:23 +0100
commit9a47a870df619656e9092f2f77622e84e640307a (patch)
treeb8640bf79ffb55d0c9ed6fc27bbd4ce16a5e1a2e /src/osd/modules/render/bgfx/effect.cpp
parentdadf8e7d79696996ab3ef840fe99a588ede538fa (diff)
First take on render API reorg, nw
Diffstat (limited to 'src/osd/modules/render/bgfx/effect.cpp')
-rw-r--r--src/osd/modules/render/bgfx/effect.cpp44
1 files changed, 44 insertions, 0 deletions
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<bgfx_uniform*> 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<std::string, bgfx_uniform*> uniform : m_uniforms)
+ {
+ delete uniform.second;
+ }
+ m_uniforms.clear();
+ bgfx::destroyProgram(m_program_handle);
+}
+
+void bgfx_effect::submit(int view)
+{
+ for (std::pair<std::string, bgfx_uniform*> 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<std::string, bgfx_uniform*>::iterator iter = m_uniforms.find(name);
+
+ if (iter != m_uniforms.end())
+ {
+ return iter->second;
+ }
+
+ return nullptr;
+} \ No newline at end of file