Pull a bunch of screen chain code from drawbgfx to chainmanager where it belongs, nw
This commit is contained in:
parent
4f43553de9
commit
4f66357f9e
@ -134,6 +134,8 @@ function osdmodulesbuild()
|
||||
|
||||
files {
|
||||
MAME_DIR .. "src/osd/modules/render/drawbgfx.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfxutil.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfxutil.h",
|
||||
MAME_DIR .. "src/osd/modules/render/binpacker.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/blendreader.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/chain.cpp",
|
||||
|
@ -10,6 +10,7 @@
|
||||
//============================================================
|
||||
|
||||
#include "emu.h"
|
||||
#include "window.h"
|
||||
|
||||
#include <rapidjson/document.h>
|
||||
#include <rapidjson/error/en.h>
|
||||
@ -17,24 +18,38 @@
|
||||
#include <bx/readerwriter.h>
|
||||
#include <bx/crtimpl.h>
|
||||
|
||||
#include "bgfxutil.h"
|
||||
|
||||
#include "chainmanager.h"
|
||||
#include "chainreader.h"
|
||||
#include "chain.h"
|
||||
|
||||
#include "texture.h"
|
||||
#include "target.h"
|
||||
#include "slider.h"
|
||||
|
||||
using namespace rapidjson;
|
||||
|
||||
chain_manager::chain_manager(running_machine& machine, osd_options& options, texture_manager& textures, target_manager& targets, effect_manager& effects, uint32_t window_index)
|
||||
: m_machine(machine)
|
||||
, m_options(options)
|
||||
, m_textures(textures)
|
||||
, m_targets(targets)
|
||||
, m_effects(effects)
|
||||
, m_window_index(window_index)
|
||||
{
|
||||
load_screen_chains(options.bgfx_screen_chains());
|
||||
}
|
||||
|
||||
chain_manager::~chain_manager()
|
||||
{
|
||||
for (bgfx_chain* chain : m_chains)
|
||||
{
|
||||
delete chain;
|
||||
}
|
||||
m_chains.clear();
|
||||
}
|
||||
|
||||
bgfx_chain* chain_manager::chain(std::string name, running_machine& machine, uint32_t window_index, uint32_t screen_index)
|
||||
{
|
||||
return load_chain(name, machine, window_index, screen_index);
|
||||
for (std::vector<bgfx_chain*> screen_chains : m_screen_chains)
|
||||
{
|
||||
for (bgfx_chain* chain : screen_chains)
|
||||
{
|
||||
delete chain;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bgfx_chain* chain_manager::load_chain(std::string name, running_machine& machine, uint32_t window_index, uint32_t screen_index)
|
||||
@ -80,7 +95,193 @@ bgfx_chain* chain_manager::load_chain(std::string name, running_machine& machine
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
m_chains.push_back(chain);
|
||||
|
||||
return chain;
|
||||
}
|
||||
|
||||
void chain_manager::load_screen_chains(std::string chain_str)
|
||||
{
|
||||
std::vector<std::vector<std::string>> chain_names = split_option_string(chain_str);
|
||||
load_chains(chain_names);
|
||||
}
|
||||
|
||||
std::vector<std::vector<std::string>> chain_manager::split_option_string(std::string chain_str) const
|
||||
{
|
||||
std::vector<std::vector<std::string>> chain_names;
|
||||
chain_names.push_back(std::vector<std::string>());
|
||||
|
||||
uint32_t length = chain_str.length();
|
||||
uint32_t win = 0;
|
||||
uint32_t last_start = 0;
|
||||
for (uint32_t i = 0; i < length + 1; i++) {
|
||||
if (i == length || chain_str[i] == ',' || chain_str[i] == ':') {
|
||||
chain_names[win].push_back(chain_str.substr(last_start, i - last_start));
|
||||
last_start = i + 1;
|
||||
if (chain_str[i] == ':') {
|
||||
win++;
|
||||
chain_names.push_back(std::vector<std::string>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return chain_names;
|
||||
}
|
||||
|
||||
void chain_manager::load_chains(std::vector<std::vector<std::string>>& chain_names)
|
||||
{
|
||||
for (uint32_t win = 0; win < chain_names.size(); win++) {
|
||||
m_screen_chains.push_back(std::vector<bgfx_chain*>());
|
||||
if (win != m_window_index) {
|
||||
continue;
|
||||
}
|
||||
for (uint32_t screen = 0; screen < chain_names[win].size(); screen++) {
|
||||
bgfx_chain* chain = load_chain(chain_names[win][screen], m_machine, win, screen);
|
||||
if (chain == nullptr) {
|
||||
chain_names.clear();
|
||||
return;
|
||||
}
|
||||
m_screen_chains[win].push_back(chain);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bgfx_chain* chain_manager::screen_chain(uint32_t screen)
|
||||
{
|
||||
if (screen >= m_screen_chains[m_window_index].size())
|
||||
{
|
||||
return m_screen_chains[m_window_index][m_screen_chains[m_window_index].size() - 1];
|
||||
}
|
||||
else
|
||||
{
|
||||
return m_screen_chains[m_window_index][screen];
|
||||
}
|
||||
}
|
||||
|
||||
void chain_manager::process_screen_quad(uint32_t view, uint32_t screen, render_primitive* prim, osd_window &window)
|
||||
{
|
||||
uint16_t tex_width(prim->texture.width);
|
||||
uint16_t tex_height(prim->texture.height);
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
bgfx_chain* chain = screen_chain(screen);
|
||||
chain->process(prim, view, screen, m_textures, window, bgfx_util::get_blend_state(PRIMFLAG_GET_BLENDMODE(prim->flags)));
|
||||
view += chain->applicable_passes();
|
||||
|
||||
m_textures.add_provider(full_name, nullptr);
|
||||
delete texture;
|
||||
}
|
||||
|
||||
std::vector<render_primitive*> chain_manager::count_screens(render_primitive* prim)
|
||||
{
|
||||
std::vector<render_primitive*> screens;
|
||||
|
||||
int screen_count = 0;
|
||||
std::vector<void*> bases;
|
||||
while (prim != nullptr) {
|
||||
if (PRIMFLAG_GET_SCREENTEX(prim->flags)) {
|
||||
bool found = false;
|
||||
for (void* base : bases) {
|
||||
if (base == prim->texture.base) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
screen_count++;
|
||||
screens.push_back(prim);
|
||||
bases.push_back(prim->texture.base);
|
||||
}
|
||||
}
|
||||
prim = prim->next();
|
||||
}
|
||||
|
||||
const uint32_t available_chains = m_screen_chains[m_window_index].size();
|
||||
if (screen_count >= available_chains)
|
||||
{
|
||||
screen_count = available_chains;
|
||||
}
|
||||
|
||||
if (screen_count > 0) {
|
||||
m_targets.update_screen_count(screen_count);
|
||||
}
|
||||
|
||||
return screens;
|
||||
}
|
||||
|
||||
uint32_t chain_manager::handle_screen_chains(uint32_t view, render_primitive *starting_prim, osd_window& window) {
|
||||
if (m_screen_chains.size() <= m_window_index || m_screen_chains[m_window_index].size() == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::vector<render_primitive*> screens = count_screens(starting_prim);
|
||||
|
||||
if (screens.size() == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const uint32_t available_chains = m_screen_chains[m_window_index].size();
|
||||
|
||||
// Process each screen as necessary
|
||||
uint32_t used_views = 0;
|
||||
int screen_index = 0;
|
||||
for (render_primitive* prim : screens) {
|
||||
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(view + used_views, screen_index, prim, window);
|
||||
used_views += screen_chain(screen_index)->applicable_passes();
|
||||
|
||||
screen_index++;
|
||||
}
|
||||
|
||||
bgfx::setViewFrameBuffer(view + used_views, BGFX_INVALID_HANDLE);
|
||||
|
||||
return used_views;
|
||||
}
|
||||
|
||||
bool chain_manager::has_applicable_pass(uint32_t screen)
|
||||
{
|
||||
return m_screen_chains.size() > m_window_index && screen < m_screen_chains[m_window_index].size();
|
||||
}
|
||||
|
||||
slider_state* chain_manager::get_slider_list()
|
||||
{
|
||||
if (m_screen_chains.size() <= m_window_index || m_screen_chains[m_window_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;
|
||||
}
|
||||
return listhead;
|
||||
}
|
@ -22,31 +22,38 @@
|
||||
#include "effectmanager.h"
|
||||
|
||||
class running_machine;
|
||||
class osd_window;
|
||||
|
||||
class bgfx_chain;
|
||||
|
||||
class chain_manager {
|
||||
public:
|
||||
chain_manager(osd_options& options, texture_manager& textures, target_manager& targets, effect_manager& effects)
|
||||
: m_options(options)
|
||||
, m_textures(textures)
|
||||
, m_targets(targets)
|
||||
, m_effects(effects)
|
||||
{
|
||||
}
|
||||
chain_manager(running_machine& machine, osd_options& options, texture_manager& textures, target_manager& targets, effect_manager& effects, uint32_t window_index);
|
||||
~chain_manager();
|
||||
|
||||
// Getters
|
||||
bgfx_chain* chain(std::string name, running_machine& machine, uint32_t window_index, uint32_t screen_index);
|
||||
uint32_t handle_screen_chains(uint32_t view, render_primitive *starting_prim, osd_window& window);
|
||||
|
||||
// Getters
|
||||
bgfx_chain* screen_chain(uint32_t screen);
|
||||
bgfx_chain* load_chain(std::string name, running_machine& machine, uint32_t window_index, uint32_t screen_index);
|
||||
bool has_applicable_pass(uint32_t screen);
|
||||
slider_state* get_slider_list();
|
||||
|
||||
private:
|
||||
bgfx_chain* load_chain(std::string name, running_machine& machine, uint32_t window_index, uint32_t screen_index);
|
||||
void load_screen_chains(std::string chain_str);
|
||||
std::vector<std::vector<std::string>> split_option_string(std::string chain_str) const;
|
||||
void load_chains(std::vector<std::vector<std::string>>& chains);
|
||||
|
||||
std::vector<render_primitive*> count_screens(render_primitive* prim);
|
||||
void process_screen_quad(uint32_t view, uint32_t screen, render_primitive* prim, osd_window &window);
|
||||
|
||||
osd_options& m_options;
|
||||
texture_manager& m_textures;
|
||||
target_manager& m_targets;
|
||||
effect_manager& m_effects;
|
||||
std::vector<bgfx_chain*> m_chains;
|
||||
running_machine& m_machine;
|
||||
osd_options& m_options;
|
||||
texture_manager& m_textures;
|
||||
target_manager& m_targets;
|
||||
effect_manager& m_effects;
|
||||
uint32_t m_window_index;
|
||||
std::vector<std::vector<bgfx_chain*>> m_screen_chains;
|
||||
};
|
||||
|
||||
#endif // __DRAWBGFX_CHAIN_MANAGER__
|
||||
|
64
src/osd/modules/render/bgfxutil.cpp
Normal file
64
src/osd/modules/render/bgfxutil.cpp
Normal file
@ -0,0 +1,64 @@
|
||||
// license:BSD-3-Clause
|
||||
// copyright-holders:Ryan Holtz
|
||||
//============================================================
|
||||
//
|
||||
// bgfxutil.cpp - BGFX renderer helper utils
|
||||
//
|
||||
//============================================================
|
||||
|
||||
// MAMEOS headers
|
||||
#include "emu.h"
|
||||
#include "bgfxutil.h"
|
||||
#include "copyutil.h"
|
||||
|
||||
const bgfx::Memory* bgfx_util::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);
|
||||
UINT32* data = reinterpret_cast<UINT32*>(mem->data);
|
||||
UINT16* src16 = reinterpret_cast<UINT16*>(base);
|
||||
UINT32* src32 = reinterpret_cast<UINT32*>(base);
|
||||
|
||||
for (int y = 0; y < height; y++)
|
||||
{
|
||||
UINT32* dst_line = data + y * width;
|
||||
UINT16* src_line16 = src16 + y * rowpixels;
|
||||
UINT32* src_line32 = src32 + y * rowpixels;
|
||||
switch (format)
|
||||
{
|
||||
case PRIMFLAG_TEXFORMAT(TEXFORMAT_PALETTE16):
|
||||
copy_util::copyline_palette16(dst_line, src_line16, width, palette);
|
||||
break;
|
||||
case PRIMFLAG_TEXFORMAT(TEXFORMAT_PALETTEA16):
|
||||
copy_util::copyline_palettea16(dst_line, src_line16, width, palette);
|
||||
break;
|
||||
case PRIMFLAG_TEXFORMAT(TEXFORMAT_YUY16):
|
||||
copy_util::copyline_yuy16_to_argb(dst_line, src_line16, width, palette, 1);
|
||||
break;
|
||||
case PRIMFLAG_TEXFORMAT(TEXFORMAT_ARGB32):
|
||||
copy_util::copyline_argb32(dst_line, src_line32, width, palette);
|
||||
break;
|
||||
case PRIMFLAG_TEXFORMAT(TEXFORMAT_RGB32):
|
||||
copy_util::copyline_rgb32(dst_line, src_line32, width, palette);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return mem;
|
||||
}
|
||||
|
||||
uint64_t bgfx_util::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;
|
||||
}
|
18
src/osd/modules/render/bgfxutil.h
Normal file
18
src/osd/modules/render/bgfxutil.h
Normal file
@ -0,0 +1,18 @@
|
||||
// license:BSD-3-Clause
|
||||
// copyright-holders:Ryan Holtz
|
||||
#pragma once
|
||||
|
||||
#ifndef __RENDER_BGFX_UTIL__
|
||||
#define __RENDER_BGFX_UTIL__
|
||||
|
||||
#include <bgfx/bgfx.h>
|
||||
|
||||
/* sdl_info is the information about SDL for the current screen */
|
||||
class bgfx_util
|
||||
{
|
||||
public:
|
||||
static const bgfx::Memory* mame_texture_data_to_bgfx_texture_data(UINT32 format, int width, int height, int rowpixels, const rgb_t *palette, void *base);
|
||||
static uint64_t get_blend_state(UINT32 blend);
|
||||
};
|
||||
|
||||
#endif // __RENDER_BGFX_UTIL__
|
@ -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"
|
||||
@ -190,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);
|
||||
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;
|
||||
@ -205,50 +204,6 @@ int renderer_bgfx::create()
|
||||
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>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//============================================================
|
||||
// destructor
|
||||
//============================================================
|
||||
@ -382,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);
|
||||
@ -523,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);
|
||||
@ -727,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;
|
||||
@ -861,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)
|
||||
@ -1089,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_pass(screen))
|
||||
{
|
||||
#if SCENE_VIEW
|
||||
setup_view(s_current_view, true);
|
||||
@ -1136,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()
|
||||
@ -1198,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);
|
||||
}
|
||||
}
|
||||
@ -1318,36 +1120,6 @@ void renderer_bgfx::allocate_buffer(render_primitive *prim, UINT32 blend, bgfx::
|
||||
|
||||
slider_state* 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();
|
||||
}
|
||||
|
@ -58,11 +58,10 @@ public:
|
||||
return &window().target()->get_primitives();
|
||||
}
|
||||
|
||||
static const char* WINDOW_PREFIX;
|
||||
static const char* WINDOW_PREFIX;
|
||||
|
||||
private:
|
||||
int handle_screen_chains();
|
||||
void parse_screen_chains(std::string chain_str);
|
||||
void handle_screen_chains(render_primitive *starting_prim);
|
||||
bgfx_chain* screen_chain(int32_t screen);
|
||||
|
||||
bool update_dimensions();
|
||||
@ -81,7 +80,6 @@ private:
|
||||
};
|
||||
buffer_status buffer_primitives(bool atlas_valid, render_primitive** prim, bgfx::TransientVertexBuffer* buffer, int32_t screen);
|
||||
|
||||
void process_screen_quad(int view, render_primitive* prim);
|
||||
void render_textured_quad(render_primitive* prim, bgfx::TransientVertexBuffer* buffer);
|
||||
void render_post_screen_quad(int view, render_primitive* prim, bgfx::TransientVertexBuffer* buffer, int32_t screen);
|
||||
|
||||
@ -90,14 +88,12 @@ private:
|
||||
void put_line(float x0, float y0, float x1, float y1, float r, UINT32 rgba, ScreenVertex* vertex, float fth = 1.0f);
|
||||
|
||||
void set_bgfx_state(UINT32 blend);
|
||||
uint64_t get_blend_state(UINT32 blend);
|
||||
|
||||
static uint32_t u32Color(uint32_t r, uint32_t g, uint32_t b, uint32_t a);
|
||||
|
||||
bool check_for_dirty_atlas();
|
||||
bool update_atlas();
|
||||
void process_atlas_packs(std::vector<std::vector<rectangle_packer::packed_rectangle>>& packed);
|
||||
const bgfx::Memory* mame_texture_data_to_bgfx_texture_data(UINT32 format, int width, int height, int rowpixels, const rgb_t *palette, void *base);
|
||||
UINT32 get_texture_hash(render_primitive *prim);
|
||||
|
||||
bgfx_target* m_framebuffer;
|
||||
@ -114,7 +110,6 @@ private:
|
||||
|
||||
bgfx_effect* m_gui_effect[4];
|
||||
bgfx_effect* m_screen_effect[4];
|
||||
std::vector<std::vector<bgfx_chain*>> m_screen_chains;
|
||||
std::vector<uint32_t> m_seen_views;
|
||||
|
||||
std::map<UINT32, rectangle_packer::packed_rectangle> m_hash_to_entry;
|
||||
|
Loading…
Reference in New Issue
Block a user