Merged in BGFX changes and adapted BGFX draw to inherit from

osd_renderer. 
Made BGFX optional for SLD builds. You have to specify USE_BGFX=1 to
enable BGFX. This is a temporary measure until dynamic linking is
resolved. (nw)
This commit is contained in:
couriersud 2015-02-01 16:01:36 +01:00
parent 041eaa6874
commit 68fb63ad77
4 changed files with 92 additions and 112 deletions

View File

@ -64,30 +64,31 @@
// core functions // core functions
static void drawbgfx_exit(void); static void drawbgfx_exit(void);
static void drawbgfx_attach(sdl_draw_info *info, sdl_window_info *window);
static int drawbgfx_window_create(sdl_window_info *window, int width, int height);
static void drawbgfx_window_resize(sdl_window_info *window, int width, int height);
static void drawbgfx_window_destroy(sdl_window_info *window);
static int drawbgfx_window_draw(sdl_window_info *window, UINT32 dc, int update);
static void drawbgfx_set_target_bounds(sdl_window_info *window);
static void drawbgfx_destroy_all_textures(sdl_window_info *window);
static void drawbgfx_window_clear(sdl_window_info *window);
static int drawbgfx_xy_to_render_target(sdl_window_info *window, int x, int y, int *xt, int *yt);
//============================================================ //============================================================
// Textures // Textures
//============================================================ //============================================================
/* sdl_info is the information about SDL for the current screen */ /* sdl_info is the information about SDL for the current screen */
struct sdl_info13 class sdl_info_bgfx : public osd_renderer
{ {
sdl_info13() public:
: m_blittimer(0), m_renderer(NULL), sdl_info_bgfx(sdl_window_info *w)
m_hofs(0), m_vofs(0), : osd_renderer(w), m_blittimer(0), m_renderer(NULL),
m_last_hofs(0), m_last_vofs(0),
m_resize_pending(0), m_resize_width(0), m_resize_height(0), m_resize_pending(0), m_resize_width(0), m_resize_height(0),
m_last_blit_time(0), m_last_blit_pixels(0) m_last_blit_time(0), m_last_blit_pixels(0)
{} {}
/* virtual */ int create(int width, int height);
/* virtual */ void resize(int width, int height);
/* virtual */ int draw(UINT32 dc, int update);
/* virtual */ void set_target_bounds();
/* virtual */ int xy_to_render_target(int x, int y, int *xt, int *yt);
/* virtual */ void destroy_all_textures();
/* virtual */ void destroy();
/* virtual */ void clear();
// void render_quad(texture_info *texture, const render_primitive *prim, const int x, const int y); // void render_quad(texture_info *texture, const render_primitive *prim, const int x, const int y);
//texture_info *texture_find(const render_primitive &prim, const quad_setup_data &setup); //texture_info *texture_find(const render_primitive &prim, const quad_setup_data &setup);
@ -98,8 +99,8 @@ struct sdl_info13
SDL_Renderer * m_renderer; SDL_Renderer * m_renderer;
//simple_list<texture_info> m_texlist; // list of active textures //simple_list<texture_info> m_texlist; // list of active textures
float m_hofs; float m_last_hofs;
float m_vofs; float m_last_vofs;
// resize information // resize information
@ -123,42 +124,27 @@ struct sdl_info13
// drawbgfx_init // drawbgfx_init
//============================================================ //============================================================
static osd_renderer *drawbgfx_create(sdl_window_info *window)
{
return global_alloc(sdl_info_bgfx(window));
}
int drawbgfx_init(running_machine &machine, sdl_draw_info *callbacks) int drawbgfx_init(running_machine &machine, sdl_draw_info *callbacks)
{ {
// fill in the callbacks // fill in the callbacks
callbacks->exit = drawbgfx_exit; callbacks->exit = drawbgfx_exit;
callbacks->attach = drawbgfx_attach; callbacks->create = drawbgfx_create;
return 0; return 0;
} }
//============================================================ //============================================================
// drawbgfx_attach // sdl_info_bgfx::create
//============================================================ //============================================================
static void drawbgfx_attach(sdl_draw_info *info, sdl_window_info *window) int sdl_info_bgfx::create(int width, int height)
{ {
// fill in the callbacks
window->create = drawbgfx_window_create;
window->resize = drawbgfx_window_resize;
window->set_target_bounds = drawbgfx_set_target_bounds;
window->draw = drawbgfx_window_draw;
window->destroy = drawbgfx_window_destroy;
window->destroy_all_textures = drawbgfx_destroy_all_textures;
window->clear = drawbgfx_window_clear;
window->xy_to_render_target = drawbgfx_xy_to_render_target;
}
//============================================================
// drawbgfx_window_create
//============================================================
static int drawbgfx_window_create(sdl_window_info *window, int width, int height)
{
// allocate memory for our structures
sdl_info13 *sdl = global_alloc(sdl_info13);
/* FIXME: On Ubuntu and potentially other Linux OS you should use /* FIXME: On Ubuntu and potentially other Linux OS you should use
* to disable panning. This has to be done before every invocation of mame. * to disable panning. This has to be done before every invocation of mame.
* *
@ -168,69 +154,67 @@ static int drawbgfx_window_create(sdl_window_info *window, int width, int height
osd_printf_verbose("Enter drawsdl2_window_create\n"); osd_printf_verbose("Enter drawsdl2_window_create\n");
window->dxdata = sdl; UINT32 extra_flags = (window().fullscreen() ?
UINT32 extra_flags = (window->fullscreen() ?
SDL_WINDOW_BORDERLESS | SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_FULLSCREEN : SDL_WINDOW_RESIZABLE); SDL_WINDOW_BORDERLESS | SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_FULLSCREEN : SDL_WINDOW_RESIZABLE);
#if defined(SDLMAME_WIN32) #if defined(SDLMAME_WIN32)
SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, "0"); SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, "0");
#endif #endif
// create the SDL window // create the SDL window
window->sdl_window = SDL_CreateWindow(window->title, window().m_sdl_window = SDL_CreateWindow(window().m_title,
window->monitor()->position_size().x, window->monitor()->position_size().y, window().monitor()->position_size().x, window().monitor()->position_size().y,
width, height, extra_flags); width, height, extra_flags);
if (window->fullscreen() && video_config.switchres) if (window().fullscreen() && video_config.switchres)
{ {
SDL_DisplayMode mode; SDL_DisplayMode mode;
//SDL_GetCurrentDisplayMode(window->monitor()->handle, &mode); //SDL_GetCurrentDisplayMode(window().monitor()->handle, &mode);
SDL_GetWindowDisplayMode(window->sdl_window, &mode); SDL_GetWindowDisplayMode(window().m_sdl_window, &mode);
sdl->m_original_mode = mode; m_original_mode = mode;
mode.w = width; mode.w = width;
mode.h = height; mode.h = height;
if (window->refresh) if (window().m_refresh)
mode.refresh_rate = window->refresh; mode.refresh_rate = window().m_refresh;
SDL_SetWindowDisplayMode(window->sdl_window, &mode); // Try to set mode SDL_SetWindowDisplayMode(window().m_sdl_window, &mode); // Try to set mode
#ifndef SDLMAME_WIN32 #ifndef SDLMAME_WIN32
/* FIXME: Warp the mouse to 0,0 in case a virtual desktop resolution /* FIXME: Warp the mouse to 0,0 in case a virtual desktop resolution
* is in place after the mode switch - which will most likely be the case * is in place after the mode switch - which will most likely be the case
* This is a hack to work around a deficiency in SDL2 * This is a hack to work around a deficiency in SDL2
*/ */
SDL_WarpMouseInWindow(window->sdl_window, 1, 1); SDL_WarpMouseInWindow(window().m_sdl_window, 1, 1);
#endif #endif
} }
else else
{ {
//SDL_SetWindowDisplayMode(window->sdl_window, NULL); // Use desktop //SDL_SetWindowDisplayMode(window().m_sdl_window, NULL); // Use desktop
} }
// create renderer // create renderer
if (video_config.waitvsync) if (video_config.waitvsync)
sdl->m_renderer = SDL_CreateRenderer(window->sdl_window, -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED); m_renderer = SDL_CreateRenderer(window().m_sdl_window, -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED);
else else
sdl->m_renderer = SDL_CreateRenderer(window->sdl_window, -1, SDL_RENDERER_ACCELERATED); m_renderer = SDL_CreateRenderer(window().m_sdl_window, -1, SDL_RENDERER_ACCELERATED);
if (!sdl->m_renderer) if (!m_renderer)
{ {
fatalerror("Error on creating renderer: %s\n", SDL_GetError()); fatalerror("Error on creating renderer: %s\n", SDL_GetError());
} }
//SDL_SelectRenderer(window->sdl_window); //SDL_SelectRenderer(window().m_sdl_window);
SDL_ShowWindow(window->sdl_window); SDL_ShowWindow(window().m_sdl_window);
//SDL_SetWindowFullscreen(window->window_id, window->fullscreen); //SDL_SetWindowFullscreen(window().window_id, window().fullscreen);
SDL_RaiseWindow(window->sdl_window); SDL_RaiseWindow(window().m_sdl_window);
SDL_GetWindowSize(window->sdl_window, &window->width, &window->height); SDL_GetWindowSize(window().m_sdl_window, &window().m_width, &window().m_height);
sdl->m_blittimer = 3; m_blittimer = 3;
SDL_RenderPresent(sdl->m_renderer); SDL_RenderPresent(m_renderer);
bgfx::sdlSetWindow(window->sdl_window); bgfx::sdlSetWindow(window().m_sdl_window);
bgfx::init(); bgfx::init();
bgfx::reset(window->width, window->height, BGFX_RESET_VSYNC); bgfx::reset(window().m_width, window().m_height, BGFX_RESET_VSYNC);
// Enable debug text. // Enable debug text.
bgfx::setDebug(BGFX_DEBUG_STATS);// BGFX_DEBUG_TEXT); bgfx::setDebug(BGFX_DEBUG_STATS);// BGFX_DEBUG_TEXT);
@ -239,54 +223,50 @@ static int drawbgfx_window_create(sdl_window_info *window, int width, int height
} }
//============================================================ //============================================================
// drawbgfx_window_resize // sdl_info_bgfx::resize
//============================================================ //============================================================
static void drawbgfx_window_resize(sdl_window_info *window, int width, int height) void sdl_info_bgfx::resize(int width, int height)
{ {
sdl_info13 *sdl = (sdl_info13 *) window->dxdata; m_resize_pending = 1;
m_resize_height = height;
m_resize_width = width;
sdl->m_resize_pending = 1; window().m_width = width;
sdl->m_resize_height = height; window().m_height = height;
sdl->m_resize_width = width;
window->width = width; m_blittimer = 3;
window->height = height;
sdl->m_blittimer = 3;
} }
//============================================================ //============================================================
// drawsdl_xy_to_render_target // drawsdl_xy_to_render_target
//============================================================ //============================================================
static int drawbgfx_xy_to_render_target(sdl_window_info *window, int x, int y, int *xt, int *yt) int sdl_info_bgfx::xy_to_render_target(int x, int y, int *xt, int *yt)
{ {
sdl_info13 *sdl = (sdl_info13 *) window->dxdata; *xt = x - m_last_hofs;
*yt = y - m_last_vofs;
*xt = x - sdl->m_hofs; if (*xt<0 || *xt >= window().m_blitwidth)
*yt = y - sdl->m_vofs;
if (*xt<0 || *xt >= window->blitwidth)
return 0; return 0;
if (*yt<0 || *yt >= window->blitheight) if (*yt<0 || *yt >= window().m_blitheight)
return 0; return 0;
return 1; return 1;
} }
//============================================================ //============================================================
// drawbgfx_window_get_primitives // sdl_info_bgfx::get_primitives
//============================================================ //============================================================
static void drawbgfx_set_target_bounds(sdl_window_info *window) void sdl_info_bgfx::set_target_bounds()
{ {
window->target->set_bounds(window->blitwidth, window->blitheight, window->monitor()->aspect()); window().m_target->set_bounds(window().m_blitwidth, window().m_blitheight, window().monitor()->aspect());
} }
//============================================================ //============================================================
// drawbgfx_window_draw // sdl_info_bgfx::draw
//============================================================ //============================================================
static int drawbgfx_window_draw(sdl_window_info *window, UINT32 dc, int update) int sdl_info_bgfx::draw(UINT32 dc, int update)
{ {
bgfx::setViewClear(0 bgfx::setViewClear(0
, BGFX_CLEAR_COLOR|BGFX_CLEAR_DEPTH , BGFX_CLEAR_COLOR|BGFX_CLEAR_DEPTH
@ -295,14 +275,14 @@ static int drawbgfx_window_draw(sdl_window_info *window, UINT32 dc, int update)
, 0 , 0
); );
// Set view 0 default viewport. // Set view 0 default viewport.
bgfx::setViewRect(0, 0, 0, window->blitwidth, window->blitheight); bgfx::setViewRect(0, 0, 0, window().m_blitwidth, window().m_blitheight);
// This dummy draw call is here to make sure that view 0 is cleared // This dummy draw call is here to make sure that view 0 is cleared
// if no other draw calls are submitted to view 0. // if no other draw calls are submitted to view 0.
bgfx::submit(0); bgfx::submit(0);
window->primlist->acquire_lock(); window().m_primlist->acquire_lock();
window->primlist->release_lock(); window().m_primlist->release_lock();
// Advance to next frame. Rendering thread will be kicked to // Advance to next frame. Rendering thread will be kicked to
// process submitted rendering primitives. // process submitted rendering primitives.
bgfx::frame(); bgfx::frame();
@ -319,38 +299,29 @@ static void drawbgfx_exit(void)
} }
//============================================================ //============================================================
// drawbgfx_window_destroy // sdl_info_bgfx::destroy
//============================================================ //============================================================
static void drawbgfx_window_destroy(sdl_window_info *window) void sdl_info_bgfx::destroy()
{ {
sdl_info13 *sdl = (sdl_info13 *) window->dxdata;
// skip if nothing
if (sdl == NULL)
return;
// free the memory in the window // free the memory in the window
drawbgfx_destroy_all_textures(window); destroy_all_textures();
if (window->fullscreen() && video_config.switchres) if (window().fullscreen() && video_config.switchres)
{ {
SDL_SetWindowFullscreen(window->sdl_window, 0); // Try to set mode SDL_SetWindowFullscreen(window().m_sdl_window, 0); // Try to set mode
SDL_SetWindowDisplayMode(window->sdl_window, &sdl->m_original_mode); // Try to set mode SDL_SetWindowDisplayMode(window().m_sdl_window, &m_original_mode); // Try to set mode
SDL_SetWindowFullscreen(window->sdl_window, SDL_WINDOW_FULLSCREEN); // Try to set mode SDL_SetWindowFullscreen(window().m_sdl_window, SDL_WINDOW_FULLSCREEN); // Try to set mode
} }
SDL_DestroyWindow(window->sdl_window); SDL_DestroyWindow(window().m_sdl_window);
global_free(sdl);
window->dxdata = NULL;
// Shutdown bgfx. // Shutdown bgfx.
bgfx::shutdown(); bgfx::shutdown();
} }
static void drawbgfx_destroy_all_textures(sdl_window_info *window) void sdl_info_bgfx::destroy_all_textures()
{ {
} }
@ -358,9 +329,7 @@ static void drawbgfx_destroy_all_textures(sdl_window_info *window)
// TEXCOPY FUNCS // TEXCOPY FUNCS
//============================================================ //============================================================
static void drawbgfx_window_clear(sdl_window_info *window) void sdl_info_bgfx::clear()
{ {
sdl_info13 *sdl = (sdl_info13 *) window->dxdata; m_blittimer = 2;
sdl->m_blittimer = 2;
} }

View File

@ -80,6 +80,10 @@ SDL_FRAMEWORK_PATH = /Library/Frameworks/
# uncomment to use SDL1.2 (depracated) # uncomment to use SDL1.2 (depracated)
# SDL_LIBVER = sdl # SDL_LIBVER = sdl
# uncomment to use BGFX
# USE_BGFX = 1
########################################################################### ###########################################################################
################## END USER-CONFIGURABLE OPTIONS ###################### ################## END USER-CONFIGURABLE OPTIONS ######################
########################################################################### ###########################################################################
@ -779,8 +783,11 @@ endif
# BGFX # BGFX
#------------------------------------------------- #-------------------------------------------------
ifdef USE_BGFX
DEFS += -DUSE_BGFX
OSDOBJS += $(SDLOBJ)/drawbgfx.o OSDOBJS += $(SDLOBJ)/drawbgfx.o
INCPATH += -I$(3RDPARTY)/bgfx/include -I$(3RDPARTY)/bx/include INCPATH += -I$(3RDPARTY)/bgfx/include -I$(3RDPARTY)/bx/include
endif
#------------------------------------------------- #-------------------------------------------------
# X11 # X11

View File

@ -636,10 +636,12 @@ void sdl_osd_interface::extract_video_config(running_machine &machine)
{ {
video_config.mode = VIDEO_MODE_SDL2ACCEL; video_config.mode = VIDEO_MODE_SDL2ACCEL;
} }
#ifdef USE_BGFX
else if (strcmp(stemp, SDLOPTVAL_BGFX) == 0) else if (strcmp(stemp, SDLOPTVAL_BGFX) == 0)
{ {
video_config.mode = VIDEO_MODE_BGFX; video_config.mode = VIDEO_MODE_BGFX;
} }
#endif
else else
{ {
osd_printf_warning("Invalid video value %s; reverting to software\n", stemp); osd_printf_warning("Invalid video value %s; reverting to software\n", stemp);

View File

@ -259,11 +259,13 @@ bool sdl_osd_interface::window_init()
video_config.mode = VIDEO_MODE_SOFT; video_config.mode = VIDEO_MODE_SOFT;
} }
#endif #endif
#ifdef USE_BGFX
if (video_config.mode == VIDEO_MODE_BGFX) if (video_config.mode == VIDEO_MODE_BGFX)
{ {
if (drawbgfx_init(machine(), &draw)) if (drawbgfx_init(machine(), &draw))
video_config.mode = VIDEO_MODE_SOFT; video_config.mode = VIDEO_MODE_SOFT;
} }
#endif
if (video_config.mode == VIDEO_MODE_SOFT) if (video_config.mode == VIDEO_MODE_SOFT)
{ {
if (drawsdl_init(&draw)) if (drawsdl_init(&draw))