summaryrefslogtreecommitdiffstatshomepage
path: root/src/osd/modules/render/bgfx/uniform.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/uniform.cpp
parentdadf8e7d79696996ab3ef840fe99a588ede538fa (diff)
First take on render API reorg, nw
Diffstat (limited to 'src/osd/modules/render/bgfx/uniform.cpp')
-rw-r--r--src/osd/modules/render/bgfx/uniform.cpp72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/osd/modules/render/bgfx/uniform.cpp b/src/osd/modules/render/bgfx/uniform.cpp
new file mode 100644
index 00000000000..a0ee1d174da
--- /dev/null
+++ b/src/osd/modules/render/bgfx/uniform.cpp
@@ -0,0 +1,72 @@
+#include "uniform.h"
+
+bgfx_uniform::bgfx_uniform(std::string name, bgfx::UniformType::Enum type)
+ : m_name(name)
+ , m_type(type)
+{
+ m_handle = bgfx::createUniform(m_name.c_str(), m_type);
+ m_data_size = get_size_for_type(type);
+ if (m_data_size > 0)
+ {
+ m_data = new uint8_t[m_data_size];
+ }
+}
+
+bgfx_uniform::~bgfx_uniform()
+{
+ bgfx::destroyUniform(m_handle);
+ delete [] m_data;
+}
+
+void bgfx_uniform::upload()
+{
+ bgfx::setUniform(m_handle, m_data);
+}
+
+bgfx_uniform* bgfx_uniform::set(float* value)
+{
+ return set(value, get_size_for_type(bgfx::UniformType::Vec4));
+}
+
+bgfx_uniform* bgfx_uniform::set_int(int value)
+{
+ return set(&value, get_size_for_type(bgfx::UniformType::Int1));
+}
+
+bgfx_uniform* bgfx_uniform::set_mat3(float* value)
+{
+ return set(value, get_size_for_type(bgfx::UniformType::Mat3));
+}
+
+bgfx_uniform* bgfx_uniform::set_mat4(float* value)
+{
+ return set(value, get_size_for_type(bgfx::UniformType::Mat4));
+}
+
+bgfx_uniform* bgfx_uniform::set(void* data, size_t size)
+{
+ int min_size = (size < m_data_size) ? size : m_data_size;
+ memcpy(m_data, data, min_size);
+ return this;
+}
+
+size_t bgfx_uniform::get_size_for_type(bgfx::UniformType::Enum type)
+{
+ switch (type)
+ {
+ case bgfx::UniformType::Vec4:
+ return sizeof(float) * 4;
+
+ case bgfx::UniformType::Int1:
+ return sizeof(int);
+
+ case bgfx::UniformType::Mat3:
+ return sizeof(float) * 3 * 3;
+
+ case bgfx::UniformType::Mat4:
+ return sizeof(float) * 4 * 4;
+
+ default:
+ return 0;
+ }
+} \ No newline at end of file