summaryrefslogtreecommitdiffstatshomepage
path: root/src/osd/modules/render/bgfx/inputpair.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/osd/modules/render/bgfx/inputpair.cpp')
-rw-r--r--src/osd/modules/render/bgfx/inputpair.cpp87
1 files changed, 49 insertions, 38 deletions
diff --git a/src/osd/modules/render/bgfx/inputpair.cpp b/src/osd/modules/render/bgfx/inputpair.cpp
index 98d0594e27a..154252db04f 100644
--- a/src/osd/modules/render/bgfx/inputpair.cpp
+++ b/src/osd/modules/render/bgfx/inputpair.cpp
@@ -9,20 +9,20 @@
//
//============================================================
-#include "emu.h"
-#include "../frontend/mame/ui/slider.h"
-
-#include "emucore.h"
-
#include "inputpair.h"
-#include "texture.h"
-#include "target.h"
-#include "effect.h"
-#include "render.h"
-#include "uniform.h"
+
#include "chainmanager.h"
+#include "effect.h"
#include "slider.h"
#include "sliderdirtynotifier.h"
+#include "target.h"
+#include "texture.h"
+#include "uniform.h"
+
+#include "../frontend/mame/ui/slider.h"
+
+#include "util/strformat.h"
+
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)
@@ -42,27 +42,46 @@ bgfx_input_pair::bgfx_input_pair(int index, std::string sampler, std::string tex
bgfx_input_pair::~bgfx_input_pair()
{
+ m_slider_state.reset();
}
void bgfx_input_pair::bind(bgfx_effect *effect, const int32_t screen) const
{
- assert(effect->uniform(m_sampler) != nullptr);
+ if (effect->uniform(m_sampler) == nullptr)
+ return;
+
std::string name = m_texture + std::to_string(screen);
bgfx_texture_handle_provider* provider = chains().textures().provider(name);
+ if (!provider)
+ return;
+
+ float rowpixels(provider->rowpixels());
+ float width_margin(provider->width_margin());
+ float height(provider->height());
+
bgfx_uniform *tex_size = effect->uniform("u_tex_size" + std::to_string(m_index));
- if (tex_size != nullptr)
+ if (tex_size && provider)
{
- float values[2] = { float(provider->width()), float(provider->height()) };
+ float values[2] = { rowpixels, height };
tex_size->set(values, sizeof(float) * 2);
}
- bgfx::setTexture(m_index, effect->uniform(m_sampler)->handle(), chains().textures().handle(name));
-}
+ bgfx_uniform *inv_tex_size = effect->uniform("u_inv_tex_size" + std::to_string(m_index));
+ if (inv_tex_size && provider)
+ {
+ float values[2] = { 1.0f / rowpixels, 1.0f / height };
+ inv_tex_size->set(values, sizeof(float) * 2);
+ }
-int32_t bgfx_input_pair::slider_changed(running_machine &machine, void *arg, int id, std::string *str, int32_t newval)
-{
- return texture_changed(id, str, newval);
+ bgfx_uniform *tex_bounds = effect->uniform("u_tex_bounds" + std::to_string(m_index));
+ if (tex_bounds && provider)
+ {
+ float values[4] = { width_margin / rowpixels, 0.0f, 1.0f + width_margin / rowpixels, 1.0f };
+ tex_bounds->set(values, sizeof(float) * 4);
+ }
+
+ bgfx::setTexture(m_index, effect->uniform(m_sampler)->handle(), chains().textures().handle(name));
}
int32_t bgfx_input_pair::texture_changed(int32_t id, std::string *str, int32_t newval)
@@ -91,7 +110,7 @@ int32_t bgfx_input_pair::texture_changed(int32_t id, std::string *str, int32_t n
file_name = file.substr(0, last_dot);
}
- *str = string_format("%s", file_name.c_str());
+ *str = file_name;
}
return m_current_texture;
@@ -99,25 +118,19 @@ int32_t bgfx_input_pair::texture_changed(int32_t id, std::string *str, int32_t n
void bgfx_input_pair::create_selection_slider(uint32_t screen_index)
{
- m_slider_state = make_unique_clear<slider_state>();
-
- m_slider_state->minval = 0;
- m_slider_state->defval = m_current_texture;
- m_slider_state->maxval = m_available_textures.size() - 1;
- m_slider_state->incval = 1;
+ int32_t minval = 0;
+ int32_t defval = m_current_texture;
+ int32_t maxval = m_available_textures.size() - 1;
+ int32_t incval = 1;
using namespace std::placeholders;
- m_slider_state->update = std::bind(&bgfx_input_pair::slider_changed, this, _1, _2, _3, _4, _5);
- m_slider_state->arg = this;
- m_slider_state->id = screen_index;
- m_slider_state->description = "Window " + std::to_string(chains().window_index()) + ", Screen " + std::to_string(screen_index) + " " + m_selection + ":";
-
- ui::menu_item item;
- item.text = m_slider_state->description;
- item.subtext = "";
- item.flags = 0;
- item.ref = m_slider_state.get();
- item.type = ui::menu_item_type::SLIDER;
+ m_slider_state = std::make_unique<slider_state>(
+ util::string_format("Window %1$u, Screen %1$u %3$s", chains().window_index(), screen_index, m_selection),
+ minval, defval, maxval, incval,
+ std::bind(&bgfx_input_pair::texture_changed, this, screen_index, _1, _2));
+
+ ui::menu_item item(ui::menu_item_type::SLIDER, m_slider_state.get());
+ item.set_text(m_slider_state->description);
m_selection_slider = item;
}
@@ -131,9 +144,7 @@ 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);