Previous 199869 Revisions Next

r34792 Saturday 31st January, 2015 at 22:58:22 UTC by Couriersud
More transition to "m_" members. (nw)
[src/osd/sdl]drawogl.c drawsdl.c input.c video.c window.c window.h

trunk/src/osd/sdl/drawogl.c
r243303r243304
218218struct sdl_info
219219{
220220   sdl_info()
221   : blittimer(0), extra_flags(0),
221   : m_blittimer(0), m_extra_flags(0),
222222#if (SDLMAME_SDL2)
223      gl_context_id(0),
223      m_gl_context_id(0),
224224#else
225225      sdlsurf(NULL),
226226#endif
227      initialized(0),
228      last_blendmode(0),
229      texture_max_width(0),
230      texture_max_height(0),
231      texpoweroftwo(0),
232      usevbo(0), usepbo(0), usefbo(0), useglsl(0), glsl(NULL),
233      glsl_program_num(0),
234      glsl_program_mb2sc(0),
235      usetexturerect(0),
236      init_context(0),
237      last_hofs(0.0f),
238      last_vofs(0.0f),
239      surf_w(0),
240      surf_h(0)
227      m_initialized(0),
228      m_last_blendmode(0),
229      m_texture_max_width(0),
230      m_texture_max_height(0),
231      m_texpoweroftwo(0),
232      m_usevbo(0), m_usepbo(0), m_usefbo(0), m_useglsl(0), m_glsl(NULL),
233      m_glsl_program_num(0),
234      m_glsl_program_mb2sc(0),
235      m_usetexturerect(0),
236      m_init_context(0),
237      m_last_hofs(0.0f),
238      m_last_vofs(0.0f),
239      m_surf_w(0),
240      m_surf_h(0)
241241   {
242242      for (int i=0; i < HASH_SIZE + OVERFLOW_SIZE; i++)
243         texhash[i] = NULL;
243         m_texhash[i] = NULL;
244244      for (int i=0; i < 2*GLSL_SHADER_MAX; i++)
245         glsl_program[i] = 0;
245         m_glsl_program[i] = 0;
246246      for (int i=0; i < 8; i++)
247         texVerticex[i] = 0.0f;
247         m_texVerticex[i] = 0.0f;
248248   }
249249
250   INT32           blittimer;
251   UINT32          extra_flags;
250   INT32           m_blittimer;
251   UINT32          m_extra_flags;
252252
253253#if (SDLMAME_SDL2)
254   SDL_GLContext   gl_context_id;
254   SDL_GLContext   m_gl_context_id;
255255#else
256256   // SDL surface
257257   SDL_Surface         *sdlsurf;
258258#endif
259259
260   int             initialized;        // is everything well initialized, i.e. all GL stuff etc.
260   int             m_initialized;        // is everything well initialized, i.e. all GL stuff etc.
261261   // 3D info (GL mode only)
262   texture_info *  texhash[HASH_SIZE + OVERFLOW_SIZE];
263   int             last_blendmode;     // previous blendmode
264   INT32           texture_max_width;      // texture maximum width
265   INT32           texture_max_height;     // texture maximum height
266   int             texpoweroftwo;          // must textures be power-of-2 sized?
267   int             usevbo;         // runtime check if VBO is available
268   int             usepbo;         // runtime check if PBO is available
269   int             usefbo;         // runtime check if FBO is available
270   int             useglsl;        // runtime check if GLSL is available
262   texture_info *  m_texhash[HASH_SIZE + OVERFLOW_SIZE];
263   int             m_last_blendmode;     // previous blendmode
264   INT32           m_texture_max_width;      // texture maximum width
265   INT32           m_texture_max_height;     // texture maximum height
266   int             m_texpoweroftwo;          // must textures be power-of-2 sized?
267   int             m_usevbo;         // runtime check if VBO is available
268   int             m_usepbo;         // runtime check if PBO is available
269   int             m_usefbo;         // runtime check if FBO is available
270   int             m_useglsl;        // runtime check if GLSL is available
271271
272   glsl_shader_info *glsl;             // glsl_shader_info
272   glsl_shader_info *m_glsl;             // glsl_shader_info
273273
274   GLhandleARB     glsl_program[2*GLSL_SHADER_MAX];  // GLSL programs, or 0
275   int             glsl_program_num;   // number of GLSL programs
276   int             glsl_program_mb2sc; // GLSL program idx, which transforms
274   GLhandleARB     m_glsl_program[2*GLSL_SHADER_MAX];  // GLSL programs, or 0
275   int             m_glsl_program_num;   // number of GLSL programs
276   int             m_glsl_program_mb2sc; // GLSL program idx, which transforms
277277                              // the mame-bitmap. screen-bitmap (size/rotation/..)
278278                              // All progs <= glsl_program_mb2sc using the mame bitmap
279279                              // as input, otherwise the screen bitmap.
280280                              // All progs >= glsl_program_mb2sc using the screen bitmap
281281                              // as output, otherwise the mame bitmap.
282   int             usetexturerect;     // use ARB_texture_rectangle for non-power-of-2, general use
282   int             m_usetexturerect;     // use ARB_texture_rectangle for non-power-of-2, general use
283283
284   int             init_context;       // initialize context before next draw
284   int             m_init_context;       // initialize context before next draw
285285
286   float           last_hofs;
287   float           last_vofs;
286   float           m_last_hofs;
287   float           m_last_vofs;
288288
289289   // Static vars from draogl_window_dra
290   INT32           surf_w;
291   INT32           surf_h;
292   GLfloat         texVerticex[8];
290   INT32           m_surf_w;
291   INT32           m_surf_h;
292   GLfloat         m_texVerticex[8];
293293};
294294
295295/* line_aa_step is used for drawing antialiased lines */
r243303r243304
330330INLINE void set_blendmode(sdl_info *sdl, int blendmode)
331331{
332332   // try to minimize texture state changes
333   if (blendmode != sdl->last_blendmode)
333   if (blendmode != sdl->m_last_blendmode)
334334   {
335335      switch (blendmode)
336336      {
r243303r243304
351351            break;
352352      }
353353
354      sdl->last_blendmode = blendmode;
354      sdl->m_last_blendmode = blendmode;
355355   }
356356}
357357
r243303r243304
541541   window->m_dxdata = sdl;
542542
543543#if (SDLMAME_SDL2)
544   sdl->extra_flags = (window->fullscreen() ?
544   sdl->m_extra_flags = (window->fullscreen() ?
545545         SDL_WINDOW_BORDERLESS | SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_FULLSCREEN : SDL_WINDOW_RESIZABLE);
546   sdl->extra_flags |= SDL_WINDOW_OPENGL;
546   sdl->m_extra_flags |= SDL_WINDOW_OPENGL;
547547
548548   SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
549549
r243303r243304
560560   // create the SDL window
561561   window->m_sdl_window = SDL_CreateWindow(window->m_title,
562562         window->monitor()->position_size().x, window->monitor()->position_size().y,
563         width, height, sdl->extra_flags);
563         width, height, sdl->m_extra_flags);
564564
565565   if  (!window->m_sdl_window )
566566   {
r243303r243304
586586   SDL_RaiseWindow(window->m_sdl_window);
587587   SDL_GetWindowSize(window->m_sdl_window, &window->m_width, &window->m_height);
588588
589   sdl->gl_context_id = SDL_GL_CreateContext(window->m_sdl_window);
590   if  (!sdl->gl_context_id)
589   sdl->m_gl_context_id = SDL_GL_CreateContext(window->m_sdl_window);
590   if  (!sdl->m_gl_context_id)
591591   {
592592      osd_printf_error("OpenGL not supported on this driver: %s\n", SDL_GetError());
593593      return 1;
r243303r243304
596596   SDL_GL_SetSwapInterval(video_config.waitvsync ? 2 : 0);
597597
598598#else
599   sdl->extra_flags = (window->fullscreen() ?  SDL_FULLSCREEN : SDL_RESIZABLE);
600   sdl->extra_flags |= SDL_OPENGL | SDL_DOUBLEBUF;
599   sdl->m_extra_flags = (window->fullscreen() ?  SDL_FULLSCREEN : SDL_RESIZABLE);
600   sdl->m_extra_flags |= SDL_OPENGL | SDL_DOUBLEBUF;
601601
602602   SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
603603   #if (SDL_VERSION_ATLEAST(1,2,10)) && (!defined(SDLMAME_EMSCRIPTEN))
r243303r243304
608608
609609   // create the SDL surface (which creates the window in windowed mode)
610610   sdl->sdlsurf = SDL_SetVideoMode(m_width, m_height,
611                     0, SDL_SWSURFACE  | SDL_ANYFORMAT | sdl->extra_flags);
611                     0, SDL_SWSURFACE  | SDL_ANYFORMAT | sdl->m_extra_flags);
612612
613613   if (!sdl->sdlsurf)
614614      return 1;
r243303r243304
629629   SDL_WM_SetCaption(window->m_title, "SDLMAME");
630630
631631#endif
632   sdl->blittimer = 0;
633   sdl->surf_w = 0;
634   sdl->surf_h = 0;
632   sdl->m_blittimer = 0;
633   sdl->m_surf_w = 0;
634   sdl->m_surf_h = 0;
635635
636   sdl->initialized = 0;
636   sdl->m_initialized = 0;
637637
638638   // in case any textures try to come up before these are validated,
639639   // OpenGL guarantees all implementations can handle something this size.
640   sdl->texture_max_width = 64;
641   sdl->texture_max_height = 64;
640   sdl->m_texture_max_width = 64;
641   sdl->m_texture_max_height = 64;
642642
643643   /* load any GL function addresses
644644    * this must be done here because we need a context
r243303r243304
656656      osd_printf_verbose("OpenGL: %s\nOpenGL: %s\nOpenGL: %s\n", vendor, (char *)glGetString(GL_RENDERER), (char *)glGetString(GL_VERSION));
657657   }
658658
659   sdl->usetexturerect = 0;
660   sdl->texpoweroftwo = 1;
661   sdl->usevbo = 0;
662   sdl->usepbo = 0;
663   sdl->usefbo = 0;
664   sdl->useglsl = 0;
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;
665665
666666   if ( video_config.allowtexturerect &&
667667         ( strstr(extstr, "GL_ARB_texture_rectangle") ||  strstr(extstr, "GL_EXT_texture_rectangle") )
r243303r243304
681681      {
682682         osd_printf_verbose("OpenGL: non-power-of-2 textures supported (new method)\n");
683683      }
684               sdl->texpoweroftwo = 0;
684               sdl->m_texpoweroftwo = 0;
685685   }
686686   else
687687   {
r243303r243304
692692         {
693693            osd_printf_verbose("OpenGL: non-power-of-2 textures supported (old method)\n");
694694         }
695         sdl->usetexturerect = 1;
695         sdl->m_usetexturerect = 1;
696696      }
697697      else
698698      {
r243303r243304
705705
706706   if (strstr(extstr, "GL_ARB_vertex_buffer_object"))
707707   {
708               sdl->usevbo = video_config.vbo;
708               sdl->m_usevbo = video_config.vbo;
709709      if (!shown_video_info)
710710      {
711         if(sdl->usevbo)
711         if(sdl->m_usevbo)
712712            osd_printf_verbose("OpenGL: vertex buffer supported\n");
713713         else
714714            osd_printf_verbose("OpenGL: vertex buffer supported, but disabled\n");
r243303r243304
717717
718718   if (strstr(extstr, "GL_ARB_pixel_buffer_object"))
719719   {
720      if( sdl->usevbo )
720      if( sdl->m_usevbo )
721721      {
722         sdl->usepbo = video_config.pbo;
722         sdl->m_usepbo = video_config.pbo;
723723         if (!shown_video_info)
724724         {
725            if(sdl->usepbo)
725            if(sdl->m_usepbo)
726726               osd_printf_verbose("OpenGL: pixel buffers supported\n");
727727            else
728728               osd_printf_verbose("OpenGL: pixel buffers supported, but disabled\n");
r243303r243304
744744
745745   if (strstr(extstr, "GL_EXT_framebuffer_object"))
746746   {
747      sdl->usefbo = 1;
747      sdl->m_usefbo = 1;
748748      if (!shown_video_info)
749749      {
750         if(sdl->usefbo)
750         if(sdl->m_usefbo)
751751            osd_printf_verbose("OpenGL: framebuffer object supported\n");
752752         else
753753            osd_printf_verbose("OpenGL: framebuffer object not supported\n");
r243303r243304
760760      strstr(extstr, "GL_ARB_fragment_shader")
761761      )
762762   {
763      sdl->useglsl = video_config.glsl;
763      sdl->m_useglsl = video_config.glsl;
764764      if (!shown_video_info)
765765      {
766         if(sdl->useglsl)
766         if(sdl->m_useglsl)
767767            osd_printf_verbose("OpenGL: GLSL supported\n");
768768         else
769769            osd_printf_verbose("OpenGL: GLSL supported, but disabled\n");
r243303r243304
777777
778778   if (osd_getenv(SDLENV_VMWARE) != NULL)
779779   {
780      sdl->usetexturerect = 1;
781      sdl->texpoweroftwo = 1;
780      sdl->m_usetexturerect = 1;
781      sdl->m_texpoweroftwo = 1;
782782   }
783   glGetIntegerv(GL_MAX_TEXTURE_SIZE, (GLint *)&sdl->texture_max_width);
784   glGetIntegerv(GL_MAX_TEXTURE_SIZE, (GLint *)&sdl->texture_max_height);
783   glGetIntegerv(GL_MAX_TEXTURE_SIZE, (GLint *)&sdl->m_texture_max_width);
784   glGetIntegerv(GL_MAX_TEXTURE_SIZE, (GLint *)&sdl->m_texture_max_height);
785785   if (!shown_video_info)
786786   {
787      osd_printf_verbose("OpenGL: max texture size %d x %d\n", sdl->texture_max_width, sdl->texture_max_height);
787      osd_printf_verbose("OpenGL: max texture size %d x %d\n", sdl->m_texture_max_width, sdl->m_texture_max_height);
788788   }
789789
790790   shown_video_info = 1;
791791
792   sdl->init_context = 0;
792   sdl->m_init_context = 0;
793793
794794   return 0;
795795}
r243303r243304
806806   //SDL_GL_MakeCurrent(window->sdl_window, sdl->gl_context_id);
807807   SDL_SetWindowSize(window->m_sdl_window, width, height);
808808   SDL_GetWindowSize(window->m_sdl_window, &window->m_width, &window->m_height);
809   sdl->blittimer = 3;
809   sdl->m_blittimer = 3;
810810#else
811811   SDL_FreeSurface(sdl->sdlsurf);
812812
813813   sdl->sdlsurf = SDL_SetVideoMode(m_width, m_height, 0,
814         SDL_SWSURFACE | SDL_ANYFORMAT | sdl->extra_flags);
814         SDL_SWSURFACE | SDL_ANYFORMAT | sdl->m_extra_flags);
815815
816816   window->m_width = sdl->sdlsurf->w;
817817   window->m_height = sdl->sdlsurf->h;
818818#endif
819   sdl->init_context = 1;
819   sdl->m_init_context = 1;
820820
821821}
822822
r243303r243304
828828{
829829   sdl_info *sdl =(sdl_info *)  window->m_dxdata;
830830
831   *xt = x - sdl->last_hofs;
832   *yt = y - sdl->last_vofs;
831   *xt = x - sdl->m_last_hofs;
832   *yt = y - sdl->m_last_vofs;
833833   if (*xt<0 || *xt >= window->m_blitwidth)
834834      return 0;
835835   if (*yt<0 || *yt >= window->m_blitheight)
r243303r243304
859859   // sdl->usepbo=FALSE; // You may want to switch PBO off, by uncommenting this statement
860860   // sdl->useglsl=FALSE; // You may want to switch GLSL off, by uncommenting this statement
861861
862   if (! sdl->usevbo)
862   if (! sdl->m_usevbo)
863863   {
864      if(sdl->usepbo) // should never ever happen ;-)
864      if(sdl->m_usepbo) // should never ever happen ;-)
865865      {
866866         if (_once)
867867         {
868868            osd_printf_warning("OpenGL: PBO not supported, no VBO support. (sdlmame error)\n");
869869         }
870         sdl->usepbo=FALSE;
870         sdl->m_usepbo=FALSE;
871871      }
872      if(sdl->useglsl) // should never ever happen ;-)
872      if(sdl->m_useglsl) // should never ever happen ;-)
873873      {
874874         if (_once)
875875         {
876876            osd_printf_warning("OpenGL: GLSL not supported, no VBO support. (sdlmame error)\n");
877877         }
878         sdl->useglsl=FALSE;
878         sdl->m_useglsl=FALSE;
879879      }
880880   }
881881
882882   // Get Pointers To The GL Functions
883883   // VBO:
884   if( sdl->usevbo )
884   if( sdl->m_usevbo )
885885   {
886886      pfn_glGenBuffers = (PFNGLGENBUFFERSPROC) SDL_GL_GetProcAddress("glGenBuffers");
887887      pfn_glDeleteBuffers = (PFNGLDELETEBUFFERSPROC) SDL_GL_GetProcAddress("glDeleteBuffers");
r243303r243304
890890      pfn_glBufferSubData = (PFNGLBUFFERSUBDATAPROC) SDL_GL_GetProcAddress("glBufferSubData");
891891   }
892892   // PBO:
893   if ( sdl->usepbo )
893   if ( sdl->m_usepbo )
894894   {
895895      pfn_glMapBuffer  = (PFNGLMAPBUFFERPROC) SDL_GL_GetProcAddress("glMapBuffer");
896896      pfn_glUnmapBuffer= (PFNGLUNMAPBUFFERPROC) SDL_GL_GetProcAddress("glUnmapBuffer");
897897   }
898898   // FBO:
899   if ( sdl->usefbo )
899   if ( sdl->m_usefbo )
900900   {
901901      pfn_glIsFramebuffer = (PFNGLISFRAMEBUFFEREXTPROC) SDL_GL_GetProcAddress("glIsFramebufferEXT");
902902      pfn_glBindFramebuffer = (PFNGLBINDFRAMEBUFFEREXTPROC) SDL_GL_GetProcAddress("glBindFramebufferEXT");
r243303r243304
906906      pfn_glFramebufferTexture2D = (PFNGLFRAMEBUFFERTEXTURE2DEXTPROC) SDL_GL_GetProcAddress("glFramebufferTexture2DEXT");
907907   }
908908
909   if ( sdl->usevbo &&
909   if ( sdl->m_usevbo &&
910910         ( !pfn_glGenBuffers || !pfn_glDeleteBuffers ||
911911         !pfn_glBindBuffer || !pfn_glBufferData || !pfn_glBufferSubData
912912      ) )
913913   {
914      sdl->usepbo=FALSE;
914      sdl->m_usepbo=FALSE;
915915      if (_once)
916916      {
917917         osd_printf_warning("OpenGL: VBO not supported, missing: ");
r243303r243304
937937         }
938938         osd_printf_warning("\n");
939939      }
940      if ( sdl->usevbo )
940      if ( sdl->m_usevbo )
941941      {
942942         if (_once)
943943         {
944944            osd_printf_warning("OpenGL: PBO not supported, no VBO support.\n");
945945         }
946         sdl->usepbo=FALSE;
946         sdl->m_usepbo=FALSE;
947947      }
948948   }
949949
950   if ( sdl->usepbo && ( !pfn_glMapBuffer || !pfn_glUnmapBuffer ) )
950   if ( sdl->m_usepbo && ( !pfn_glMapBuffer || !pfn_glUnmapBuffer ) )
951951   {
952      sdl->usepbo=FALSE;
952      sdl->m_usepbo=FALSE;
953953      if (_once)
954954      {
955955         osd_printf_warning("OpenGL: PBO not supported, missing: ");
r243303r243304
965965      }
966966   }
967967
968   if ( sdl->usefbo &&
968   if ( sdl->m_usefbo &&
969969      ( !pfn_glIsFramebuffer || !pfn_glBindFramebuffer || !pfn_glDeleteFramebuffers ||
970970         !pfn_glGenFramebuffers || !pfn_glCheckFramebufferStatus || !pfn_glFramebufferTexture2D
971971      ))
972972   {
973      sdl->usefbo=FALSE;
973      sdl->m_usefbo=FALSE;
974974      if (_once)
975975      {
976976         osd_printf_warning("OpenGL: FBO not supported, missing: ");
r243303r243304
10041004
10051005   if (_once)
10061006   {
1007      if ( sdl->usevbo )
1007      if ( sdl->m_usevbo )
10081008      {
10091009         osd_printf_verbose("OpenGL: VBO supported\n");
10101010      }
r243303r243304
10131013         osd_printf_warning("OpenGL: VBO not supported\n");
10141014      }
10151015
1016      if ( sdl->usepbo )
1016      if ( sdl->m_usepbo )
10171017      {
10181018         osd_printf_verbose("OpenGL: PBO supported\n");
10191019      }
r243303r243304
10221022         osd_printf_warning("OpenGL: PBO not supported\n");
10231023      }
10241024
1025      if ( sdl->usefbo )
1025      if ( sdl->m_usefbo )
10261026      {
10271027         osd_printf_verbose("OpenGL: FBO supported\n");
10281028      }
r243303r243304
10321032      }
10331033   }
10341034
1035   if ( sdl->useglsl )
1035   if ( sdl->m_useglsl )
10361036   {
10371037      #ifdef GL_ARB_multitexture
10381038      pfn_glActiveTexture = (PFNGLACTIVETEXTUREARBPROC) SDL_GL_GetProcAddress("glActiveTextureARB");
r243303r243304
10451045         {
10461046            osd_printf_warning("OpenGL: GLSL disabled, glActiveTexture(ARB) not supported\n");
10471047         }
1048         sdl->useglsl = 0;
1048         sdl->m_useglsl = 0;
10491049      }
10501050   }
10511051
1052   if ( sdl->useglsl )
1052   if ( sdl->m_useglsl )
10531053   {
1054      sdl->glsl = glsl_shader_init();
1055      sdl->useglsl = (sdl->glsl != NULL ? 1 : 0);
1054      sdl->m_glsl = glsl_shader_init();
1055      sdl->m_useglsl = (sdl->m_glsl != NULL ? 1 : 0);
10561056
1057      if ( ! sdl->useglsl )
1057      if ( ! sdl->m_useglsl )
10581058      {
10591059         if (_once)
10601060         {
r243303r243304
10631063      }
10641064   }
10651065
1066   if ( sdl->useglsl )
1066   if ( sdl->m_useglsl )
10671067   {
10681068      if ( window->m_prescale != 1 )
10691069      {
1070         sdl->useglsl = 0;
1070         sdl->m_useglsl = 0;
10711071         if (_once)
10721072         {
10731073            osd_printf_warning("OpenGL: GLSL supported, but disabled due to: prescale !=1 \n");
r243303r243304
10751075      }
10761076   }
10771077
1078   if ( sdl->useglsl )
1078   if ( sdl->m_useglsl )
10791079   {
10801080      int i;
10811081      video_config.filter = FALSE;
10821082      glsl_shader_feature = GLSL_SHADER_FEAT_PLAIN;
1083      sdl->glsl_program_num = 0;
1084      sdl->glsl_program_mb2sc = 0;
1083      sdl->m_glsl_program_num = 0;
1084      sdl->m_glsl_program_mb2sc = 0;
10851085
10861086      for(i=0; i<video_config.glsl_shader_mamebm_num; i++)
10871087      {
1088         if ( !sdl->usefbo && sdl->glsl_program_num==1 )
1088         if ( !sdl->m_usefbo && sdl->m_glsl_program_num==1 )
10891089         {
10901090            if (_once)
10911091            {
r243303r243304
10941094            break;
10951095         }
10961096
1097         if ( glsl_shader_add_mamebm(sdl->glsl, video_config.glsl_shader_mamebm[i], sdl->glsl_program_num) )
1097         if ( glsl_shader_add_mamebm(sdl->m_glsl, video_config.glsl_shader_mamebm[i], sdl->m_glsl_program_num) )
10981098         {
10991099            osd_printf_error("OpenGL: GLSL loading mame bitmap shader %d failed (%s)\n",
11001100               i, video_config.glsl_shader_mamebm[i]);
r243303r243304
11031103            if (_once)
11041104            {
11051105               osd_printf_verbose("OpenGL: GLSL using mame bitmap shader filter %d: '%s'\n",
1106                  sdl->glsl_program_num, video_config.glsl_shader_mamebm[i]);
1106                  sdl->m_glsl_program_num, video_config.glsl_shader_mamebm[i]);
11071107            }
1108            sdl->glsl_program_mb2sc = sdl->glsl_program_num; // the last mame_bitmap (mb) shader does it.
1109            sdl->glsl_program_num++;
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++;
11101110         }
11111111      }
11121112
1113      if ( video_config.glsl_shader_scrn_num > 0 && sdl->glsl_program_num==0 )
1113      if ( video_config.glsl_shader_scrn_num > 0 && sdl->m_glsl_program_num==0 )
11141114      {
11151115         osd_printf_verbose("OpenGL: GLSL cannot use screen bitmap shader without bitmap shader\n");
11161116      }
11171117
1118      for(i=0; sdl->usefbo && sdl->glsl_program_num>0 && i<video_config.glsl_shader_scrn_num; i++)
1118      for(i=0; sdl->m_usefbo && sdl->m_glsl_program_num>0 && i<video_config.glsl_shader_scrn_num; i++)
11191119      {
1120         if ( glsl_shader_add_scrn(sdl->glsl, video_config.glsl_shader_scrn[i],
1121                                 sdl->glsl_program_num-1-sdl->glsl_program_mb2sc) )
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) )
11221122         {
11231123            osd_printf_error("OpenGL: GLSL loading screen bitmap shader %d failed (%s)\n",
11241124               i, video_config.glsl_shader_scrn[i]);
r243303r243304
11261126            if (_once)
11271127            {
11281128               osd_printf_verbose("OpenGL: GLSL using screen bitmap shader filter %d: '%s'\n",
1129                  sdl->glsl_program_num, video_config.glsl_shader_scrn[i]);
1129                  sdl->m_glsl_program_num, video_config.glsl_shader_scrn[i]);
11301130            }
1131            sdl->glsl_program_num++;
1131            sdl->m_glsl_program_num++;
11321132         }
11331133      }
11341134
1135      if ( 0==sdl->glsl_program_num &&
1135      if ( 0==sdl->m_glsl_program_num &&
11361136            0 <= video_config.glsl_filter && video_config.glsl_filter < GLSL_SHADER_FEAT_INT_NUMBER )
11371137      {
1138         sdl->glsl_program_mb2sc = sdl->glsl_program_num; // the last mame_bitmap (mb) shader does it.
1139         sdl->glsl_program_num++;
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++;
11401140         glsl_shader_feature = video_config.glsl_filter;
11411141
11421142         if (_once)
11431143         {
11441144            osd_printf_verbose("OpenGL: GLSL using shader filter '%s', idx: %d, num %d (vid filter: %d)\n",
11451145               glsl_shader_get_filter_name_mamebm(glsl_shader_feature),
1146               glsl_shader_feature, sdl->glsl_program_num, video_config.filter);
1146               glsl_shader_feature, sdl->m_glsl_program_num, video_config.filter);
11471147         }
11481148      }
11491149
r243303r243304
11761176   }
11771177
11781178#if (SDLMAME_SDL2)
1179   SDL_GL_MakeCurrent(window->m_sdl_window, sdl->gl_context_id);
1179   SDL_GL_MakeCurrent(window->m_sdl_window, sdl->m_gl_context_id);
11801180#else
1181   if (!sdl->init_context)
1181   if (!sdl->m_init_context)
11821182   {
11831183      screen_device_iterator myiter(window->machine().root_device());
11841184      for (screen = myiter.first(); screen != NULL; screen = myiter.next())
r243303r243304
11991199   }
12001200#endif
12011201
1202   if (sdl->init_context)
1202   if (sdl->m_init_context)
12031203   {
12041204      // do some one-time OpenGL setup
12051205#if (SDLMAME_SDL2)
r243303r243304
12321232   }
12331233
12341234   // only clear if the geometry changes (and for 2 frames afterward to clear double and triple buffers)
1235   if ((sdl->blittimer > 0) || (is_vector))
1235   if ((sdl->m_blittimer > 0) || (is_vector))
12361236   {
12371237      glClear(GL_COLOR_BUFFER_BIT);
1238      sdl->blittimer--;
1238      sdl->m_blittimer--;
12391239   }
12401240
1241   if ( !sdl->initialized ||
1242         window->m_width!= sdl->surf_w || window->m_height!= sdl->surf_h )
1241   if ( !sdl->m_initialized ||
1242         window->m_width!= sdl->m_surf_w || window->m_height!= sdl->m_surf_h )
12431243   {
1244      if ( !sdl->initialized )
1244      if ( !sdl->m_initialized )
12451245      {
12461246         loadGLExtensions(window);
12471247      }
12481248
1249      sdl->surf_w=window->m_width;
1250      sdl->surf_h=window->m_height;
1249      sdl->m_surf_w=window->m_width;
1250      sdl->m_surf_h=window->m_height;
12511251
12521252      // we're doing nothing 3d, so the Z-buffer is currently not interesting
12531253      glDisable(GL_DEPTH_TEST);
r243303r243304
12721272      // enable blending
12731273      glEnable(GL_BLEND);
12741274      glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1275      sdl->last_blendmode = BLENDMODE_ALPHA;
1275      sdl->m_last_blendmode = BLENDMODE_ALPHA;
12761276
12771277      // set lines and points just barely above normal size to get proper results
12781278      glLineWidth(video_config.beamwidth);
r243303r243304
12951295      glMatrixMode(GL_MODELVIEW);
12961296      glLoadIdentity();
12971297
1298      if ( ! sdl->initialized )
1298      if ( ! sdl->m_initialized )
12991299      {
13001300         glEnableClientState(GL_VERTEX_ARRAY);
1301         glVertexPointer(2, GL_FLOAT, 0, sdl->texVerticex); // no VBO, since it's too volatile
1301         glVertexPointer(2, GL_FLOAT, 0, sdl->m_texVerticex); // no VBO, since it's too volatile
13021302
1303         sdl->initialized = 1;
1303         sdl->m_initialized = 1;
13041304      }
13051305   }
13061306
r243303r243304
13321332      }
13331333   }
13341334
1335   sdl->last_hofs = hofs;
1336   sdl->last_vofs = vofs;
1335   sdl->m_last_hofs = hofs;
1336   sdl->m_last_vofs = vofs;
13371337
13381338   window->m_primlist->acquire_lock();
13391339
r243303r243304
14921492
14931493            if ( texture && texture->type==TEXTURE_TYPE_SHADER )
14941494            {
1495               for(i=0; i<sdl->glsl_program_num; i++)
1495               for(i=0; i<sdl->m_glsl_program_num; i++)
14961496               {
1497                  if ( i==sdl->glsl_program_mb2sc )
1497                  if ( i==sdl->m_glsl_program_mb2sc )
14981498                  {
14991499                     // i==sdl->glsl_program_mb2sc -> transformation mamebm->scrn
1500                     sdl->texVerticex[0]=prim->bounds.x0 + hofs;
1501                     sdl->texVerticex[1]=prim->bounds.y0 + vofs;
1502                     sdl->texVerticex[2]=prim->bounds.x1 + hofs;
1503                     sdl->texVerticex[3]=prim->bounds.y0 + vofs;
1504                     sdl->texVerticex[4]=prim->bounds.x1 + hofs;
1505                     sdl->texVerticex[5]=prim->bounds.y1 + vofs;
1506                     sdl->texVerticex[6]=prim->bounds.x0 + hofs;
1507                     sdl->texVerticex[7]=prim->bounds.y1 + vofs;
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;
15081508                  } else {
15091509                     // 1:1 tex coord CCW (0/0) (1/0) (1/1) (0/1) on texture dimensions
1510                     sdl->texVerticex[0]=(GLfloat)0.0;
1511                     sdl->texVerticex[1]=(GLfloat)0.0;
1512                     sdl->texVerticex[2]=(GLfloat)window->m_width;
1513                     sdl->texVerticex[3]=(GLfloat)0.0;
1514                     sdl->texVerticex[4]=(GLfloat)window->m_width;
1515                     sdl->texVerticex[5]=(GLfloat)window->m_height;
1516                     sdl->texVerticex[6]=(GLfloat)0.0;
1517                     sdl->texVerticex[7]=(GLfloat)window->m_height;
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;
15181518                  }
15191519
15201520                  if(i>0) // first fetch already done
r243303r243304
15241524                  glDrawArrays(GL_QUADS, 0, 4);
15251525               }
15261526            } else {
1527               sdl->texVerticex[0]=prim->bounds.x0 + hofs;
1528               sdl->texVerticex[1]=prim->bounds.y0 + vofs;
1529               sdl->texVerticex[2]=prim->bounds.x1 + hofs;
1530               sdl->texVerticex[3]=prim->bounds.y0 + vofs;
1531               sdl->texVerticex[4]=prim->bounds.x1 + hofs;
1532               sdl->texVerticex[5]=prim->bounds.y1 + vofs;
1533               sdl->texVerticex[6]=prim->bounds.x0 + hofs;
1534               sdl->texVerticex[7]=prim->bounds.y1 + vofs;
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;
15351535
15361536               glDrawArrays(GL_QUADS, 0, 4);
15371537            }
r243303r243304
15551555   }
15561556
15571557   window->m_primlist->release_lock();
1558   sdl->init_context = 0;
1558   sdl->m_init_context = 0;
15591559
15601560#if (!SDLMAME_SDL2)
15611561   SDL_GL_SwapBuffers();
r243303r243304
16421642   drawogl_destroy_all_textures(window);
16431643
16441644#if (SDLMAME_SDL2)
1645   SDL_GL_DeleteContext(sdl->gl_context_id);
1645   SDL_GL_DeleteContext(sdl->m_gl_context_id);
16461646   SDL_DestroyWindow(window->m_sdl_window);
16471647#else
16481648   if (sdl->sdlsurf)
r243303r243304
16761676         !PRIMFLAG_GET_SCREENTEX(flags))
16771677   {
16781678      texture->type = TEXTURE_TYPE_PLAIN;
1679            texture->texTarget = (sdl->usetexturerect)?GL_TEXTURE_RECTANGLE_ARB:GL_TEXTURE_2D;
1680            texture->texpow2   = (sdl->usetexturerect)?0:sdl->texpoweroftwo;
1679            texture->texTarget = (sdl->m_usetexturerect)?GL_TEXTURE_RECTANGLE_ARB:GL_TEXTURE_2D;
1680            texture->texpow2   = (sdl->m_usetexturerect)?0:sdl->m_texpoweroftwo;
16811681   }
16821682
1683   if ( texture->type == TEXTURE_TYPE_NONE && sdl->useglsl &&
1683   if ( texture->type == TEXTURE_TYPE_NONE && sdl->m_useglsl &&
16841684         texture->xprescale == 1 && texture->yprescale == 1 &&
1685         texsource->rowpixels <= sdl->texture_max_width )
1685         texsource->rowpixels <= sdl->m_texture_max_width )
16861686      {
16871687         texture->type      = TEXTURE_TYPE_SHADER;
16881688         texture->texTarget = GL_TEXTURE_2D;
1689         texture->texpow2   = sdl->texpoweroftwo;
1689         texture->texpow2   = sdl->m_texpoweroftwo;
16901690      }
16911691
16921692   // determine if we can skip the copy step
r243303r243304
16951695         !texture_copy_properties[texture->format][SDL_TEXFORMAT_SRC_HAS_PALETTE] &&
16961696         texture->xprescale == 1 && texture->yprescale == 1 &&
16971697         !texture->borderpix && !texsource->palette() &&
1698         texsource->rowpixels <= sdl->texture_max_width )
1698         texsource->rowpixels <= sdl->m_texture_max_width )
16991699   {
17001700      texture->nocopy = TRUE;
17011701   }
17021702
17031703   if( texture->type == TEXTURE_TYPE_NONE &&
1704      sdl->usepbo && !texture->nocopy )
1704      sdl->m_usepbo && !texture->nocopy )
17051705   {
17061706      texture->type      = TEXTURE_TYPE_DYNAMIC;
1707      texture->texTarget = (sdl->usetexturerect)?GL_TEXTURE_RECTANGLE_ARB:GL_TEXTURE_2D;
1708      texture->texpow2   = (sdl->usetexturerect)?0:sdl->texpoweroftwo;
1707      texture->texTarget = (sdl->m_usetexturerect)?GL_TEXTURE_RECTANGLE_ARB:GL_TEXTURE_2D;
1708      texture->texpow2   = (sdl->m_usetexturerect)?0:sdl->m_texpoweroftwo;
17091709   }
17101710
17111711   if( texture->type == TEXTURE_TYPE_NONE )
17121712   {
17131713      texture->type      = TEXTURE_TYPE_SURFACE;
1714      texture->texTarget = (sdl->usetexturerect)?GL_TEXTURE_RECTANGLE_ARB:GL_TEXTURE_2D;
1715      texture->texpow2   = (sdl->usetexturerect)?0:sdl->texpoweroftwo;
1714      texture->texTarget = (sdl->m_usetexturerect)?GL_TEXTURE_RECTANGLE_ARB:GL_TEXTURE_2D;
1715      texture->texpow2   = (sdl->m_usetexturerect)?0:sdl->m_texpoweroftwo;
17161716   }
17171717}
17181718
r243303r243304
17461746      }
17471747
17481748   // don't prescale above max texture size
1749   while (texture->xprescale > 1 && width_create * texture->xprescale > sdl->texture_max_width)
1749   while (texture->xprescale > 1 && width_create * texture->xprescale > sdl->m_texture_max_width)
17501750      texture->xprescale--;
1751   while (texture->yprescale > 1 && height_create * texture->yprescale > sdl->texture_max_height)
1751   while (texture->yprescale > 1 && height_create * texture->yprescale > sdl->m_texture_max_height)
17521752      texture->yprescale--;
17531753   if (PRIMFLAG_GET_SCREENTEX(flags) && (texture->xprescale != window->m_prescale || texture->yprescale != window->m_prescale))
17541754      osd_printf_warning("SDL: adjusting prescale from %dx%d to %dx%d\n", window->m_prescale, window->m_prescale, texture->xprescale, texture->yprescale);
r243303r243304
17931793
17941794   // if we added pixels for the border, and that just barely pushed us over, take it back
17951795   if (texture->borderpix &&
1796      ((finalwidth > sdl->texture_max_width && finalwidth - 2 <= sdl->texture_max_width) ||
1797         (finalheight > sdl->texture_max_height && finalheight - 2 <= sdl->texture_max_height)))
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)))
17981798   {
17991799      texture->borderpix = FALSE;
18001800
r243303r243304
18051805   }
18061806
18071807   // if we're above the max width/height, do what?
1808   if (finalwidth_create > sdl->texture_max_width || finalheight_create > sdl->texture_max_height)
1808   if (finalwidth_create > sdl->m_texture_max_width || finalheight_create > sdl->m_texture_max_height)
18091809   {
18101810      static int printed = FALSE;
18111811      if (!printed)
1812         osd_printf_warning("Texture too big! (wanted: %dx%d, max is %dx%d)\n", finalwidth_create, finalheight_create, sdl->texture_max_width, sdl->texture_max_height);
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);
18131813      printed = TRUE;
18141814   }
18151815
r243303r243304
18311831         (int)texture_copy_properties[texture->format][SDL_TEXFORMAT_SRC_EQUALS_DEST],
18321832         (int)texture_copy_properties[texture->format][SDL_TEXFORMAT_SRC_HAS_PALETTE],
18331833         texture->xprescale, texture->yprescale,
1834         texture->borderpix, texsource->rowpixels, finalwidth, sdl->texture_max_width,
1834         texture->borderpix, texsource->rowpixels, finalwidth, sdl->m_texture_max_width,
18351835         (int)sizeof(UINT32)
18361836         );
18371837   }
r243303r243304
19401940
19411941   GL_CHECK_ERROR_QUIET();
19421942
1943   if( sdl->glsl_program_num > 1 )
1943   if( sdl->m_glsl_program_num > 1 )
19441944   {
19451945      // multipass mode
1946      assert(sdl->usefbo);
1946      assert(sdl->m_usefbo);
19471947
19481948      // GL_TEXTURE3 GLSL Uniforms
19491949      texture->mpass_dest_idx = 0;
r243303r243304
19511951      texture->mpass_textureunit[1] = GL_TEXTURE2;
19521952   }
19531953
1954   for(i=0; i<sdl->glsl_program_num; i++)
1954   for(i=0; i<sdl->m_glsl_program_num; i++)
19551955   {
1956      if ( i<=sdl->glsl_program_mb2sc )
1956      if ( i<=sdl->m_glsl_program_mb2sc )
19571957      {
1958         sdl->glsl_program[i] = glsl_shader_get_program_mamebm(glsl_shader_feature, i);
1958         sdl->m_glsl_program[i] = glsl_shader_get_program_mamebm(glsl_shader_feature, i);
19591959      } else {
1960         sdl->glsl_program[i] = glsl_shader_get_program_scrn(i-1-sdl->glsl_program_mb2sc);
1960         sdl->m_glsl_program[i] = glsl_shader_get_program_scrn(i-1-sdl->m_glsl_program_mb2sc);
19611961      }
1962      pfn_glUseProgramObjectARB(sdl->glsl_program[i]);
1962      pfn_glUseProgramObjectARB(sdl->m_glsl_program[i]);
19631963
1964      if ( i<=sdl->glsl_program_mb2sc )
1964      if ( i<=sdl->m_glsl_program_mb2sc )
19651965      {
19661966         // GL_TEXTURE0 GLSL Uniforms
1967         uniform_location = pfn_glGetUniformLocationARB(sdl->glsl_program[i], "color_texture");
1967         uniform_location = pfn_glGetUniformLocationARB(sdl->m_glsl_program[i], "color_texture");
19681968         pfn_glUniform1iARB(uniform_location, 0);
19691969         GL_CHECK_ERROR_NORMAL();
19701970      }
19711971
19721972      {
19731973         GLfloat color_texture_sz[2] = { (GLfloat)texture->rawwidth, (GLfloat)texture->rawheight };
1974         uniform_location = pfn_glGetUniformLocationARB(sdl->glsl_program[i], "color_texture_sz");
1974         uniform_location = pfn_glGetUniformLocationARB(sdl->m_glsl_program[i], "color_texture_sz");
19751975         pfn_glUniform2fvARB(uniform_location, 1, &(color_texture_sz[0]));
19761976         GL_CHECK_ERROR_NORMAL();
19771977      }
19781978
19791979      GLfloat color_texture_pow2_sz[2] = { (GLfloat)texture->rawwidth_create, (GLfloat)texture->rawheight_create };
1980      uniform_location = pfn_glGetUniformLocationARB(sdl->glsl_program[i], "color_texture_pow2_sz");
1980      uniform_location = pfn_glGetUniformLocationARB(sdl->m_glsl_program[i], "color_texture_pow2_sz");
19811981      pfn_glUniform2fvARB(uniform_location, 1, &(color_texture_pow2_sz[0]));
19821982      GL_CHECK_ERROR_NORMAL();
19831983
19841984      GLfloat screen_texture_sz[2] = { (GLfloat)window->m_blitwidth, (GLfloat)window->m_blitheight };
1985      uniform_location = pfn_glGetUniformLocationARB(sdl->glsl_program[i], "screen_texture_sz");
1985      uniform_location = pfn_glGetUniformLocationARB(sdl->m_glsl_program[i], "screen_texture_sz");
19861986      pfn_glUniform2fvARB(uniform_location, 1, &(screen_texture_sz[0]));
19871987      GL_CHECK_ERROR_NORMAL();
19881988
19891989      GLfloat screen_texture_pow2_sz[2] = { (GLfloat)surf_w_pow2, (GLfloat)surf_h_pow2 };
1990      uniform_location = pfn_glGetUniformLocationARB(sdl->glsl_program[i], "screen_texture_pow2_sz");
1990      uniform_location = pfn_glGetUniformLocationARB(sdl->m_glsl_program[i], "screen_texture_pow2_sz");
19911991      pfn_glUniform2fvARB(uniform_location, 1, &(screen_texture_pow2_sz[0]));
19921992      GL_CHECK_ERROR_NORMAL();
19931993   }
19941994
1995   pfn_glUseProgramObjectARB(sdl->glsl_program[0]); // start with 1st shader
1995   pfn_glUseProgramObjectARB(sdl->m_glsl_program[0]); // start with 1st shader
19961996
1997   if( sdl->glsl_program_num > 1 )
1997   if( sdl->m_glsl_program_num > 1 )
19981998   {
19991999      // multipass mode
20002000      // GL_TEXTURE2/GL_TEXTURE3
r243303r243304
20182018         texture->rawwidth, texture->rawheight, texture->rawwidth_create, texture->rawheight_create);
20192019   }
20202020
2021   if( sdl->glsl_program_num > 1 && sdl->glsl_program_mb2sc < sdl->glsl_program_num - 1 )
2021   if( sdl->m_glsl_program_num > 1 && sdl->m_glsl_program_mb2sc < sdl->m_glsl_program_num - 1 )
20222022   {
20232023      // multipass mode
20242024      // GL_TEXTURE2/GL_TEXTURE3
r243303r243304
21732173
21742174   texture->pbo=0;
21752175
2176   if ( texture->type != TEXTURE_TYPE_SHADER && sdl->useglsl)
2176   if ( texture->type != TEXTURE_TYPE_SHADER && sdl->m_useglsl)
21772177   {
21782178      pfn_glUseProgramObjectARB(0); // back to fixed function pipeline
21792179   }
r243303r243304
22372237
22382238   if ( texture->type == TEXTURE_TYPE_DYNAMIC )
22392239   {
2240      assert(sdl->usepbo);
2240      assert(sdl->m_usepbo);
22412241
22422242      // create the PBO
22432243      pfn_glGenBuffers(1, (GLuint *)&texture->pbo);
r243303r243304
22572257   }
22582258
22592259   // add us to the texture list
2260   if (sdl->texhash[texture->hash] == NULL)
2261      sdl->texhash[texture->hash] = texture;
2260   if (sdl->m_texhash[texture->hash] == NULL)
2261      sdl->m_texhash[texture->hash] = texture;
22622262   else
22632263   {
22642264      int i;
22652265      for (i = HASH_SIZE; i < HASH_SIZE + OVERFLOW_SIZE; i++)
2266         if (sdl->texhash[i] == NULL)
2266         if (sdl->m_texhash[i] == NULL)
22672267         {
2268            sdl->texhash[i] = texture;
2268            sdl->m_texhash[i] = texture;
22692269            break;
22702270         }
22712271      assert_always(i < HASH_SIZE + OVERFLOW_SIZE, "texture hash exhausted ...");
22722272   }
22732273
2274   if(sdl->usevbo)
2274   if(sdl->m_usevbo)
22752275   {
22762276      // Generate And Bind The Texture Coordinate Buffer
22772277      pfn_glGenBuffers( 1, &(texture->texCoordBufferName) );
r243303r243304
27012701   HashT texhash = texture_compute_hash(&prim->texture, prim->flags);
27022702   texture_info *texture;
27032703
2704   texture = sdl->texhash[texhash];
2704   texture = sdl->m_texhash[texhash];
27052705   if (texture != NULL)
27062706   {
27072707      int i;
r243303r243304
27092709         return texture;
27102710      for (i=HASH_SIZE; i<HASH_SIZE + OVERFLOW_SIZE; i++)
27112711      {
2712         texture = sdl->texhash[i];
2712         texture = sdl->m_texhash[i];
27132713         if (texture != NULL && compare_texture_primitive(texture, prim))
27142714            return texture;
27152715      }
r243303r243304
27302730   float du, dv;
27312731
27322732   if ( texture->type != TEXTURE_TYPE_SHADER ||
2733         ( texture->type == TEXTURE_TYPE_SHADER && shaderIdx<=sdl->glsl_program_mb2sc ) )
2733         ( texture->type == TEXTURE_TYPE_SHADER && shaderIdx<=sdl->m_glsl_program_mb2sc ) )
27342734   {
27352735      // compute the U/V scale factors
27362736      if (texture->borderpix)
r243303r243304
27482748         vstop  = (float)(prim->texture.height*texture->yprescale) / (float)texture->rawheight_create;
27492749      }
27502750   }
2751   else if ( texture->type == TEXTURE_TYPE_SHADER && shaderIdx>sdl->glsl_program_mb2sc )
2751   else if ( texture->type == TEXTURE_TYPE_SHADER && shaderIdx>sdl->m_glsl_program_mb2sc )
27522752   {
27532753      int surf_w_pow2  = get_valid_pow2_value (window->m_width, texture->texpow2);
27542754      int surf_h_pow2  = get_valid_pow2_value (window->m_height, texture->texpow2);
r243303r243304
27722772      dv *= (float)texture->rawheight;
27732773   }
27742774
2775   if ( texture->type == TEXTURE_TYPE_SHADER && shaderIdx!=sdl->glsl_program_mb2sc )
2775   if ( texture->type == TEXTURE_TYPE_SHADER && shaderIdx!=sdl->m_glsl_program_mb2sc )
27762776   {
27772777      // 1:1 tex coord CCW (0/0) (1/0) (1/1) (0/1)
27782778      // we must go CW here due to the mame bitmap order
r243303r243304
28082808   if ( shaderIdx>0 )
28092809   {
28102810      int uniform_location;
2811      uniform_location = pfn_glGetUniformLocationARB(sdl->glsl_program[shaderIdx], "mpass_texture");
2811      uniform_location = pfn_glGetUniformLocationARB(sdl->m_glsl_program[shaderIdx], "mpass_texture");
28122812      pfn_glUniform1iARB(uniform_location, texture->mpass_textureunit[mpass_src_idx]-GL_TEXTURE0);
28132813      GL_CHECK_ERROR_NORMAL();
28142814   }
28152815
28162816   pfn_glActiveTexture(texture->mpass_textureunit[mpass_src_idx]);
2817   if ( shaderIdx<=sdl->glsl_program_mb2sc )
2817   if ( shaderIdx<=sdl->m_glsl_program_mb2sc )
28182818   {
28192819      glBindTexture(texture->texTarget, texture->mpass_texture_mamebm[mpass_src_idx]);
28202820   }
r243303r243304
28272827
28282828   pfn_glActiveTexture(texture->mpass_textureunit[texture->mpass_dest_idx]);
28292829
2830   if ( shaderIdx<sdl->glsl_program_num-1 )
2830   if ( shaderIdx<sdl->m_glsl_program_num-1 )
28312831   {
2832      if ( shaderIdx>=sdl->glsl_program_mb2sc )
2832      if ( shaderIdx>=sdl->m_glsl_program_mb2sc )
28332833      {
28342834         glBindTexture(texture->texTarget, texture->mpass_texture_scrn[texture->mpass_dest_idx]);
28352835         pfn_glBindFramebuffer(GL_FRAMEBUFFER_EXT, texture->mpass_fbo_scrn[texture->mpass_dest_idx]);
r243303r243304
28462846         GL_CHECK_ERROR_NORMAL();
28472847         glViewport(0.0, 0.0, (GLsizei)texture->rawwidth, (GLsizei)texture->rawheight);
28482848      }
2849      else if ( shaderIdx==sdl->glsl_program_mb2sc )
2849      else if ( shaderIdx==sdl->m_glsl_program_mb2sc )
28502850      {
2851         assert ( sdl->glsl_program_mb2sc < sdl->glsl_program_num-1 );
2851         assert ( sdl->m_glsl_program_mb2sc < sdl->m_glsl_program_num-1 );
28522852         glPopAttrib(); // glViewport(0.0, 0.0, (GLsizei)window->width, (GLsizei)window->height)
28532853         GL_CHECK_ERROR_NORMAL();
28542854      }
r243303r243304
28592859      glBindTexture(texture->texTarget, 0);
28602860      pfn_glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0);
28612861
2862      if ( sdl->glsl_program_mb2sc == sdl->glsl_program_num-1 )
2862      if ( sdl->m_glsl_program_mb2sc == sdl->m_glsl_program_num-1 )
28632863      {
28642864         glPopAttrib(); // glViewport(0.0, 0.0, (GLsizei)window->width, (GLsizei)window->height)
28652865         GL_CHECK_ERROR_NORMAL();
r243303r243304
29052905      vid_attributes[2] = settings.brightness;
29062906#endif
29072907      vid_attributes[3] = 0.0f;
2908      uniform_location = pfn_glGetUniformLocationARB(sdl->glsl_program[shaderIdx], "vid_attributes");
2908      uniform_location = pfn_glGetUniformLocationARB(sdl->m_glsl_program[shaderIdx], "vid_attributes");
29092909      pfn_glUniform4fvARB(uniform_location, 1, &(vid_attributes[shaderIdx]));
29102910      if ( GL_CHECK_ERROR_QUIET() ) {
29112911         osd_printf_verbose("GLSL: could not set 'vid_attributes' for shader prog idx %d\n", shaderIdx);
r243303r243304
29322932   {
29332933      if ( texture->type == TEXTURE_TYPE_SHADER )
29342934      {
2935         pfn_glUseProgramObjectARB(sdl->glsl_program[shaderIdx]); // back to our shader
2935         pfn_glUseProgramObjectARB(sdl->m_glsl_program[shaderIdx]); // back to our shader
29362936      }
29372937      else if ( texture->type == TEXTURE_TYPE_DYNAMIC )
29382938      {
2939         assert ( sdl->usepbo ) ;
2939         assert ( sdl->m_usepbo ) ;
29402940         pfn_glBindBuffer( GL_PIXEL_UNPACK_BUFFER_ARB, texture->pbo);
29412941         glEnable(texture->texTarget);
29422942      }
r243303r243304
29512951      if ( texture->type == TEXTURE_TYPE_SHADER )
29522952      {
29532953         texture_shader_update(window, texture, shaderIdx);
2954         if ( sdl->glsl_program_num>1 )
2954         if ( sdl->m_glsl_program_num>1 )
29552955         {
29562956            texture_mpass_flip(sdl, texture, shaderIdx);
29572957         }
r243303r243304
29752975      texture_coord_update(window, texture, prim, shaderIdx);
29762976
29772977      glEnableClientState(GL_TEXTURE_COORD_ARRAY);
2978      if(sdl->usevbo)
2978      if(sdl->m_usevbo)
29792979      {
29802980         pfn_glBindBuffer( GL_ARRAY_BUFFER_ARB, texture->texCoordBufferName );
29812981         // Load The Data
r243303r243304
29952995{
29962996   if ( texture->type == TEXTURE_TYPE_SHADER )
29972997   {
2998      assert ( sdl->useglsl );
2998      assert ( sdl->m_useglsl );
29992999      pfn_glUseProgramObjectARB(0); // back to fixed function pipeline
30003000   } else if ( texture->type == TEXTURE_TYPE_DYNAMIC )
30013001   {
r243303r243304
30083008
30093009static void texture_all_disable(sdl_info *sdl)
30103010{
3011   if ( sdl->useglsl )
3011   if ( sdl->m_useglsl )
30123012   {
30133013      pfn_glUseProgramObjectARB(0); // back to fixed function pipeline
30143014
30153015      pfn_glActiveTexture(GL_TEXTURE3);
30163016      glBindTexture(GL_TEXTURE_2D, 0);
3017      if ( sdl->usefbo ) pfn_glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0);
3017      if ( sdl->m_usefbo ) pfn_glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0);
30183018      pfn_glActiveTexture(GL_TEXTURE2);
30193019      glBindTexture(GL_TEXTURE_2D, 0);
3020      if ( sdl->usefbo ) pfn_glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0);
3020      if ( sdl->m_usefbo ) pfn_glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0);
30213021      pfn_glActiveTexture(GL_TEXTURE1);
30223022      glBindTexture(GL_TEXTURE_2D, 0);
3023      if ( sdl->usefbo ) pfn_glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0);
3023      if ( sdl->m_usefbo ) pfn_glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0);
30243024      pfn_glActiveTexture(GL_TEXTURE0);
30253025      glBindTexture(GL_TEXTURE_2D, 0);
3026      if ( sdl->usefbo ) pfn_glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0);
3026      if ( sdl->m_usefbo ) pfn_glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0);
30273027   }
30283028   glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0);
30293029
3030   if(sdl->usetexturerect)
3030   if(sdl->m_usetexturerect)
30313031   {
30323032      glDisable(GL_TEXTURE_RECTANGLE_ARB);
30333033   }
30343034   glDisable(GL_TEXTURE_2D);
30353035
30363036   glDisableClientState(GL_TEXTURE_COORD_ARRAY);
3037   if(sdl->usevbo)
3037   if(sdl->m_usevbo)
30383038   {
30393039      pfn_glBindBuffer( GL_ARRAY_BUFFER_ARB, 0); // unbind ..
30403040   }
3041   if ( sdl->usepbo )
3041   if ( sdl->m_usepbo )
30423042   {
30433043      pfn_glBindBuffer( GL_PIXEL_UNPACK_BUFFER_ARB, 0);
30443044   }
r243303r243304
30543054   if (sdl == NULL)
30553055      return;
30563056
3057   if ( !sdl->initialized )
3057   if ( !sdl->m_initialized )
30583058      return;
30593059
30603060#if (SDLMAME_SDL2)
3061   SDL_GL_MakeCurrent(window->m_sdl_window, sdl->gl_context_id);
3061   SDL_GL_MakeCurrent(window->m_sdl_window, sdl->m_gl_context_id);
30623062#endif
30633063
30643064   if(window->m_primlist)
r243303r243304
30763076   i=0;
30773077   while (i<HASH_SIZE+OVERFLOW_SIZE)
30783078   {
3079      texture = sdl->texhash[i];
3080      sdl->texhash[i] = NULL;
3079      texture = sdl->m_texhash[i];
3080      sdl->m_texhash[i] = NULL;
30813081      if (texture != NULL)
30823082      {
3083         if(sdl->usevbo)
3083         if(sdl->m_usevbo)
30843084         {
30853085            pfn_glDeleteBuffers( 1, &(texture->texCoordBufferName) );
30863086            texture->texCoordBufferName=0;
30873087         }
30883088
3089         if(sdl->usepbo && texture->pbo)
3089         if(sdl->m_usepbo && texture->pbo)
30903090         {
30913091            pfn_glDeleteBuffers( 1, (GLuint *)&(texture->pbo) );
30923092            texture->pbo=0;
30933093         }
30943094
3095         if( sdl->glsl_program_num > 1 )
3095         if( sdl->m_glsl_program_num > 1 )
30963096         {
3097            assert(sdl->usefbo);
3097            assert(sdl->m_usefbo);
30983098            pfn_glDeleteFramebuffers(2, (GLuint *)&texture->mpass_fbo_mamebm[0]);
30993099            glDeleteTextures(2, (GLuint *)&texture->mpass_texture_mamebm[0]);
31003100         }
31013101
3102         if ( sdl->glsl_program_mb2sc < sdl->glsl_program_num - 1 )
3102         if ( sdl->m_glsl_program_mb2sc < sdl->m_glsl_program_num - 1 )
31033103         {
3104            assert(sdl->usefbo);
3104            assert(sdl->m_usefbo);
31053105            pfn_glDeleteFramebuffers(2, (GLuint *)&texture->mpass_fbo_scrn[0]);
31063106            glDeleteTextures(2, (GLuint *)&texture->mpass_texture_scrn[0]);
31073107         }
r243303r243304
31173117      }
31183118      i++;
31193119   }
3120   if ( sdl->useglsl )
3120   if ( sdl->m_useglsl )
31213121   {
3122      glsl_shader_free(sdl->glsl);
3123      sdl->glsl = NULL;
3122      glsl_shader_free(sdl->m_glsl);
3123      sdl->m_glsl = NULL;
31243124   }
31253125
3126   sdl->initialized = 0;
3126   sdl->m_initialized = 0;
31273127
31283128   if (lock)
31293129      window->m_primlist->release_lock();
r243303r243304
31383138   sdl_info *sdl = (sdl_info *) window->m_dxdata;
31393139
31403140   //FIXME: Handled in drawogl_window_draw as well
3141   sdl->blittimer = 3;
3141   sdl->m_blittimer = 3;
31423142}
trunk/src/osd/sdl/drawsdl.c
r243303r243304
4848/* sdl_info is the information about SDL for the current screen */
4949struct sdl_info
5050{
51   INT32               blittimer;
52   UINT32              extra_flags;
51   INT32               m_blittimer;
52   UINT32              m_extra_flags;
5353
5454#if (SDLMAME_SDL2)
55   SDL_Renderer        *sdl_renderer;
56   SDL_Texture         *texture_id;
55   SDL_Renderer        *m_sdl_renderer;
56   SDL_Texture         *m_texture_id;
5757#else
5858   // SDL surface
59   SDL_Surface         *sdlsurf;
60   SDL_Overlay         *yuvsurf;
59   SDL_Surface         *m_sdlsurf;
60   SDL_Overlay         *m_yuvsurf;
6161#endif
6262
6363   // YUV overlay
64   UINT32              *yuv_lookup;
65   UINT16              *yuv_bitmap;
64   UINT32              *m_yuv_lookup;
65   UINT16              *m_yuv_bitmap;
6666
6767   // if we leave scaling to SDL and the underlying driver, this
6868   // is the render_target_width/height to use
6969
70   int                 hw_scale_width;
71   int                 hw_scale_height;
72   int                 last_hofs;
73   int                 last_vofs;
74   int                 old_blitwidth;
75   int                 old_blitheight;
70   int                 m_hw_scale_width;
71   int                 m_hw_scale_height;
72   int                 m_last_hofs;
73   int                 m_last_vofs;
74   int                 m_old_blitwidth;
75   int                 m_old_blitheight;
7676};
7777
7878struct sdl_scale_mode
r243303r243304
8383   int             mult_w;             /* Width multiplier      */
8484   int             mult_h;             /* Height multiplier     */
8585#if (!SDLMAME_SDL2)
86   int             extra_flags;        /* Texture/surface flags */
86   int             m_extra_flags;        /* Texture/surface flags */
8787#else
8888   const char      *sdl_scale_mode;        /* what to use as a hint ? */
8989#endif
r243303r243304
253253   // Determine preferred pixelformat and set up yuv if necessary
254254   SDL_GetCurrentDisplayMode(window->monitor()->handle(), &mode);
255255
256   if (sdl->yuv_bitmap)
256   if (sdl->m_yuv_bitmap)
257257   {
258      global_free_array(sdl->yuv_bitmap);
259      sdl->yuv_bitmap = NULL;
258      global_free_array(sdl->m_yuv_bitmap);
259      sdl->m_yuv_bitmap = NULL;
260260   }
261261
262262   if (sdl_sm->is_scale)
263263   {
264      window->m_target->compute_minimum_size(sdl->hw_scale_width, sdl->hw_scale_height);
264      window->m_target->compute_minimum_size(sdl->m_hw_scale_width, sdl->m_hw_scale_height);
265265      if (video_config.prescale)
266266      {
267         sdl->hw_scale_width *= video_config.prescale;
268         sdl->hw_scale_height *= video_config.prescale;
267         sdl->m_hw_scale_width *= video_config.prescale;
268         sdl->m_hw_scale_height *= video_config.prescale;
269269
270270         /* This must be a multiple of 2 */
271         sdl->hw_scale_width = (sdl->hw_scale_width + 1) & ~1;
271         sdl->m_hw_scale_width = (sdl->m_hw_scale_width + 1) & ~1;
272272      }
273273   }
274274
275275   if (sdl_sm->is_yuv)
276      sdl->yuv_bitmap = global_alloc_array(UINT16, sdl->hw_scale_width * sdl->hw_scale_height);
276      sdl->m_yuv_bitmap = global_alloc_array(UINT16, sdl->m_hw_scale_width * sdl->m_hw_scale_height);
277277
278278   fmt = (sdl_sm->pixel_format ? sdl_sm->pixel_format : mode.format);
279279
280280   if (sdl_sm->is_scale)
281281   {
282      int w = sdl->hw_scale_width * sdl_sm->mult_w;
283      int h = sdl->hw_scale_height * sdl_sm->mult_h;
282      int w = sdl->m_hw_scale_width * sdl_sm->mult_w;
283      int h = sdl->m_hw_scale_height * sdl_sm->mult_h;
284284
285      sdl->texture_id = SDL_CreateTexture(sdl->sdl_renderer, fmt, SDL_TEXTUREACCESS_STREAMING, w, h);
285      sdl->m_texture_id = SDL_CreateTexture(sdl->m_sdl_renderer, fmt, SDL_TEXTUREACCESS_STREAMING, w, h);
286286
287287   }
288288   else
289289   {
290      sdl->texture_id = SDL_CreateTexture(sdl->sdl_renderer,fmt, SDL_TEXTUREACCESS_STREAMING,
290      sdl->m_texture_id = SDL_CreateTexture(sdl->m_sdl_renderer,fmt, SDL_TEXTUREACCESS_STREAMING,
291291            tempwidth, tempheight);
292292   }
293293}
r243303r243304
318318      sdl->yuvsurf = NULL;
319319   }
320320
321   if (sdl->yuv_bitmap != NULL)
321   if (sdl->m_yuv_bitmap != NULL)
322322   {
323      global_free_array(sdl->yuv_bitmap);
323      global_free_array(sdl->m_yuv_bitmap);
324324   }
325325
326326   osd_printf_verbose("SDL: Creating %d x %d YUV-Overlay ...\n", minimum_width, minimum_height);
327327
328   sdl->yuv_bitmap = global_alloc_array(UINT16, minimum_width*minimum_height);
328   sdl->m_yuv_bitmap = global_alloc_array(UINT16, minimum_width*minimum_height);
329329
330330   sdl->yuvsurf = SDL_CreateYUVOverlay(minimum_width * sdl_sm->mult_w, minimum_height * sdl_sm->mult_h,
331331         sdl_sm->pixel_format, sdl->sdlsurf);
r243303r243304
335335      //return 1;
336336   }
337337
338   sdl->hw_scale_width = minimum_width;
339   sdl->hw_scale_height = minimum_height;
338   sdl->m_hw_scale_width = minimum_width;
339   sdl->m_hw_scale_height = minimum_height;
340340
341341   if (!shown_video_info)
342342   {
r243303r243304
402402
403403   SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, sm->sdl_scale_mode);
404404
405   sdl->extra_flags = (window->fullscreen() ?
405   sdl->m_extra_flags = (window->fullscreen() ?
406406         SDL_WINDOW_BORDERLESS | SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_MOUSE_FOCUS
407407         | SDL_WINDOW_INPUT_GRABBED : SDL_WINDOW_RESIZABLE);
408408
409409   window->m_sdl_window = SDL_CreateWindow(window->m_title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
410         width, height, sdl->extra_flags);
410         width, height, sdl->m_extra_flags);
411411
412412   if (window->fullscreen() && video_config.switchres)
413413   {
r243303r243304
435435   // create a texture
436436
437437   if (video_config.waitvsync)
438      sdl->sdl_renderer = SDL_CreateRenderer(window->m_sdl_window, -1, /*SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTDISCARD |*/ SDL_RENDERER_PRESENTVSYNC);
438      sdl->m_sdl_renderer = SDL_CreateRenderer(window->m_sdl_window, -1, /*SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTDISCARD |*/ SDL_RENDERER_PRESENTVSYNC);
439439   else
440      sdl->sdl_renderer = SDL_CreateRenderer(window->m_sdl_window, -1, /*SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTDISCARD*/ 0);
440      sdl->m_sdl_renderer = SDL_CreateRenderer(window->m_sdl_window, -1, /*SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTDISCARD*/ 0);
441441
442442   //SDL_SelectRenderer(window->sdl_window);
443443
444444   {
445445      struct SDL_RendererInfo render_info;
446446
447      SDL_GetRendererInfo(sdl->sdl_renderer, &render_info);
447      SDL_GetRendererInfo(sdl->m_sdl_renderer, &render_info);
448448      drawsdl_show_info(window, &render_info);
449449
450450      // Check scale mode
r243303r243304
467467
468468   setup_texture(window, width, height);
469469#else
470   sdl->extra_flags = (window->fullscreen() ?  SDL_FULLSCREEN : SDL_RESIZABLE);
470   sdl->m_extra_flags = (window->fullscreen() ?  SDL_FULLSCREEN : SDL_RESIZABLE);
471471
472   sdl->extra_flags |= sm->extra_flags;
472   sdl->m_extra_flags |= sm->m_extra_flags;
473473
474474   sdl->sdlsurf = SDL_SetVideoMode(m_width, m_height,
475               0, SDL_SWSURFACE | SDL_ANYFORMAT | sdl->extra_flags);
475               0, SDL_SWSURFACE | SDL_ANYFORMAT | sdl->m_extra_flags);
476476
477477   if (!sdl->sdlsurf)
478478      return 1;
r243303r243304
486486   // set the window title
487487   SDL_WM_SetCaption(window->m_title, "SDLMAME");
488488#endif
489   sdl->yuv_lookup = NULL;
490   sdl->blittimer = 0;
489   sdl->m_yuv_lookup = NULL;
490   sdl->m_blittimer = 0;
491491
492492   drawsdl_yuv_init(sdl);
493493   return 0;
r243303r243304
518518   //printf("SetVideoMode %d %d\n", wp->resize_new_width, wp->resize_new_height);
519519
520520   sdl->sdlsurf = SDL_SetVideoMode(m_width, m_height, 0,
521         SDL_SWSURFACE | SDL_ANYFORMAT | sdl->extra_flags);
521         SDL_SWSURFACE | SDL_ANYFORMAT | sdl->m_extra_flags);
522522   window->m_width = sdl->sdlsurf->w;
523523   window->m_height = sdl->sdlsurf->h;
524524
r243303r243304
545545
546546#if (SDLMAME_SDL2)
547547   //SDL_SelectRenderer(window->sdl_window);
548   SDL_DestroyTexture(sdl->texture_id);
548   SDL_DestroyTexture(sdl->m_texture_id);
549549   //SDL_DestroyRenderer(window->sdl_window);
550550   SDL_DestroyWindow(window->m_sdl_window);
551551#else
r243303r243304
563563#endif
564564   // free the memory in the window
565565
566   if (sdl->yuv_lookup != NULL)
566   if (sdl->m_yuv_lookup != NULL)
567567   {
568      global_free_array(sdl->yuv_lookup);
569      sdl->yuv_lookup = NULL;
568      global_free_array(sdl->m_yuv_lookup);
569      sdl->m_yuv_lookup = NULL;
570570   }
571   if (sdl->yuv_bitmap != NULL)
571   if (sdl->m_yuv_bitmap != NULL)
572572   {
573      global_free_array(sdl->yuv_bitmap);
574      sdl->yuv_bitmap = NULL;
573      global_free_array(sdl->m_yuv_bitmap);
574      sdl->m_yuv_bitmap = NULL;
575575   }
576576   osd_free(sdl);
577577   window->m_dxdata = NULL;
r243303r243304
585585{
586586   sdl_info *sdl = (sdl_info *) window->m_dxdata;
587587
588   sdl->blittimer = 3;
588   sdl->m_blittimer = 3;
589589}
590590
591591//============================================================
r243303r243304
597597   sdl_info *sdl = (sdl_info *) window->m_dxdata;
598598   const sdl_scale_mode *sm = &scale_modes[video_config.scale_mode];
599599
600   *xt = x - sdl->last_hofs;
601   *yt = y - sdl->last_vofs;
600   *xt = x - sdl->m_last_hofs;
601   *yt = y - sdl->m_last_vofs;
602602   if (*xt<0 || *xt >= window->m_blitwidth)
603603      return 0;
604604   if (*yt<0 || *xt >= window->m_blitheight)
r243303r243304
608608      return 1;
609609   }
610610   /* Rescale */
611   *xt = (*xt * sdl->hw_scale_width) / window->m_blitwidth;
612   *yt = (*yt * sdl->hw_scale_height) / window->m_blitheight;
611   *xt = (*xt * sdl->m_hw_scale_width) / window->m_blitwidth;
612   *yt = (*yt * sdl->m_hw_scale_height) / window->m_blitheight;
613613   return 1;
614614}
615615
r243303r243304
625625   if (!sm->is_scale)
626626      window->m_target->set_bounds(window->m_blitwidth, window->m_blitheight, window->monitor()->aspect());
627627   else
628      window->m_target->set_bounds(sdl->hw_scale_width, sdl->hw_scale_height);
628      window->m_target->set_bounds(sdl->m_hw_scale_width, sdl->m_hw_scale_height);
629629}
630630
631631//============================================================
r243303r243304
664664   bmask = sdl->sdlsurf->format->Bmask;
665665//  amask = sdl->sdlsurf->format->Amask;
666666
667   if (window->m_blitwidth != sdl->old_blitwidth || window->m_blitheight != sdl->old_blitheight)
667   if (window->m_blitwidth != sdl->m_old_blitwidth || window->m_blitheight != sdl->m_old_blitheight)
668668   {
669669      if (sm->is_yuv)
670670         yuv_overlay_init(window);
671      sdl->old_blitwidth = window->m_blitwidth;
672      sdl->old_blitheight = window->m_blitheight;
673      sdl->blittimer = 3;
671      sdl->m_old_blitwidth = window->m_blitwidth;
672      sdl->m_old_blitheight = window->m_blitheight;
673      sdl->m_blittimer = 3;
674674   }
675675
676676   if (SDL_MUSTLOCK(sdl->sdlsurf)) SDL_LockSurface(sdl->sdlsurf);
677677   // Clear if necessary
678678
679   if (sdl->blittimer > 0)
679   if (sdl->m_blittimer > 0)
680680   {
681681      memset(sdl->sdlsurf->pixels, 0, window->m_height * sdl->sdlsurf->pitch);
682      sdl->blittimer--;
682      sdl->m_blittimer--;
683683   }
684684
685685
686686   if (sm->is_yuv)
687687   {
688688      SDL_LockYUVOverlay(sdl->yuvsurf);
689      surfptr = sdl->yuvsurf->pixels[0]; // (UINT8 *) sdl->yuv_bitmap;
690      pitch = sdl->yuvsurf->pitches[0]; // (UINT8 *) sdl->yuv_bitmap;
689      surfptr = sdl->yuvsurf->pixels[0]; // (UINT8 *) sdl->m_yuv_bitmap;
690      pitch = sdl->yuvsurf->pitches[0]; // (UINT8 *) sdl->m_yuv_bitmap;
691691   }
692692   else
693693      surfptr = (UINT8 *)sdl->sdlsurf->pixels;
694694#else
695695   //SDL_SelectRenderer(window->sdl_window);
696696
697   if (window->m_blitwidth != sdl->old_blitwidth || window->m_blitheight != sdl->old_blitheight)
697   if (window->m_blitwidth != sdl->m_old_blitwidth || window->m_blitheight != sdl->m_old_blitheight)
698698   {
699      SDL_RenderSetViewport(sdl->sdl_renderer, NULL);
699      SDL_RenderSetViewport(sdl->m_sdl_renderer, NULL);
700700
701      SDL_DestroyTexture(sdl->texture_id);
701      SDL_DestroyTexture(sdl->m_texture_id);
702702      setup_texture(window, window->m_blitwidth, window->m_blitheight);
703      sdl->old_blitwidth = window->m_blitwidth;
704      sdl->old_blitheight = window->m_blitheight;
705      sdl->blittimer = 3;
703      sdl->m_old_blitwidth = window->m_blitwidth;
704      sdl->m_old_blitheight = window->m_blitheight;
705      sdl->m_blittimer = 3;
706706   }
707707
708708   {
709709      Uint32 format;
710710      int access, w, h;
711711
712      SDL_QueryTexture(sdl->texture_id, &format, &access, &w, &h);
712      SDL_QueryTexture(sdl->m_texture_id, &format, &access, &w, &h);
713713      SDL_PixelFormatEnumToMasks(format, &bpp, &rmask, &gmask, &bmask, &amask);
714714      bpp = bpp / 8; /* convert to bytes per pixels */
715715   }
716716
717717   // Clear if necessary
718   if (sdl->blittimer > 0)
718   if (sdl->m_blittimer > 0)
719719   {
720720      /* SDL Underlays need alpha = 0 ! */
721      SDL_SetRenderDrawColor(sdl->sdl_renderer,0,0,0,0);
722      SDL_RenderFillRect(sdl->sdl_renderer,NULL);
721      SDL_SetRenderDrawColor(sdl->m_sdl_renderer,0,0,0,0);
722      SDL_RenderFillRect(sdl->m_sdl_renderer,NULL);
723723      //SDL_RenderFill(0,0,0,0 /*255*/,NULL);
724      sdl->blittimer--;
724      sdl->m_blittimer--;
725725   }
726726
727   SDL_LockTexture(sdl->texture_id, NULL, (void **) &surfptr, &pitch);
727   SDL_LockTexture(sdl->m_texture_id, NULL, (void **) &surfptr, &pitch);
728728
729729#endif
730730   // get ready to center the image
r243303r243304
765765      hofs = (cw - window->m_blitwidth) / 2;
766766   }
767767
768   sdl->last_hofs = hofs;
769   sdl->last_vofs = vofs;
768   sdl->m_last_hofs = hofs;
769   sdl->m_last_vofs = vofs;
770770
771771   window->m_primlist->acquire_lock();
772772
r243303r243304
785785      }
786786      else
787787      {
788         mamewidth = sdl->hw_scale_width;
789         mameheight = sdl->hw_scale_height;
788         mamewidth = sdl->m_hw_scale_width;
789         mameheight = sdl->m_hw_scale_height;
790790      }
791791      switch (rmask)
792792      {
r243303r243304
817817   }
818818   else
819819   {
820      assert (sdl->yuv_bitmap != NULL);
820      assert (sdl->m_yuv_bitmap != NULL);
821821      assert (surfptr != NULL);
822      software_renderer<UINT16, 3,3,3, 10,5,0>::draw_primitives(*window->m_primlist, sdl->yuv_bitmap, sdl->hw_scale_width, sdl->hw_scale_height, sdl->hw_scale_width);
823      sm->yuv_blit((UINT16 *)sdl->yuv_bitmap, sdl, surfptr, pitch);
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);
824824   }
825825
826826   window->m_primlist->release_lock();
r243303r243304
844844      SDL_DisplayYUVOverlay(sdl->yuvsurf, &r);
845845   }
846846#else
847   SDL_UnlockTexture(sdl->texture_id);
847   SDL_UnlockTexture(sdl->m_texture_id);
848848   {
849849      SDL_Rect r;
850850
r243303r243304
854854      r.h=blitheight;
855855      //printf("blitwidth %d %d - %d %d\n", blitwidth, blitheight, window->width, window->height);
856856      //SDL_UpdateTexture(sdl->sdltex, NULL, sdl->sdlsurf->pixels, pitch);
857      SDL_RenderCopy(sdl->sdl_renderer,sdl->texture_id, NULL, &r);
858      SDL_RenderPresent(sdl->sdl_renderer);
857      SDL_RenderCopy(sdl->m_sdl_renderer,sdl->m_texture_id, NULL, &r);
858      SDL_RenderPresent(sdl->m_sdl_renderer);
859859   }
860860#endif
861861   return 0;
r243303r243304
910910
911911   /* Storing this data in YUYV order simplifies using the data for
912912      YUY2, both with and without smoothing... */
913   sdl->yuv_lookup[pen]=(y<<Y1SHIFT)|(u<<USHIFT)|(y<<Y2SHIFT)|(v<<VSHIFT);
913   sdl->m_yuv_lookup[pen]=(y<<Y1SHIFT)|(u<<USHIFT)|(y<<Y2SHIFT)|(v<<VSHIFT);
914914}
915915
916916static void drawsdl_yuv_init(sdl_info *sdl)
917917{
918918   unsigned char r,g,b;
919   if (sdl->yuv_lookup == NULL)
920      sdl->yuv_lookup = global_alloc_array(UINT32, 65536);
919   if (sdl->m_yuv_lookup == NULL)
920      sdl->m_yuv_lookup = global_alloc_array(UINT32, 65536);
921921   for (r = 0; r < 32; r++)
922922      for (g = 0; g < 32; g++)
923923         for (b = 0; b < 32; b++)
r243303r243304
938938   UINT8 *dest_v;
939939   UINT16 *src;
940940   UINT16 *src2;
941   UINT32 *lookup = sdl->yuv_lookup;
941   UINT32 *lookup = sdl->m_yuv_lookup;
942942   UINT8 *pixels[3];
943943   int u1,v1,y1,u2,v2,y2,u3,v3,y3,u4,v4,y4;      /* 12 */
944944
945945   pixels[0] = ptr;
946   pixels[1] = ptr + pitch * sdl->hw_scale_height;
947   pixels[2] = pixels[1] + pitch * sdl->hw_scale_height / 4;
946   pixels[1] = ptr + pitch * sdl->m_hw_scale_height;
947   pixels[2] = pixels[1] + pitch * sdl->m_hw_scale_height / 4;
948948
949   for(y=0;y<sdl->hw_scale_height;y+=2)
949   for(y=0;y<sdl->m_hw_scale_height;y+=2)
950950   {
951      src=bitmap + (y * sdl->hw_scale_width) ;
952      src2=src + sdl->hw_scale_width;
951      src=bitmap + (y * sdl->m_hw_scale_width) ;
952      src2=src + sdl->m_hw_scale_width;
953953
954954      dest_y = pixels[0] + y * pitch;
955955      dest_v = pixels[1] + (y>>1) * pitch / 2;
956956      dest_u = pixels[2] + (y>>1) * pitch / 2;
957957
958      for(x=0;x<sdl->hw_scale_width;x+=2)
958      for(x=0;x<sdl->m_hw_scale_width;x+=2)
959959      {
960960         v1 = lookup[src[x]];
961961         y1 = (v1>>Y1SHIFT) & 0xff;
r243303r243304
10011001   UINT8 *pixels[3];
10021002
10031003   pixels[0] = ptr;
1004   pixels[1] = ptr + pitch * sdl->hw_scale_height * 2;
1005   pixels[2] = pixels[1] + pitch * sdl->hw_scale_height / 2;
1004   pixels[1] = ptr + pitch * sdl->m_hw_scale_height * 2;
1005   pixels[2] = pixels[1] + pitch * sdl->m_hw_scale_height / 2;
10061006
1007   for(y=0;y<sdl->hw_scale_height;y++)
1007   for(y=0;y<sdl->m_hw_scale_height;y++)
10081008   {
1009      src = bitmap + (y * sdl->hw_scale_width) ;
1009      src = bitmap + (y * sdl->m_hw_scale_width) ;
10101010
10111011      dest_y = (UINT16 *)(pixels[0] + 2 * y * pitch);
10121012      dest_v = pixels[1] + y * pitch / 2;
10131013      dest_u = pixels[2] + y * pitch / 2;
1014      for(x=0;x<sdl->hw_scale_width;x++)
1014      for(x=0;x<sdl->m_hw_scale_width;x++)
10151015      {
1016         v1 = sdl->yuv_lookup[src[x]];
1016         v1 = sdl->m_yuv_lookup[src[x]];
10171017         y1 = (v1 >> Y1SHIFT) & 0xff;
10181018         u1 = (v1 >> USHIFT)  & 0xff;
10191019         v1 = (v1 >> VSHIFT)  & 0xff;
r243303r243304
10341034   UINT16 *src;
10351035   UINT16 *end;
10361036   UINT32 p1,p2,uv;
1037   UINT32 *lookup = sdl->yuv_lookup;
1037   UINT32 *lookup = sdl->m_yuv_lookup;
10381038   int yuv_pitch = pitch/4;
10391039
1040   for(y=0;y<sdl->hw_scale_height;y++)
1040   for(y=0;y<sdl->m_hw_scale_height;y++)
10411041   {
1042      src=bitmap + (y * sdl->hw_scale_width) ;
1043      end=src+sdl->hw_scale_width;
1042      src=bitmap + (y * sdl->m_hw_scale_width) ;
1043      end=src+sdl->m_hw_scale_width;
10441044
10451045      dest = (UINT32 *) ptr;
10461046      dest += y * yuv_pitch;
r243303r243304
10621062   UINT32 *dest;
10631063   UINT16 *src;
10641064   UINT16 *end;
1065   UINT32 *lookup = sdl->yuv_lookup;
1065   UINT32 *lookup = sdl->m_yuv_lookup;
10661066   int yuv_pitch = pitch / 4;
10671067
1068   for(y=0;y<sdl->hw_scale_height;y++)
1068   for(y=0;y<sdl->m_hw_scale_height;y++)
10691069   {
1070      src=bitmap + (y * sdl->hw_scale_width) ;
1071      end=src+sdl->hw_scale_width;
1070      src=bitmap + (y * sdl->m_hw_scale_width) ;
1071      end=src+sdl->m_hw_scale_width;
10721072
10731073      dest = (UINT32 *) ptr;
10741074      dest += (y * yuv_pitch);
trunk/src/osd/sdl/input.c
r243303r243304
15441544   sdl_window_info *w;
15451545   SDL_Window *window = SDL_GetWindowFromID(windowID);
15461546
1547   for (w = sdl_window_list; w != NULL; w = w->next)
1547   for (w = sdl_window_list; w != NULL; w = w->m_next)
15481548   {
15491549      //printf("w->window_id: %d\n", w->window_id);
15501550      if (w->m_sdl_window == window)
r243303r243304
15621562
15631563   if (SDL13_COMBINE_RESIZE)
15641564   {
1565      for (w = sdl_window_list; w != NULL; w = w->next)
1565      for (w = sdl_window_list; w != NULL; w = w->m_next)
15661566      {
15671567         if (w->m_resize_width && w->m_resize_height && ((now - w->m_last_resize) > osd_ticks_per_second() / 10))
15681568         {
trunk/src/osd/sdl/video.c
r243303r243304
307307   if (!skip_redraw)
308308   {
309309//      profiler_mark(PROFILER_BLIT);
310      for (window = sdl_window_list; window != NULL; window = window->next)
310      for (window = sdl_window_list; window != NULL; window = window->m_next)
311311         window->video_window_update(machine());
312312//      profiler_mark(PROFILER_END);
313313   }
r243303r243304
550550      while (curwin != (sdl_window_info *)NULL)
551551      {
552552         curwin->toggle_full_screen(machine);
553         curwin = curwin->next;
553         curwin = curwin->m_next;
554554      }
555555   }
556556
trunk/src/osd/sdl/window.c
r243303r243304
354354   while (sdl_window_list != NULL)
355355   {
356356      sdl_window_info *temp = sdl_window_list;
357      sdl_window_list = temp->next;
357      sdl_window_list = temp->m_next;
358358      temp->video_window_destroy(machine());
359359      // free the window itself
360360      global_free(temp);
r243303r243304
720720
721721   // add us to the list
722722   *last_window_ptr = window;
723   last_window_ptr = &window->next;
723   last_window_ptr = &window->m_next;
724724
725725   draw.attach(&draw, window);
726726
r243303r243304
804804   //osd_event_wait(window->rendered_event, osd_ticks_per_second()*10);
805805
806806   // remove us from the list
807   for (prevptr = &sdl_window_list; *prevptr != NULL; prevptr = &(*prevptr)->next)
807   for (prevptr = &sdl_window_list; *prevptr != NULL; prevptr = &(*prevptr)->m_next)
808808      if (*prevptr == this)
809809      {
810         *prevptr = this->next;
810         *prevptr = this->m_next;
811811         break;
812812      }
813813
trunk/src/osd/sdl/window.h
r243303r243304
3232//  TYPE DEFINITIONS
3333//============================================================
3434
35struct sdl_window_info;
35class sdl_window_info;
3636
3737class osd_renderer
3838{
r243303r243304
5555   sdl_window_info *m_window;
5656};
5757
58struct sdl_window_info
58class sdl_window_info
5959{
60public:
6061   sdl_window_info(running_machine *a_machine, sdl_monitor_info *a_monitor,
6162         int index, const sdl_window_config *config)
62   : next(NULL), m_minwidth(0), m_minheight(0),
63   : m_next(NULL), m_minwidth(0), m_minheight(0),
6364      m_startmaximized(0),
6465      m_rendered_event(0), m_target(0), m_primlist(NULL), m_dxdata(NULL),
6566      m_width(0), m_height(0), m_blitwidth(0), m_blitheight(0),
r243303r243304
8990   }
9091
9192   void video_window_update(running_machine &machine);
92   void blit_surface_size(int window_width, int window_height);
93   //void blit_surface_size(int window_width, int window_height);
9394   void toggle_full_screen(running_machine &machine);
9495   void modify_prescale(running_machine &machine, int dir);
9596   void window_resize(INT32 width, INT32 height);
9697   void window_clear();
9798
9899   void video_window_destroy(running_machine &machine);
99   void pick_best_mode(int *fswidth, int *fsheight);
100   //void pick_best_mode(int *fswidth, int *fsheight);
100101   void get_min_bounds(int *window_width, int *window_height, int constrain);
101102   void get_max_bounds(int *window_width, int *window_height, int constrain);
102103
103   // Pointer to next window
104   sdl_window_info *   next;
105
106104   running_machine &machine() const { assert(m_machine != NULL); return *m_machine; }
107105   sdl_monitor_info *monitor() const { return m_monitor; }
108106   int fullscreen() const { return m_fullscreen; }
109   int index() const { return m_index; }
110107
111108   void set_fullscreen(int afullscreen) { m_fullscreen = afullscreen; }
112109
110   void blit_surface_size(int window_width, int window_height);
111   void pick_best_mode(int *fswidth, int *fsheight);
112   int index() const { return m_index; }
113
113114#if 1
114115   // Draw Callbacks
115116   int (*create)(sdl_window_info *window, int m_width, int m_height);
r243303r243304
122123   void (*clear)(sdl_window_info *window);
123124#endif
124125
126   // Pointer to next window
127   sdl_window_info *   m_next;
128
125129   // window handle and info
126130   char                m_title[256];
127131


Previous 199869 Revisions Next


© 1997-2024 The MAME Team