summaryrefslogtreecommitdiffstatshomepage
path: root/src/osd/modules/render/bgfx/effect.cpp
diff options
context:
space:
mode:
author ImJezze <jezze@gmx.net>2016-02-21 14:50:24 +0100
committer ImJezze <jezze@gmx.net>2016-02-21 14:50:24 +0100
commitbf4640c309c655c6cb7bc5b9bbab5c03029ccd86 (patch)
treec50f6f204d34c7a1888ab41cdf6c5250ffe7b8af /src/osd/modules/render/bgfx/effect.cpp
parentcc24a339d8c0517259084b5c178d784626ba965c (diff)
parenta0ba40749d98488dafb84d365e4a6e44a4c01f84 (diff)
Merge remote-tracking branch 'refs/remotes/mamedev/master'
Resolved Conflicts: - src/osd/modules/render/d3d/d3dhlsl.cpp - src/osd/modules/render/d3d/d3dhlsl.h - src/osd/modules/render/drawd3d.cpp - src/osd/modules/render/drawd3d.h - src/osd/windows/winmain.cpp
Diffstat (limited to 'src/osd/modules/render/bgfx/effect.cpp')
-rw-r--r--src/osd/modules/render/bgfx/effect.cpp52
1 files changed, 52 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..bf6ccb963c5
--- /dev/null
+++ b/src/osd/modules/render/bgfx/effect.cpp
@@ -0,0 +1,52 @@
+// license:BSD-3-Clause
+// copyright-holders:Ryan Holtz
+//============================================================
+//
+// effect.cpp - BGFX shader material to be applied to a mesh
+//
+//============================================================
+
+#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