Previous 199869 Revisions Next

r34793 Sunday 1st February, 2015 at 02:00:21 UTC by Couriersud
introduced concept of an osd_renderer. Changed draw code to
inherit from this interface. (nw)
[src/osd/sdl]draw13.c drawogl.c drawsdl.c input.c window.c window.h

trunk/src/osd/sdl/draw13.c
r243304r243305
7979//  Textures
8080//============================================================
8181
82struct sdl_info13;
82class sdl_info13;
8383struct copy_info_t;
8484
8585/* texture_info holds information about a texture */
r243304r243305
139139#include "blit13.h"
140140
141141/* sdl_info is the information about SDL for the current screen */
142struct sdl_info13
142class sdl_info13 : public osd_renderer
143143{
144    sdl_info13()
145    : m_blittimer(0), m_renderer(NULL),
144public:
145    sdl_info13(sdl_window_info *w)
146    : osd_renderer(w), m_blittimer(0), m_renderer(NULL),
146147      m_hofs(0), m_vofs(0),
147148      m_resize_pending(0), m_resize_width(0), m_resize_height(0),
148149      m_last_blit_time(0), m_last_blit_pixels(0)
149150    {}
150151
152   /* virtual */ int create(int width, int height);
153   /* virtual */ void resize(int width, int height);
154   /* virtual */ int draw(UINT32 dc, int update);
155   /* virtual */ void set_target_bounds();
156   /* virtual */ int xy_to_render_target(int x, int y, int *xt, int *yt);
157   /* virtual */ void destroy_all_textures();
158   /* virtual */ void destroy();
159   /* virtual */ void clear();
160
151161    void render_quad(texture_info *texture, const render_primitive *prim, const int x, const int y);
152162
153163    texture_info *texture_find(const render_primitive &prim, const quad_setup_data &setup);
r243304r243305
198208// core functions
199209
200210static void drawsdl2_exit(void);
201static void drawsdl2_attach(sdl_draw_info *info, sdl_window_info *window);
202static int drawsdl2_window_create(sdl_window_info *window, int width, int height);
203static void drawsdl2_window_resize(sdl_window_info *window, int width, int height);
204static void drawsdl2_window_destroy(sdl_window_info *window);
205static int drawsdl2_window_draw(sdl_window_info *window, UINT32 dc, int update);
206static void drawsdl2_set_target_bounds(sdl_window_info *window);
207static void drawsdl2_destroy_all_textures(sdl_window_info *window);
208static void drawsdl2_window_clear(sdl_window_info *window);
209static int drawsdl2_xy_to_render_target(sdl_window_info *window, int x, int y, int *xt, int *yt);
210211
211212//============================================================
212213//  STATIC VARIABLES
r243304r243305
483484   }
484485}
485486
487static osd_renderer *drawsdl2_create(sdl_window_info *window)
488{
489   return global_alloc(sdl_info13(window));
490}
491
486492// FIXME: machine only used to access options.
487493int drawsdl2_init(running_machine &machine, sdl_draw_info *callbacks)
488494{
r243304r243305
490496
491497   // fill in the callbacks
492498   callbacks->exit = drawsdl2_exit;
493   callbacks->attach = drawsdl2_attach;
499   callbacks->create = drawsdl2_create;
494500
495501   osd_printf_verbose("Using SDL native texturing driver (SDL 2.0+)\n");
496502
r243304r243305
550556}
551557
552558//============================================================
553//  drawsdl2_attach
559//  sdl_info13::create
554560//============================================================
555561
556static void drawsdl2_attach(sdl_draw_info *info, sdl_window_info *window)
562int sdl_info13::create(int width, int height)
557563{
558   // fill in the callbacks
559   window->create = drawsdl2_window_create;
560   window->resize = drawsdl2_window_resize;
561   window->set_target_bounds = drawsdl2_set_target_bounds;
562   window->draw = drawsdl2_window_draw;
563   window->destroy = drawsdl2_window_destroy;
564   window->destroy_all_textures = drawsdl2_destroy_all_textures;
565   window->clear = drawsdl2_window_clear;
566   window->xy_to_render_target = drawsdl2_xy_to_render_target;
567}
568
569//============================================================
570//  drawsdl2_window_create
571//============================================================
572
573static int drawsdl2_window_create(sdl_window_info *window, int width, int height)
574{
575   // allocate memory for our structures
576   sdl_info13 *sdl = global_alloc(sdl_info13);
577
578564   /* FIXME: On Ubuntu and potentially other Linux OS you should use
579565    * to disable panning. This has to be done before every invocation of mame.
580566    *
r243304r243305
582568    *
583569    */
584570
585   osd_printf_verbose("Enter drawsdl2_window_create\n");
571   osd_printf_verbose("Enter sdl_info13::create\n");
586572
587   window->m_dxdata = sdl;
588
589   UINT32 extra_flags = (window->fullscreen() ?
573   UINT32 extra_flags = (window().fullscreen() ?
590574         SDL_WINDOW_BORDERLESS | SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_FULLSCREEN : SDL_WINDOW_RESIZABLE);
591575
592576#if defined(SDLMAME_WIN32)
593577   SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, "0");
594578#endif
595579   // create the SDL window
596   window->m_sdl_window = SDL_CreateWindow(window->m_title,
597         window->monitor()->position_size().x, window->monitor()->position_size().y,
580   window().m_sdl_window = SDL_CreateWindow(window().m_title,
581         window().monitor()->position_size().x, window().monitor()->position_size().y,
598582         width, height, extra_flags);
599583
600   if (window->fullscreen() && video_config.switchres)
584   if (window().fullscreen() && video_config.switchres)
601585   {
602586      SDL_DisplayMode mode;
603      //SDL_GetCurrentDisplayMode(window->monitor()->handle, &mode);
604      SDL_GetWindowDisplayMode(window->m_sdl_window, &mode);
605      sdl->m_original_mode = mode;
587      //SDL_GetCurrentDisplayMode(window().monitor()->handle, &mode);
588      SDL_GetWindowDisplayMode(window().m_sdl_window, &mode);
589      m_original_mode = mode;
606590      mode.w = width;
607591      mode.h = height;
608      if (window->m_refresh)
609         mode.refresh_rate = window->m_refresh;
592      if (window().m_refresh)
593         mode.refresh_rate = window().m_refresh;
610594#if 0
611      if (window->depth)
595      if (window().depth)
612596      {
613         switch (window->depth)
597         switch (window().depth)
614598         {
615599         case 15:
616600            mode.format = SDL_PIXELFORMAT_RGB555;
r243304r243305
625609            mode.format = SDL_PIXELFORMAT_RGB888;
626610            break;
627611         default:
628            osd_printf_warning("Ignoring depth %d\n", window->depth);
612            osd_printf_warning("Ignoring depth %d\n", window().depth);
629613         }
630614      }
631615#endif
632616
633      SDL_SetWindowDisplayMode(window->m_sdl_window, &mode);    // Try to set mode
617      SDL_SetWindowDisplayMode(window().m_sdl_window, &mode);    // Try to set mode
634618#ifndef SDLMAME_WIN32
635619      /* FIXME: Warp the mouse to 0,0 in case a virtual desktop resolution
636620       * is in place after the mode switch - which will most likely be the case
637621       * This is a hack to work around a deficiency in SDL2
638622       */
639      SDL_WarpMouseInWindow(window->m_sdl_window, 1, 1);
623      SDL_WarpMouseInWindow(window().m_sdl_window, 1, 1);
640624#endif
641625   }
642626   else
643627   {
644      //SDL_SetWindowDisplayMode(window->sdl_window, NULL); // Use desktop
628      //SDL_SetWindowDisplayMode(window().sdl_window, NULL); // Use desktop
645629   }
646630   // create renderer
647631
648632   if (video_config.waitvsync)
649      sdl->m_renderer = SDL_CreateRenderer(window->m_sdl_window, -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED);
633      m_renderer = SDL_CreateRenderer(window().m_sdl_window, -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED);
650634   else
651      sdl->m_renderer = SDL_CreateRenderer(window->m_sdl_window, -1, SDL_RENDERER_ACCELERATED);
635      m_renderer = SDL_CreateRenderer(window().m_sdl_window, -1, SDL_RENDERER_ACCELERATED);
652636
653   if (!sdl->m_renderer)
637   if (!m_renderer)
654638   {
655639      fatalerror("Error on creating renderer: %s\n", SDL_GetError());
656640   }
657641
658   //SDL_SelectRenderer(window->sdl_window);
659   SDL_ShowWindow(window->m_sdl_window);
660   //SDL_SetWindowFullscreen(window->window_id, window->fullscreen);
661   SDL_RaiseWindow(window->m_sdl_window);
642   //SDL_SelectRenderer(window().sdl_window);
643   SDL_ShowWindow(window().m_sdl_window);
644   //SDL_SetWindowFullscreen(window().window_id, window().fullscreen);
645   SDL_RaiseWindow(window().m_sdl_window);
662646
663   SDL_GetWindowSize(window->m_sdl_window, &window->m_width, &window->m_height);
647   SDL_GetWindowSize(window().m_sdl_window, &window().m_width, &window().m_height);
664648
665   sdl->m_blittimer = 3;
649   m_blittimer = 3;
666650
667   SDL_RenderPresent(sdl->m_renderer);
668   osd_printf_verbose("Leave drawsdl2_window_create\n");
651   SDL_RenderPresent(m_renderer);
652   osd_printf_verbose("Leave sdl_info13::create\n");
669653   return 0;
670654}
671655
672656//============================================================
673//  drawsdl2_window_resize
657//  sdl_info13::resize
674658//============================================================
675659
676static void drawsdl2_window_resize(sdl_window_info *window, int width, int height)
660void sdl_info13::resize(int width, int height)
677661{
678   sdl_info13 *sdl = (sdl_info13 *) window->m_dxdata;
662   m_resize_pending = 1;
663   m_resize_height = height;
664   m_resize_width = width;
679665
680   sdl->m_resize_pending = 1;
681   sdl->m_resize_height = height;
682   sdl->m_resize_width = width;
666   window().m_width = width;
667   window().m_height = height;
683668
684   window->m_width = width;
685   window->m_height = height;
669   m_blittimer = 3;
686670
687   sdl->m_blittimer = 3;
688
689671}
690672
691673//============================================================
692674//  drawsdl_xy_to_render_target
693675//============================================================
694676
695static int drawsdl2_xy_to_render_target(sdl_window_info *window, int x, int y, int *xt, int *yt)
677int sdl_info13::xy_to_render_target(int x, int y, int *xt, int *yt)
696678{
697   sdl_info13 *sdl = (sdl_info13 *) window->m_dxdata;
698679
699   *xt = x - sdl->m_hofs;
700   *yt = y - sdl->m_vofs;
701   if (*xt<0 || *xt >= window->m_blitwidth)
680   *xt = x - m_hofs;
681   *yt = y - m_vofs;
682   if (*xt<0 || *xt >= window().m_blitwidth)
702683      return 0;
703   if (*yt<0 || *yt >= window->m_blitheight)
684   if (*yt<0 || *yt >= window().m_blitheight)
704685      return 0;
705686   return 1;
706687}
707688
708689//============================================================
709//  drawsdl2_window_get_primitives
690//  sdl_info13::get_primitives
710691//============================================================
711692
712static void drawsdl2_set_target_bounds(sdl_window_info *window)
693void sdl_info13::set_target_bounds()
713694{
714   window->m_target->set_bounds(window->m_blitwidth, window->m_blitheight, window->monitor()->aspect());
695   window().m_target->set_bounds(window().m_blitwidth, window().m_blitheight, window().monitor()->aspect());
715696}
716697
717698//============================================================
718//  drawsdl2_window_draw
699//  sdl_info13::draw
719700//============================================================
720701
721static int drawsdl2_window_draw(sdl_window_info *window, UINT32 dc, int update)
702int sdl_info13::draw(UINT32 dc, int update)
722703{
723   sdl_info13 *sdl = (sdl_info13 *) window->m_dxdata;
724704   render_primitive *prim;
725705   texture_info *texture=NULL;
726706   float vofs, hofs;
r243304r243305
731711      return 0;
732712   }
733713
734   if (sdl->m_resize_pending)
714   if (m_resize_pending)
735715   {
736      SDL_SetWindowSize(window->m_sdl_window, sdl->m_resize_width, sdl->m_resize_height);
737      SDL_GetWindowSize(window->m_sdl_window, &window->m_width, &window->m_height);
738      sdl->m_resize_pending = 0;
739      SDL_RenderSetViewport(sdl->m_renderer, NULL);
740      //sdlvideo_monitor_refresh(window->monitor());
716      SDL_SetWindowSize(window().m_sdl_window, m_resize_width, m_resize_height);
717      SDL_GetWindowSize(window().m_sdl_window, &window().m_width, &window().m_height);
718      m_resize_pending = 0;
719      SDL_RenderSetViewport(m_renderer, NULL);
720      //sdlvideo_monitor_refresh(window().monitor());
741721
742722   }
743723
744   //SDL_SelectRenderer(window->sdl_window);
724   //SDL_SelectRenderer(window().sdl_window);
745725
746   if (sdl->m_blittimer > 0)
726   if (m_blittimer > 0)
747727   {
748728      /* SDL Underlays need alpha = 0 ! */
749      SDL_SetRenderDrawBlendMode(sdl->m_renderer, SDL_BLENDMODE_NONE);
729      SDL_SetRenderDrawBlendMode(m_renderer, SDL_BLENDMODE_NONE);
750730      //SDL_SetRenderDrawColor(0,0,0,255);
751      SDL_SetRenderDrawColor(sdl->m_renderer, 0,0,0,0);
752      SDL_RenderFillRect(sdl->m_renderer, NULL);
753      sdl->m_blittimer--;
731      SDL_SetRenderDrawColor(m_renderer, 0,0,0,0);
732      SDL_RenderFillRect(m_renderer, NULL);
733      m_blittimer--;
754734   }
755735
756736   // compute centering parameters
r243304r243305
760740   {
761741      int ch, cw;
762742
763      if ((window->fullscreen()) && (!video_config.switchres))
743      if ((window().fullscreen()) && (!video_config.switchres))
764744      {
765         ch = window->monitor()->center_height();
766         cw = window->monitor()->center_width();
745         ch = window().monitor()->center_height();
746         cw = window().monitor()->center_width();
767747      }
768748      else
769749      {
770         ch = window->m_height;
771         cw = window->m_width;
750         ch = window().m_height;
751         cw = window().m_width;
772752      }
773753
774754      if (video_config.centerv)
775755      {
776         vofs = (ch - window->m_blitheight) / 2.0f;
756         vofs = (ch - window().m_blitheight) / 2.0f;
777757      }
778758      if (video_config.centerh)
779759      {
780         hofs = (cw - window->m_blitwidth) / 2.0f;
760         hofs = (cw - window().m_blitwidth) / 2.0f;
781761      }
782762   }
783763
784   sdl->m_hofs = hofs;
785   sdl->m_vofs = vofs;
764   m_hofs = hofs;
765   m_vofs = vofs;
786766
787   window->m_primlist->acquire_lock();
767   window().m_primlist->acquire_lock();
788768
789769   // now draw
790   for (prim = window->m_primlist->first(); prim != NULL; prim = prim->next())
770   for (prim = window().m_primlist->first(); prim != NULL; prim = prim->next())
791771   {
792772      Uint8 sr, sg, sb, sa;
793773
r243304r243305
799779            sb = (int)(255.0f * prim->color.b);
800780            sa = (int)(255.0f * prim->color.a);
801781
802            SDL_SetRenderDrawBlendMode(sdl->m_renderer, map_blendmode(PRIMFLAG_GET_BLENDMODE(prim->flags)));
803            SDL_SetRenderDrawColor(sdl->m_renderer, sr, sg, sb, sa);
804            SDL_RenderDrawLine(sdl->m_renderer, prim->bounds.x0 + hofs, prim->bounds.y0 + vofs,
782            SDL_SetRenderDrawBlendMode(m_renderer, map_blendmode(PRIMFLAG_GET_BLENDMODE(prim->flags)));
783            SDL_SetRenderDrawColor(m_renderer, sr, sg, sb, sa);
784            SDL_RenderDrawLine(m_renderer, prim->bounds.x0 + hofs, prim->bounds.y0 + vofs,
805785                  prim->bounds.x1 + hofs, prim->bounds.y1 + vofs);
806786            break;
807787         case render_primitive::QUAD:
808            texture = sdl->texture_update(*prim);
788            texture = texture_update(*prim);
809789            if (texture)
810790               blit_pixels += (texture->raw_height() * texture->raw_width());
811            sdl->render_quad(texture, prim,
791            render_quad(texture, prim,
812792                  round_nearest(hofs + prim->bounds.x0),
813793                  round_nearest(vofs + prim->bounds.y0));
814794            break;
r243304r243305
817797      }
818798   }
819799
820   window->m_primlist->release_lock();
800   window().m_primlist->release_lock();
821801
822   sdl->m_last_blit_pixels = blit_pixels;
823   sdl->m_last_blit_time = -osd_ticks();
824   SDL_RenderPresent(sdl->m_renderer);
825   sdl->m_last_blit_time += osd_ticks();
802   m_last_blit_pixels = blit_pixels;
803   m_last_blit_time = -osd_ticks();
804   SDL_RenderPresent(m_renderer);
805   m_last_blit_time += osd_ticks();
826806
827807   return 0;
828808}
829809
830810
831811//============================================================
832//  drawsdl2_window_clear
812//  sdl_info13::clear
833813//============================================================
834814
835static void drawsdl2_window_clear(sdl_window_info *window)
815void sdl_info13::clear()
836816{
837   sdl_info13 *sdl = (sdl_info13 *) window->m_dxdata;
838
839   sdl->m_blittimer = 2;
817   m_blittimer = 2;
840818}
841819
842820
843821//============================================================
844//  drawsdl2_window_destroy
822//  sdl_info13::destroy
845823//============================================================
846824
847static void drawsdl2_window_destroy(sdl_window_info *window)
825void sdl_info13::destroy()
848826{
849   sdl_info13 *sdl = (sdl_info13 *) window->m_dxdata;
850
851   // skip if nothing
852   if (sdl == NULL)
853      return;
854
855827   // free the memory in the window
856828
857   drawsdl2_destroy_all_textures(window);
829   destroy_all_textures();
858830
859   if (window->fullscreen() && video_config.switchres)
831   if (window().fullscreen() && video_config.switchres)
860832   {
861      SDL_SetWindowFullscreen(window->m_sdl_window, 0);    // Try to set mode
862      SDL_SetWindowDisplayMode(window->m_sdl_window, &sdl->m_original_mode);    // Try to set mode
863      SDL_SetWindowFullscreen(window->m_sdl_window, SDL_WINDOW_FULLSCREEN);    // Try to set mode
833      SDL_SetWindowFullscreen(window().m_sdl_window, 0);    // Try to set mode
834      SDL_SetWindowDisplayMode(window().m_sdl_window, &m_original_mode);    // Try to set mode
835      SDL_SetWindowFullscreen(window().m_sdl_window, SDL_WINDOW_FULLSCREEN);    // Try to set mode
864836   }
865837
866   SDL_DestroyWindow(window->m_sdl_window);
838   SDL_DestroyWindow(window().m_sdl_window);
867839
868   global_free(sdl);
869   window->m_dxdata = NULL;
870840}
871841
872842//============================================================
r243304r243305
11881158}
11891159
11901160
1191static void drawsdl2_destroy_all_textures(sdl_window_info *window)
1161void sdl_info13::destroy_all_textures()
11921162{
1193   sdl_info13 *sdl = (sdl_info13 *) window->m_dxdata;
1194
1195   if (sdl == NULL)
1196      return;
1197
1198   if(window->m_primlist)
1163   if(window().m_primlist)
11991164   {
1200      window->m_primlist->acquire_lock();
1201      sdl->m_texlist.reset();
1202      window->m_primlist->release_lock();
1165      window().m_primlist->acquire_lock();
1166      m_texlist.reset();
1167      window().m_primlist->release_lock();
12031168   }
12041169   else
1205      sdl->m_texlist.reset();
1170      m_texlist.reset();
12061171}
trunk/src/osd/sdl/drawogl.c
r243304r243305
215215};
216216
217217/* sdl_info is the information about SDL for the current screen */
218struct sdl_info
218class sdl_info_ogl : public osd_renderer
219219{
220   sdl_info()
221   : m_blittimer(0), m_extra_flags(0),
220public:
221   sdl_info_ogl(sdl_window_info *window)
222   : osd_renderer(window), m_blittimer(0), m_extra_flags(0),
222223#if (SDLMAME_SDL2)
223224      m_gl_context_id(0),
224225#else
r243304r243305
247248         m_texVerticex[i] = 0.0f;
248249   }
249250
251   /* virtual */ int create(int width, int height);
252   /* virtual */ void resize(int width, int height);
253   /* virtual */ int draw(UINT32 dc, int update);
254   /* virtual */ void set_target_bounds();
255   /* virtual */ int xy_to_render_target(int x, int y, int *xt, int *yt);
256   /* virtual */ void destroy_all_textures();
257   /* virtual */ void destroy();
258   /* virtual */ void clear();
259
260   void loadGLExtensions();
261   void set_blendmode(int blendmode);
262   void texture_compute_type_subroutine(const render_texinfo *texsource, texture_info *texture, UINT32 flags);
263   void texture_compute_size_subroutine(texture_info *texture, UINT32 flags,
264            UINT32 width, UINT32 height,
265            int* p_width, int* p_height, int* p_width_create, int* p_height_create);
266   void texture_compute_size_type(const render_texinfo *texsource, texture_info *texture, UINT32 flags);
267   texture_info *texture_create(const render_texinfo *texsource, UINT32 flags);
268   int texture_shader_create(const render_texinfo *texsource, texture_info *texture, UINT32 flags);
269   texture_info *texture_find(const render_primitive *prim);
270   void texture_coord_update(texture_info *texture, const render_primitive *prim, int shaderIdx);
271   void texture_mpass_flip(texture_info *texture, int shaderIdx);
272   void texture_shader_update(texture_info *texture, int shaderIdx);
273   texture_info * texture_update(const render_primitive *prim, int shaderIdx);
274   void texture_disable(texture_info * texture);
275   void texture_all_disable();
276
250277   INT32           m_blittimer;
251278   UINT32          m_extra_flags;
252279
r243304r243305
327354   return (h >> 8) % HASH_SIZE;
328355}
329356
330INLINE void set_blendmode(sdl_info *sdl, int blendmode)
357void sdl_info_ogl::set_blendmode(int blendmode)
331358{
332359   // try to minimize texture state changes
333   if (blendmode != sdl->m_last_blendmode)
360   if (blendmode != m_last_blendmode)
334361   {
335362      switch (blendmode)
336363      {
r243304r243305
351378            break;
352379      }
353380
354      sdl->m_last_blendmode = blendmode;
381      m_last_blendmode = blendmode;
355382   }
356383}
357384
r243304r243305
362389// core functions
363390
364391static void drawogl_exit(void);
365static void drawogl_attach(sdl_draw_info *info, sdl_window_info *window);
366static int drawogl_window_create(sdl_window_info *window, int width, int height);
367static void drawogl_window_resize(sdl_window_info *window, int width, int height);
368static void drawogl_window_destroy(sdl_window_info *window);
369static int drawogl_window_draw(sdl_window_info *window, UINT32 dc, int update);
370static void drawogl_set_target_bounds(sdl_window_info *window);
371static void drawogl_destroy_all_textures(sdl_window_info *window);
372static void drawogl_window_clear(sdl_window_info *window);
373static int drawogl_xy_to_render_target(sdl_window_info *window, int x, int y, int *xt, int *yt);
374392static void load_gl_lib(running_machine &machine);
375393
376394
r243304r243305
408426//============================================================
409427
410428static void texture_set_data(texture_info *texture, const render_texinfo *texsource, UINT32 flags);
411static texture_info *texture_create(sdl_window_info *window, const render_texinfo *texsource, UINT32 flags);
412static texture_info *texture_find(sdl_info *sdl, const render_primitive *prim);
413static texture_info * texture_update(sdl_window_info *window, const render_primitive *prim, int shaderIdx);
414static void texture_all_disable(sdl_info *sdl);
415static void texture_disable(sdl_info *sdl, texture_info * texture);
416429
417430//============================================================
418431//  Static Variables
r243304r243305
425438//  drawogl_init
426439//============================================================
427440
441static osd_renderer *drawogl_create(sdl_window_info *window)
442{
443   return global_alloc(sdl_info_ogl(window));
444}
445
428446int drawogl_init(running_machine &machine, sdl_draw_info *callbacks)
429447{
430448   // fill in the callbacks
431449   callbacks->exit = drawogl_exit;
432   callbacks->attach = drawogl_attach;
450   callbacks->create = drawogl_create;
433451
434452   dll_loaded = 0;
435453
r243304r243305
449467//  drawogl_attach
450468//============================================================
451469
452static void drawogl_attach(sdl_draw_info *info, sdl_window_info *window)
453{
454   // fill in the callbacks
455   window->create = drawogl_window_create;
456   window->resize = drawogl_window_resize;
457   window->set_target_bounds = drawogl_set_target_bounds;
458   window->draw = drawogl_window_draw;
459   window->destroy = drawogl_window_destroy;
460   window->destroy_all_textures = drawogl_destroy_all_textures;
461   window->clear = drawogl_window_clear;
462   window->xy_to_render_target = drawogl_xy_to_render_target;
463}
464
465
466470//============================================================
467471// Load the OGL function addresses
468472//============================================================
r243304r243305
525529}
526530
527531//============================================================
528//  drawogl_window_create
532//  sdl_info::create
529533//============================================================
530534
531static int drawogl_window_create(sdl_window_info *window, int width, int height)
535int sdl_info_ogl::create(int width, int height)
532536{
533   sdl_info *sdl;
534537   char *extstr;
535538   char *vendor;
536539   int has_and_allow_texturerect = 0;
537540
538   // allocate memory for our structures
539   sdl = global_alloc(sdl_info);
540
541   window->m_dxdata = sdl;
542
543541#if (SDLMAME_SDL2)
544   sdl->m_extra_flags = (window->fullscreen() ?
542   m_extra_flags = (window().fullscreen() ?
545543         SDL_WINDOW_BORDERLESS | SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_FULLSCREEN : SDL_WINDOW_RESIZABLE);
546   sdl->m_extra_flags |= SDL_WINDOW_OPENGL;
544   m_extra_flags |= SDL_WINDOW_OPENGL;
547545
548546   SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
549547
r243304r243305
555553    */
556554
557555   //Moved into init
558   //load_gl_lib(window->machine());
556   //load_gl_lib(window().machine());
559557
560558   // create the SDL window
561   window->m_sdl_window = SDL_CreateWindow(window->m_title,
562         window->monitor()->position_size().x, window->monitor()->position_size().y,
563         width, height, sdl->m_extra_flags);
559   window().m_sdl_window = SDL_CreateWindow(window().m_title,
560         window().monitor()->position_size().x, window().monitor()->position_size().y,
561         width, height, m_extra_flags);
564562
565   if  (!window->m_sdl_window )
563   if  (!window().m_sdl_window )
566564   {
567565      osd_printf_error("OpenGL not supported on this driver: %s\n", SDL_GetError());
568566      return 1;
569567   }
570568
571   if (window->fullscreen() && video_config.switchres)
569   if (window().fullscreen() && video_config.switchres)
572570   {
573571      SDL_DisplayMode mode;
574      SDL_GetCurrentDisplayMode(window->monitor()->handle(), &mode);
572      SDL_GetCurrentDisplayMode(window().monitor()->handle(), &mode);
575573      mode.w = width;
576574      mode.h = height;
577      if (window->m_refresh)
578         mode.refresh_rate = window->m_refresh;
579      SDL_SetWindowDisplayMode(window->m_sdl_window, &mode);    // Try to set mode
575      if (window().m_refresh)
576         mode.refresh_rate = window().m_refresh;
577      SDL_SetWindowDisplayMode(window().m_sdl_window, &mode);    // Try to set mode
580578   }
581579   else
582      SDL_SetWindowDisplayMode(window->m_sdl_window, NULL); // Use desktop
580      SDL_SetWindowDisplayMode(window().m_sdl_window, NULL); // Use desktop
583581
584   SDL_ShowWindow(window->m_sdl_window);
585   //SDL_SetWindowFullscreen(window->sdl_window, window->fullscreen);
586   SDL_RaiseWindow(window->m_sdl_window);
587   SDL_GetWindowSize(window->m_sdl_window, &window->m_width, &window->m_height);
582   SDL_ShowWindow(window().m_sdl_window);
583   //SDL_SetWindowFullscreen(window().sdl_window, window().fullscreen);
584   SDL_RaiseWindow(window().m_sdl_window);
585   SDL_GetWindowSize(window().m_sdl_window, &window().m_width, &window().m_height);
588586
589   sdl->m_gl_context_id = SDL_GL_CreateContext(window->m_sdl_window);
590   if  (!sdl->m_gl_context_id)
587   m_gl_context_id = SDL_GL_CreateContext(window().m_sdl_window);
588   if  (!m_gl_context_id)
591589   {
592590      osd_printf_error("OpenGL not supported on this driver: %s\n", SDL_GetError());
593591      return 1;
r243304r243305
596594   SDL_GL_SetSwapInterval(video_config.waitvsync ? 2 : 0);
597595
598596#else
599   sdl->m_extra_flags = (window->fullscreen() ?  SDL_FULLSCREEN : SDL_RESIZABLE);
600   sdl->m_extra_flags |= SDL_OPENGL | SDL_DOUBLEBUF;
597   m_extra_flags = (window().fullscreen() ?  SDL_FULLSCREEN : SDL_RESIZABLE);
598   m_extra_flags |= SDL_OPENGL | SDL_DOUBLEBUF;
601599
602600   SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
603601   #if (SDL_VERSION_ATLEAST(1,2,10)) && (!defined(SDLMAME_EMSCRIPTEN))
604602   SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, video_config.waitvsync ? 1 : 0);
605603   #endif
606604
607   load_gl_lib(window->machine());
605   load_gl_lib(window().machine());
608606
609607   // create the SDL surface (which creates the window in windowed mode)
610   sdl->sdlsurf = SDL_SetVideoMode(m_width, m_height,
611                     0, SDL_SWSURFACE  | SDL_ANYFORMAT | sdl->m_extra_flags);
608   sdlsurf = SDL_SetVideoMode(width, height,
609                     0, SDL_SWSURFACE  | SDL_ANYFORMAT | m_extra_flags);
612610
613   if (!sdl->sdlsurf)
611   if (!sdlsurf)
614612      return 1;
615613
616   window->m_width = sdl->sdlsurf->w;
617   window->m_height = sdl->sdlsurf->h;
614   window().m_width = sdlsurf->w;
615   window().m_height = sdlsurf->h;
618616
619   window->screen_width = 0;
620   window->screen_height = 0;
617   window().m_screen_width = 0;
618   window().m_screen_height = 0;
621619
622   if ( (video_config.mode  == VIDEO_MODE_OPENGL) && !(sdl->sdlsurf->flags & SDL_OPENGL) )
620   if ( (video_config.mode  == VIDEO_MODE_OPENGL) && !(sdlsurf->flags & SDL_OPENGL) )
623621   {
624622      osd_printf_error("OpenGL not supported on this driver!\n");
625623      return 1;
626624   }
627625
628626   // set the window title
629   SDL_WM_SetCaption(window->m_title, "SDLMAME");
627   SDL_WM_SetCaption(window().m_title, "SDLMAME");
630628
631629#endif
632   sdl->m_blittimer = 0;
633   sdl->m_surf_w = 0;
634   sdl->m_surf_h = 0;
630   m_blittimer = 0;
631   m_surf_w = 0;
632   m_surf_h = 0;
635633
636   sdl->m_initialized = 0;
634   m_initialized = 0;
637635
638636   // in case any textures try to come up before these are validated,
639637   // OpenGL guarantees all implementations can handle something this size.
640   sdl->m_texture_max_width = 64;
641   sdl->m_texture_max_height = 64;
638   m_texture_max_width = 64;
639   m_texture_max_height = 64;
642640
643641   /* load any GL function addresses
644642    * this must be done here because we need a context
r243304r243305
656654      osd_printf_verbose("OpenGL: %s\nOpenGL: %s\nOpenGL: %s\n", vendor, (char *)glGetString(GL_RENDERER), (char *)glGetString(GL_VERSION));
657655   }
658656
659   sdl->m_usetexturerect = 0;
660   sdl->m_texpoweroftwo = 1;
661   sdl->m_usevbo = 0;
662   sdl->m_usepbo = 0;
663   sdl->m_usefbo = 0;
664   sdl->m_useglsl = 0;
657   m_usetexturerect = 0;
658   m_texpoweroftwo = 1;
659   m_usevbo = 0;
660   m_usepbo = 0;
661   m_usefbo = 0;
662   m_useglsl = 0;
665663
666664   if ( video_config.allowtexturerect &&
667665         ( strstr(extstr, "GL_ARB_texture_rectangle") ||  strstr(extstr, "GL_EXT_texture_rectangle") )
r243304r243305
681679      {
682680         osd_printf_verbose("OpenGL: non-power-of-2 textures supported (new method)\n");
683681      }
684               sdl->m_texpoweroftwo = 0;
682               m_texpoweroftwo = 0;
685683   }
686684   else
687685   {
r243304r243305
692690         {
693691            osd_printf_verbose("OpenGL: non-power-of-2 textures supported (old method)\n");
694692         }
695         sdl->m_usetexturerect = 1;
693         m_usetexturerect = 1;
696694      }
697695      else
698696      {
r243304r243305
705703
706704   if (strstr(extstr, "GL_ARB_vertex_buffer_object"))
707705   {
708               sdl->m_usevbo = video_config.vbo;
706               m_usevbo = video_config.vbo;
709707      if (!shown_video_info)
710708      {
711         if(sdl->m_usevbo)
709         if(m_usevbo)
712710            osd_printf_verbose("OpenGL: vertex buffer supported\n");
713711         else
714712            osd_printf_verbose("OpenGL: vertex buffer supported, but disabled\n");
r243304r243305
717715
718716   if (strstr(extstr, "GL_ARB_pixel_buffer_object"))
719717   {
720      if( sdl->m_usevbo )
718      if( m_usevbo )
721719      {
722         sdl->m_usepbo = video_config.pbo;
720         m_usepbo = video_config.pbo;
723721         if (!shown_video_info)
724722         {
725            if(sdl->m_usepbo)
723            if(m_usepbo)
726724               osd_printf_verbose("OpenGL: pixel buffers supported\n");
727725            else
728726               osd_printf_verbose("OpenGL: pixel buffers supported, but disabled\n");
r243304r243305
744742
745743   if (strstr(extstr, "GL_EXT_framebuffer_object"))
746744   {
747      sdl->m_usefbo = 1;
745      m_usefbo = 1;
748746      if (!shown_video_info)
749747      {
750         if(sdl->m_usefbo)
748         if(m_usefbo)
751749            osd_printf_verbose("OpenGL: framebuffer object supported\n");
752750         else
753751            osd_printf_verbose("OpenGL: framebuffer object not supported\n");
r243304r243305
760758      strstr(extstr, "GL_ARB_fragment_shader")
761759      )
762760   {
763      sdl->m_useglsl = video_config.glsl;
761      m_useglsl = video_config.glsl;
764762      if (!shown_video_info)
765763      {
766         if(sdl->m_useglsl)
764         if(m_useglsl)
767765            osd_printf_verbose("OpenGL: GLSL supported\n");
768766         else
769767            osd_printf_verbose("OpenGL: GLSL supported, but disabled\n");
r243304r243305
777775
778776   if (osd_getenv(SDLENV_VMWARE) != NULL)
779777   {
780      sdl->m_usetexturerect = 1;
781      sdl->m_texpoweroftwo = 1;
778      m_usetexturerect = 1;
779      m_texpoweroftwo = 1;
782780   }
783   glGetIntegerv(GL_MAX_TEXTURE_SIZE, (GLint *)&sdl->m_texture_max_width);
784   glGetIntegerv(GL_MAX_TEXTURE_SIZE, (GLint *)&sdl->m_texture_max_height);
781   glGetIntegerv(GL_MAX_TEXTURE_SIZE, (GLint *)&m_texture_max_width);
782   glGetIntegerv(GL_MAX_TEXTURE_SIZE, (GLint *)&m_texture_max_height);
785783   if (!shown_video_info)
786784   {
787      osd_printf_verbose("OpenGL: max texture size %d x %d\n", sdl->m_texture_max_width, sdl->m_texture_max_height);
785      osd_printf_verbose("OpenGL: max texture size %d x %d\n", m_texture_max_width, m_texture_max_height);
788786   }
789787
790788   shown_video_info = 1;
791789
792   sdl->m_init_context = 0;
790   m_init_context = 0;
793791
794792   return 0;
795793}
796794
797795//============================================================
798//  drawogl_window_resize
796//  sdl_info::resize
799797//============================================================
800798
801static void drawogl_window_resize(sdl_window_info *window, int width, int height)
799void sdl_info_ogl::resize(int width, int height)
802800{
803   sdl_info *sdl = (sdl_info *) window->m_dxdata;
804
805801#if (SDLMAME_SDL2)
806   //SDL_GL_MakeCurrent(window->sdl_window, sdl->gl_context_id);
807   SDL_SetWindowSize(window->m_sdl_window, width, height);
808   SDL_GetWindowSize(window->m_sdl_window, &window->m_width, &window->m_height);
809   sdl->m_blittimer = 3;
802   //SDL_GL_MakeCurrent(window().sdl_window, gl_context_id);
803   SDL_SetWindowSize(window().m_sdl_window, width, height);
804   SDL_GetWindowSize(window().m_sdl_window, &window().m_width, &window().m_height);
805   m_blittimer = 3;
810806#else
811   SDL_FreeSurface(sdl->sdlsurf);
807   SDL_FreeSurface(sdlsurf);
812808
813   sdl->sdlsurf = SDL_SetVideoMode(m_width, m_height, 0,
814         SDL_SWSURFACE | SDL_ANYFORMAT | sdl->m_extra_flags);
809   sdlsurf = SDL_SetVideoMode(width, height, 0,
810         SDL_SWSURFACE | SDL_ANYFORMAT | m_extra_flags);
815811
816   window->m_width = sdl->sdlsurf->w;
817   window->m_height = sdl->sdlsurf->h;
812   window().m_width = sdlsurf->w;
813   window().m_height = sdlsurf->h;
818814#endif
819   sdl->m_init_context = 1;
815   m_init_context = 1;
820816
821817}
822818
r243304r243305
824820//  drawsdl_xy_to_render_target
825821//============================================================
826822
827static int drawogl_xy_to_render_target(sdl_window_info *window, int x, int y, int *xt, int *yt)
823int sdl_info_ogl::xy_to_render_target(int x, int y, int *xt, int *yt)
828824{
829   sdl_info *sdl =(sdl_info *)  window->m_dxdata;
830
831   *xt = x - sdl->m_last_hofs;
832   *yt = y - sdl->m_last_vofs;
833   if (*xt<0 || *xt >= window->m_blitwidth)
825   *xt = x - m_last_hofs;
826   *yt = y - m_last_vofs;
827   if (*xt<0 || *xt >= window().m_blitwidth)
834828      return 0;
835   if (*yt<0 || *yt >= window->m_blitheight)
829   if (*yt<0 || *yt >= window().m_blitheight)
836830      return 0;
837831   return 1;
838832}
839833
840834//============================================================
841//  drawogl_window_get_primitives
835//  sdl_info::get_primitives
842836//============================================================
843837
844static void drawogl_set_target_bounds(sdl_window_info *window)
838void sdl_info_ogl::set_target_bounds()
845839{
846   window->m_target->set_bounds(window->m_blitwidth, window->m_blitheight, window->monitor()->aspect());
840   window().m_target->set_bounds(window().m_blitwidth, window().m_blitheight, window().monitor()->aspect());
847841}
848842
849843//============================================================
850844//  loadGLExtensions
851845//============================================================
852846
853static void loadGLExtensions(sdl_window_info *window)
847void sdl_info_ogl::loadGLExtensions()
854848{
855   sdl_info *sdl = (sdl_info *) window->m_dxdata;
856849   static int _once = 1;
857850
858   // sdl->usevbo=FALSE; // You may want to switch VBO and PBO off, by uncommenting this statement
859   // sdl->usepbo=FALSE; // You may want to switch PBO off, by uncommenting this statement
860   // sdl->useglsl=FALSE; // You may want to switch GLSL off, by uncommenting this statement
851   // usevbo=FALSE; // You may want to switch VBO and PBO off, by uncommenting this statement
852   // usepbo=FALSE; // You may want to switch PBO off, by uncommenting this statement
853   // useglsl=FALSE; // You may want to switch GLSL off, by uncommenting this statement
861854
862   if (! sdl->m_usevbo)
855   if (! m_usevbo)
863856   {
864      if(sdl->m_usepbo) // should never ever happen ;-)
857      if(m_usepbo) // should never ever happen ;-)
865858      {
866859         if (_once)
867860         {
868861            osd_printf_warning("OpenGL: PBO not supported, no VBO support. (sdlmame error)\n");
869862         }
870         sdl->m_usepbo=FALSE;
863         m_usepbo=FALSE;
871864      }
872      if(sdl->m_useglsl) // should never ever happen ;-)
865      if(m_useglsl) // should never ever happen ;-)
873866      {
874867         if (_once)
875868         {
876869            osd_printf_warning("OpenGL: GLSL not supported, no VBO support. (sdlmame error)\n");
877870         }
878         sdl->m_useglsl=FALSE;
871         m_useglsl=FALSE;
879872      }
880873   }
881874
882875   // Get Pointers To The GL Functions
883876   // VBO:
884   if( sdl->m_usevbo )
877   if( m_usevbo )
885878   {
886879      pfn_glGenBuffers = (PFNGLGENBUFFERSPROC) SDL_GL_GetProcAddress("glGenBuffers");
887880      pfn_glDeleteBuffers = (PFNGLDELETEBUFFERSPROC) SDL_GL_GetProcAddress("glDeleteBuffers");
r243304r243305
890883      pfn_glBufferSubData = (PFNGLBUFFERSUBDATAPROC) SDL_GL_GetProcAddress("glBufferSubData");
891884   }
892885   // PBO:
893   if ( sdl->m_usepbo )
886   if ( m_usepbo )
894887   {
895888      pfn_glMapBuffer  = (PFNGLMAPBUFFERPROC) SDL_GL_GetProcAddress("glMapBuffer");
896889      pfn_glUnmapBuffer= (PFNGLUNMAPBUFFERPROC) SDL_GL_GetProcAddress("glUnmapBuffer");
897890   }
898891   // FBO:
899   if ( sdl->m_usefbo )
892   if ( m_usefbo )
900893   {
901894      pfn_glIsFramebuffer = (PFNGLISFRAMEBUFFEREXTPROC) SDL_GL_GetProcAddress("glIsFramebufferEXT");
902895      pfn_glBindFramebuffer = (PFNGLBINDFRAMEBUFFEREXTPROC) SDL_GL_GetProcAddress("glBindFramebufferEXT");
r243304r243305
906899      pfn_glFramebufferTexture2D = (PFNGLFRAMEBUFFERTEXTURE2DEXTPROC) SDL_GL_GetProcAddress("glFramebufferTexture2DEXT");
907900   }
908901
909   if ( sdl->m_usevbo &&
902   if ( m_usevbo &&
910903         ( !pfn_glGenBuffers || !pfn_glDeleteBuffers ||
911904         !pfn_glBindBuffer || !pfn_glBufferData || !pfn_glBufferSubData
912905      ) )
913906   {
914      sdl->m_usepbo=FALSE;
907      m_usepbo=FALSE;
915908      if (_once)
916909      {
917910         osd_printf_warning("OpenGL: VBO not supported, missing: ");
r243304r243305
937930         }
938931         osd_printf_warning("\n");
939932      }
940      if ( sdl->m_usevbo )
933      if ( m_usevbo )
941934      {
942935         if (_once)
943936         {
944937            osd_printf_warning("OpenGL: PBO not supported, no VBO support.\n");
945938         }
946         sdl->m_usepbo=FALSE;
939         m_usepbo=FALSE;
947940      }
948941   }
949942
950   if ( sdl->m_usepbo && ( !pfn_glMapBuffer || !pfn_glUnmapBuffer ) )
943   if ( m_usepbo && ( !pfn_glMapBuffer || !pfn_glUnmapBuffer ) )
951944   {
952      sdl->m_usepbo=FALSE;
945      m_usepbo=FALSE;
953946      if (_once)
954947      {
955948         osd_printf_warning("OpenGL: PBO not supported, missing: ");
r243304r243305
965958      }
966959   }
967960
968   if ( sdl->m_usefbo &&
961   if ( m_usefbo &&
969962      ( !pfn_glIsFramebuffer || !pfn_glBindFramebuffer || !pfn_glDeleteFramebuffers ||
970963         !pfn_glGenFramebuffers || !pfn_glCheckFramebufferStatus || !pfn_glFramebufferTexture2D
971964      ))
972965   {
973      sdl->m_usefbo=FALSE;
966      m_usefbo=FALSE;
974967      if (_once)
975968      {
976969         osd_printf_warning("OpenGL: FBO not supported, missing: ");
r243304r243305
1004997
1005998   if (_once)
1006999   {
1007      if ( sdl->m_usevbo )
1000      if ( m_usevbo )
10081001      {
10091002         osd_printf_verbose("OpenGL: VBO supported\n");
10101003      }
r243304r243305
10131006         osd_printf_warning("OpenGL: VBO not supported\n");
10141007      }
10151008
1016      if ( sdl->m_usepbo )
1009      if ( m_usepbo )
10171010      {
10181011         osd_printf_verbose("OpenGL: PBO supported\n");
10191012      }
r243304r243305
10221015         osd_printf_warning("OpenGL: PBO not supported\n");
10231016      }
10241017
1025      if ( sdl->m_usefbo )
1018      if ( m_usefbo )
10261019      {
10271020         osd_printf_verbose("OpenGL: FBO supported\n");
10281021      }
r243304r243305
10321025      }
10331026   }
10341027
1035   if ( sdl->m_useglsl )
1028   if ( m_useglsl )
10361029   {
10371030      #ifdef GL_ARB_multitexture
10381031      pfn_glActiveTexture = (PFNGLACTIVETEXTUREARBPROC) SDL_GL_GetProcAddress("glActiveTextureARB");
r243304r243305
10451038         {
10461039            osd_printf_warning("OpenGL: GLSL disabled, glActiveTexture(ARB) not supported\n");
10471040         }
1048         sdl->m_useglsl = 0;
1041         m_useglsl = 0;
10491042      }
10501043   }
10511044
1052   if ( sdl->m_useglsl )
1045   if ( m_useglsl )
10531046   {
1054      sdl->m_glsl = glsl_shader_init();
1055      sdl->m_useglsl = (sdl->m_glsl != NULL ? 1 : 0);
1047      m_glsl = glsl_shader_init();
1048      m_useglsl = (m_glsl != NULL ? 1 : 0);
10561049
1057      if ( ! sdl->m_useglsl )
1050      if ( ! m_useglsl )
10581051      {
10591052         if (_once)
10601053         {
r243304r243305
10631056      }
10641057   }
10651058
1066   if ( sdl->m_useglsl )
1059   if ( m_useglsl )
10671060   {
1068      if ( window->m_prescale != 1 )
1061      if ( window().m_prescale != 1 )
10691062      {
1070         sdl->m_useglsl = 0;
1063         m_useglsl = 0;
10711064         if (_once)
10721065         {
10731066            osd_printf_warning("OpenGL: GLSL supported, but disabled due to: prescale !=1 \n");
r243304r243305
10751068      }
10761069   }
10771070
1078   if ( sdl->m_useglsl )
1071   if ( m_useglsl )
10791072   {
10801073      int i;
10811074      video_config.filter = FALSE;
10821075      glsl_shader_feature = GLSL_SHADER_FEAT_PLAIN;
1083      sdl->m_glsl_program_num = 0;
1084      sdl->m_glsl_program_mb2sc = 0;
1076      m_glsl_program_num = 0;
1077      m_glsl_program_mb2sc = 0;
10851078
10861079      for(i=0; i<video_config.glsl_shader_mamebm_num; i++)
10871080      {
1088         if ( !sdl->m_usefbo && sdl->m_glsl_program_num==1 )
1081         if ( !m_usefbo && m_glsl_program_num==1 )
10891082         {
10901083            if (_once)
10911084            {
r243304r243305
10941087            break;
10951088         }
10961089
1097         if ( glsl_shader_add_mamebm(sdl->m_glsl, video_config.glsl_shader_mamebm[i], sdl->m_glsl_program_num) )
1090         if ( glsl_shader_add_mamebm(m_glsl, video_config.glsl_shader_mamebm[i], m_glsl_program_num) )
10981091         {
10991092            osd_printf_error("OpenGL: GLSL loading mame bitmap shader %d failed (%s)\n",
11001093               i, video_config.glsl_shader_mamebm[i]);
r243304r243305
11031096            if (_once)
11041097            {
11051098               osd_printf_verbose("OpenGL: GLSL using mame bitmap shader filter %d: '%s'\n",
1106                  sdl->m_glsl_program_num, video_config.glsl_shader_mamebm[i]);
1099                  m_glsl_program_num, video_config.glsl_shader_mamebm[i]);
11071100            }
1108            sdl->m_glsl_program_mb2sc = sdl->m_glsl_program_num; // the last mame_bitmap (mb) shader does it.
1109            sdl->m_glsl_program_num++;
1101            m_glsl_program_mb2sc = m_glsl_program_num; // the last mame_bitmap (mb) shader does it.
1102            m_glsl_program_num++;
11101103         }
11111104      }
11121105
1113      if ( video_config.glsl_shader_scrn_num > 0 && sdl->m_glsl_program_num==0 )
1106      if ( video_config.glsl_shader_scrn_num > 0 && m_glsl_program_num==0 )
11141107      {
11151108         osd_printf_verbose("OpenGL: GLSL cannot use screen bitmap shader without bitmap shader\n");
11161109      }
11171110
1118      for(i=0; sdl->m_usefbo && sdl->m_glsl_program_num>0 && i<video_config.glsl_shader_scrn_num; i++)
1111      for(i=0; m_usefbo && m_glsl_program_num>0 && i<video_config.glsl_shader_scrn_num; i++)
11191112      {
1120         if ( glsl_shader_add_scrn(sdl->m_glsl, video_config.glsl_shader_scrn[i],
1121                                 sdl->m_glsl_program_num-1-sdl->m_glsl_program_mb2sc) )
1113         if ( glsl_shader_add_scrn(m_glsl, video_config.glsl_shader_scrn[i],
1114                                 m_glsl_program_num-1-m_glsl_program_mb2sc) )
11221115         {
11231116            osd_printf_error("OpenGL: GLSL loading screen bitmap shader %d failed (%s)\n",
11241117               i, video_config.glsl_shader_scrn[i]);
r243304r243305
11261119            if (_once)
11271120            {
11281121               osd_printf_verbose("OpenGL: GLSL using screen bitmap shader filter %d: '%s'\n",
1129                  sdl->m_glsl_program_num, video_config.glsl_shader_scrn[i]);
1122                  m_glsl_program_num, video_config.glsl_shader_scrn[i]);
11301123            }
1131            sdl->m_glsl_program_num++;
1124            m_glsl_program_num++;
11321125         }
11331126      }
11341127
1135      if ( 0==sdl->m_glsl_program_num &&
1128      if ( 0==m_glsl_program_num &&
11361129            0 <= video_config.glsl_filter && video_config.glsl_filter < GLSL_SHADER_FEAT_INT_NUMBER )
11371130      {
1138         sdl->m_glsl_program_mb2sc = sdl->m_glsl_program_num; // the last mame_bitmap (mb) shader does it.
1139         sdl->m_glsl_program_num++;
1131         m_glsl_program_mb2sc = m_glsl_program_num; // the last mame_bitmap (mb) shader does it.
1132         m_glsl_program_num++;
11401133         glsl_shader_feature = video_config.glsl_filter;
11411134
11421135         if (_once)
11431136         {
11441137            osd_printf_verbose("OpenGL: GLSL using shader filter '%s', idx: %d, num %d (vid filter: %d)\n",
11451138               glsl_shader_get_filter_name_mamebm(glsl_shader_feature),
1146               glsl_shader_feature, sdl->m_glsl_program_num, video_config.filter);
1139               glsl_shader_feature, m_glsl_program_num, video_config.filter);
11471140         }
11481141      }
11491142
r243304r243305
11581151}
11591152
11601153//============================================================
1161//  drawogl_window_draw
1154//  sdl_info::draw
11621155//============================================================
11631156
1164static int drawogl_window_draw(sdl_window_info *window, UINT32 dc, int update)
1157int sdl_info_ogl::draw(UINT32 dc, int update)
11651158{
1166   sdl_info *sdl = (sdl_info *) window->m_dxdata;
11671159   render_primitive *prim;
11681160   texture_info *texture=NULL;
11691161   float vofs, hofs;
r243304r243305
11761168   }
11771169
11781170#if (SDLMAME_SDL2)
1179   SDL_GL_MakeCurrent(window->m_sdl_window, sdl->m_gl_context_id);
1171   SDL_GL_MakeCurrent(window().m_sdl_window, m_gl_context_id);
11801172#else
1181   if (!sdl->m_init_context)
1173   if (!m_init_context)
11821174   {
1183      screen_device_iterator myiter(window->machine().root_device());
1175      screen_device_iterator myiter(window().machine().root_device());
11841176      for (screen = myiter.first(); screen != NULL; screen = myiter.next())
11851177      {
1186         if (window->index() == 0)
1178         if (window().index() == 0)
11871179         {
1188            if ((screen->m_width() != window->screen_width) || (screen->m_height() != window->screen_height))
1180            if ((screen->width() != window().m_screen_width) || (screen->height() != window().m_screen_height))
11891181            {
1190               window->screen_width = screen->m_width();
1191               window->screen_height = screen->m_height();
1182               window().m_screen_width = screen->width();
1183               window().m_screen_height = screen->height();
11921184
11931185               // force all textures to be regenerated
1194               drawogl_destroy_all_textures(window);
1186               destroy_all_textures();
11951187            }
11961188            break;
11971189         }
r243304r243305
11991191   }
12001192#endif
12011193
1202   if (sdl->m_init_context)
1194   if (m_init_context)
12031195   {
12041196      // do some one-time OpenGL setup
12051197#if (SDLMAME_SDL2)
r243304r243305
12171209
12181210   // figure out if we're vector
12191211   scrnum = is_vector = 0;
1220   screen_device_iterator iter(window->machine().root_device());
1212   screen_device_iterator iter(window().machine().root_device());
12211213   for (screen = iter.first(); screen != NULL; screen = iter.next())
12221214   {
1223      if (scrnum == window->index())
1215      if (scrnum == window().index())
12241216      {
12251217         is_vector = (screen->screen_type() == SCREEN_TYPE_VECTOR) ? 1 : 0;
12261218         break;
r243304r243305
12321224   }
12331225
12341226   // only clear if the geometry changes (and for 2 frames afterward to clear double and triple buffers)
1235   if ((sdl->m_blittimer > 0) || (is_vector))
1227   if ((m_blittimer > 0) || (is_vector))
12361228   {
12371229      glClear(GL_COLOR_BUFFER_BIT);
1238      sdl->m_blittimer--;
1230      m_blittimer--;
12391231   }
12401232
1241   if ( !sdl->m_initialized ||
1242         window->m_width!= sdl->m_surf_w || window->m_height!= sdl->m_surf_h )
1233   if ( !m_initialized ||
1234         window().m_width!= m_surf_w || window().m_height!= m_surf_h )
12431235   {
1244      if ( !sdl->m_initialized )
1236      if ( !m_initialized )
12451237      {
1246         loadGLExtensions(window);
1238         loadGLExtensions();
12471239      }
12481240
1249      sdl->m_surf_w=window->m_width;
1250      sdl->m_surf_h=window->m_height;
1241      m_surf_w=window().m_width;
1242      m_surf_h=window().m_height;
12511243
12521244      // we're doing nothing 3d, so the Z-buffer is currently not interesting
12531245      glDisable(GL_DEPTH_TEST);
12541246
1255      if (window->machine().options().antialias())
1247      if (window().machine().options().antialias())
12561248      {
12571249         // enable antialiasing for lines
12581250         glEnable(GL_LINE_SMOOTH);
r243304r243305
12721264      // enable blending
12731265      glEnable(GL_BLEND);
12741266      glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1275      sdl->m_last_blendmode = BLENDMODE_ALPHA;
1267      m_last_blendmode = BLENDMODE_ALPHA;
12761268
12771269      // set lines and points just barely above normal size to get proper results
12781270      glLineWidth(video_config.beamwidth);
r243304r243305
12881280      //   |_________|
12891281      // (0,h)     (w,h)
12901282
1291      glViewport(0.0, 0.0, (GLsizei)window->m_width, (GLsizei)window->m_height);
1283      glViewport(0.0, 0.0, (GLsizei)window().m_width, (GLsizei)window().m_height);
12921284      glMatrixMode(GL_PROJECTION);
12931285      glLoadIdentity();
1294      glOrtho(0.0, (GLdouble)window->m_width, (GLdouble)window->m_height, 0.0, 0.0, -1.0);
1286      glOrtho(0.0, (GLdouble)window().m_width, (GLdouble)window().m_height, 0.0, 0.0, -1.0);
12951287      glMatrixMode(GL_MODELVIEW);
12961288      glLoadIdentity();
12971289
1298      if ( ! sdl->m_initialized )
1290      if ( ! m_initialized )
12991291      {
13001292         glEnableClientState(GL_VERTEX_ARRAY);
1301         glVertexPointer(2, GL_FLOAT, 0, sdl->m_texVerticex); // no VBO, since it's too volatile
1293         glVertexPointer(2, GL_FLOAT, 0, m_texVerticex); // no VBO, since it's too volatile
13021294
1303         sdl->m_initialized = 1;
1295         m_initialized = 1;
13041296      }
13051297   }
13061298
r243304r243305
13111303   {
13121304      int ch, cw;
13131305
1314      if ((window->fullscreen()) && (!video_config.switchres))
1306      if ((window().fullscreen()) && (!video_config.switchres))
13151307      {
1316         ch = window->monitor()->center_height();
1317         cw = window->monitor()->center_width();
1308         ch = window().monitor()->center_height();
1309         cw = window().monitor()->center_width();
13181310      }
13191311      else
13201312      {
1321         ch = window->m_height;
1322         cw = window->m_width;
1313         ch = window().m_height;
1314         cw = window().m_width;
13231315      }
13241316
13251317      if (video_config.centerv)
13261318      {
1327         vofs = (ch - window->m_blitheight) / 2.0f;
1319         vofs = (ch - window().m_blitheight) / 2.0f;
13281320      }
13291321      if (video_config.centerh)
13301322      {
1331         hofs = (cw - window->m_blitwidth) / 2.0f;
1323         hofs = (cw - window().m_blitwidth) / 2.0f;
13321324      }
13331325   }
13341326
1335   sdl->m_last_hofs = hofs;
1336   sdl->m_last_vofs = vofs;
1327   m_last_hofs = hofs;
1328   m_last_vofs = vofs;
13371329
1338   window->m_primlist->acquire_lock();
1330   window().m_primlist->acquire_lock();
13391331
13401332   // now draw
1341   for (prim = window->m_primlist->first(); prim != NULL; prim = prim->next())
1333   for (prim = window().m_primlist->first(); prim != NULL; prim = prim->next())
13421334   {
13431335      int i;
13441336
r243304r243305
13661358
13671359                  if ( pendingPrimitive==GL_NO_PRIMITIVE )
13681360            {
1369                     set_blendmode(sdl, PRIMFLAG_GET_BLENDMODE(prim->flags));
1361                     set_blendmode(PRIMFLAG_GET_BLENDMODE(prim->flags));
13701362            }
13711363
13721364            glColor4f(prim->color.r, prim->color.g, prim->color.b, prim->color.a);
r243304r243305
14861478
14871479            glColor4f(prim->color.r, prim->color.g, prim->color.b, prim->color.a);
14881480
1489            set_blendmode(sdl, PRIMFLAG_GET_BLENDMODE(prim->flags));
1481            set_blendmode(PRIMFLAG_GET_BLENDMODE(prim->flags));
14901482
1491            texture = texture_update(window, prim, 0);
1483            texture = texture_update(prim, 0);
14921484
14931485            if ( texture && texture->type==TEXTURE_TYPE_SHADER )
14941486            {
1495               for(i=0; i<sdl->m_glsl_program_num; i++)
1487               for(i=0; i<m_glsl_program_num; i++)
14961488               {
1497                  if ( i==sdl->m_glsl_program_mb2sc )
1489                  if ( i==m_glsl_program_mb2sc )
14981490                  {
1499                     // i==sdl->glsl_program_mb2sc -> transformation mamebm->scrn
1500                     sdl->m_texVerticex[0]=prim->bounds.x0 + hofs;
1501                     sdl->m_texVerticex[1]=prim->bounds.y0 + vofs;
1502                     sdl->m_texVerticex[2]=prim->bounds.x1 + hofs;
1503                     sdl->m_texVerticex[3]=prim->bounds.y0 + vofs;
1504                     sdl->m_texVerticex[4]=prim->bounds.x1 + hofs;
1505                     sdl->m_texVerticex[5]=prim->bounds.y1 + vofs;
1506                     sdl->m_texVerticex[6]=prim->bounds.x0 + hofs;
1507                     sdl->m_texVerticex[7]=prim->bounds.y1 + vofs;
1491                     // i==glsl_program_mb2sc -> transformation mamebm->scrn
1492                     m_texVerticex[0]=prim->bounds.x0 + hofs;
1493                     m_texVerticex[1]=prim->bounds.y0 + vofs;
1494                     m_texVerticex[2]=prim->bounds.x1 + hofs;
1495                     m_texVerticex[3]=prim->bounds.y0 + vofs;
1496                     m_texVerticex[4]=prim->bounds.x1 + hofs;
1497                     m_texVerticex[5]=prim->bounds.y1 + vofs;
1498                     m_texVerticex[6]=prim->bounds.x0 + hofs;
1499                     m_texVerticex[7]=prim->bounds.y1 + vofs;
15081500                  } else {
15091501                     // 1:1 tex coord CCW (0/0) (1/0) (1/1) (0/1) on texture dimensions
1510                     sdl->m_texVerticex[0]=(GLfloat)0.0;
1511                     sdl->m_texVerticex[1]=(GLfloat)0.0;
1512                     sdl->m_texVerticex[2]=(GLfloat)window->m_width;
1513                     sdl->m_texVerticex[3]=(GLfloat)0.0;
1514                     sdl->m_texVerticex[4]=(GLfloat)window->m_width;
1515                     sdl->m_texVerticex[5]=(GLfloat)window->m_height;
1516                     sdl->m_texVerticex[6]=(GLfloat)0.0;
1517                     sdl->m_texVerticex[7]=(GLfloat)window->m_height;
1502                     m_texVerticex[0]=(GLfloat)0.0;
1503                     m_texVerticex[1]=(GLfloat)0.0;
1504                     m_texVerticex[2]=(GLfloat)window().m_width;
1505                     m_texVerticex[3]=(GLfloat)0.0;
1506                     m_texVerticex[4]=(GLfloat)window().m_width;
1507                     m_texVerticex[5]=(GLfloat)window().m_height;
1508                     m_texVerticex[6]=(GLfloat)0.0;
1509                     m_texVerticex[7]=(GLfloat)window().m_height;
15181510                  }
15191511
15201512                  if(i>0) // first fetch already done
15211513                  {
1522                     texture = texture_update(window, prim, i);
1514                     texture = texture_update(prim, i);
15231515                  }
15241516                  glDrawArrays(GL_QUADS, 0, 4);
15251517               }
15261518            } else {
1527               sdl->m_texVerticex[0]=prim->bounds.x0 + hofs;
1528               sdl->m_texVerticex[1]=prim->bounds.y0 + vofs;
1529               sdl->m_texVerticex[2]=prim->bounds.x1 + hofs;
1530               sdl->m_texVerticex[3]=prim->bounds.y0 + vofs;
1531               sdl->m_texVerticex[4]=prim->bounds.x1 + hofs;
1532               sdl->m_texVerticex[5]=prim->bounds.y1 + vofs;
1533               sdl->m_texVerticex[6]=prim->bounds.x0 + hofs;
1534               sdl->m_texVerticex[7]=prim->bounds.y1 + vofs;
1519               m_texVerticex[0]=prim->bounds.x0 + hofs;
1520               m_texVerticex[1]=prim->bounds.y0 + vofs;
1521               m_texVerticex[2]=prim->bounds.x1 + hofs;
1522               m_texVerticex[3]=prim->bounds.y0 + vofs;
1523               m_texVerticex[4]=prim->bounds.x1 + hofs;
1524               m_texVerticex[5]=prim->bounds.y1 + vofs;
1525               m_texVerticex[6]=prim->bounds.x0 + hofs;
1526               m_texVerticex[7]=prim->bounds.y1 + vofs;
15351527
15361528               glDrawArrays(GL_QUADS, 0, 4);
15371529            }
15381530
15391531            if ( texture )
15401532            {
1541               texture_disable(sdl, texture);
1533               texture_disable(texture);
15421534               texture=NULL;
15431535            }
15441536            break;
r243304r243305
15541546      pendingPrimitive=GL_NO_PRIMITIVE;
15551547   }
15561548
1557   window->m_primlist->release_lock();
1558   sdl->m_init_context = 0;
1549   window().m_primlist->release_lock();
1550   m_init_context = 0;
15591551
15601552#if (!SDLMAME_SDL2)
15611553   SDL_GL_SwapBuffers();
15621554#else
1563   SDL_GL_SwapWindow(window->m_sdl_window);
1555   SDL_GL_SwapWindow(window().m_sdl_window);
15641556#endif
15651557   return 0;
15661558}
r243304r243305
16261618}
16271619
16281620//============================================================
1629//  drawogl_window_destroy
1621//  sdl_info::destroy
16301622//============================================================
16311623
1632static void drawogl_window_destroy(sdl_window_info *window)
1624void sdl_info_ogl::destroy()
16331625{
1634   sdl_info *sdl = (sdl_info *) window->m_dxdata;
16351626
1636   // skip if nothing
1637   if (sdl == NULL)
1638      return;
1639
16401627   // free the memory in the window
16411628
1642   drawogl_destroy_all_textures(window);
1629   destroy_all_textures();
16431630
16441631#if (SDLMAME_SDL2)
1645   SDL_GL_DeleteContext(sdl->m_gl_context_id);
1646   SDL_DestroyWindow(window->m_sdl_window);
1632   SDL_GL_DeleteContext(m_gl_context_id);
1633   SDL_DestroyWindow(window().m_sdl_window);
16471634#else
1648   if (sdl->sdlsurf)
1635   if (sdlsurf)
16491636   {
1650      SDL_FreeSurface(sdl->sdlsurf);
1651      sdl->sdlsurf = NULL;
1637      SDL_FreeSurface(sdlsurf);
1638      sdlsurf = NULL;
16521639   }
16531640#endif
1654
1655   global_free(sdl);
1656   window->m_dxdata = NULL;
16571641}
16581642
16591643//============================================================
r243304r243305
16671651// we also don't want to use PBO's in the case of nocopy==TRUE,
16681652// since we now might have GLSL shaders - this decision simplifies out life ;-)
16691653//
1670static void texture_compute_type_subroutine(sdl_info *sdl, const render_texinfo *texsource, texture_info *texture, UINT32 flags)
1654void sdl_info_ogl::texture_compute_type_subroutine(const render_texinfo *texsource, texture_info *texture, UINT32 flags)
16711655{
16721656   texture->type = TEXTURE_TYPE_NONE;
16731657   texture->nocopy = FALSE;
r243304r243305
16761660         !PRIMFLAG_GET_SCREENTEX(flags))
16771661   {
16781662      texture->type = TEXTURE_TYPE_PLAIN;
1679            texture->texTarget = (sdl->m_usetexturerect)?GL_TEXTURE_RECTANGLE_ARB:GL_TEXTURE_2D;
1680            texture->texpow2   = (sdl->m_usetexturerect)?0:sdl->m_texpoweroftwo;
1663            texture->texTarget = (m_usetexturerect)?GL_TEXTURE_RECTANGLE_ARB:GL_TEXTURE_2D;
1664            texture->texpow2   = (m_usetexturerect)?0:m_texpoweroftwo;
16811665   }
16821666
1683   if ( texture->type == TEXTURE_TYPE_NONE && sdl->m_useglsl &&
1667   if ( texture->type == TEXTURE_TYPE_NONE && m_useglsl &&
16841668         texture->xprescale == 1 && texture->yprescale == 1 &&
1685         texsource->rowpixels <= sdl->m_texture_max_width )
1669         texsource->rowpixels <= m_texture_max_width )
16861670      {
16871671         texture->type      = TEXTURE_TYPE_SHADER;
16881672         texture->texTarget = GL_TEXTURE_2D;
1689         texture->texpow2   = sdl->m_texpoweroftwo;
1673         texture->texpow2   = m_texpoweroftwo;
16901674      }
16911675
16921676   // determine if we can skip the copy step
r243304r243305
16951679         !texture_copy_properties[texture->format][SDL_TEXFORMAT_SRC_HAS_PALETTE] &&
16961680         texture->xprescale == 1 && texture->yprescale == 1 &&
16971681         !texture->borderpix && !texsource->palette() &&
1698         texsource->rowpixels <= sdl->m_texture_max_width )
1682         texsource->rowpixels <= m_texture_max_width )
16991683   {
17001684      texture->nocopy = TRUE;
17011685   }
17021686
17031687   if( texture->type == TEXTURE_TYPE_NONE &&
1704      sdl->m_usepbo && !texture->nocopy )
1688      m_usepbo && !texture->nocopy )
17051689   {
17061690      texture->type      = TEXTURE_TYPE_DYNAMIC;
1707      texture->texTarget = (sdl->m_usetexturerect)?GL_TEXTURE_RECTANGLE_ARB:GL_TEXTURE_2D;
1708      texture->texpow2   = (sdl->m_usetexturerect)?0:sdl->m_texpoweroftwo;
1691      texture->texTarget = (m_usetexturerect)?GL_TEXTURE_RECTANGLE_ARB:GL_TEXTURE_2D;
1692      texture->texpow2   = (m_usetexturerect)?0:m_texpoweroftwo;
17091693   }
17101694
17111695   if( texture->type == TEXTURE_TYPE_NONE )
17121696   {
17131697      texture->type      = TEXTURE_TYPE_SURFACE;
1714      texture->texTarget = (sdl->m_usetexturerect)?GL_TEXTURE_RECTANGLE_ARB:GL_TEXTURE_2D;
1715      texture->texpow2   = (sdl->m_usetexturerect)?0:sdl->m_texpoweroftwo;
1698      texture->texTarget = (m_usetexturerect)?GL_TEXTURE_RECTANGLE_ARB:GL_TEXTURE_2D;
1699      texture->texpow2   = (m_usetexturerect)?0:m_texpoweroftwo;
17161700   }
17171701}
17181702
r243304r243305
17211705   return (needPow2)?gl_round_to_pow2(v):v;
17221706}
17231707
1724static void texture_compute_size_subroutine(sdl_window_info *window, texture_info *texture, UINT32 flags,
1708void sdl_info_ogl::texture_compute_size_subroutine(texture_info *texture, UINT32 flags,
17251709                                 UINT32 width, UINT32 height,
17261710                                 int* p_width, int* p_height, int* p_width_create, int* p_height_create)
17271711{
1728   sdl_info *sdl = (sdl_info *) window->m_dxdata;
17291712   int width_create;
17301713   int height_create;
17311714
r243304r243305
17461729      }
17471730
17481731   // don't prescale above max texture size
1749   while (texture->xprescale > 1 && width_create * texture->xprescale > sdl->m_texture_max_width)
1732   while (texture->xprescale > 1 && width_create * texture->xprescale > m_texture_max_width)
17501733      texture->xprescale--;
1751   while (texture->yprescale > 1 && height_create * texture->yprescale > sdl->m_texture_max_height)
1734   while (texture->yprescale > 1 && height_create * texture->yprescale > m_texture_max_height)
17521735      texture->yprescale--;
1753   if (PRIMFLAG_GET_SCREENTEX(flags) && (texture->xprescale != window->m_prescale || texture->yprescale != window->m_prescale))
1754      osd_printf_warning("SDL: adjusting prescale from %dx%d to %dx%d\n", window->m_prescale, window->m_prescale, texture->xprescale, texture->yprescale);
1736   if (PRIMFLAG_GET_SCREENTEX(flags) && (texture->xprescale != window().m_prescale || texture->yprescale != window().m_prescale))
1737      osd_printf_warning("SDL: adjusting prescale from %dx%d to %dx%d\n", window().m_prescale, window().m_prescale, texture->xprescale, texture->yprescale);
17551738
17561739   width  *= texture->xprescale;
17571740   height *= texture->yprescale;
r243304r243305
17731756      *p_height_create=height_create;
17741757}
17751758
1776static void texture_compute_size_type(sdl_window_info *window, const render_texinfo *texsource, texture_info *texture, UINT32 flags)
1759void sdl_info_ogl::texture_compute_size_type(const render_texinfo *texsource, texture_info *texture, UINT32 flags)
17771760{
1778   sdl_info *sdl = (sdl_info *) window->m_dxdata;
17791761   int finalheight, finalwidth;
17801762   int finalheight_create, finalwidth_create;
17811763
r243304r243305
17861768      texture->borderpix = 0; // don't border the screen right now, there's a bug
17871769   }
17881770
1789   texture_compute_type_subroutine(sdl, texsource, texture, flags);
1771   texture_compute_type_subroutine(texsource, texture, flags);
17901772
1791   texture_compute_size_subroutine(window, texture, flags, texsource->width, texsource->height,
1773   texture_compute_size_subroutine(texture, flags, texsource->width, texsource->height,
17921774                           &finalwidth, &finalheight, &finalwidth_create, &finalheight_create);
17931775
17941776   // if we added pixels for the border, and that just barely pushed us over, take it back
17951777   if (texture->borderpix &&
1796      ((finalwidth > sdl->m_texture_max_width && finalwidth - 2 <= sdl->m_texture_max_width) ||
1797         (finalheight > sdl->m_texture_max_height && finalheight - 2 <= sdl->m_texture_max_height)))
1778      ((finalwidth > m_texture_max_width && finalwidth - 2 <= m_texture_max_width) ||
1779         (finalheight > m_texture_max_height && finalheight - 2 <= m_texture_max_height)))
17981780   {
17991781      texture->borderpix = FALSE;
18001782
1801      texture_compute_type_subroutine(sdl, texsource, texture, flags);
1783      texture_compute_type_subroutine(texsource, texture, flags);
18021784
1803      texture_compute_size_subroutine(window, texture, flags, texsource->width, texsource->height,
1785      texture_compute_size_subroutine(texture, flags, texsource->width, texsource->height,
18041786                              &finalwidth, &finalheight, &finalwidth_create, &finalheight_create);
18051787   }
18061788
18071789   // if we're above the max width/height, do what?
1808   if (finalwidth_create > sdl->m_texture_max_width || finalheight_create > sdl->m_texture_max_height)
1790   if (finalwidth_create > m_texture_max_width || finalheight_create > m_texture_max_height)
18091791   {
18101792      static int printed = FALSE;
18111793      if (!printed)
1812         osd_printf_warning("Texture too big! (wanted: %dx%d, max is %dx%d)\n", finalwidth_create, finalheight_create, sdl->m_texture_max_width, sdl->m_texture_max_height);
1794         osd_printf_warning("Texture too big! (wanted: %dx%d, max is %dx%d)\n", finalwidth_create, finalheight_create, m_texture_max_width, m_texture_max_height);
18131795      printed = TRUE;
18141796   }
18151797
r243304r243305
18311813         (int)texture_copy_properties[texture->format][SDL_TEXFORMAT_SRC_EQUALS_DEST],
18321814         (int)texture_copy_properties[texture->format][SDL_TEXFORMAT_SRC_HAS_PALETTE],
18331815         texture->xprescale, texture->yprescale,
1834         texture->borderpix, texsource->rowpixels, finalwidth, sdl->m_texture_max_width,
1816         texture->borderpix, texsource->rowpixels, finalwidth, m_texture_max_width,
18351817         (int)sizeof(UINT32)
18361818         );
18371819   }
r243304r243305
19271909   return 0;
19281910}
19291911
1930static int texture_shader_create(sdl_window_info *window,
1931                           const render_texinfo *texsource, texture_info *texture, UINT32 flags)
1912int sdl_info_ogl::texture_shader_create(const render_texinfo *texsource, texture_info *texture, UINT32 flags)
19321913{
1933   sdl_info *sdl = (sdl_info *) window->m_dxdata;
19341914   int uniform_location;
19351915   int i;
1936   int surf_w_pow2  = get_valid_pow2_value (window->m_blitwidth, texture->texpow2);
1937   int surf_h_pow2  = get_valid_pow2_value (window->m_blitheight, texture->texpow2);
1916   int surf_w_pow2  = get_valid_pow2_value (window().m_blitwidth, texture->texpow2);
1917   int surf_h_pow2  = get_valid_pow2_value (window().m_blitheight, texture->texpow2);
19381918
19391919   assert ( texture->type==TEXTURE_TYPE_SHADER );
19401920
19411921   GL_CHECK_ERROR_QUIET();
19421922
1943   if( sdl->m_glsl_program_num > 1 )
1923   if( m_glsl_program_num > 1 )
19441924   {
19451925      // multipass mode
1946      assert(sdl->m_usefbo);
1926      assert(m_usefbo);
19471927
19481928      // GL_TEXTURE3 GLSL Uniforms
19491929      texture->mpass_dest_idx = 0;
r243304r243305
19511931      texture->mpass_textureunit[1] = GL_TEXTURE2;
19521932   }
19531933
1954   for(i=0; i<sdl->m_glsl_program_num; i++)
1934   for(i=0; i<m_glsl_program_num; i++)
19551935   {
1956      if ( i<=sdl->m_glsl_program_mb2sc )
1936      if ( i<=m_glsl_program_mb2sc )
19571937      {
1958         sdl->m_glsl_program[i] = glsl_shader_get_program_mamebm(glsl_shader_feature, i);
1938         m_glsl_program[i] = glsl_shader_get_program_mamebm(glsl_shader_feature, i);
19591939      } else {
1960         sdl->m_glsl_program[i] = glsl_shader_get_program_scrn(i-1-sdl->m_glsl_program_mb2sc);
1940         m_glsl_program[i] = glsl_shader_get_program_scrn(i-1-m_glsl_program_mb2sc);
19611941      }
1962      pfn_glUseProgramObjectARB(sdl->m_glsl_program[i]);
1942      pfn_glUseProgramObjectARB(m_glsl_program[i]);
19631943
1964      if ( i<=sdl->m_glsl_program_mb2sc )
1944      if ( i<=m_glsl_program_mb2sc )
19651945      {
19661946         // GL_TEXTURE0 GLSL Uniforms
1967         uniform_location = pfn_glGetUniformLocationARB(sdl->m_glsl_program[i], "color_texture");
1947         uniform_location = pfn_glGetUniformLocationARB(m_glsl_program[i], "color_texture");
19681948         pfn_glUniform1iARB(uniform_location, 0);
19691949         GL_CHECK_ERROR_NORMAL();
19701950      }
19711951
19721952      {
19731953         GLfloat color_texture_sz[2] = { (GLfloat)texture->rawwidth, (GLfloat)texture->rawheight };
1974         uniform_location = pfn_glGetUniformLocationARB(sdl->m_glsl_program[i], "color_texture_sz");
1954         uniform_location = pfn_glGetUniformLocationARB(m_glsl_program[i], "color_texture_sz");
19751955         pfn_glUniform2fvARB(uniform_location, 1, &(color_texture_sz[0]));
19761956         GL_CHECK_ERROR_NORMAL();
19771957      }
19781958
19791959      GLfloat color_texture_pow2_sz[2] = { (GLfloat)texture->rawwidth_create, (GLfloat)texture->rawheight_create };
1980      uniform_location = pfn_glGetUniformLocationARB(sdl->m_glsl_program[i], "color_texture_pow2_sz");
1960      uniform_location = pfn_glGetUniformLocationARB(m_glsl_program[i], "color_texture_pow2_sz");
19811961      pfn_glUniform2fvARB(uniform_location, 1, &(color_texture_pow2_sz[0]));
19821962      GL_CHECK_ERROR_NORMAL();
19831963
1984      GLfloat screen_texture_sz[2] = { (GLfloat)window->m_blitwidth, (GLfloat)window->m_blitheight };
1985      uniform_location = pfn_glGetUniformLocationARB(sdl->m_glsl_program[i], "screen_texture_sz");
1964      GLfloat screen_texture_sz[2] = { (GLfloat)window().m_blitwidth, (GLfloat)window().m_blitheight };
1965      uniform_location = pfn_glGetUniformLocationARB(m_glsl_program[i], "screen_texture_sz");
19861966      pfn_glUniform2fvARB(uniform_location, 1, &(screen_texture_sz[0]));
19871967      GL_CHECK_ERROR_NORMAL();
19881968
19891969      GLfloat screen_texture_pow2_sz[2] = { (GLfloat)surf_w_pow2, (GLfloat)surf_h_pow2 };
1990      uniform_location = pfn_glGetUniformLocationARB(sdl->m_glsl_program[i], "screen_texture_pow2_sz");
1970      uniform_location = pfn_glGetUniformLocationARB(m_glsl_program[i], "screen_texture_pow2_sz");
19911971      pfn_glUniform2fvARB(uniform_location, 1, &(screen_texture_pow2_sz[0]));
19921972      GL_CHECK_ERROR_NORMAL();
19931973   }
19941974
1995   pfn_glUseProgramObjectARB(sdl->m_glsl_program[0]); // start with 1st shader
1975   pfn_glUseProgramObjectARB(m_glsl_program[0]); // start with 1st shader
19961976
1997   if( sdl->m_glsl_program_num > 1 )
1977   if( m_glsl_program_num > 1 )
19981978   {
19991979      // multipass mode
20001980      // GL_TEXTURE2/GL_TEXTURE3
r243304r243305
20181998         texture->rawwidth, texture->rawheight, texture->rawwidth_create, texture->rawheight_create);
20191999   }
20202000
2021   if( sdl->m_glsl_program_num > 1 && sdl->m_glsl_program_mb2sc < sdl->m_glsl_program_num - 1 )
2001   if( m_glsl_program_num > 1 && m_glsl_program_mb2sc < m_glsl_program_num - 1 )
20222002   {
20232003      // multipass mode
20242004      // GL_TEXTURE2/GL_TEXTURE3
r243304r243305
20372017      }
20382018
20392019      osd_printf_verbose("GL texture: mpass screen-bmp 2x %dx%d (pow2 %dx%d)\n",
2040         window->m_width, window->m_height, surf_w_pow2, surf_h_pow2);
2020         window().m_width, window().m_height, surf_w_pow2, surf_h_pow2);
20412021   }
20422022
20432023   // GL_TEXTURE0
r243304r243305
21022082   return 0;
21032083}
21042084
2105static texture_info *texture_create(sdl_window_info *window, const render_texinfo *texsource, UINT32 flags)
2085texture_info *sdl_info_ogl::texture_create(const render_texinfo *texsource, UINT32 flags)
21062086{
2107   sdl_info *sdl = (sdl_info *) window->m_dxdata;
21082087   texture_info *texture;
21092088
21102089   // allocate a new texture
r243304r243305
21172096   texture->texinfo.seqid = -1; // force set data
21182097   if (PRIMFLAG_GET_SCREENTEX(flags))
21192098   {
2120      texture->xprescale = window->m_prescale;
2121      texture->yprescale = window->m_prescale;
2099      texture->xprescale = window().m_prescale;
2100      texture->yprescale = window().m_prescale;
21222101   }
21232102   else
21242103   {
r243304r243305
21692148   }
21702149
21712150   // compute the size
2172   texture_compute_size_type(window, texsource, texture, flags);
2151   texture_compute_size_type(texsource, texture, flags);
21732152
21742153   texture->pbo=0;
21752154
2176   if ( texture->type != TEXTURE_TYPE_SHADER && sdl->m_useglsl)
2155   if ( texture->type != TEXTURE_TYPE_SHADER && m_useglsl)
21772156   {
21782157      pfn_glUseProgramObjectARB(0); // back to fixed function pipeline
21792158   }
21802159
21812160   if ( texture->type==TEXTURE_TYPE_SHADER )
21822161   {
2183      if ( texture_shader_create(window, texsource, texture, flags) )
2162      if ( texture_shader_create(texsource, texture, flags) )
21842163      {
21852164         global_free(texture);
21862165         return NULL;
r243304r243305
22372216
22382217   if ( texture->type == TEXTURE_TYPE_DYNAMIC )
22392218   {
2240      assert(sdl->m_usepbo);
2219      assert(m_usepbo);
22412220
22422221      // create the PBO
22432222      pfn_glGenBuffers(1, (GLuint *)&texture->pbo);
r243304r243305
22572236   }
22582237
22592238   // add us to the texture list
2260   if (sdl->m_texhash[texture->hash] == NULL)
2261      sdl->m_texhash[texture->hash] = texture;
2239   if (m_texhash[texture->hash] == NULL)
2240      m_texhash[texture->hash] = texture;
22622241   else
22632242   {
22642243      int i;
22652244      for (i = HASH_SIZE; i < HASH_SIZE + OVERFLOW_SIZE; i++)
2266         if (sdl->m_texhash[i] == NULL)
2245         if (m_texhash[i] == NULL)
22672246         {
2268            sdl->m_texhash[i] = texture;
2247            m_texhash[i] = texture;
22692248            break;
22702249         }
22712250      assert_always(i < HASH_SIZE + OVERFLOW_SIZE, "texture hash exhausted ...");
22722251   }
22732252
2274   if(sdl->m_usevbo)
2253   if(m_usevbo)
22752254   {
22762255      // Generate And Bind The Texture Coordinate Buffer
22772256      pfn_glGenBuffers( 1, &(texture->texCoordBufferName) );
r243304r243305
26962675      return 0;
26972676}
26982677
2699static texture_info *texture_find(sdl_info *sdl, const render_primitive *prim)
2678texture_info *sdl_info_ogl::texture_find(const render_primitive *prim)
27002679{
27012680   HashT texhash = texture_compute_hash(&prim->texture, prim->flags);
27022681   texture_info *texture;
27032682
2704   texture = sdl->m_texhash[texhash];
2683   texture = m_texhash[texhash];
27052684   if (texture != NULL)
27062685   {
27072686      int i;
r243304r243305
27092688         return texture;
27102689      for (i=HASH_SIZE; i<HASH_SIZE + OVERFLOW_SIZE; i++)
27112690      {
2712         texture = sdl->m_texhash[i];
2691         texture = m_texhash[i];
27132692         if (texture != NULL && compare_texture_primitive(texture, prim))
27142693            return texture;
27152694      }
r243304r243305
27212700//  texture_update
27222701//============================================================
27232702
2724static void texture_coord_update(sdl_window_info *window,
2725                           texture_info *texture, const render_primitive *prim, int shaderIdx)
2703void sdl_info_ogl::texture_coord_update(texture_info *texture, const render_primitive *prim, int shaderIdx)
27262704{
2727   sdl_info *sdl = (sdl_info *) window->m_dxdata;
27282705   float ustart = 0.0f, ustop = 0.0f;            // beginning/ending U coordinates
27292706   float vstart = 0.0f, vstop = 0.0f;            // beginning/ending V coordinates
27302707   float du, dv;
27312708
27322709   if ( texture->type != TEXTURE_TYPE_SHADER ||
2733         ( texture->type == TEXTURE_TYPE_SHADER && shaderIdx<=sdl->m_glsl_program_mb2sc ) )
2710         ( texture->type == TEXTURE_TYPE_SHADER && shaderIdx<=m_glsl_program_mb2sc ) )
27342711   {
27352712      // compute the U/V scale factors
27362713      if (texture->borderpix)
r243304r243305
27482725         vstop  = (float)(prim->texture.height*texture->yprescale) / (float)texture->rawheight_create;
27492726      }
27502727   }
2751   else if ( texture->type == TEXTURE_TYPE_SHADER && shaderIdx>sdl->m_glsl_program_mb2sc )
2728   else if ( texture->type == TEXTURE_TYPE_SHADER && shaderIdx>m_glsl_program_mb2sc )
27522729   {
2753      int surf_w_pow2  = get_valid_pow2_value (window->m_width, texture->texpow2);
2754      int surf_h_pow2  = get_valid_pow2_value (window->m_height, texture->texpow2);
2730      int surf_w_pow2  = get_valid_pow2_value (window().m_width, texture->texpow2);
2731      int surf_h_pow2  = get_valid_pow2_value (window().m_height, texture->texpow2);
27552732
2756      ustop  = (float)(window->m_width) / (float)surf_w_pow2;
2757      vstop  = (float)(window->m_height) / (float)surf_h_pow2;
2733      ustop  = (float)(window().m_width) / (float)surf_w_pow2;
2734      vstop  = (float)(window().m_height) / (float)surf_h_pow2;
27582735   }
27592736   else
27602737   {
r243304r243305
27722749      dv *= (float)texture->rawheight;
27732750   }
27742751
2775   if ( texture->type == TEXTURE_TYPE_SHADER && shaderIdx!=sdl->m_glsl_program_mb2sc )
2752   if ( texture->type == TEXTURE_TYPE_SHADER && shaderIdx!=m_glsl_program_mb2sc )
27762753   {
27772754      // 1:1 tex coord CCW (0/0) (1/0) (1/1) (0/1)
27782755      // we must go CW here due to the mame bitmap order
r243304r243305
27992776   }
28002777}
28012778
2802static void texture_mpass_flip(sdl_info *sdl, texture_info *texture, int shaderIdx)
2779void sdl_info_ogl::texture_mpass_flip(texture_info *texture, int shaderIdx)
28032780{
28042781   UINT32 mpass_src_idx = texture->mpass_dest_idx;
28052782
r243304r243305
28082785   if ( shaderIdx>0 )
28092786   {
28102787      int uniform_location;
2811      uniform_location = pfn_glGetUniformLocationARB(sdl->m_glsl_program[shaderIdx], "mpass_texture");
2788      uniform_location = pfn_glGetUniformLocationARB(m_glsl_program[shaderIdx], "mpass_texture");
28122789      pfn_glUniform1iARB(uniform_location, texture->mpass_textureunit[mpass_src_idx]-GL_TEXTURE0);
28132790      GL_CHECK_ERROR_NORMAL();
28142791   }
28152792
28162793   pfn_glActiveTexture(texture->mpass_textureunit[mpass_src_idx]);
2817   if ( shaderIdx<=sdl->m_glsl_program_mb2sc )
2794   if ( shaderIdx<=m_glsl_program_mb2sc )
28182795   {
28192796      glBindTexture(texture->texTarget, texture->mpass_texture_mamebm[mpass_src_idx]);
28202797   }
r243304r243305
28272804
28282805   pfn_glActiveTexture(texture->mpass_textureunit[texture->mpass_dest_idx]);
28292806
2830   if ( shaderIdx<sdl->m_glsl_program_num-1 )
2807   if ( shaderIdx<m_glsl_program_num-1 )
28312808   {
2832      if ( shaderIdx>=sdl->m_glsl_program_mb2sc )
2809      if ( shaderIdx>=m_glsl_program_mb2sc )
28332810      {
28342811         glBindTexture(texture->texTarget, texture->mpass_texture_scrn[texture->mpass_dest_idx]);
28352812         pfn_glBindFramebuffer(GL_FRAMEBUFFER_EXT, texture->mpass_fbo_scrn[texture->mpass_dest_idx]);
r243304r243305
28462823         GL_CHECK_ERROR_NORMAL();
28472824         glViewport(0.0, 0.0, (GLsizei)texture->rawwidth, (GLsizei)texture->rawheight);
28482825      }
2849      else if ( shaderIdx==sdl->m_glsl_program_mb2sc )
2826      else if ( shaderIdx==m_glsl_program_mb2sc )
28502827      {
2851         assert ( sdl->m_glsl_program_mb2sc < sdl->m_glsl_program_num-1 );
2852         glPopAttrib(); // glViewport(0.0, 0.0, (GLsizei)window->width, (GLsizei)window->height)
2828         assert ( m_glsl_program_mb2sc < m_glsl_program_num-1 );
2829         glPopAttrib(); // glViewport(0.0, 0.0, (GLsizei)window().width, (GLsizei)window().height)
28532830         GL_CHECK_ERROR_NORMAL();
28542831      }
28552832      glClear(GL_COLOR_BUFFER_BIT); // make sure the whole texture is redrawn ..
r243304r243305
28592836      glBindTexture(texture->texTarget, 0);
28602837      pfn_glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0);
28612838
2862      if ( sdl->m_glsl_program_mb2sc == sdl->m_glsl_program_num-1 )
2839      if ( m_glsl_program_mb2sc == m_glsl_program_num-1 )
28632840      {
2864         glPopAttrib(); // glViewport(0.0, 0.0, (GLsizei)window->width, (GLsizei)window->height)
2841         glPopAttrib(); // glViewport(0.0, 0.0, (GLsizei)window().width, (GLsizei)window().height)
28652842         GL_CHECK_ERROR_NORMAL();
28662843      }
28672844
r243304r243305
28702847   }
28712848}
28722849
2873static void texture_shader_update(sdl_window_info *window, texture_info *texture, int shaderIdx)
2850void sdl_info_ogl::texture_shader_update(texture_info *texture, int shaderIdx)
28742851{
2875   sdl_info *sdl = (sdl_info *) window->m_dxdata;
28762852   int uniform_location, scrnum;
28772853   render_container *container;
28782854   GLfloat vid_attributes[4];
28792855
28802856   scrnum = 0;
28812857   container = (render_container *)NULL;
2882   screen_device_iterator iter(window->machine().root_device());
2858   screen_device_iterator iter(window().machine().root_device());
28832859   for (screen_device *screen = iter.first(); screen != NULL; screen = iter.next())
28842860   {
2885      if (scrnum == window->m_start_viewscreen)
2861      if (scrnum == window().m_start_viewscreen)
28862862      {
28872863         container = &screen->container();
28882864      }
r243304r243305
28962872      container->get_user_settings(settings);
28972873      //FIXME: Intended behaviour
28982874#if 1
2899      vid_attributes[0] = window->machine().options().gamma();
2900      vid_attributes[1] = window->machine().options().contrast();
2901      vid_attributes[2] = window->machine().options().brightness();
2875      vid_attributes[0] = window().machine().options().gamma();
2876      vid_attributes[1] = window().machine().options().contrast();
2877      vid_attributes[2] = window().machine().options().brightness();
29022878#else
29032879      vid_attributes[0] = settings.gamma;
29042880      vid_attributes[1] = settings.contrast;
29052881      vid_attributes[2] = settings.brightness;
29062882#endif
29072883      vid_attributes[3] = 0.0f;
2908      uniform_location = pfn_glGetUniformLocationARB(sdl->m_glsl_program[shaderIdx], "vid_attributes");
2884      uniform_location = pfn_glGetUniformLocationARB(m_glsl_program[shaderIdx], "vid_attributes");
29092885      pfn_glUniform4fvARB(uniform_location, 1, &(vid_attributes[shaderIdx]));
29102886      if ( GL_CHECK_ERROR_QUIET() ) {
29112887         osd_printf_verbose("GLSL: could not set 'vid_attributes' for shader prog idx %d\n", shaderIdx);
r243304r243305
29132889   }
29142890   else
29152891   {
2916      osd_printf_verbose("GLSL: could not get render container for screen %d\n", window->m_start_viewscreen);
2892      osd_printf_verbose("GLSL: could not get render container for screen %d\n", window().m_start_viewscreen);
29172893   }
29182894}
29192895
2920static texture_info * texture_update(sdl_window_info *window, const render_primitive *prim, int shaderIdx)
2896texture_info * sdl_info_ogl::texture_update(const render_primitive *prim, int shaderIdx)
29212897{
2922   sdl_info *sdl = (sdl_info *) window->m_dxdata;
2923   texture_info *texture = texture_find(sdl, prim);
2898   texture_info *texture = texture_find(prim);
29242899   int texBound = 0;
29252900
29262901   // if we didn't find one, create a new texture
29272902   if (texture == NULL && prim->texture.base != NULL)
29282903   {
2929      texture = texture_create(window, &prim->texture, prim->flags);
2904      texture = texture_create(&prim->texture, prim->flags);
29302905   }
29312906   else if (texture != NULL)
29322907   {
29332908      if ( texture->type == TEXTURE_TYPE_SHADER )
29342909      {
2935         pfn_glUseProgramObjectARB(sdl->m_glsl_program[shaderIdx]); // back to our shader
2910         pfn_glUseProgramObjectARB(m_glsl_program[shaderIdx]); // back to our shader
29362911      }
29372912      else if ( texture->type == TEXTURE_TYPE_DYNAMIC )
29382913      {
2939         assert ( sdl->m_usepbo ) ;
2914         assert ( m_usepbo ) ;
29402915         pfn_glBindBuffer( GL_PIXEL_UNPACK_BUFFER_ARB, texture->pbo);
29412916         glEnable(texture->texTarget);
29422917      }
r243304r243305
29502925   {
29512926      if ( texture->type == TEXTURE_TYPE_SHADER )
29522927      {
2953         texture_shader_update(window, texture, shaderIdx);
2954         if ( sdl->m_glsl_program_num>1 )
2928         texture_shader_update(texture, shaderIdx);
2929         if ( m_glsl_program_num>1 )
29552930         {
2956            texture_mpass_flip(sdl, texture, shaderIdx);
2931            texture_mpass_flip(texture, shaderIdx);
29572932         }
29582933      }
29592934
r243304r243305
29722947      if (!texBound) {
29732948         glBindTexture(texture->texTarget, texture->texture);
29742949      }
2975      texture_coord_update(window, texture, prim, shaderIdx);
2950      texture_coord_update(texture, prim, shaderIdx);
29762951
29772952      glEnableClientState(GL_TEXTURE_COORD_ARRAY);
2978      if(sdl->m_usevbo)
2953      if(m_usevbo)
29792954      {
29802955         pfn_glBindBuffer( GL_ARRAY_BUFFER_ARB, texture->texCoordBufferName );
29812956         // Load The Data
r243304r243305
29912966      return texture;
29922967}
29932968
2994static void texture_disable(sdl_info *sdl, texture_info * texture)
2969void sdl_info_ogl::texture_disable(texture_info * texture)
29952970{
29962971   if ( texture->type == TEXTURE_TYPE_SHADER )
29972972   {
2998      assert ( sdl->m_useglsl );
2973      assert ( m_useglsl );
29992974      pfn_glUseProgramObjectARB(0); // back to fixed function pipeline
30002975   } else if ( texture->type == TEXTURE_TYPE_DYNAMIC )
30012976   {
r243304r243305
30062981   }
30072982}
30082983
3009static void texture_all_disable(sdl_info *sdl)
2984void sdl_info_ogl::texture_all_disable()
30102985{
3011   if ( sdl->m_useglsl )
2986   if ( m_useglsl )
30122987   {
30132988      pfn_glUseProgramObjectARB(0); // back to fixed function pipeline
30142989
30152990      pfn_glActiveTexture(GL_TEXTURE3);
30162991      glBindTexture(GL_TEXTURE_2D, 0);
3017      if ( sdl->m_usefbo ) pfn_glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0);
2992      if ( m_usefbo ) pfn_glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0);
30182993      pfn_glActiveTexture(GL_TEXTURE2);
30192994      glBindTexture(GL_TEXTURE_2D, 0);
3020      if ( sdl->m_usefbo ) pfn_glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0);
2995      if ( m_usefbo ) pfn_glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0);
30212996      pfn_glActiveTexture(GL_TEXTURE1);
30222997      glBindTexture(GL_TEXTURE_2D, 0);
3023      if ( sdl->m_usefbo ) pfn_glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0);
2998      if ( m_usefbo ) pfn_glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0);
30242999      pfn_glActiveTexture(GL_TEXTURE0);
30253000      glBindTexture(GL_TEXTURE_2D, 0);
3026      if ( sdl->m_usefbo ) pfn_glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0);
3001      if ( m_usefbo ) pfn_glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0);
30273002   }
30283003   glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0);
30293004
3030   if(sdl->m_usetexturerect)
3005   if(m_usetexturerect)
30313006   {
30323007      glDisable(GL_TEXTURE_RECTANGLE_ARB);
30333008   }
30343009   glDisable(GL_TEXTURE_2D);
30353010
30363011   glDisableClientState(GL_TEXTURE_COORD_ARRAY);
3037   if(sdl->m_usevbo)
3012   if(m_usevbo)
30383013   {
30393014      pfn_glBindBuffer( GL_ARRAY_BUFFER_ARB, 0); // unbind ..
30403015   }
3041   if ( sdl->m_usepbo )
3016   if ( m_usepbo )
30423017   {
30433018      pfn_glBindBuffer( GL_PIXEL_UNPACK_BUFFER_ARB, 0);
30443019   }
30453020}
30463021
3047static void drawogl_destroy_all_textures(sdl_window_info *window)
3022void sdl_info_ogl::destroy_all_textures()
30483023{
3049   sdl_info *sdl = (sdl_info *) window->m_dxdata;
30503024   texture_info *texture = NULL;
30513025   int lock=FALSE;
30523026   int i;
30533027
3054   if (sdl == NULL)
3028   if ( !m_initialized )
30553029      return;
30563030
3057   if ( !sdl->m_initialized )
3058      return;
3059
30603031#if (SDLMAME_SDL2)
3061   SDL_GL_MakeCurrent(window->m_sdl_window, sdl->m_gl_context_id);
3032   SDL_GL_MakeCurrent(window().m_sdl_window, m_gl_context_id);
30623033#endif
30633034
3064   if(window->m_primlist)
3035   if(window().m_primlist)
30653036   {
30663037      lock=TRUE;
3067      window->m_primlist->acquire_lock();
3038      window().m_primlist->acquire_lock();
30683039   }
30693040
30703041   glFinish();
30713042
3072   texture_all_disable(sdl);
3043   texture_all_disable();
30733044   glFinish();
30743045   glDisableClientState(GL_VERTEX_ARRAY);
30753046
30763047   i=0;
30773048   while (i<HASH_SIZE+OVERFLOW_SIZE)
30783049   {
3079      texture = sdl->m_texhash[i];
3080      sdl->m_texhash[i] = NULL;
3050      texture = m_texhash[i];
3051      m_texhash[i] = NULL;
30813052      if (texture != NULL)
30823053      {
3083         if(sdl->m_usevbo)
3054         if(m_usevbo)
30843055         {
30853056            pfn_glDeleteBuffers( 1, &(texture->texCoordBufferName) );
30863057            texture->texCoordBufferName=0;
30873058         }
30883059
3089         if(sdl->m_usepbo && texture->pbo)
3060         if(m_usepbo && texture->pbo)
30903061         {
30913062            pfn_glDeleteBuffers( 1, (GLuint *)&(texture->pbo) );
30923063            texture->pbo=0;
30933064         }
30943065
3095         if( sdl->m_glsl_program_num > 1 )
3066         if( m_glsl_program_num > 1 )
30963067         {
3097            assert(sdl->m_usefbo);
3068            assert(m_usefbo);
30983069            pfn_glDeleteFramebuffers(2, (GLuint *)&texture->mpass_fbo_mamebm[0]);
30993070            glDeleteTextures(2, (GLuint *)&texture->mpass_texture_mamebm[0]);
31003071         }
31013072
3102         if ( sdl->m_glsl_program_mb2sc < sdl->m_glsl_program_num - 1 )
3073         if ( m_glsl_program_mb2sc < m_glsl_program_num - 1 )
31033074         {
3104            assert(sdl->m_usefbo);
3075            assert(m_usefbo);
31053076            pfn_glDeleteFramebuffers(2, (GLuint *)&texture->mpass_fbo_scrn[0]);
31063077            glDeleteTextures(2, (GLuint *)&texture->mpass_texture_scrn[0]);
31073078         }
r243304r243305
31173088      }
31183089      i++;
31193090   }
3120   if ( sdl->m_useglsl )
3091   if ( m_useglsl )
31213092   {
3122      glsl_shader_free(sdl->m_glsl);
3123      sdl->m_glsl = NULL;
3093      glsl_shader_free(m_glsl);
3094      m_glsl = NULL;
31243095   }
31253096
3126   sdl->m_initialized = 0;
3097   m_initialized = 0;
31273098
31283099   if (lock)
3129      window->m_primlist->release_lock();
3100      window().m_primlist->release_lock();
31303101}
31313102
31323103//============================================================
31333104//  TEXCOPY FUNCS
31343105//============================================================
31353106
3136static void drawogl_window_clear(sdl_window_info *window)
3107void sdl_info_ogl::clear()
31373108{
3138   sdl_info *sdl = (sdl_info *) window->m_dxdata;
3139
3140   //FIXME: Handled in drawogl_window_draw as well
3141   sdl->m_blittimer = 3;
3109   //FIXME: Handled in sdl_info::draw as well
3110   m_blittimer = 3;
31423111}
trunk/src/osd/sdl/drawsdl.c
r243304r243305
4646#endif
4747
4848/* sdl_info is the information about SDL for the current screen */
49struct sdl_info
49class sdl_info : public osd_renderer
5050{
51public:
52
53   sdl_info(sdl_window_info *w)
54   : osd_renderer(w),
55   m_blittimer(0),
56   m_extra_flags(0),
57
58   #if (SDLMAME_SDL2)
59   m_sdl_renderer(NULL),
60   m_texture_id(NULL),
61   #else
62   m_sdlsurf(NULL),
63   m_yuvsurf(NULL),
64   #endif
65   m_yuv_lookup(NULL),
66   m_yuv_bitmap(NULL),
67   m_hw_scale_width(0),
68   m_hw_scale_height(0),
69   m_last_hofs(0),
70   m_last_vofs(0),
71   m_old_blitwidth(0),
72   m_old_blitheight(0)
73   { }
74
75   /* virtual */ int create(int width, int height);
76   /* virtual */ void resize(int width, int height);
77   /* virtual */ int draw(UINT32 dc, int update);
78   /* virtual */ void set_target_bounds();
79   /* virtual */ int xy_to_render_target(int x, int y, int *xt, int *yt);
80   /* virtual */ void destroy_all_textures();
81   /* virtual */ void destroy();
82   /* virtual */ void clear();
83
84   void yuv_init();
85#if (SDLMAME_SDL2)
86   void setup_texture(int tempwidth, int tempheight);
87#endif
88   void yuv_lookup_set(unsigned int pen, unsigned char red,
89            unsigned char green, unsigned char blue);
90
91#if (!SDLMAME_SDL2)
92   void yuv_overlay_init();
93#endif
94
5195   INT32               m_blittimer;
5296   UINT32              m_extra_flags;
5397
r243304r243305
101145
102146// core functions
103147static void drawsdl_exit(void);
104static void drawsdl_attach(sdl_draw_info *info, sdl_window_info *window);
105static int drawsdl_window_create(sdl_window_info *window, int width, int height);
106static void drawsdl_window_resize(sdl_window_info *window, int width, int height);
107static void drawsdl_window_destroy(sdl_window_info *window);
108static void drawsdl_set_target_bounds(sdl_window_info *window);
109static int drawsdl_window_draw(sdl_window_info *window, UINT32 dc, int update);
110static void drawsdl_destroy_all_textures(sdl_window_info *window);
111static void drawsdl_window_clear(sdl_window_info *window);
112static int drawsdl_xy_to_render_target(sdl_window_info *window, int x, int y, int *xt, int *yt);
113148
114#if (SDLMAME_SDL2)
115static void setup_texture(sdl_window_info *window, int tempwidth, int tempheight);
116#endif
117
118149// YUV overlays
119150
120static void drawsdl_yuv_init(sdl_info *sdl);
121151static void yuv_RGB_to_YV12(UINT16 *bitmap, sdl_info *sdl, UINT8 *ptr, int pitch);
122152static void yuv_RGB_to_YV12X2(UINT16 *bitmap, sdl_info *sdl, UINT8 *ptr, int pitch);
123153static void yuv_RGB_to_YUY2(UINT16 *bitmap, sdl_info *sdl, UINT8 *ptr, int pitch);
r243304r243305
190220//  drawsdl_init
191221//============================================================
192222
223static osd_renderer *drawsdl_create(sdl_window_info *window)
224{
225   return global_alloc(sdl_info(window));
226}
227
228
193229int drawsdl_init(sdl_draw_info *callbacks)
194230{
195231   // fill in the callbacks
232   callbacks->create = drawsdl_create;
196233   callbacks->exit = drawsdl_exit;
197   callbacks->attach = drawsdl_attach;
198234
199235   if (SDLMAME_SDL2)
200236      osd_printf_verbose("Using SDL multi-window soft driver (SDL 2.0+)\n");
r243304r243305
213249}
214250
215251//============================================================
216//  drawsdl_attach
217//============================================================
218
219static void drawsdl_attach(sdl_draw_info *info, sdl_window_info *window)
220{
221   // fill in the callbacks
222   window->create = drawsdl_window_create;
223   window->resize = drawsdl_window_resize;
224   window->set_target_bounds = drawsdl_set_target_bounds;
225   window->draw = drawsdl_window_draw;
226   window->destroy = drawsdl_window_destroy;
227   window->destroy_all_textures = drawsdl_destroy_all_textures;
228   window->clear = drawsdl_window_clear;
229   window->xy_to_render_target = drawsdl_xy_to_render_target;
230}
231
232//============================================================
233252//  drawsdl_destroy_all_textures
234253//============================================================
235254
236static void drawsdl_destroy_all_textures(sdl_window_info *window)
255void sdl_info::destroy_all_textures()
237256{
238257   /* nothing to be done in soft mode */
239258}
r243304r243305
243262//============================================================
244263
245264#if (SDLMAME_SDL2)
246static void setup_texture(sdl_window_info *window, int tempwidth, int tempheight)
265void sdl_info::setup_texture(int tempwidth, int tempheight)
247266{
248   sdl_info *sdl = (sdl_info *) window->m_dxdata;
249267   const sdl_scale_mode *sdl_sm = &scale_modes[video_config.scale_mode];
250268   SDL_DisplayMode mode;
251269   UINT32 fmt;
252270
253271   // Determine preferred pixelformat and set up yuv if necessary
254   SDL_GetCurrentDisplayMode(window->monitor()->handle(), &mode);
272   SDL_GetCurrentDisplayMode(window().monitor()->handle(), &mode);
255273
256   if (sdl->m_yuv_bitmap)
274   if (m_yuv_bitmap)
257275   {
258      global_free_array(sdl->m_yuv_bitmap);
259      sdl->m_yuv_bitmap = NULL;
276      global_free_array(m_yuv_bitmap);
277      m_yuv_bitmap = NULL;
260278   }
261279
262280   if (sdl_sm->is_scale)
263281   {
264      window->m_target->compute_minimum_size(sdl->m_hw_scale_width, sdl->m_hw_scale_height);
282      window().m_target->compute_minimum_size(m_hw_scale_width, m_hw_scale_height);
265283      if (video_config.prescale)
266284      {
267         sdl->m_hw_scale_width *= video_config.prescale;
268         sdl->m_hw_scale_height *= video_config.prescale;
285         m_hw_scale_width *= video_config.prescale;
286         m_hw_scale_height *= video_config.prescale;
269287
270288         /* This must be a multiple of 2 */
271         sdl->m_hw_scale_width = (sdl->m_hw_scale_width + 1) & ~1;
289         m_hw_scale_width = (m_hw_scale_width + 1) & ~1;
272290      }
273291   }
274292
275293   if (sdl_sm->is_yuv)
276      sdl->m_yuv_bitmap = global_alloc_array(UINT16, sdl->m_hw_scale_width * sdl->m_hw_scale_height);
294      m_yuv_bitmap = global_alloc_array(UINT16, m_hw_scale_width * m_hw_scale_height);
277295
278296   fmt = (sdl_sm->pixel_format ? sdl_sm->pixel_format : mode.format);
279297
280298   if (sdl_sm->is_scale)
281299   {
282      int w = sdl->m_hw_scale_width * sdl_sm->mult_w;
283      int h = sdl->m_hw_scale_height * sdl_sm->mult_h;
300      int w = m_hw_scale_width * sdl_sm->mult_w;
301      int h = m_hw_scale_height * sdl_sm->mult_h;
284302
285      sdl->m_texture_id = SDL_CreateTexture(sdl->m_sdl_renderer, fmt, SDL_TEXTUREACCESS_STREAMING, w, h);
303      m_texture_id = SDL_CreateTexture(m_sdl_renderer, fmt, SDL_TEXTUREACCESS_STREAMING, w, h);
286304
287305   }
288306   else
289307   {
290      sdl->m_texture_id = SDL_CreateTexture(sdl->m_sdl_renderer,fmt, SDL_TEXTUREACCESS_STREAMING,
308      m_texture_id = SDL_CreateTexture(m_sdl_renderer,fmt, SDL_TEXTUREACCESS_STREAMING,
291309            tempwidth, tempheight);
292310   }
293311}
r243304r243305
298316//============================================================
299317
300318#if (!SDLMAME_SDL2)
301static void yuv_overlay_init(sdl_window_info *window)
319void sdl_info::yuv_overlay_init()
302320{
303   sdl_info *sdl = (sdl_info *) window->m_dxdata;
304321   const sdl_scale_mode *sdl_sm = &scale_modes[video_config.scale_mode];
305322   int minimum_width, minimum_height;
306323
307   window->m_target->compute_minimum_size(minimum_width, minimum_height);
324   window().m_target->compute_minimum_size(minimum_width, minimum_height);
308325
309326   if (video_config.prescale)
310327   {
r243304r243305
312329      minimum_height *= video_config.prescale;
313330   }
314331
315   if (sdl->yuvsurf != NULL)
332   if (m_yuvsurf != NULL)
316333   {
317      SDL_FreeYUVOverlay(sdl->yuvsurf);
318      sdl->yuvsurf = NULL;
334      SDL_FreeYUVOverlay(m_yuvsurf);
335      m_yuvsurf = NULL;
319336   }
320337
321   if (sdl->m_yuv_bitmap != NULL)
338   if (m_yuv_bitmap != NULL)
322339   {
323      global_free_array(sdl->m_yuv_bitmap);
340      global_free_array(m_yuv_bitmap);
324341   }
325342
326343   osd_printf_verbose("SDL: Creating %d x %d YUV-Overlay ...\n", minimum_width, minimum_height);
327344
328   sdl->m_yuv_bitmap = global_alloc_array(UINT16, minimum_width*minimum_height);
345   m_yuv_bitmap = global_alloc_array(UINT16, minimum_width*minimum_height);
329346
330   sdl->yuvsurf = SDL_CreateYUVOverlay(minimum_width * sdl_sm->mult_w, minimum_height * sdl_sm->mult_h,
331         sdl_sm->pixel_format, sdl->sdlsurf);
347   m_yuvsurf = SDL_CreateYUVOverlay(minimum_width * sdl_sm->mult_w, minimum_height * sdl_sm->mult_h,
348         sdl_sm->pixel_format, m_sdlsurf);
332349
333   if ( sdl->yuvsurf == NULL ) {
350   if ( m_yuvsurf == NULL ) {
334351      osd_printf_error("SDL: Couldn't create SDL_yuv_overlay: %s\n", SDL_GetError());
335352      //return 1;
336353   }
337354
338   sdl->m_hw_scale_width = minimum_width;
339   sdl->m_hw_scale_height = minimum_height;
355   m_hw_scale_width = minimum_width;
356   m_hw_scale_height = minimum_height;
340357
341358   if (!shown_video_info)
342359   {
343360      osd_printf_verbose("YUV Mode         : %s\n", sdl_sm->name);
344361      osd_printf_verbose("YUV Overlay Size : %d x %d\n", minimum_width, minimum_height);
345      osd_printf_verbose("YUV Acceleration : %s\n", sdl->yuvsurf->hw_overlay ? "Hardware" : "Software");
362      osd_printf_verbose("YUV Acceleration : %s\n", m_yuvsurf->hw_overlay ? "Hardware" : "Software");
346363      shown_video_info = 1;
347364   }
348365}
r243304r243305
353370//============================================================
354371
355372#if (SDLMAME_SDL2)
356static void drawsdl_show_info(sdl_window_info *window, struct SDL_RendererInfo *render_info)
373static void drawsdl_show_info(struct SDL_RendererInfo *render_info)
357374{
358375#define RF_ENTRY(x) {x, #x }
359376   static struct {
r243304r243305
385402//  drawsdl_window_create
386403//============================================================
387404
388static int drawsdl_window_create(sdl_window_info *window, int width, int height)
405int sdl_info::create(int width, int height)
389406{
390   sdl_info *sdl;
391407   const sdl_scale_mode *sm = &scale_modes[video_config.scale_mode];
392408
393   // allocate memory for our structures
394   sdl = (sdl_info *) osd_malloc(sizeof(sdl_info));
395   memset(sdl, 0, sizeof(sdl_info));
396
397   window->m_dxdata = sdl;
398
399409#if (SDLMAME_SDL2)
400410
401411   /* set hints ... */
402412
403413   SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, sm->sdl_scale_mode);
404414
405   sdl->m_extra_flags = (window->fullscreen() ?
415   m_extra_flags = (window().fullscreen() ?
406416         SDL_WINDOW_BORDERLESS | SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_MOUSE_FOCUS
407417         | SDL_WINDOW_INPUT_GRABBED : SDL_WINDOW_RESIZABLE);
408418
409   window->m_sdl_window = SDL_CreateWindow(window->m_title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
410         width, height, sdl->m_extra_flags);
419   window().m_sdl_window = SDL_CreateWindow(window().m_title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
420         width, height, m_extra_flags);
411421
412   if (window->fullscreen() && video_config.switchres)
422   if (window().fullscreen() && video_config.switchres)
413423   {
414424      SDL_DisplayMode mode;
415      SDL_GetCurrentDisplayMode(window->monitor()->handle(), &mode);
425      SDL_GetCurrentDisplayMode(window().monitor()->handle(), &mode);
416426      mode.w = width;
417427      mode.h = height;
418      if (window->m_refresh)
419         mode.refresh_rate = window->m_refresh;
420      SDL_SetWindowDisplayMode(window->m_sdl_window, &mode);    // Try to set mode
428      if (window().m_refresh)
429         mode.refresh_rate = window().m_refresh;
430      SDL_SetWindowDisplayMode(window().m_sdl_window, &mode);    // Try to set mode
421431   }
422432   else
423      SDL_SetWindowDisplayMode(window->m_sdl_window, NULL); // Use desktop
433      SDL_SetWindowDisplayMode(window().m_sdl_window, NULL); // Use desktop
424434
425   SDL_ShowWindow(window->m_sdl_window);
435   SDL_ShowWindow(window().m_sdl_window);
426436
427   SDL_SetWindowFullscreen(window->m_sdl_window, (SDL_bool) window->fullscreen());
428   SDL_GetWindowSize(window->m_sdl_window, &window->m_width, &window->m_height);
429   SDL_RaiseWindow(window->m_sdl_window);
437   SDL_SetWindowFullscreen(window().m_sdl_window, (SDL_bool) window().fullscreen());
438   SDL_GetWindowSize(window().m_sdl_window, &window().m_width, &window().m_height);
439   SDL_RaiseWindow(window().m_sdl_window);
430440
431441   /* FIXME: Bug in SDL 1.3 */
432   if (window->fullscreen())
433      SDL_SetWindowGrab(window->m_sdl_window, SDL_TRUE);
442   if (window().fullscreen())
443      SDL_SetWindowGrab(window().m_sdl_window, SDL_TRUE);
434444
435445   // create a texture
436446
437447   if (video_config.waitvsync)
438      sdl->m_sdl_renderer = SDL_CreateRenderer(window->m_sdl_window, -1, /*SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTDISCARD |*/ SDL_RENDERER_PRESENTVSYNC);
448      m_sdl_renderer = SDL_CreateRenderer(window().m_sdl_window, -1, /*SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTDISCARD |*/ SDL_RENDERER_PRESENTVSYNC);
439449   else
440      sdl->m_sdl_renderer = SDL_CreateRenderer(window->m_sdl_window, -1, /*SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTDISCARD*/ 0);
450      m_sdl_renderer = SDL_CreateRenderer(window().m_sdl_window, -1, /*SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTDISCARD*/ 0);
441451
442   //SDL_SelectRenderer(window->sdl_window);
452   //SDL_SelectRenderer(window().sdl_window);
443453
444454   {
445455      struct SDL_RendererInfo render_info;
446456
447      SDL_GetRendererInfo(sdl->m_sdl_renderer, &render_info);
448      drawsdl_show_info(window, &render_info);
457      SDL_GetRendererInfo(m_sdl_renderer, &render_info);
458      drawsdl_show_info(&render_info);
449459
450460      // Check scale mode
451461
r243304r243305
465475      }
466476   }
467477
468   setup_texture(window, width, height);
478   setup_texture(width, height);
469479#else
470   sdl->m_extra_flags = (window->fullscreen() ?  SDL_FULLSCREEN : SDL_RESIZABLE);
480   m_extra_flags = (window().fullscreen() ?  SDL_FULLSCREEN : SDL_RESIZABLE);
471481
472   sdl->m_extra_flags |= sm->m_extra_flags;
482   m_extra_flags |= sm->m_extra_flags;
473483
474   sdl->sdlsurf = SDL_SetVideoMode(m_width, m_height,
475               0, SDL_SWSURFACE | SDL_ANYFORMAT | sdl->m_extra_flags);
484   m_sdlsurf = SDL_SetVideoMode(width, height,
485               0, SDL_SWSURFACE | SDL_ANYFORMAT | m_extra_flags);
476486
477   if (!sdl->sdlsurf)
487   if (!m_sdlsurf)
478488      return 1;
479489
480   window->m_width = sdl->sdlsurf->w;
481   window->m_height = sdl->sdlsurf->h;
490   window().m_width = m_sdlsurf->w;
491   window().m_height = m_sdlsurf->h;
482492
483493   if (sm->is_yuv)
484      yuv_overlay_init(window);
494      yuv_overlay_init();
485495
486496   // set the window title
487   SDL_WM_SetCaption(window->m_title, "SDLMAME");
497   SDL_WM_SetCaption(window().m_title, "SDLMAME");
488498#endif
489   sdl->m_yuv_lookup = NULL;
490   sdl->m_blittimer = 0;
499   m_yuv_lookup = NULL;
500   m_blittimer = 0;
491501
492   drawsdl_yuv_init(sdl);
502   yuv_init();
493503   return 0;
494504}
495505
r243304r243305
497507//  drawsdl_window_resize
498508//============================================================
499509
500static void drawsdl_window_resize(sdl_window_info *window, int width, int height)
510void sdl_info::resize(int width, int height)
501511{
502512#if (!SDLMAME_SDL2)
503513   const sdl_scale_mode *sdl_sm = &scale_modes[video_config.scale_mode];
504514#endif
505515#if (SDLMAME_SDL2)
506   SDL_SetWindowSize(window->m_sdl_window, width, height);
507   SDL_GetWindowSize(window->m_sdl_window, &window->m_width, &window->m_height);
516   SDL_SetWindowSize(window().m_sdl_window, width, height);
517   SDL_GetWindowSize(window().m_sdl_window, &window().m_width, &window().m_height);
508518
509519#else
510   sdl_info *sdl = (sdl_info *) window->m_dxdata;
511
512   if (sdl->yuvsurf != NULL)
520   if (m_yuvsurf != NULL)
513521   {
514      SDL_FreeYUVOverlay(sdl->yuvsurf);
515      sdl->yuvsurf = NULL;
522      SDL_FreeYUVOverlay(m_yuvsurf);
523      m_yuvsurf = NULL;
516524   }
517   SDL_FreeSurface(sdl->sdlsurf);
525   SDL_FreeSurface(m_sdlsurf);
518526   //printf("SetVideoMode %d %d\n", wp->resize_new_width, wp->resize_new_height);
519527
520   sdl->sdlsurf = SDL_SetVideoMode(m_width, m_height, 0,
521         SDL_SWSURFACE | SDL_ANYFORMAT | sdl->m_extra_flags);
522   window->m_width = sdl->sdlsurf->w;
523   window->m_height = sdl->sdlsurf->h;
528   m_sdlsurf = SDL_SetVideoMode(width, height, 0,
529         SDL_SWSURFACE | SDL_ANYFORMAT | m_extra_flags);
530   window().m_width = m_sdlsurf->w;
531   window().m_height = m_sdlsurf->h;
524532
525533   if (sdl_sm->is_yuv)
526534   {
527      yuv_overlay_init(window);
535      yuv_overlay_init();
528536   }
529537
530538#endif
r243304r243305
535543//  drawsdl_window_destroy
536544//============================================================
537545
538static void drawsdl_window_destroy(sdl_window_info *window)
546void sdl_info::destroy()
539547{
540   sdl_info *sdl = (sdl_info *) window->m_dxdata;
541548
542   // skip if nothing
543   if (sdl == NULL)
544      return;
545
546549#if (SDLMAME_SDL2)
547   //SDL_SelectRenderer(window->sdl_window);
548   SDL_DestroyTexture(sdl->m_texture_id);
549   //SDL_DestroyRenderer(window->sdl_window);
550   SDL_DestroyWindow(window->m_sdl_window);
550   //SDL_SelectRenderer(window().sdl_window);
551   SDL_DestroyTexture(m_texture_id);
552   //SDL_DestroyRenderer(window().sdl_window);
553   SDL_DestroyWindow(window().m_sdl_window);
551554#else
552   if (sdl->yuvsurf != NULL)
555   if (m_yuvsurf != NULL)
553556   {
554      SDL_FreeYUVOverlay(sdl->yuvsurf);
555      sdl->yuvsurf = NULL;
557      SDL_FreeYUVOverlay(m_yuvsurf);
558      m_yuvsurf = NULL;
556559   }
557560
558   if (sdl->sdlsurf)
561   if (m_sdlsurf)
559562   {
560      SDL_FreeSurface(sdl->sdlsurf);
561      sdl->sdlsurf = NULL;
563      SDL_FreeSurface(m_sdlsurf);
564      m_sdlsurf = NULL;
562565   }
563566#endif
564567   // free the memory in the window
565568
566   if (sdl->m_yuv_lookup != NULL)
569   if (m_yuv_lookup != NULL)
567570   {
568      global_free_array(sdl->m_yuv_lookup);
569      sdl->m_yuv_lookup = NULL;
571      global_free_array(m_yuv_lookup);
572      m_yuv_lookup = NULL;
570573   }
571   if (sdl->m_yuv_bitmap != NULL)
574   if (m_yuv_bitmap != NULL)
572575   {
573      global_free_array(sdl->m_yuv_bitmap);
574      sdl->m_yuv_bitmap = NULL;
576      global_free_array(m_yuv_bitmap);
577      m_yuv_bitmap = NULL;
575578   }
576   osd_free(sdl);
577   window->m_dxdata = NULL;
578579}
579580
580581//============================================================
581582//  drawsdl_window_clear
582583//============================================================
583584
584static void drawsdl_window_clear(sdl_window_info *window)
585void sdl_info::clear()
585586{
586   sdl_info *sdl = (sdl_info *) window->m_dxdata;
587
588   sdl->m_blittimer = 3;
587   m_blittimer = 3;
589588}
590589
591590//============================================================
592591//  drawsdl_xy_to_render_target
593592//============================================================
594593
595static int drawsdl_xy_to_render_target(sdl_window_info *window, int x, int y, int *xt, int *yt)
594int sdl_info::xy_to_render_target(int x, int y, int *xt, int *yt)
596595{
597   sdl_info *sdl = (sdl_info *) window->m_dxdata;
598596   const sdl_scale_mode *sm = &scale_modes[video_config.scale_mode];
599597
600   *xt = x - sdl->m_last_hofs;
601   *yt = y - sdl->m_last_vofs;
602   if (*xt<0 || *xt >= window->m_blitwidth)
598   *xt = x - m_last_hofs;
599   *yt = y - m_last_vofs;
600   if (*xt<0 || *xt >= window().m_blitwidth)
603601      return 0;
604   if (*yt<0 || *xt >= window->m_blitheight)
602   if (*yt<0 || *xt >= window().m_blitheight)
605603      return 0;
606604   if (!sm->is_scale)
607605   {
608606      return 1;
609607   }
610608   /* Rescale */
611   *xt = (*xt * sdl->m_hw_scale_width) / window->m_blitwidth;
612   *yt = (*yt * sdl->m_hw_scale_height) / window->m_blitheight;
609   *xt = (*xt * m_hw_scale_width) / window().m_blitwidth;
610   *yt = (*yt * m_hw_scale_height) / window().m_blitheight;
613611   return 1;
614612}
615613
r243304r243305
617615//  drawsdl_window_get_primitives
618616//============================================================
619617
620static void drawsdl_set_target_bounds(sdl_window_info *window)
618void sdl_info::set_target_bounds()
621619{
622   sdl_info *sdl = (sdl_info *) window->m_dxdata;
623620   const sdl_scale_mode *sm = &scale_modes[video_config.scale_mode];
624621
625622   if (!sm->is_scale)
626      window->m_target->set_bounds(window->m_blitwidth, window->m_blitheight, window->monitor()->aspect());
623      window().m_target->set_bounds(window().m_blitwidth, window().m_blitheight, window().monitor()->aspect());
627624   else
628      window->m_target->set_bounds(sdl->m_hw_scale_width, sdl->m_hw_scale_height);
625      window().m_target->set_bounds(m_hw_scale_width, m_hw_scale_height);
629626}
630627
631628//============================================================
632629//  drawsdl_window_draw
633630//============================================================
634631
635static int drawsdl_window_draw(sdl_window_info *window, UINT32 dc, int update)
632int sdl_info::draw(UINT32 dc, int update)
636633{
637   sdl_info *sdl = (sdl_info *) window->m_dxdata;
638634   const sdl_scale_mode *sm = &scale_modes[video_config.scale_mode];
639635   UINT8 *surfptr;
640636   INT32 pitch;
r243304r243305
650646      return 0;
651647   }
652648
653   // if we haven't been created, just punt
654   if (sdl == NULL)
655      return 1;
656
657649   // lock it if we need it
658650#if (!SDLMAME_SDL2)
659651
660   pitch = sdl->sdlsurf->pitch;
661   bpp = sdl->sdlsurf->format->BytesPerPixel;
662   rmask = sdl->sdlsurf->format->Rmask;
663   gmask = sdl->sdlsurf->format->Gmask;
664   bmask = sdl->sdlsurf->format->Bmask;
665//  amask = sdl->sdlsurf->format->Amask;
652   pitch = m_sdlsurf->pitch;
653   bpp = m_sdlsurf->format->BytesPerPixel;
654   rmask = m_sdlsurf->format->Rmask;
655   gmask = m_sdlsurf->format->Gmask;
656   bmask = m_sdlsurf->format->Bmask;
657//  amask = sdlsurf->format->Amask;
666658
667   if (window->m_blitwidth != sdl->m_old_blitwidth || window->m_blitheight != sdl->m_old_blitheight)
659   if (window().m_blitwidth != m_old_blitwidth || window().m_blitheight != m_old_blitheight)
668660   {
669661      if (sm->is_yuv)
670         yuv_overlay_init(window);
671      sdl->m_old_blitwidth = window->m_blitwidth;
672      sdl->m_old_blitheight = window->m_blitheight;
673      sdl->m_blittimer = 3;
662         yuv_overlay_init();
663      m_old_blitwidth = window().m_blitwidth;
664      m_old_blitheight = window().m_blitheight;
665      m_blittimer = 3;
674666   }
675667
676   if (SDL_MUSTLOCK(sdl->sdlsurf)) SDL_LockSurface(sdl->sdlsurf);
677   // Clear if necessary
668   if (SDL_MUSTLOCK(m_sdlsurf))
669      SDL_LockSurface(m_sdlsurf);
678670
679   if (sdl->m_blittimer > 0)
671   // Clear if necessary
672   if (m_blittimer > 0)
680673   {
681      memset(sdl->sdlsurf->pixels, 0, window->m_height * sdl->sdlsurf->pitch);
682      sdl->m_blittimer--;
674      memset(m_sdlsurf->pixels, 0, window().m_height * m_sdlsurf->pitch);
675      m_blittimer--;
683676   }
684677
685678
686679   if (sm->is_yuv)
687680   {
688      SDL_LockYUVOverlay(sdl->yuvsurf);
689      surfptr = sdl->yuvsurf->pixels[0]; // (UINT8 *) sdl->m_yuv_bitmap;
690      pitch = sdl->yuvsurf->pitches[0]; // (UINT8 *) sdl->m_yuv_bitmap;
681      SDL_LockYUVOverlay(m_yuvsurf);
682      surfptr = m_yuvsurf->pixels[0]; // (UINT8 *) m_yuv_bitmap;
683      pitch = m_yuvsurf->pitches[0]; // (UINT8 *) m_yuv_bitmap;
691684   }
692685   else
693      surfptr = (UINT8 *)sdl->sdlsurf->pixels;
686      surfptr = (UINT8 *)m_sdlsurf->pixels;
694687#else
695   //SDL_SelectRenderer(window->sdl_window);
688   //SDL_SelectRenderer(window().sdl_window);
696689
697   if (window->m_blitwidth != sdl->m_old_blitwidth || window->m_blitheight != sdl->m_old_blitheight)
690   if (window().m_blitwidth != m_old_blitwidth || window().m_blitheight != m_old_blitheight)
698691   {
699      SDL_RenderSetViewport(sdl->m_sdl_renderer, NULL);
692      SDL_RenderSetViewport(m_sdl_renderer, NULL);
700693
701      SDL_DestroyTexture(sdl->m_texture_id);
702      setup_texture(window, window->m_blitwidth, window->m_blitheight);
703      sdl->m_old_blitwidth = window->m_blitwidth;
704      sdl->m_old_blitheight = window->m_blitheight;
705      sdl->m_blittimer = 3;
694      SDL_DestroyTexture(m_texture_id);
695      setup_texture(window().m_blitwidth, window().m_blitheight);
696      m_old_blitwidth = window().m_blitwidth;
697      m_old_blitheight = window().m_blitheight;
698      m_blittimer = 3;
706699   }
707700
708701   {
709702      Uint32 format;
710703      int access, w, h;
711704
712      SDL_QueryTexture(sdl->m_texture_id, &format, &access, &w, &h);
705      SDL_QueryTexture(m_texture_id, &format, &access, &w, &h);
713706      SDL_PixelFormatEnumToMasks(format, &bpp, &rmask, &gmask, &bmask, &amask);
714707      bpp = bpp / 8; /* convert to bytes per pixels */
715708   }
716709
717710   // Clear if necessary
718   if (sdl->m_blittimer > 0)
711   if (m_blittimer > 0)
719712   {
720713      /* SDL Underlays need alpha = 0 ! */
721      SDL_SetRenderDrawColor(sdl->m_sdl_renderer,0,0,0,0);
722      SDL_RenderFillRect(sdl->m_sdl_renderer,NULL);
714      SDL_SetRenderDrawColor(m_sdl_renderer,0,0,0,0);
715      SDL_RenderFillRect(m_sdl_renderer,NULL);
723716      //SDL_RenderFill(0,0,0,0 /*255*/,NULL);
724      sdl->m_blittimer--;
717      m_blittimer--;
725718   }
726719
727   SDL_LockTexture(sdl->m_texture_id, NULL, (void **) &surfptr, &pitch);
720   SDL_LockTexture(m_texture_id, NULL, (void **) &surfptr, &pitch);
728721
729722#endif
730723   // get ready to center the image
731724   vofs = hofs = 0;
732   blitwidth = window->m_blitwidth;
733   blitheight = window->m_blitheight;
725   blitwidth = window().m_blitwidth;
726   blitheight = window().m_blitheight;
734727
735728   // figure out what coordinate system to use for centering - in window mode it's always the
736729   // SDL surface size.  in fullscreen the surface covers all monitors, so center according to
737730   // the first one only
738   if ((window->fullscreen()) && (!video_config.switchres))
731   if ((window().fullscreen()) && (!video_config.switchres))
739732   {
740      ch = window->monitor()->center_height();
741      cw = window->monitor()->center_width();
733      ch = window().monitor()->center_height();
734      cw = window().monitor()->center_width();
742735   }
743736   else
744737   {
745      ch = window->m_height;
746      cw = window->m_width;
738      ch = window().m_height;
739      cw = window().m_width;
747740   }
748741
749742   // do not crash if the window's smaller than the blit area
r243304r243305
753746   }
754747   else if (video_config.centerv)
755748   {
756      vofs = (ch - window->m_blitheight) / 2;
749      vofs = (ch - window().m_blitheight) / 2;
757750   }
758751
759752   if (blitwidth > cw)
r243304r243305
762755   }
763756   else if (video_config.centerh)
764757   {
765      hofs = (cw - window->m_blitwidth) / 2;
758      hofs = (cw - window().m_blitwidth) / 2;
766759   }
767760
768   sdl->m_last_hofs = hofs;
769   sdl->m_last_vofs = vofs;
761   m_last_hofs = hofs;
762   m_last_vofs = vofs;
770763
771   window->m_primlist->acquire_lock();
764   window().m_primlist->acquire_lock();
772765
773766   // render to it
774767   if (!sm->is_yuv)
r243304r243305
785778      }
786779      else
787780      {
788         mamewidth = sdl->m_hw_scale_width;
789         mameheight = sdl->m_hw_scale_height;
781         mamewidth = m_hw_scale_width;
782         mameheight = m_hw_scale_height;
790783      }
791784      switch (rmask)
792785      {
793786         case 0x0000ff00:
794            software_renderer<UINT32, 0,0,0, 8,16,24>::draw_primitives(*window->m_primlist, surfptr, mamewidth, mameheight, pitch / 4);
787            software_renderer<UINT32, 0,0,0, 8,16,24>::draw_primitives(*window().m_primlist, surfptr, mamewidth, mameheight, pitch / 4);
795788            break;
796789
797790         case 0x00ff0000:
798            software_renderer<UINT32, 0,0,0, 16,8,0>::draw_primitives(*window->m_primlist, surfptr, mamewidth, mameheight, pitch / 4);
791            software_renderer<UINT32, 0,0,0, 16,8,0>::draw_primitives(*window().m_primlist, surfptr, mamewidth, mameheight, pitch / 4);
799792            break;
800793
801794         case 0x000000ff:
802            software_renderer<UINT32, 0,0,0, 0,8,16>::draw_primitives(*window->m_primlist, surfptr, mamewidth, mameheight, pitch / 4);
795            software_renderer<UINT32, 0,0,0, 0,8,16>::draw_primitives(*window().m_primlist, surfptr, mamewidth, mameheight, pitch / 4);
803796            break;
804797
805798         case 0xf800:
806            software_renderer<UINT16, 3,2,3, 11,5,0>::draw_primitives(*window->m_primlist, surfptr, mamewidth, mameheight, pitch / 2);
799            software_renderer<UINT16, 3,2,3, 11,5,0>::draw_primitives(*window().m_primlist, surfptr, mamewidth, mameheight, pitch / 2);
807800            break;
808801
809802         case 0x7c00:
810            software_renderer<UINT16, 3,3,3, 10,5,0>::draw_primitives(*window->m_primlist, surfptr, mamewidth, mameheight, pitch / 2);
803            software_renderer<UINT16, 3,3,3, 10,5,0>::draw_primitives(*window().m_primlist, surfptr, mamewidth, mameheight, pitch / 2);
811804            break;
812805
813806         default:
r243304r243305
817810   }
818811   else
819812   {
820      assert (sdl->m_yuv_bitmap != NULL);
813      assert (m_yuv_bitmap != NULL);
821814      assert (surfptr != NULL);
822      software_renderer<UINT16, 3,3,3, 10,5,0>::draw_primitives(*window->m_primlist, sdl->m_yuv_bitmap, sdl->m_hw_scale_width, sdl->m_hw_scale_height, sdl->m_hw_scale_width);
823      sm->yuv_blit((UINT16 *)sdl->m_yuv_bitmap, sdl, surfptr, pitch);
815      software_renderer<UINT16, 3,3,3, 10,5,0>::draw_primitives(*window().m_primlist, m_yuv_bitmap, m_hw_scale_width, m_hw_scale_height, m_hw_scale_width);
816      sm->yuv_blit((UINT16 *)m_yuv_bitmap, this, surfptr, pitch);
824817   }
825818
826   window->m_primlist->release_lock();
819   window().m_primlist->release_lock();
827820
828821   // unlock and flip
829822#if (!SDLMAME_SDL2)
830   if (SDL_MUSTLOCK(sdl->sdlsurf)) SDL_UnlockSurface(sdl->sdlsurf);
823   if (SDL_MUSTLOCK(m_sdlsurf)) SDL_UnlockSurface(m_sdlsurf);
831824   if (!sm->is_yuv)
832825   {
833      SDL_Flip(sdl->sdlsurf);
826      SDL_Flip(m_sdlsurf);
834827   }
835828   else
836829   {
837830      SDL_Rect r;
838831
839      SDL_UnlockYUVOverlay(sdl->yuvsurf);
840      r.x=hofs;
841      r.y=vofs;
842      r.w=m_blitwidth;
843      r.h=m_blitheight;
844      SDL_DisplayYUVOverlay(sdl->yuvsurf, &r);
832      SDL_UnlockYUVOverlay(m_yuvsurf);
833      r.x = hofs;
834      r.y = vofs;
835      r.w = blitwidth;
836      r.h = blitheight;
837      SDL_DisplayYUVOverlay(m_yuvsurf, &r);
845838   }
846839#else
847   SDL_UnlockTexture(sdl->m_texture_id);
840   SDL_UnlockTexture(m_texture_id);
848841   {
849842      SDL_Rect r;
850843
r243304r243305
852845      r.y=vofs;
853846      r.w=blitwidth;
854847      r.h=blitheight;
855      //printf("blitwidth %d %d - %d %d\n", blitwidth, blitheight, window->width, window->height);
856      //SDL_UpdateTexture(sdl->sdltex, NULL, sdl->sdlsurf->pixels, pitch);
857      SDL_RenderCopy(sdl->m_sdl_renderer,sdl->m_texture_id, NULL, &r);
858      SDL_RenderPresent(sdl->m_sdl_renderer);
848      //printf("blitwidth %d %d - %d %d\n", blitwidth, blitheight, window().width, window().height);
849      //SDL_UpdateTexture(sdltex, NULL, sdlsurf->pixels, pitch);
850      SDL_RenderCopy(m_sdl_renderer,m_texture_id, NULL, &r);
851      SDL_RenderPresent(m_sdl_renderer);
859852   }
860853#endif
861854   return 0;
r243304r243305
901894#define YMASK  (Y1MASK|Y2MASK)
902895#define UVMASK (UMASK|VMASK)
903896
904static void yuv_lookup_set(sdl_info *sdl, unsigned int pen, unsigned char red,
897void sdl_info::yuv_lookup_set(unsigned int pen, unsigned char red,
905898         unsigned char green, unsigned char blue)
906899{
907900   UINT32 y,u,v;
r243304r243305
910903
911904   /* Storing this data in YUYV order simplifies using the data for
912905      YUY2, both with and without smoothing... */
913   sdl->m_yuv_lookup[pen]=(y<<Y1SHIFT)|(u<<USHIFT)|(y<<Y2SHIFT)|(v<<VSHIFT);
906   m_yuv_lookup[pen]=(y<<Y1SHIFT)|(u<<USHIFT)|(y<<Y2SHIFT)|(v<<VSHIFT);
914907}
915908
916static void drawsdl_yuv_init(sdl_info *sdl)
909void sdl_info::yuv_init()
917910{
918911   unsigned char r,g,b;
919   if (sdl->m_yuv_lookup == NULL)
920      sdl->m_yuv_lookup = global_alloc_array(UINT32, 65536);
912   if (m_yuv_lookup == NULL)
913      m_yuv_lookup = global_alloc_array(UINT32, 65536);
921914   for (r = 0; r < 32; r++)
922915      for (g = 0; g < 32; g++)
923916         for (b = 0; b < 32; b++)
924917         {
925918            int idx = (r << 10) | (g << 5) | b;
926            yuv_lookup_set(sdl, idx,
919            yuv_lookup_set(idx,
927920               (r << 3) | (r >> 2),
928921               (g << 3) | (g >> 2),
929922               (b << 3) | (b >> 2));
trunk/src/osd/sdl/input.c
r243304r243305
18591859            int cx, cy;
18601860            osd_ticks_t click = osd_ticks() * 1000 / osd_ticks_per_second();
18611861            sdl_window_info *window = GET_FOCUS_WINDOW(&event.button);
1862            if (window != NULL && window->xy_to_render_target(window, event.button.x,event.button.y, &cx, &cy) )
1862            if (window != NULL && window->renderer().xy_to_render_target(event.button.x,event.button.y, &cx, &cy) )
18631863            {
18641864               ui_input_push_mouse_down_event(machine, window->m_target, cx, cy);
18651865               // FIXME Parameter ?
r243304r243305
18931893            int cx, cy;
18941894            sdl_window_info *window = GET_FOCUS_WINDOW(&event.button);
18951895
1896            if (window != NULL && window->xy_to_render_target(window, event.button.x,event.button.y, &cx, &cy) )
1896            if (window != NULL && window->renderer().xy_to_render_target(event.button.x,event.button.y, &cx, &cy) )
18971897            {
18981898               ui_input_push_mouse_up_event(machine, window->m_target, cx, cy);
18991899            }
r243304r243305
19181918            int cx=-1, cy=-1;
19191919            sdl_window_info *window = GET_FOCUS_WINDOW(&event.motion);
19201920
1921            if (window != NULL && window->xy_to_render_target(window, event.motion.x, event.motion.y, &cx, &cy) )
1921            if (window != NULL && window->renderer().xy_to_render_target(event.motion.x, event.motion.y, &cx, &cy) )
19221922               ui_input_push_mouse_move_event(machine, window->m_target, cx, cy);
19231923         }
19241924         break;
trunk/src/osd/sdl/window.c
r243304r243305
483483
484484   ASSERT_WINDOW_THREAD();
485485
486   window->destroy_all_textures(window);
487   window->resize(window, wp->new_width(), wp->new_height());
486   window->renderer().destroy_all_textures();
487   window->renderer().resize(wp->new_width(), wp->new_height());
488488
489489   window->blit_surface_size(wp->new_width(), wp->new_height());
490490
r243304r243305
517517
518518   ASSERT_WINDOW_THREAD();
519519
520   window->clear(window);
520   window->renderer().clear();
521521   osd_free(wp);
522522   return NULL;
523523}
r243304r243305
558558      window->m_windowed_height = window->m_height;
559559   }
560560
561   window->destroy(window);
561   window->renderer().destroy();
562562   sdlinput_release_keys(wp->machine());
563563
564564   // toggle the window mode
r243304r243305
582582
583583   sdl_window_info *window = wp->window();
584584
585   window->destroy_all_textures(window);
585   window->renderer().destroy_all_textures();
586586
587587   osd_free(wp);
588588   return NULL;
r243304r243305
722722   *last_window_ptr = window;
723723   last_window_ptr = &window->m_next;
724724
725   draw.attach(&draw, window);
725   window->set_renderer(draw.create(window));
726726
727727   // create an event that we can use to skip blitting
728728   window->m_rendered_event = osd_event_alloc(FALSE, TRUE);
r243304r243305
781781   ASSERT_WINDOW_THREAD();
782782
783783   // free the textures etc
784   window->destroy(window);
784   window->renderer().destroy();
785785
786786   // release all keys ...
787787   sdlinput_release_keys(wp->machine());
r243304r243305
10271027         }
10281028
10291029         // ensure the target bounds are up-to-date, and then get the primitives
1030         set_target_bounds(this);
1030         renderer().set_target_bounds();
10311031
10321032         render_primitive_list &primlist = m_target->get_primitives();
10331033
r243304r243305
11161116   }
11171117
11181118   // initialize the drawing backend
1119   if (window->create(window, tempwidth, tempheight))
1119   if (window->renderer().create(tempwidth, tempheight))
11201120      return (void *) &result[1];
11211121
11221122   // Make sure we have a consistent state
r243304r243305
11471147
11481148   t0 = osd_ticks();
11491149
1150   window->draw(window, dc, update);
1150   window->renderer().draw(dc, update);
11511151
11521152   frames++;
11531153   currentTime = osd_ticks();
r243304r243305
11981198      if( video_config.perftest )
11991199         measure_fps(window, dc, update);
12001200      else
1201         window->draw(window, dc, update);
1201         window->renderer().draw(dc, update);
12021202   }
12031203
12041204   /* all done, ready for next */
trunk/src/osd/sdl/window.h
r243304r243305
4040   osd_renderer(sdl_window_info *window)
4141   : m_window(window) { }
4242
43   virtual ~osd_renderer() { }
44
4345   sdl_window_info &window() { return *m_window; }
4446
4547   virtual int create(int width, int height) = 0;
4648   virtual void resize(int width, int height) = 0;
4749   virtual int draw(UINT32 dc, int update) = 0;
4850   virtual void set_target_bounds() = 0;
49   virtual int y_to_render_target(int x, int y, int *xt, int *yt) = 0;
51   virtual int xy_to_render_target(int x, int y, int *xt, int *yt) = 0;
5052   virtual void destroy_all_textures() = 0;
5153   virtual void destroy() = 0;
5254   virtual void clear() = 0;
r243304r243305
6264         int index, const sdl_window_config *config)
6365   : m_next(NULL), m_minwidth(0), m_minheight(0),
6466      m_startmaximized(0),
65      m_rendered_event(0), m_target(0), m_primlist(NULL), m_dxdata(NULL),
67      m_rendered_event(0), m_target(0), m_primlist(NULL),
6668      m_width(0), m_height(0), m_blitwidth(0), m_blitheight(0),
6769      m_start_viewscreen(0),
6870#if (SDLMAME_SDL2)
r243304r243305
7173      m_resize_height(0),
7274      m_last_resize(0),
7375#else
74      screen_width(0), screen_height(0),
76      m_screen_width(0), m_screen_height(0),
7577#endif
7678      m_machine(a_machine), m_monitor(a_monitor), m_fullscreen(0), m_index(0)
7779   {
r243304r243305
8991      m_windowed_height = config->height;
9092   }
9193
94   ~sdl_window_info()
95   {
96      global_free(m_renderer);
97   }
98
9299   void video_window_update(running_machine &machine);
93   //void blit_surface_size(int window_width, int window_height);
94100   void toggle_full_screen(running_machine &machine);
95101   void modify_prescale(running_machine &machine, int dir);
96102   void window_resize(INT32 width, INT32 height);
97103   void window_clear();
98104
99105   void video_window_destroy(running_machine &machine);
100   //void pick_best_mode(int *fswidth, int *fsheight);
101106   void get_min_bounds(int *window_width, int *window_height, int constrain);
102107   void get_max_bounds(int *window_width, int *window_height, int constrain);
103108
r243304r243305
111116   void pick_best_mode(int *fswidth, int *fsheight);
112117   int index() const { return m_index; }
113118
114#if 1
115   // Draw Callbacks
116   int (*create)(sdl_window_info *window, int m_width, int m_height);
117   void (*resize)(sdl_window_info *window, int m_width, int m_height);
118   int (*draw)(sdl_window_info *window, UINT32 dc, int update);
119   void (*set_target_bounds)(sdl_window_info *window);
120   int (*xy_to_render_target)(sdl_window_info *window, int x, int y, int *xt, int *yt);
121   void (*destroy_all_textures)(sdl_window_info *window);
122   void (*destroy)(sdl_window_info *window);
123   void (*clear)(sdl_window_info *window);
124#endif
119   osd_renderer &renderer() { return *m_renderer; }
125120
126121   // Pointer to next window
127122   sdl_window_info *   m_next;
r243304r243305
143138   render_target *     m_target;
144139   render_primitive_list *m_primlist;
145140
146   // drawing data
147   void *              m_dxdata;
148
149141   // cache of physical m_width and m_height
150142   int                 m_width;
151143   int                 m_height;
r243304r243305
171163   int                 m_screen_height;
172164#endif
173165
166   void set_renderer(osd_renderer *renderer)
167   {
168      m_renderer = renderer;
169   }
174170private:
175171   void constrain_to_aspect_ratio(int *window_width, int *window_height, int adjustment);
176172
r243304r243305
186182
187183struct sdl_draw_info
188184{
185   osd_renderer *(*create)(sdl_window_info *window);
189186   void (*exit)(void);
190   void (*attach)(sdl_draw_info *info, sdl_window_info *window);
191187};
192188
193189//============================================================


Previous 199869 Revisions Next


© 1997-2024 The MAME Team