Previous 199869 Revisions Next

r34798 Sunday 1st February, 2015 at 15:01:36 UTC by Couriersud
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 sdl.mak video.c window.c

trunk/src/osd/sdl/drawbgfx.c
r243309r243310
6464// core functions
6565
6666static void drawbgfx_exit(void);
67static void drawbgfx_attach(sdl_draw_info *info, sdl_window_info *window);
68static int drawbgfx_window_create(sdl_window_info *window, int width, int height);
69static void drawbgfx_window_resize(sdl_window_info *window, int width, int height);
70static void drawbgfx_window_destroy(sdl_window_info *window);
71static int drawbgfx_window_draw(sdl_window_info *window, UINT32 dc, int update);
72static void drawbgfx_set_target_bounds(sdl_window_info *window);
73static void drawbgfx_destroy_all_textures(sdl_window_info *window);
74static void drawbgfx_window_clear(sdl_window_info *window);
75static int drawbgfx_xy_to_render_target(sdl_window_info *window, int x, int y, int *xt, int *yt);
7667
7768//============================================================
7869//  Textures
7970//============================================================
8071
8172/* sdl_info is the information about SDL for the current screen */
82struct sdl_info13
73class sdl_info_bgfx : public osd_renderer
8374{
84    sdl_info13()
85    : m_blittimer(0), m_renderer(NULL),
86      m_hofs(0), m_vofs(0),
75public:
76    sdl_info_bgfx(sdl_window_info *w)
77    : osd_renderer(w), m_blittimer(0), m_renderer(NULL),
78      m_last_hofs(0), m_last_vofs(0),
8779      m_resize_pending(0), m_resize_width(0), m_resize_height(0),
8880      m_last_blit_time(0), m_last_blit_pixels(0)
8981    {}
9082
83   /* virtual */ int create(int width, int height);
84   /* virtual */ void resize(int width, int height);
85   /* virtual */ int draw(UINT32 dc, int update);
86   /* virtual */ void set_target_bounds();
87   /* virtual */ int xy_to_render_target(int x, int y, int *xt, int *yt);
88   /* virtual */ void destroy_all_textures();
89   /* virtual */ void destroy();
90   /* virtual */ void clear();
91
9192   // void render_quad(texture_info *texture, const render_primitive *prim, const int x, const int y);
9293
9394    //texture_info *texture_find(const render_primitive &prim, const quad_setup_data &setup);
r243309r243310
9899   SDL_Renderer *  m_renderer;
99100   //simple_list<texture_info>  m_texlist;                // list of active textures
100101
101   float           m_hofs;
102   float           m_vofs;
102   float           m_last_hofs;
103   float           m_last_vofs;
103104
104105   // resize information
105106
r243309r243310
123124//  drawbgfx_init
124125//============================================================
125126
127static osd_renderer *drawbgfx_create(sdl_window_info *window)
128{
129   return global_alloc(sdl_info_bgfx(window));
130}
131
132
126133int drawbgfx_init(running_machine &machine, sdl_draw_info *callbacks)
127134{
128135   // fill in the callbacks
129136   callbacks->exit = drawbgfx_exit;
130   callbacks->attach = drawbgfx_attach;
137   callbacks->create = drawbgfx_create;
131138     
132139   return 0;
133140}
134141
135
136142//============================================================
137//  drawbgfx_attach
143//  sdl_info_bgfx::create
138144//============================================================
139145
140static void drawbgfx_attach(sdl_draw_info *info, sdl_window_info *window)
146int sdl_info_bgfx::create(int width, int height)
141147{
142   // fill in the callbacks
143   window->create = drawbgfx_window_create;
144   window->resize = drawbgfx_window_resize;
145   window->set_target_bounds = drawbgfx_set_target_bounds;
146   window->draw = drawbgfx_window_draw;
147   window->destroy = drawbgfx_window_destroy;
148   window->destroy_all_textures = drawbgfx_destroy_all_textures;
149   window->clear = drawbgfx_window_clear;
150   window->xy_to_render_target = drawbgfx_xy_to_render_target;
151}
152
153//============================================================
154//  drawbgfx_window_create
155//============================================================
156
157static int drawbgfx_window_create(sdl_window_info *window, int width, int height)
158{
159   // allocate memory for our structures
160   sdl_info13 *sdl = global_alloc(sdl_info13);
161
162148   /* FIXME: On Ubuntu and potentially other Linux OS you should use
163149    * to disable panning. This has to be done before every invocation of mame.
164150    *
r243309r243310
168154
169155   osd_printf_verbose("Enter drawsdl2_window_create\n");
170156
171   window->dxdata = sdl;
172
173   UINT32 extra_flags = (window->fullscreen() ?
157   UINT32 extra_flags = (window().fullscreen() ?
174158         SDL_WINDOW_BORDERLESS | SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_FULLSCREEN : SDL_WINDOW_RESIZABLE);
175159
176160#if defined(SDLMAME_WIN32)
177161   SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, "0");
178162#endif
179163   // create the SDL window
180   window->sdl_window = SDL_CreateWindow(window->title,
181         window->monitor()->position_size().x, window->monitor()->position_size().y,
164   window().m_sdl_window = SDL_CreateWindow(window().m_title,
165         window().monitor()->position_size().x, window().monitor()->position_size().y,
182166         width, height, extra_flags);
183167
184   if (window->fullscreen() && video_config.switchres)
168   if (window().fullscreen() && video_config.switchres)
185169   {
186170      SDL_DisplayMode mode;
187      //SDL_GetCurrentDisplayMode(window->monitor()->handle, &mode);
188      SDL_GetWindowDisplayMode(window->sdl_window, &mode);
189      sdl->m_original_mode = mode;
171      //SDL_GetCurrentDisplayMode(window().monitor()->handle, &mode);
172      SDL_GetWindowDisplayMode(window().m_sdl_window, &mode);
173      m_original_mode = mode;
190174      mode.w = width;
191175      mode.h = height;
192      if (window->refresh)
193         mode.refresh_rate = window->refresh;
176      if (window().m_refresh)
177         mode.refresh_rate = window().m_refresh;
194178
195      SDL_SetWindowDisplayMode(window->sdl_window, &mode);    // Try to set mode
179      SDL_SetWindowDisplayMode(window().m_sdl_window, &mode);    // Try to set mode
196180#ifndef SDLMAME_WIN32
197181      /* FIXME: Warp the mouse to 0,0 in case a virtual desktop resolution
198182       * is in place after the mode switch - which will most likely be the case
199183       * This is a hack to work around a deficiency in SDL2
200184       */
201      SDL_WarpMouseInWindow(window->sdl_window, 1, 1);
185      SDL_WarpMouseInWindow(window().m_sdl_window, 1, 1);
202186#endif
203187   }
204188   else
205189   {
206      //SDL_SetWindowDisplayMode(window->sdl_window, NULL); // Use desktop
190      //SDL_SetWindowDisplayMode(window().m_sdl_window, NULL); // Use desktop
207191   }
208192   // create renderer
209193
210194   if (video_config.waitvsync)
211      sdl->m_renderer = SDL_CreateRenderer(window->sdl_window, -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED);
195      m_renderer = SDL_CreateRenderer(window().m_sdl_window, -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED);
212196   else
213      sdl->m_renderer = SDL_CreateRenderer(window->sdl_window, -1, SDL_RENDERER_ACCELERATED);
197      m_renderer = SDL_CreateRenderer(window().m_sdl_window, -1, SDL_RENDERER_ACCELERATED);
214198
215   if (!sdl->m_renderer)
199   if (!m_renderer)
216200   {
217201      fatalerror("Error on creating renderer: %s\n", SDL_GetError());
218202   }
219203
220   //SDL_SelectRenderer(window->sdl_window);
221   SDL_ShowWindow(window->sdl_window);
222   //SDL_SetWindowFullscreen(window->window_id, window->fullscreen);
223   SDL_RaiseWindow(window->sdl_window);
204   //SDL_SelectRenderer(window().m_sdl_window);
205   SDL_ShowWindow(window().m_sdl_window);
206   //SDL_SetWindowFullscreen(window().window_id, window().fullscreen);
207   SDL_RaiseWindow(window().m_sdl_window);
224208
225   SDL_GetWindowSize(window->sdl_window, &window->width, &window->height);
209   SDL_GetWindowSize(window().m_sdl_window, &window().m_width, &window().m_height);
226210
227   sdl->m_blittimer = 3;
211   m_blittimer = 3;
228212
229   SDL_RenderPresent(sdl->m_renderer);
213   SDL_RenderPresent(m_renderer);
230214   
231   bgfx::sdlSetWindow(window->sdl_window);
215   bgfx::sdlSetWindow(window().m_sdl_window);
232216   bgfx::init();
233   bgfx::reset(window->width, window->height, BGFX_RESET_VSYNC);
217   bgfx::reset(window().m_width, window().m_height, BGFX_RESET_VSYNC);
234218   
235219   // Enable debug text.
236220   bgfx::setDebug(BGFX_DEBUG_STATS);// BGFX_DEBUG_TEXT);
r243309r243310
239223}
240224
241225//============================================================
242//  drawbgfx_window_resize
226//  sdl_info_bgfx::resize
243227//============================================================
244228
245static void drawbgfx_window_resize(sdl_window_info *window, int width, int height)
229void sdl_info_bgfx::resize(int width, int height)
246230{
247   sdl_info13 *sdl = (sdl_info13 *) window->dxdata;
231   m_resize_pending = 1;
232   m_resize_height = height;
233   m_resize_width = width;
248234
249   sdl->m_resize_pending = 1;
250   sdl->m_resize_height = height;
251   sdl->m_resize_width = width;
235   window().m_width = width;
236   window().m_height = height;
252237
253   window->width = width;
254   window->height = height;
255
256   sdl->m_blittimer = 3;
238   m_blittimer = 3;
257239}
258240
259241//============================================================
260242//  drawsdl_xy_to_render_target
261243//============================================================
262244
263static int drawbgfx_xy_to_render_target(sdl_window_info *window, int x, int y, int *xt, int *yt)
245int sdl_info_bgfx::xy_to_render_target(int x, int y, int *xt, int *yt)
264246{
265   sdl_info13 *sdl = (sdl_info13 *) window->dxdata;
266
267   *xt = x - sdl->m_hofs;
268   *yt = y - sdl->m_vofs;
269   if (*xt<0 || *xt >= window->blitwidth)
247   *xt = x - m_last_hofs;
248   *yt = y - m_last_vofs;
249   if (*xt<0 || *xt >= window().m_blitwidth)
270250      return 0;
271   if (*yt<0 || *yt >= window->blitheight)
251   if (*yt<0 || *yt >= window().m_blitheight)
272252      return 0;
273253   return 1;
274254}
275255
276256//============================================================
277//  drawbgfx_window_get_primitives
257//  sdl_info_bgfx::get_primitives
278258//============================================================
279259
280static void drawbgfx_set_target_bounds(sdl_window_info *window)
260void sdl_info_bgfx::set_target_bounds()
281261{
282   window->target->set_bounds(window->blitwidth, window->blitheight, window->monitor()->aspect());
262   window().m_target->set_bounds(window().m_blitwidth, window().m_blitheight, window().monitor()->aspect());
283263}
284264
285265//============================================================
286//  drawbgfx_window_draw
266//  sdl_info_bgfx::draw
287267//============================================================
288268
289static int drawbgfx_window_draw(sdl_window_info *window, UINT32 dc, int update)
269int sdl_info_bgfx::draw(UINT32 dc, int update)
290270{
291271   bgfx::setViewClear(0
292272      , BGFX_CLEAR_COLOR|BGFX_CLEAR_DEPTH
r243309r243310
295275      , 0
296276      );
297277   // Set view 0 default viewport.
298   bgfx::setViewRect(0, 0, 0, window->blitwidth, window->blitheight);
278   bgfx::setViewRect(0, 0, 0, window().m_blitwidth, window().m_blitheight);
299279
300280   // This dummy draw call is here to make sure that view 0 is cleared
301281   // if no other draw calls are submitted to view 0.
302282   bgfx::submit(0);
303283
304   window->primlist->acquire_lock();
305   window->primlist->release_lock();   
284   window().m_primlist->acquire_lock();
285   window().m_primlist->release_lock();
306286   // Advance to next frame. Rendering thread will be kicked to
307287   // process submitted rendering primitives.
308288   bgfx::frame();
r243309r243310
319299}
320300
321301//============================================================
322//  drawbgfx_window_destroy
302//  sdl_info_bgfx::destroy
323303//============================================================
324304
325static void drawbgfx_window_destroy(sdl_window_info *window)
305void sdl_info_bgfx::destroy()
326306{
327   sdl_info13 *sdl = (sdl_info13 *) window->dxdata;
328
329   // skip if nothing
330   if (sdl == NULL)
331      return;
332
333307   // free the memory in the window
334308
335   drawbgfx_destroy_all_textures(window);
309   destroy_all_textures();
336310
337   if (window->fullscreen() && video_config.switchres)
311   if (window().fullscreen() && video_config.switchres)
338312   {
339      SDL_SetWindowFullscreen(window->sdl_window, 0);    // Try to set mode
340      SDL_SetWindowDisplayMode(window->sdl_window, &sdl->m_original_mode);    // Try to set mode
341      SDL_SetWindowFullscreen(window->sdl_window, SDL_WINDOW_FULLSCREEN);    // Try to set mode
313      SDL_SetWindowFullscreen(window().m_sdl_window, 0);    // Try to set mode
314      SDL_SetWindowDisplayMode(window().m_sdl_window, &m_original_mode);    // Try to set mode
315      SDL_SetWindowFullscreen(window().m_sdl_window, SDL_WINDOW_FULLSCREEN);    // Try to set mode
342316   }
343317
344   SDL_DestroyWindow(window->sdl_window);
345
346   global_free(sdl);
347   window->dxdata = NULL;
318   SDL_DestroyWindow(window().m_sdl_window);
348319   
349320   // Shutdown bgfx.
350321   bgfx::shutdown();
351322}
352323
353static void drawbgfx_destroy_all_textures(sdl_window_info *window)
324void sdl_info_bgfx::destroy_all_textures()
354325{
355326}
356327
r243309r243310
358329//  TEXCOPY FUNCS
359330//============================================================
360331
361static void drawbgfx_window_clear(sdl_window_info *window)
332void sdl_info_bgfx::clear()
362333{
363   sdl_info13 *sdl = (sdl_info13 *) window->dxdata;
364
365   sdl->m_blittimer = 2;
334   m_blittimer = 2;
366335}
trunk/src/osd/sdl/sdl.mak
r243309r243310
8080# uncomment to use SDL1.2 (depracated)
8181# SDL_LIBVER = sdl
8282
83# uncomment to use BGFX
84
85# USE_BGFX = 1
86
8387###########################################################################
8488##################   END USER-CONFIGURABLE OPTIONS   ######################
8589###########################################################################
r243309r243310
779783# BGFX
780784#-------------------------------------------------
781785
786ifdef USE_BGFX
787DEFS += -DUSE_BGFX
782788OSDOBJS += $(SDLOBJ)/drawbgfx.o
783789INCPATH += -I$(3RDPARTY)/bgfx/include -I$(3RDPARTY)/bx/include
790endif
784791
785792#-------------------------------------------------
786793# X11
trunk/src/osd/sdl/video.c
r243309r243310
636636   {
637637      video_config.mode = VIDEO_MODE_SDL2ACCEL;
638638   }
639#ifdef USE_BGFX
639640   else if (strcmp(stemp, SDLOPTVAL_BGFX) == 0)
640641   {
641642      video_config.mode = VIDEO_MODE_BGFX;
642643   }
644#endif
643645   else
644646   {
645647      osd_printf_warning("Invalid video value %s; reverting to software\n", stemp);
trunk/src/osd/sdl/window.c
r243309r243310
259259         video_config.mode = VIDEO_MODE_SOFT;
260260   }
261261#endif
262#ifdef USE_BGFX
262263   if (video_config.mode == VIDEO_MODE_BGFX)
263264   {
264265      if (drawbgfx_init(machine(), &draw))
265266         video_config.mode = VIDEO_MODE_SOFT;
266267   }
268#endif
267269   if (video_config.mode == VIDEO_MODE_SOFT)
268270   {
269271      if (drawsdl_init(&draw))


Previous 199869 Revisions Next


© 1997-2024 The MAME Team