summaryrefslogtreecommitdiffstatshomepage
path: root/src/osd/modules/render/bgfx/inputpair.cpp
diff options
context:
space:
mode:
author ImJezze <jezze@gmx.net>2016-04-24 20:36:42 +0200
committer ImJezze <jezze@gmx.net>2016-04-24 20:36:42 +0200
commit07d8b25571860897fdad90c0c215b3e949f96ea9 (patch)
treeec378412f51fd296d87162871bdbdbe8926b9d71 /src/osd/modules/render/bgfx/inputpair.cpp
parent29f51e85db4572febadf40956e2808f5444d2135 (diff)
Added "selection" parameter to chain input sampler
- if specified all textures (.png) within the same directoy of the given texture will be selectable via slider in the UI - also added slider for "shadow mask tile mode" to HLSL chain
Diffstat (limited to 'src/osd/modules/render/bgfx/inputpair.cpp')
-rw-r--r--src/osd/modules/render/bgfx/inputpair.cpp109
1 files changed, 103 insertions, 6 deletions
diff --git a/src/osd/modules/render/bgfx/inputpair.cpp b/src/osd/modules/render/bgfx/inputpair.cpp
index d8777257187..4de54404a6b 100644
--- a/src/osd/modules/render/bgfx/inputpair.cpp
+++ b/src/osd/modules/render/bgfx/inputpair.cpp
@@ -9,29 +9,42 @@
//
//============================================================
+#include "ui/uimain.h"
+
#include "emucore.h"
#include "inputpair.h"
#include "texture.h"
#include "target.h"
#include "effect.h"
+#include "render.h"
#include "uniform.h"
-#include "texturemanager.h"
-#include "targetmanager.h"
+#include "chainmanager.h"
+#include "slider.h"
+#include "sliderdirtynotifier.h"
-bgfx_input_pair::bgfx_input_pair(int index, std::string sampler, std::string texture)
+bgfx_input_pair::bgfx_input_pair(int index, std::string sampler, std::string texture, std::vector<std::string> available_textures, std::string selection, chain_manager& chains, uint32_t screen_index)
: m_index(index)
, m_sampler(sampler)
, m_texture(texture)
+ , m_available_textures(available_textures)
+ , m_selection(selection)
+ , m_chains(chains)
{
+ if (m_available_textures.size() > 0)
+ {
+ m_current_texture = std::find(m_available_textures.begin(), m_available_textures.end(), m_texture) - m_available_textures.begin();
+
+ create_selection_slider(screen_index);
+ }
}
-void bgfx_input_pair::bind(bgfx_effect *effect, target_manager& targets, texture_manager& textures, const int32_t screen) const
+void bgfx_input_pair::bind(bgfx_effect *effect, const int32_t screen) const
{
assert(effect->uniform(m_sampler) != nullptr);
std::string name = m_texture + std::to_string(screen);
- bgfx_texture_handle_provider* provider = textures.provider(name);
+ bgfx_texture_handle_provider* provider = chains().textures().provider(name);
bgfx_uniform *tex_size = effect->uniform("u_tex_size" + std::to_string(m_index));
if (tex_size != nullptr)
{
@@ -39,5 +52,89 @@ void bgfx_input_pair::bind(bgfx_effect *effect, target_manager& targets, texture
tex_size->set(values, sizeof(float) * 2);
}
- bgfx::setTexture(m_index, effect->uniform(m_sampler)->handle(), textures.handle(name));
+ bgfx::setTexture(m_index, effect->uniform(m_sampler)->handle(), chains().textures().handle(name));
+}
+
+static INT32 update_trampoline(running_machine &machine, void *arg, int id, std::string *str, INT32 newval)
+{
+ if (arg != nullptr)
+ {
+ return reinterpret_cast<bgfx_input_pair*>(arg)->texture_changed(id, str, newval);
+ }
+ return 0;
+}
+
+int32_t bgfx_input_pair::texture_changed(int32_t id, std::string *str, int32_t newval)
+{
+ if (newval != SLIDER_NOCHANGE)
+ {
+ m_current_texture = newval;
+ m_texture = m_available_textures[m_current_texture];
+
+ chains().slider_notifier().set_sliders_dirty();
+ }
+
+ if (str != nullptr)
+ {
+ std::string file = m_texture;
+ const size_t last_slash = m_texture.rfind('/');
+ if (last_slash != std::string::npos)
+ {
+ file = m_texture.substr(last_slash + 1, m_texture.length() - (last_slash + 1));
+ }
+
+ std::string file_name;
+ const size_t last_dot = file.rfind('.');
+ if (last_dot != std::string::npos)
+ {
+ file_name = file.substr(0, last_dot);
+ }
+
+ *str = string_format("%s", file_name.c_str());
+ }
+
+ return m_current_texture;
+}
+
+void bgfx_input_pair::create_selection_slider(uint32_t screen_index)
+{
+ std::string description = "Window " + std::to_string(chains().window_index()) + ", Screen " + std::to_string(screen_index) + " " + m_selection + ":";
+ size_t size = sizeof(slider_state) + description.length();
+ slider_state *state = reinterpret_cast<slider_state *>(auto_alloc_array_clear(chains().machine(), UINT8, size));
+
+ state->minval = 0;
+ state->defval = m_current_texture;
+ state->maxval = m_available_textures.size() - 1;
+ state->incval = 1;
+ state->update = update_trampoline;
+ state->arg = this;
+ state->id = screen_index;
+ strcpy(state->description, description.c_str());
+
+ ui_menu_item item;
+ item.text = state->description;
+ item.subtext = "";
+ item.flags = 0;
+ item.ref = state;
+ item.type = ui_menu_item_type::SLIDER;
+ m_selection_slider = item;
+}
+
+bool bgfx_input_pair::needs_sliders()
+{
+ return chains().screen_count() > 0 && m_available_textures.size() > 1;
+}
+
+std::vector<ui_menu_item> bgfx_input_pair::get_slider_list()
+{
+ std::vector<ui_menu_item> sliders;
+
+ if (!needs_sliders())
+ {
+ return sliders;
+ }
+
+ sliders.push_back(m_selection_slider);
+
+ return sliders;
}