From 68fb63ad774d6920ab5c6da75d240dfa4d2cf838 Mon Sep 17 00:00:00 2001 From: couriersud Date: Sun, 1 Feb 2015 16:01:36 +0100 Subject: [PATCH] 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) --- src/osd/sdl/drawbgfx.c | 193 +++++++++++++++++------------------------ src/osd/sdl/sdl.mak | 7 ++ src/osd/sdl/video.c | 2 + src/osd/sdl/window.c | 2 + 4 files changed, 92 insertions(+), 112 deletions(-) diff --git a/src/osd/sdl/drawbgfx.c b/src/osd/sdl/drawbgfx.c index 4088149093f..a9992b9426a 100644 --- a/src/osd/sdl/drawbgfx.c +++ b/src/osd/sdl/drawbgfx.c @@ -64,30 +64,31 @@ // core functions 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 //============================================================ /* sdl_info is the information about SDL for the current screen */ -struct sdl_info13 +class sdl_info_bgfx : public osd_renderer { - sdl_info13() - : m_blittimer(0), m_renderer(NULL), - m_hofs(0), m_vofs(0), +public: + sdl_info_bgfx(sdl_window_info *w) + : 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_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); //texture_info *texture_find(const render_primitive &prim, const quad_setup_data &setup); @@ -98,8 +99,8 @@ struct sdl_info13 SDL_Renderer * m_renderer; //simple_list m_texlist; // list of active textures - float m_hofs; - float m_vofs; + float m_last_hofs; + float m_last_vofs; // resize information @@ -123,42 +124,27 @@ struct sdl_info13 // 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) { // fill in the callbacks callbacks->exit = drawbgfx_exit; - callbacks->attach = drawbgfx_attach; + callbacks->create = drawbgfx_create; 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 * 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"); - 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); #if defined(SDLMAME_WIN32) SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, "0"); #endif // create the SDL window - window->sdl_window = SDL_CreateWindow(window->title, - window->monitor()->position_size().x, window->monitor()->position_size().y, + window().m_sdl_window = SDL_CreateWindow(window().m_title, + window().monitor()->position_size().x, window().monitor()->position_size().y, width, height, extra_flags); - if (window->fullscreen() && video_config.switchres) + if (window().fullscreen() && video_config.switchres) { SDL_DisplayMode mode; - //SDL_GetCurrentDisplayMode(window->monitor()->handle, &mode); - SDL_GetWindowDisplayMode(window->sdl_window, &mode); - sdl->m_original_mode = mode; + //SDL_GetCurrentDisplayMode(window().monitor()->handle, &mode); + SDL_GetWindowDisplayMode(window().m_sdl_window, &mode); + m_original_mode = mode; mode.w = width; mode.h = height; - if (window->refresh) - mode.refresh_rate = window->refresh; + if (window().m_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 /* 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 * 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 } else { - //SDL_SetWindowDisplayMode(window->sdl_window, NULL); // Use desktop + //SDL_SetWindowDisplayMode(window().m_sdl_window, NULL); // Use desktop } // create renderer 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 - 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()); } - //SDL_SelectRenderer(window->sdl_window); - SDL_ShowWindow(window->sdl_window); - //SDL_SetWindowFullscreen(window->window_id, window->fullscreen); - SDL_RaiseWindow(window->sdl_window); + //SDL_SelectRenderer(window().m_sdl_window); + SDL_ShowWindow(window().m_sdl_window); + //SDL_SetWindowFullscreen(window().window_id, window().fullscreen); + 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::reset(window->width, window->height, BGFX_RESET_VSYNC); + bgfx::reset(window().m_width, window().m_height, BGFX_RESET_VSYNC); // Enable 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; - sdl->m_resize_height = height; - sdl->m_resize_width = width; + window().m_width = width; + window().m_height = height; - window->width = width; - window->height = height; - - sdl->m_blittimer = 3; + m_blittimer = 3; } //============================================================ // 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 - sdl->m_hofs; - *yt = y - sdl->m_vofs; - if (*xt<0 || *xt >= window->blitwidth) + *xt = x - m_last_hofs; + *yt = y - m_last_vofs; + if (*xt<0 || *xt >= window().m_blitwidth) return 0; - if (*yt<0 || *yt >= window->blitheight) + if (*yt<0 || *yt >= window().m_blitheight) return 0; 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_CLEAR_COLOR|BGFX_CLEAR_DEPTH @@ -295,14 +275,14 @@ static int drawbgfx_window_draw(sdl_window_info *window, UINT32 dc, int update) , 0 ); // 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 // if no other draw calls are submitted to view 0. bgfx::submit(0); - window->primlist->acquire_lock(); - window->primlist->release_lock(); + window().m_primlist->acquire_lock(); + window().m_primlist->release_lock(); // Advance to next frame. Rendering thread will be kicked to // process submitted rendering primitives. 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 - 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_SetWindowDisplayMode(window->sdl_window, &sdl->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, 0); // Try to set mode + SDL_SetWindowDisplayMode(window().m_sdl_window, &m_original_mode); // Try to set mode + SDL_SetWindowFullscreen(window().m_sdl_window, SDL_WINDOW_FULLSCREEN); // Try to set mode } - SDL_DestroyWindow(window->sdl_window); - - global_free(sdl); - window->dxdata = NULL; + SDL_DestroyWindow(window().m_sdl_window); // Shutdown bgfx. 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 //============================================================ -static void drawbgfx_window_clear(sdl_window_info *window) +void sdl_info_bgfx::clear() { - sdl_info13 *sdl = (sdl_info13 *) window->dxdata; - - sdl->m_blittimer = 2; + m_blittimer = 2; } diff --git a/src/osd/sdl/sdl.mak b/src/osd/sdl/sdl.mak index b788aa8c486..a765bb8a5ae 100644 --- a/src/osd/sdl/sdl.mak +++ b/src/osd/sdl/sdl.mak @@ -80,6 +80,10 @@ SDL_FRAMEWORK_PATH = /Library/Frameworks/ # uncomment to use SDL1.2 (depracated) # SDL_LIBVER = sdl +# uncomment to use BGFX + +# USE_BGFX = 1 + ########################################################################### ################## END USER-CONFIGURABLE OPTIONS ###################### ########################################################################### @@ -779,8 +783,11 @@ endif # BGFX #------------------------------------------------- +ifdef USE_BGFX +DEFS += -DUSE_BGFX OSDOBJS += $(SDLOBJ)/drawbgfx.o INCPATH += -I$(3RDPARTY)/bgfx/include -I$(3RDPARTY)/bx/include +endif #------------------------------------------------- # X11 diff --git a/src/osd/sdl/video.c b/src/osd/sdl/video.c index c646664d6a1..9b45ee2aae4 100644 --- a/src/osd/sdl/video.c +++ b/src/osd/sdl/video.c @@ -636,10 +636,12 @@ void sdl_osd_interface::extract_video_config(running_machine &machine) { video_config.mode = VIDEO_MODE_SDL2ACCEL; } +#ifdef USE_BGFX else if (strcmp(stemp, SDLOPTVAL_BGFX) == 0) { video_config.mode = VIDEO_MODE_BGFX; } +#endif else { osd_printf_warning("Invalid video value %s; reverting to software\n", stemp); diff --git a/src/osd/sdl/window.c b/src/osd/sdl/window.c index bb34c21e7b6..d0a555d48e5 100644 --- a/src/osd/sdl/window.c +++ b/src/osd/sdl/window.c @@ -259,11 +259,13 @@ bool sdl_osd_interface::window_init() video_config.mode = VIDEO_MODE_SOFT; } #endif +#ifdef USE_BGFX if (video_config.mode == VIDEO_MODE_BGFX) { if (drawbgfx_init(machine(), &draw)) video_config.mode = VIDEO_MODE_SOFT; } +#endif if (video_config.mode == VIDEO_MODE_SOFT) { if (drawsdl_init(&draw))