summaryrefslogtreecommitdiffstatshomepage
path: root/src/osd/modules/render/drawbgfx.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/osd/modules/render/drawbgfx.cpp')
-rw-r--r--src/osd/modules/render/drawbgfx.cpp263
1 files changed, 23 insertions, 240 deletions
diff --git a/src/osd/modules/render/drawbgfx.cpp b/src/osd/modules/render/drawbgfx.cpp
index 415e5ef33e4..32f45515a08 100644
--- a/src/osd/modules/render/drawbgfx.cpp
+++ b/src/osd/modules/render/drawbgfx.cpp
@@ -28,7 +28,7 @@
#include <algorithm>
#include "drawbgfx.h"
-#include "copyutil.h"
+#include "bgfxutil.h"
#include "bgfx/texturemanager.h"
#include "bgfx/targetmanager.h"
#include "bgfx/shadermanager.h"
@@ -43,6 +43,8 @@
#include "bgfx/slider.h"
#include "bgfx/target.h"
+#include "imgui/imgui.h"
+
//============================================================
// DEBUGGING
//============================================================
@@ -188,8 +190,7 @@ int renderer_bgfx::create()
m_screen_effect[2] = m_effects->effect("screen_multiply");
m_screen_effect[3] = m_effects->effect("screen_add");
- m_chains = new chain_manager(options, *m_textures, *m_targets, *m_effects);
- parse_screen_chains(options.bgfx_screen_chains());
+ m_chains = new chain_manager(window().machine(), options, *m_textures, *m_targets, *m_effects, window().m_index, *this);
m_sliders_dirty = true;
uint32_t flags = BGFX_TEXTURE_U_CLAMP | BGFX_TEXTURE_V_CLAMP | BGFX_TEXTURE_MIN_POINT | BGFX_TEXTURE_MAG_POINT | BGFX_TEXTURE_MIP_POINT;
@@ -198,51 +199,9 @@ int renderer_bgfx::create()
memset(m_white, 0xff, sizeof(uint32_t) * 16 * 16);
m_texinfo.push_back(rectangle_packer::packable_rectangle(WHITE_HASH, PRIMFLAG_TEXFORMAT(TEXFORMAT_ARGB32), 16, 16, 16, nullptr, m_white));
- return 0;
-}
-
-//============================================================
-// parse_screen_chains
-//============================================================
-
-void renderer_bgfx::parse_screen_chains(std::string chain_str)
-{
- std::vector<std::vector<std::string>> chains;
- uint32_t length = chain_str.length();
- uint32_t last_start = 0;
- uint32_t win = 0;
- chains.push_back(std::vector<std::string>());
- for (uint32_t i = 0; i < length + 1; i++)
- {
- if (i == length || chain_str[i] == ',' || chain_str[i] == ':')
- {
- chains[win].push_back(chain_str.substr(last_start, i - last_start));
- last_start = i + 1;
- if (chain_str[i] == ':')
- {
- win++;
- chains.push_back(std::vector<std::string>());
- }
- }
- }
+ imguiCreate();
- for (win = 0; win < chains.size(); win++)
- {
- m_screen_chains.push_back(std::vector<bgfx_chain*>());
- if (win != window().m_index)
- {
- continue;
- }
- for (uint32_t screen = 0; screen < chains[win].size(); screen++)
- {
- bgfx_chain* chain = m_chains->chain(chains[win][screen], window().machine(), win, screen);
- if (chain == nullptr) {
- chains.clear();
- return;
- }
- m_screen_chains[win].push_back(chain);
- }
- }
+ return 0;
}
//============================================================
@@ -261,6 +220,8 @@ renderer_bgfx::~renderer_bgfx()
void renderer_bgfx::exit()
{
+ imguiDestroy();
+
bgfx::shutdown();
s_window_set = false;
}
@@ -376,27 +337,6 @@ void renderer_bgfx::put_packed_quad(render_primitive *prim, UINT32 hash, ScreenV
vertex[5].m_v = v[0];
}
-void renderer_bgfx::process_screen_quad(int screen, render_primitive* prim)
-{
- uint16_t tex_width(prim->texture.width);
- uint16_t tex_height(prim->texture.height);
-
- const bgfx::Memory* mem = mame_texture_data_to_bgfx_texture_data(prim->flags & PRIMFLAG_TEXFORMAT_MASK,
- tex_width, tex_height, prim->texture.rowpixels, prim->texture.palette, prim->texture.base);
-
- std::string full_name = "screen" + std::to_string(screen);
- bgfx_texture *texture = new bgfx_texture(full_name, bgfx::TextureFormat::RGBA8, tex_width, tex_height, mem);
- m_textures->add_provider(full_name, texture);
-
- m_targets->update_target_sizes(screen, tex_width, tex_height, TARGET_STYLE_GUEST);
-
- screen_chain(screen)->process(prim, s_current_view, screen, *m_textures, window(), get_blend_state(PRIMFLAG_GET_BLENDMODE(prim->flags)));
- s_current_view += screen_chain(screen)->applicable_passes();
-
- m_textures->add_provider(full_name, nullptr);
- delete texture;
-}
-
void renderer_bgfx::render_post_screen_quad(int view, render_primitive* prim, bgfx::TransientVertexBuffer* buffer, int32_t screen)
{
ScreenVertex* vertex = reinterpret_cast<ScreenVertex*>(buffer->data);
@@ -517,7 +457,7 @@ void renderer_bgfx::render_textured_quad(render_primitive* prim, bgfx::Transient
uint16_t tex_width(prim->texture.width);
uint16_t tex_height(prim->texture.height);
- const bgfx::Memory* mem = mame_texture_data_to_bgfx_texture_data(prim->flags & PRIMFLAG_TEXFORMAT_MASK,
+ const bgfx::Memory* mem = bgfx_util::mame_texture_data_to_bgfx_texture_data(prim->flags & PRIMFLAG_TEXFORMAT_MASK,
tex_width, tex_height, prim->texture.rowpixels, prim->texture.palette, prim->texture.base);
bgfx::TextureHandle texture = bgfx::createTexture2D(tex_width, tex_height, 1, bgfx::TextureFormat::RGBA8, texture_flags, mem);
@@ -721,124 +661,6 @@ uint32_t renderer_bgfx::u32Color(uint32_t r, uint32_t g, uint32_t b, uint32_t a
return (a << 24) | (b << 16) | (g << 8) | r;
}
-const bgfx::Memory* renderer_bgfx::mame_texture_data_to_bgfx_texture_data(UINT32 format, int width, int height, int rowpixels, const rgb_t *palette, void *base)
-{
- const bgfx::Memory* mem = bgfx::alloc(width * height * 4);
- for (int y = 0; y < height; y++)
- {
- switch (format)
- {
- case PRIMFLAG_TEXFORMAT(TEXFORMAT_PALETTE16):
- copy_util::copyline_palette16((UINT32*)mem->data + y * width, (UINT16*)base + y * rowpixels, width, palette);
- break;
- case PRIMFLAG_TEXFORMAT(TEXFORMAT_PALETTEA16):
- copy_util::copyline_palettea16((UINT32*)mem->data + y * width, (UINT16*)base + y * rowpixels, width, palette);
- break;
- case PRIMFLAG_TEXFORMAT(TEXFORMAT_YUY16):
- copy_util::copyline_yuy16_to_argb((UINT32*)mem->data + y * width, (UINT16*)base + y * rowpixels, width, palette, 1);
- break;
- case PRIMFLAG_TEXFORMAT(TEXFORMAT_ARGB32):
- copy_util::copyline_argb32((UINT32*)mem->data + y * width, (UINT32*)base + y * rowpixels, width, palette);
- break;
- case PRIMFLAG_TEXFORMAT(TEXFORMAT_RGB32):
- copy_util::copyline_rgb32((UINT32*)mem->data + y * width, (UINT32*)base + y * rowpixels, width, palette);
- break;
- default:
- break;
- }
- }
- return mem;
-}
-
-int renderer_bgfx::handle_screen_chains()
-{
- if (m_screen_chains.size() <= window().m_index || m_screen_chains[window().m_index].size() == 0)
- {
- return 0;
- }
-
- window().m_primlist->acquire_lock();
-
- render_primitive *prim = window().m_primlist->first();
-
- // Determine how many post-processing passes are needed
- int screens = 0;
- int total_screen_textures = 0;
- std::vector<void*> bases;
- while (prim != nullptr)
- {
- if (PRIMFLAG_GET_SCREENTEX(prim->flags))
- {
- total_screen_textures++;
- bool found = false;
- for (void* base : bases)
- {
- if (base == prim->texture.base)
- {
- found = true;
- break;
- }
- }
- if (!found)
- {
- screens++;
- bases.push_back(prim->texture.base);
- }
- }
- prim = prim->next();
- }
-
- const uint32_t available_chains = m_screen_chains[window().m_index].size();
- screens = screens >= available_chains ? available_chains : screens;
-
- if (screens > 0)
- {
- m_targets->update_screen_count(screens);
- }
-
- // Process each screen as necessary
- prim = window().m_primlist->first();
- int screen_index = 0;
- while (prim != nullptr)
- {
- if (PRIMFLAG_GET_SCREENTEX(prim->flags))
- {
- if (screen_index >= available_chains)
- {
- break;
- }
- uint16_t screen_width(floor((prim->bounds.x1 - prim->bounds.x0) + 0.5f));
- uint16_t screen_height(floor((prim->bounds.y1 - prim->bounds.y0) + 0.5f));
- if(window().swap_xy())
- {
- std::swap(screen_width, screen_height);
- }
- m_targets->update_target_sizes(screen_index, screen_width, screen_height, TARGET_STYLE_NATIVE);
- process_screen_quad(screen_index, prim);
- screen_index++;
- }
- prim = prim->next();
- }
-
- window().m_primlist->release_lock();
-
- bgfx::setViewFrameBuffer(s_current_view, BGFX_INVALID_HANDLE);
-
- return s_current_view;
-}
-
-bgfx_chain* renderer_bgfx::screen_chain(int32_t screen)
-{
- if (screen >= m_screen_chains[window().m_index].size())
- {
- return m_screen_chains[window().m_index][m_screen_chains[window().m_index].size() - 1];
- }
- else
- {
- return m_screen_chains[window().m_index][screen];
- }
-}
-
int renderer_bgfx::draw(int update)
{
int window_index = window().m_index;
@@ -855,7 +677,9 @@ int renderer_bgfx::draw(int update)
m_width[window_index] = wdim.width();
m_height[window_index] = wdim.height();
- handle_screen_chains();
+ window().m_primlist->acquire_lock();
+ s_current_view += m_chains->handle_screen_chains(s_current_view, window().m_primlist->first(), window());
+ window().m_primlist->release_lock();
bool skip_frame = update_dimensions();
if (skip_frame)
@@ -1083,7 +907,7 @@ renderer_bgfx::buffer_status renderer_bgfx::buffer_primitives(bool atlas_valid,
return BUFFER_PRE_FLUSH;
}
- if (PRIMFLAG_GET_SCREENTEX((*prim)->flags) && m_screen_chains.size() > window().m_index && screen < m_screen_chains[window().m_index].size())
+ if (PRIMFLAG_GET_SCREENTEX((*prim)->flags) && m_chains->has_applicable_chain(screen))
{
#if SCENE_VIEW
setup_view(s_current_view, true);
@@ -1130,26 +954,10 @@ renderer_bgfx::buffer_status renderer_bgfx::buffer_primitives(bool atlas_valid,
return BUFFER_FLUSH;
}
-uint64_t renderer_bgfx::get_blend_state(UINT32 blend)
-{
- switch (blend)
- {
- case BLENDMODE_ALPHA:
- return BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_SRC_ALPHA, BGFX_STATE_BLEND_INV_SRC_ALPHA);
- case BLENDMODE_RGB_MULTIPLY:
- return BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_DST_COLOR, BGFX_STATE_BLEND_ZERO);
- case BLENDMODE_ADD:
- return BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_SRC_ALPHA, BGFX_STATE_BLEND_ONE);
- default:
- return 0L;
- }
- return 0L;
-}
-
void renderer_bgfx::set_bgfx_state(UINT32 blend)
{
uint64_t flags = BGFX_STATE_RGB_WRITE | BGFX_STATE_ALPHA_WRITE | BGFX_STATE_DEPTH_TEST_ALWAYS;
- bgfx::setState(flags | get_blend_state(blend));
+ bgfx::setState(flags | bgfx_util::get_blend_state(blend));
}
bool renderer_bgfx::update_atlas()
@@ -1192,7 +1000,7 @@ void renderer_bgfx::process_atlas_packs(std::vector<std::vector<rectangle_packer
continue;
}
m_hash_to_entry[rect.hash()] = rect;
- const bgfx::Memory* mem = mame_texture_data_to_bgfx_texture_data(rect.format(), rect.width(), rect.height(), rect.rowpixels(), rect.palette(), rect.base());
+ const bgfx::Memory* mem = bgfx_util::mame_texture_data_to_bgfx_texture_data(rect.format(), rect.width(), rect.height(), rect.rowpixels(), rect.palette(), rect.base());
bgfx::updateTexture2D(m_texture_cache->texture(), 0, rect.x(), rect.y(), rect.width(), rect.height(), mem);
}
}
@@ -1310,38 +1118,13 @@ void renderer_bgfx::allocate_buffer(render_primitive *prim, UINT32 blend, bgfx::
}
}
-slider_state* renderer_bgfx::get_slider_list()
+std::vector<ui_menu_item> renderer_bgfx::get_slider_list()
{
- if (m_screen_chains.size() <= window().m_index || m_screen_chains[window().m_index].size() == 0)
- {
- return nullptr;
- }
-
- slider_state *listhead = nullptr;
- slider_state **tailptr = &listhead;
- for (std::vector<bgfx_chain*> screen : m_screen_chains)
- {
- for (bgfx_chain* chain : screen)
- {
- std::vector<bgfx_slider*> sliders = chain->sliders();
- for (bgfx_slider* slider : sliders)
- {
- if (*tailptr == nullptr)
- {
- *tailptr = slider->core_slider();
- }
- else
- {
- (*tailptr)->next = slider->core_slider();
- tailptr = &(*tailptr)->next;
- }
- }
- }
- }
- if (*tailptr != nullptr)
- {
- (*tailptr)->next = nullptr;
- }
- m_sliders_dirty = false;
- return listhead;
+ m_sliders_dirty = false;
+ return m_chains->get_slider_list();
}
+
+void renderer_bgfx::set_sliders_dirty()
+{
+ m_sliders_dirty = true;
+} \ No newline at end of file