diff --git a/src/osd/sdl/draw13.c b/src/osd/sdl/draw13.c index 4bda7932776..3bca9596872 100644 --- a/src/osd/sdl/draw13.c +++ b/src/osd/sdl/draw13.c @@ -79,7 +79,7 @@ struct quad_setup_data // Textures //============================================================ -struct sdl_info13; +class sdl_info13; struct copy_info_t; /* texture_info holds information about a texture */ @@ -139,15 +139,25 @@ private: #include "blit13.h" /* sdl_info is the information about SDL for the current screen */ -struct sdl_info13 +class sdl_info13 : public osd_renderer { - sdl_info13() - : m_blittimer(0), m_renderer(NULL), +public: + sdl_info13(sdl_window_info *w) + : osd_renderer(w), m_blittimer(0), m_renderer(NULL), m_hofs(0), m_vofs(0), m_resize_pending(0), m_resize_width(0), m_resize_height(0), m_last_blit_time(0), m_last_blit_pixels(0) {} + /* virtual */ int create(int width, int height); + /* virtual */ void resize(int width, int height); + /* virtual */ int draw(UINT32 dc, int update); + /* virtual */ void set_target_bounds(); + /* virtual */ int xy_to_render_target(int x, int y, int *xt, int *yt); + /* virtual */ void destroy_all_textures(); + /* virtual */ void destroy(); + /* virtual */ void clear(); + void render_quad(texture_info *texture, const render_primitive *prim, const int x, const int y); texture_info *texture_find(const render_primitive &prim, const quad_setup_data &setup); @@ -198,15 +208,6 @@ struct copy_info_t { // core functions static void drawsdl2_exit(void); -static void drawsdl2_attach(sdl_draw_info *info, sdl_window_info *window); -static int drawsdl2_window_create(sdl_window_info *window, int width, int height); -static void drawsdl2_window_resize(sdl_window_info *window, int width, int height); -static void drawsdl2_window_destroy(sdl_window_info *window); -static int drawsdl2_window_draw(sdl_window_info *window, UINT32 dc, int update); -static void drawsdl2_set_target_bounds(sdl_window_info *window); -static void drawsdl2_destroy_all_textures(sdl_window_info *window); -static void drawsdl2_window_clear(sdl_window_info *window); -static int drawsdl2_xy_to_render_target(sdl_window_info *window, int x, int y, int *xt, int *yt); //============================================================ // STATIC VARIABLES @@ -483,6 +484,11 @@ static void expand_copy_info(copy_info_t *list) } } +static osd_renderer *drawsdl2_create(sdl_window_info *window) +{ + return global_alloc(sdl_info13(window)); +} + // FIXME: machine only used to access options. int drawsdl2_init(running_machine &machine, sdl_draw_info *callbacks) { @@ -490,7 +496,7 @@ int drawsdl2_init(running_machine &machine, sdl_draw_info *callbacks) // fill in the callbacks callbacks->exit = drawsdl2_exit; - callbacks->attach = drawsdl2_attach; + callbacks->create = drawsdl2_create; osd_printf_verbose("Using SDL native texturing driver (SDL 2.0+)\n"); @@ -550,31 +556,11 @@ static void drawsdl2_exit(void) } //============================================================ -// drawsdl2_attach +// sdl_info13::create //============================================================ -static void drawsdl2_attach(sdl_draw_info *info, sdl_window_info *window) +int sdl_info13::create(int width, int height) { - // fill in the callbacks - window->create = drawsdl2_window_create; - window->resize = drawsdl2_window_resize; - window->set_target_bounds = drawsdl2_set_target_bounds; - window->draw = drawsdl2_window_draw; - window->destroy = drawsdl2_window_destroy; - window->destroy_all_textures = drawsdl2_destroy_all_textures; - window->clear = drawsdl2_window_clear; - window->xy_to_render_target = drawsdl2_xy_to_render_target; -} - -//============================================================ -// drawsdl2_window_create -//============================================================ - -static int drawsdl2_window_create(sdl_window_info *window, int width, int height) -{ - // allocate memory for our structures - sdl_info13 *sdl = global_alloc(sdl_info13); - /* FIXME: On Ubuntu and potentially other Linux OS you should use * to disable panning. This has to be done before every invocation of mame. * @@ -582,35 +568,33 @@ static int drawsdl2_window_create(sdl_window_info *window, int width, int height * */ - osd_printf_verbose("Enter drawsdl2_window_create\n"); + osd_printf_verbose("Enter sdl_info13::create\n"); - window->m_dxdata = sdl; - - UINT32 extra_flags = (window->fullscreen() ? + UINT32 extra_flags = (window().fullscreen() ? SDL_WINDOW_BORDERLESS | SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_FULLSCREEN : SDL_WINDOW_RESIZABLE); #if defined(SDLMAME_WIN32) SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, "0"); #endif // create the SDL window - window->m_sdl_window = SDL_CreateWindow(window->m_title, - window->monitor()->position_size().x, window->monitor()->position_size().y, + window().m_sdl_window = SDL_CreateWindow(window().m_title, + window().monitor()->position_size().x, window().monitor()->position_size().y, width, height, extra_flags); - if (window->fullscreen() && video_config.switchres) + if (window().fullscreen() && video_config.switchres) { SDL_DisplayMode mode; - //SDL_GetCurrentDisplayMode(window->monitor()->handle, &mode); - SDL_GetWindowDisplayMode(window->m_sdl_window, &mode); - sdl->m_original_mode = mode; + //SDL_GetCurrentDisplayMode(window().monitor()->handle, &mode); + SDL_GetWindowDisplayMode(window().m_sdl_window, &mode); + m_original_mode = mode; mode.w = width; mode.h = height; - if (window->m_refresh) - mode.refresh_rate = window->m_refresh; + if (window().m_refresh) + mode.refresh_rate = window().m_refresh; #if 0 - if (window->depth) + if (window().depth) { - switch (window->depth) + switch (window().depth) { case 15: mode.format = SDL_PIXELFORMAT_RGB555; @@ -625,66 +609,64 @@ static int drawsdl2_window_create(sdl_window_info *window, int width, int height mode.format = SDL_PIXELFORMAT_RGB888; break; default: - osd_printf_warning("Ignoring depth %d\n", window->depth); + osd_printf_warning("Ignoring depth %d\n", window().depth); } } #endif - SDL_SetWindowDisplayMode(window->m_sdl_window, &mode); // Try to set mode + SDL_SetWindowDisplayMode(window().m_sdl_window, &mode); // Try to set mode #ifndef SDLMAME_WIN32 /* FIXME: Warp the mouse to 0,0 in case a virtual desktop resolution * is in place after the mode switch - which will most likely be the case * This is a hack to work around a deficiency in SDL2 */ - SDL_WarpMouseInWindow(window->m_sdl_window, 1, 1); + SDL_WarpMouseInWindow(window().m_sdl_window, 1, 1); #endif } else { - //SDL_SetWindowDisplayMode(window->sdl_window, NULL); // Use desktop + //SDL_SetWindowDisplayMode(window().sdl_window, NULL); // Use desktop } // create renderer if (video_config.waitvsync) - sdl->m_renderer = SDL_CreateRenderer(window->m_sdl_window, -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED); + m_renderer = SDL_CreateRenderer(window().m_sdl_window, -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED); else - sdl->m_renderer = SDL_CreateRenderer(window->m_sdl_window, -1, SDL_RENDERER_ACCELERATED); + m_renderer = SDL_CreateRenderer(window().m_sdl_window, -1, SDL_RENDERER_ACCELERATED); - if (!sdl->m_renderer) + if (!m_renderer) { fatalerror("Error on creating renderer: %s\n", SDL_GetError()); } - //SDL_SelectRenderer(window->sdl_window); - SDL_ShowWindow(window->m_sdl_window); - //SDL_SetWindowFullscreen(window->window_id, window->fullscreen); - SDL_RaiseWindow(window->m_sdl_window); + //SDL_SelectRenderer(window().sdl_window); + SDL_ShowWindow(window().m_sdl_window); + //SDL_SetWindowFullscreen(window().window_id, window().fullscreen); + SDL_RaiseWindow(window().m_sdl_window); - SDL_GetWindowSize(window->m_sdl_window, &window->m_width, &window->m_height); + SDL_GetWindowSize(window().m_sdl_window, &window().m_width, &window().m_height); - sdl->m_blittimer = 3; + m_blittimer = 3; - SDL_RenderPresent(sdl->m_renderer); - osd_printf_verbose("Leave drawsdl2_window_create\n"); + SDL_RenderPresent(m_renderer); + osd_printf_verbose("Leave sdl_info13::create\n"); return 0; } //============================================================ -// drawsdl2_window_resize +// sdl_info13::resize //============================================================ -static void drawsdl2_window_resize(sdl_window_info *window, int width, int height) +void sdl_info13::resize(int width, int height) { - sdl_info13 *sdl = (sdl_info13 *) window->m_dxdata; + m_resize_pending = 1; + m_resize_height = height; + m_resize_width = width; - sdl->m_resize_pending = 1; - sdl->m_resize_height = height; - sdl->m_resize_width = width; + window().m_width = width; + window().m_height = height; - window->m_width = width; - window->m_height = height; - - sdl->m_blittimer = 3; + m_blittimer = 3; } @@ -692,35 +674,33 @@ static void drawsdl2_window_resize(sdl_window_info *window, int width, int heigh // drawsdl_xy_to_render_target //============================================================ -static int drawsdl2_xy_to_render_target(sdl_window_info *window, int x, int y, int *xt, int *yt) +int sdl_info13::xy_to_render_target(int x, int y, int *xt, int *yt) { - sdl_info13 *sdl = (sdl_info13 *) window->m_dxdata; - *xt = x - sdl->m_hofs; - *yt = y - sdl->m_vofs; - if (*xt<0 || *xt >= window->m_blitwidth) + *xt = x - m_hofs; + *yt = y - m_vofs; + if (*xt<0 || *xt >= window().m_blitwidth) return 0; - if (*yt<0 || *yt >= window->m_blitheight) + if (*yt<0 || *yt >= window().m_blitheight) return 0; return 1; } //============================================================ -// drawsdl2_window_get_primitives +// sdl_info13::get_primitives //============================================================ -static void drawsdl2_set_target_bounds(sdl_window_info *window) +void sdl_info13::set_target_bounds() { - window->m_target->set_bounds(window->m_blitwidth, window->m_blitheight, window->monitor()->aspect()); + window().m_target->set_bounds(window().m_blitwidth, window().m_blitheight, window().monitor()->aspect()); } //============================================================ -// drawsdl2_window_draw +// sdl_info13::draw //============================================================ -static int drawsdl2_window_draw(sdl_window_info *window, UINT32 dc, int update) +int sdl_info13::draw(UINT32 dc, int update) { - sdl_info13 *sdl = (sdl_info13 *) window->m_dxdata; render_primitive *prim; texture_info *texture=NULL; float vofs, hofs; @@ -731,26 +711,26 @@ static int drawsdl2_window_draw(sdl_window_info *window, UINT32 dc, int update) return 0; } - if (sdl->m_resize_pending) + if (m_resize_pending) { - SDL_SetWindowSize(window->m_sdl_window, sdl->m_resize_width, sdl->m_resize_height); - SDL_GetWindowSize(window->m_sdl_window, &window->m_width, &window->m_height); - sdl->m_resize_pending = 0; - SDL_RenderSetViewport(sdl->m_renderer, NULL); - //sdlvideo_monitor_refresh(window->monitor()); + SDL_SetWindowSize(window().m_sdl_window, m_resize_width, m_resize_height); + SDL_GetWindowSize(window().m_sdl_window, &window().m_width, &window().m_height); + m_resize_pending = 0; + SDL_RenderSetViewport(m_renderer, NULL); + //sdlvideo_monitor_refresh(window().monitor()); } - //SDL_SelectRenderer(window->sdl_window); + //SDL_SelectRenderer(window().sdl_window); - if (sdl->m_blittimer > 0) + if (m_blittimer > 0) { /* SDL Underlays need alpha = 0 ! */ - SDL_SetRenderDrawBlendMode(sdl->m_renderer, SDL_BLENDMODE_NONE); + SDL_SetRenderDrawBlendMode(m_renderer, SDL_BLENDMODE_NONE); //SDL_SetRenderDrawColor(0,0,0,255); - SDL_SetRenderDrawColor(sdl->m_renderer, 0,0,0,0); - SDL_RenderFillRect(sdl->m_renderer, NULL); - sdl->m_blittimer--; + SDL_SetRenderDrawColor(m_renderer, 0,0,0,0); + SDL_RenderFillRect(m_renderer, NULL); + m_blittimer--; } // compute centering parameters @@ -760,34 +740,34 @@ static int drawsdl2_window_draw(sdl_window_info *window, UINT32 dc, int update) { int ch, cw; - if ((window->fullscreen()) && (!video_config.switchres)) + if ((window().fullscreen()) && (!video_config.switchres)) { - ch = window->monitor()->center_height(); - cw = window->monitor()->center_width(); + ch = window().monitor()->center_height(); + cw = window().monitor()->center_width(); } else { - ch = window->m_height; - cw = window->m_width; + ch = window().m_height; + cw = window().m_width; } if (video_config.centerv) { - vofs = (ch - window->m_blitheight) / 2.0f; + vofs = (ch - window().m_blitheight) / 2.0f; } if (video_config.centerh) { - hofs = (cw - window->m_blitwidth) / 2.0f; + hofs = (cw - window().m_blitwidth) / 2.0f; } } - sdl->m_hofs = hofs; - sdl->m_vofs = vofs; + m_hofs = hofs; + m_vofs = vofs; - window->m_primlist->acquire_lock(); + window().m_primlist->acquire_lock(); // now draw - for (prim = window->m_primlist->first(); prim != NULL; prim = prim->next()) + for (prim = window().m_primlist->first(); prim != NULL; prim = prim->next()) { Uint8 sr, sg, sb, sa; @@ -799,16 +779,16 @@ static int drawsdl2_window_draw(sdl_window_info *window, UINT32 dc, int update) sb = (int)(255.0f * prim->color.b); sa = (int)(255.0f * prim->color.a); - SDL_SetRenderDrawBlendMode(sdl->m_renderer, map_blendmode(PRIMFLAG_GET_BLENDMODE(prim->flags))); - SDL_SetRenderDrawColor(sdl->m_renderer, sr, sg, sb, sa); - SDL_RenderDrawLine(sdl->m_renderer, prim->bounds.x0 + hofs, prim->bounds.y0 + vofs, + SDL_SetRenderDrawBlendMode(m_renderer, map_blendmode(PRIMFLAG_GET_BLENDMODE(prim->flags))); + SDL_SetRenderDrawColor(m_renderer, sr, sg, sb, sa); + SDL_RenderDrawLine(m_renderer, prim->bounds.x0 + hofs, prim->bounds.y0 + vofs, prim->bounds.x1 + hofs, prim->bounds.y1 + vofs); break; case render_primitive::QUAD: - texture = sdl->texture_update(*prim); + texture = texture_update(*prim); if (texture) blit_pixels += (texture->raw_height() * texture->raw_width()); - sdl->render_quad(texture, prim, + render_quad(texture, prim, round_nearest(hofs + prim->bounds.x0), round_nearest(vofs + prim->bounds.y0)); break; @@ -817,56 +797,46 @@ static int drawsdl2_window_draw(sdl_window_info *window, UINT32 dc, int update) } } - window->m_primlist->release_lock(); + window().m_primlist->release_lock(); - sdl->m_last_blit_pixels = blit_pixels; - sdl->m_last_blit_time = -osd_ticks(); - SDL_RenderPresent(sdl->m_renderer); - sdl->m_last_blit_time += osd_ticks(); + m_last_blit_pixels = blit_pixels; + m_last_blit_time = -osd_ticks(); + SDL_RenderPresent(m_renderer); + m_last_blit_time += osd_ticks(); return 0; } //============================================================ -// drawsdl2_window_clear +// sdl_info13::clear //============================================================ -static void drawsdl2_window_clear(sdl_window_info *window) +void sdl_info13::clear() { - sdl_info13 *sdl = (sdl_info13 *) window->m_dxdata; - - sdl->m_blittimer = 2; + m_blittimer = 2; } //============================================================ -// drawsdl2_window_destroy +// sdl_info13::destroy //============================================================ -static void drawsdl2_window_destroy(sdl_window_info *window) +void sdl_info13::destroy() { - sdl_info13 *sdl = (sdl_info13 *) window->m_dxdata; - - // skip if nothing - if (sdl == NULL) - return; - // free the memory in the window - drawsdl2_destroy_all_textures(window); + destroy_all_textures(); - if (window->fullscreen() && video_config.switchres) + if (window().fullscreen() && video_config.switchres) { - SDL_SetWindowFullscreen(window->m_sdl_window, 0); // Try to set mode - SDL_SetWindowDisplayMode(window->m_sdl_window, &sdl->m_original_mode); // Try to set mode - SDL_SetWindowFullscreen(window->m_sdl_window, SDL_WINDOW_FULLSCREEN); // Try to set mode + SDL_SetWindowFullscreen(window().m_sdl_window, 0); // Try to set mode + SDL_SetWindowDisplayMode(window().m_sdl_window, &m_original_mode); // Try to set mode + SDL_SetWindowFullscreen(window().m_sdl_window, SDL_WINDOW_FULLSCREEN); // Try to set mode } - SDL_DestroyWindow(window->m_sdl_window); + SDL_DestroyWindow(window().m_sdl_window); - global_free(sdl); - window->m_dxdata = NULL; } //============================================================ @@ -1188,19 +1158,14 @@ texture_info * sdl_info13::texture_update(const render_primitive &prim) } -static void drawsdl2_destroy_all_textures(sdl_window_info *window) +void sdl_info13::destroy_all_textures() { - sdl_info13 *sdl = (sdl_info13 *) window->m_dxdata; - - if (sdl == NULL) - return; - - if(window->m_primlist) + if(window().m_primlist) { - window->m_primlist->acquire_lock(); - sdl->m_texlist.reset(); - window->m_primlist->release_lock(); + window().m_primlist->acquire_lock(); + m_texlist.reset(); + window().m_primlist->release_lock(); } else - sdl->m_texlist.reset(); + m_texlist.reset(); } diff --git a/src/osd/sdl/drawogl.c b/src/osd/sdl/drawogl.c index 510b99fba4f..61bf6ab867e 100644 --- a/src/osd/sdl/drawogl.c +++ b/src/osd/sdl/drawogl.c @@ -215,10 +215,11 @@ struct texture_info }; /* sdl_info is the information about SDL for the current screen */ -struct sdl_info +class sdl_info_ogl : public osd_renderer { - sdl_info() - : m_blittimer(0), m_extra_flags(0), +public: + sdl_info_ogl(sdl_window_info *window) + : osd_renderer(window), m_blittimer(0), m_extra_flags(0), #if (SDLMAME_SDL2) m_gl_context_id(0), #else @@ -247,6 +248,32 @@ struct sdl_info m_texVerticex[i] = 0.0f; } + /* virtual */ int create(int width, int height); + /* virtual */ void resize(int width, int height); + /* virtual */ int draw(UINT32 dc, int update); + /* virtual */ void set_target_bounds(); + /* virtual */ int xy_to_render_target(int x, int y, int *xt, int *yt); + /* virtual */ void destroy_all_textures(); + /* virtual */ void destroy(); + /* virtual */ void clear(); + + void loadGLExtensions(); + void set_blendmode(int blendmode); + void texture_compute_type_subroutine(const render_texinfo *texsource, texture_info *texture, UINT32 flags); + void texture_compute_size_subroutine(texture_info *texture, UINT32 flags, + UINT32 width, UINT32 height, + int* p_width, int* p_height, int* p_width_create, int* p_height_create); + void texture_compute_size_type(const render_texinfo *texsource, texture_info *texture, UINT32 flags); + texture_info *texture_create(const render_texinfo *texsource, UINT32 flags); + int texture_shader_create(const render_texinfo *texsource, texture_info *texture, UINT32 flags); + texture_info *texture_find(const render_primitive *prim); + void texture_coord_update(texture_info *texture, const render_primitive *prim, int shaderIdx); + void texture_mpass_flip(texture_info *texture, int shaderIdx); + void texture_shader_update(texture_info *texture, int shaderIdx); + texture_info * texture_update(const render_primitive *prim, int shaderIdx); + void texture_disable(texture_info * texture); + void texture_all_disable(); + INT32 m_blittimer; UINT32 m_extra_flags; @@ -327,10 +354,10 @@ INLINE HashT texture_compute_hash(const render_texinfo *texture, UINT32 flags) return (h >> 8) % HASH_SIZE; } -INLINE void set_blendmode(sdl_info *sdl, int blendmode) +void sdl_info_ogl::set_blendmode(int blendmode) { // try to minimize texture state changes - if (blendmode != sdl->m_last_blendmode) + if (blendmode != m_last_blendmode) { switch (blendmode) { @@ -351,7 +378,7 @@ INLINE void set_blendmode(sdl_info *sdl, int blendmode) break; } - sdl->m_last_blendmode = blendmode; + m_last_blendmode = blendmode; } } @@ -362,15 +389,6 @@ INLINE void set_blendmode(sdl_info *sdl, int blendmode) // core functions static void drawogl_exit(void); -static void drawogl_attach(sdl_draw_info *info, sdl_window_info *window); -static int drawogl_window_create(sdl_window_info *window, int width, int height); -static void drawogl_window_resize(sdl_window_info *window, int width, int height); -static void drawogl_window_destroy(sdl_window_info *window); -static int drawogl_window_draw(sdl_window_info *window, UINT32 dc, int update); -static void drawogl_set_target_bounds(sdl_window_info *window); -static void drawogl_destroy_all_textures(sdl_window_info *window); -static void drawogl_window_clear(sdl_window_info *window); -static int drawogl_xy_to_render_target(sdl_window_info *window, int x, int y, int *xt, int *yt); static void load_gl_lib(running_machine &machine); @@ -408,11 +426,6 @@ static int glsl_shader_feature = GLSL_SHADER_FEAT_PLAIN; //============================================================ static void texture_set_data(texture_info *texture, const render_texinfo *texsource, UINT32 flags); -static texture_info *texture_create(sdl_window_info *window, const render_texinfo *texsource, UINT32 flags); -static texture_info *texture_find(sdl_info *sdl, const render_primitive *prim); -static texture_info * texture_update(sdl_window_info *window, const render_primitive *prim, int shaderIdx); -static void texture_all_disable(sdl_info *sdl); -static void texture_disable(sdl_info *sdl, texture_info * texture); //============================================================ // Static Variables @@ -425,11 +438,16 @@ static int dll_loaded = 0; // drawogl_init //============================================================ +static osd_renderer *drawogl_create(sdl_window_info *window) +{ + return global_alloc(sdl_info_ogl(window)); +} + int drawogl_init(running_machine &machine, sdl_draw_info *callbacks) { // fill in the callbacks callbacks->exit = drawogl_exit; - callbacks->attach = drawogl_attach; + callbacks->create = drawogl_create; dll_loaded = 0; @@ -449,20 +467,6 @@ int drawogl_init(running_machine &machine, sdl_draw_info *callbacks) // drawogl_attach //============================================================ -static void drawogl_attach(sdl_draw_info *info, sdl_window_info *window) -{ - // fill in the callbacks - window->create = drawogl_window_create; - window->resize = drawogl_window_resize; - window->set_target_bounds = drawogl_set_target_bounds; - window->draw = drawogl_window_draw; - window->destroy = drawogl_window_destroy; - window->destroy_all_textures = drawogl_destroy_all_textures; - window->clear = drawogl_window_clear; - window->xy_to_render_target = drawogl_xy_to_render_target; -} - - //============================================================ // Load the OGL function addresses //============================================================ @@ -525,25 +529,19 @@ static void load_gl_lib(running_machine &machine) } //============================================================ -// drawogl_window_create +// sdl_info::create //============================================================ -static int drawogl_window_create(sdl_window_info *window, int width, int height) +int sdl_info_ogl::create(int width, int height) { - sdl_info *sdl; char *extstr; char *vendor; int has_and_allow_texturerect = 0; - // allocate memory for our structures - sdl = global_alloc(sdl_info); - - window->m_dxdata = sdl; - #if (SDLMAME_SDL2) - sdl->m_extra_flags = (window->fullscreen() ? + m_extra_flags = (window().fullscreen() ? SDL_WINDOW_BORDERLESS | SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_FULLSCREEN : SDL_WINDOW_RESIZABLE); - sdl->m_extra_flags |= SDL_WINDOW_OPENGL; + m_extra_flags |= SDL_WINDOW_OPENGL; SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); @@ -555,39 +553,39 @@ static int drawogl_window_create(sdl_window_info *window, int width, int height) */ //Moved into init - //load_gl_lib(window->machine()); + //load_gl_lib(window().machine()); // create the SDL window - window->m_sdl_window = SDL_CreateWindow(window->m_title, - window->monitor()->position_size().x, window->monitor()->position_size().y, - width, height, sdl->m_extra_flags); + window().m_sdl_window = SDL_CreateWindow(window().m_title, + window().monitor()->position_size().x, window().monitor()->position_size().y, + width, height, m_extra_flags); - if (!window->m_sdl_window ) + if (!window().m_sdl_window ) { osd_printf_error("OpenGL not supported on this driver: %s\n", SDL_GetError()); return 1; } - if (window->fullscreen() && video_config.switchres) + if (window().fullscreen() && video_config.switchres) { SDL_DisplayMode mode; - SDL_GetCurrentDisplayMode(window->monitor()->handle(), &mode); + SDL_GetCurrentDisplayMode(window().monitor()->handle(), &mode); mode.w = width; mode.h = height; - if (window->m_refresh) - mode.refresh_rate = window->m_refresh; - SDL_SetWindowDisplayMode(window->m_sdl_window, &mode); // Try to set mode + if (window().m_refresh) + mode.refresh_rate = window().m_refresh; + SDL_SetWindowDisplayMode(window().m_sdl_window, &mode); // Try to set mode } else - SDL_SetWindowDisplayMode(window->m_sdl_window, NULL); // Use desktop + SDL_SetWindowDisplayMode(window().m_sdl_window, NULL); // Use desktop - SDL_ShowWindow(window->m_sdl_window); - //SDL_SetWindowFullscreen(window->sdl_window, window->fullscreen); - SDL_RaiseWindow(window->m_sdl_window); - SDL_GetWindowSize(window->m_sdl_window, &window->m_width, &window->m_height); + SDL_ShowWindow(window().m_sdl_window); + //SDL_SetWindowFullscreen(window().sdl_window, window().fullscreen); + SDL_RaiseWindow(window().m_sdl_window); + SDL_GetWindowSize(window().m_sdl_window, &window().m_width, &window().m_height); - sdl->m_gl_context_id = SDL_GL_CreateContext(window->m_sdl_window); - if (!sdl->m_gl_context_id) + m_gl_context_id = SDL_GL_CreateContext(window().m_sdl_window); + if (!m_gl_context_id) { osd_printf_error("OpenGL not supported on this driver: %s\n", SDL_GetError()); return 1; @@ -596,49 +594,49 @@ static int drawogl_window_create(sdl_window_info *window, int width, int height) SDL_GL_SetSwapInterval(video_config.waitvsync ? 2 : 0); #else - sdl->m_extra_flags = (window->fullscreen() ? SDL_FULLSCREEN : SDL_RESIZABLE); - sdl->m_extra_flags |= SDL_OPENGL | SDL_DOUBLEBUF; + m_extra_flags = (window().fullscreen() ? SDL_FULLSCREEN : SDL_RESIZABLE); + m_extra_flags |= SDL_OPENGL | SDL_DOUBLEBUF; SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); #if (SDL_VERSION_ATLEAST(1,2,10)) && (!defined(SDLMAME_EMSCRIPTEN)) SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, video_config.waitvsync ? 1 : 0); #endif - load_gl_lib(window->machine()); + load_gl_lib(window().machine()); // create the SDL surface (which creates the window in windowed mode) - sdl->sdlsurf = SDL_SetVideoMode(m_width, m_height, - 0, SDL_SWSURFACE | SDL_ANYFORMAT | sdl->m_extra_flags); + sdlsurf = SDL_SetVideoMode(width, height, + 0, SDL_SWSURFACE | SDL_ANYFORMAT | m_extra_flags); - if (!sdl->sdlsurf) + if (!sdlsurf) return 1; - window->m_width = sdl->sdlsurf->w; - window->m_height = sdl->sdlsurf->h; + window().m_width = sdlsurf->w; + window().m_height = sdlsurf->h; - window->screen_width = 0; - window->screen_height = 0; + window().m_screen_width = 0; + window().m_screen_height = 0; - if ( (video_config.mode == VIDEO_MODE_OPENGL) && !(sdl->sdlsurf->flags & SDL_OPENGL) ) + if ( (video_config.mode == VIDEO_MODE_OPENGL) && !(sdlsurf->flags & SDL_OPENGL) ) { osd_printf_error("OpenGL not supported on this driver!\n"); return 1; } // set the window title - SDL_WM_SetCaption(window->m_title, "SDLMAME"); + SDL_WM_SetCaption(window().m_title, "SDLMAME"); #endif - sdl->m_blittimer = 0; - sdl->m_surf_w = 0; - sdl->m_surf_h = 0; + m_blittimer = 0; + m_surf_w = 0; + m_surf_h = 0; - sdl->m_initialized = 0; + m_initialized = 0; // in case any textures try to come up before these are validated, // OpenGL guarantees all implementations can handle something this size. - sdl->m_texture_max_width = 64; - sdl->m_texture_max_height = 64; + m_texture_max_width = 64; + m_texture_max_height = 64; /* load any GL function addresses * this must be done here because we need a context @@ -656,12 +654,12 @@ static int drawogl_window_create(sdl_window_info *window, int width, int height) osd_printf_verbose("OpenGL: %s\nOpenGL: %s\nOpenGL: %s\n", vendor, (char *)glGetString(GL_RENDERER), (char *)glGetString(GL_VERSION)); } - sdl->m_usetexturerect = 0; - sdl->m_texpoweroftwo = 1; - sdl->m_usevbo = 0; - sdl->m_usepbo = 0; - sdl->m_usefbo = 0; - sdl->m_useglsl = 0; + m_usetexturerect = 0; + m_texpoweroftwo = 1; + m_usevbo = 0; + m_usepbo = 0; + m_usefbo = 0; + m_useglsl = 0; if ( video_config.allowtexturerect && ( strstr(extstr, "GL_ARB_texture_rectangle") || strstr(extstr, "GL_EXT_texture_rectangle") ) @@ -681,7 +679,7 @@ static int drawogl_window_create(sdl_window_info *window, int width, int height) { osd_printf_verbose("OpenGL: non-power-of-2 textures supported (new method)\n"); } - sdl->m_texpoweroftwo = 0; + m_texpoweroftwo = 0; } else { @@ -692,7 +690,7 @@ static int drawogl_window_create(sdl_window_info *window, int width, int height) { osd_printf_verbose("OpenGL: non-power-of-2 textures supported (old method)\n"); } - sdl->m_usetexturerect = 1; + m_usetexturerect = 1; } else { @@ -705,10 +703,10 @@ static int drawogl_window_create(sdl_window_info *window, int width, int height) if (strstr(extstr, "GL_ARB_vertex_buffer_object")) { - sdl->m_usevbo = video_config.vbo; + m_usevbo = video_config.vbo; if (!shown_video_info) { - if(sdl->m_usevbo) + if(m_usevbo) osd_printf_verbose("OpenGL: vertex buffer supported\n"); else osd_printf_verbose("OpenGL: vertex buffer supported, but disabled\n"); @@ -717,12 +715,12 @@ static int drawogl_window_create(sdl_window_info *window, int width, int height) if (strstr(extstr, "GL_ARB_pixel_buffer_object")) { - if( sdl->m_usevbo ) + if( m_usevbo ) { - sdl->m_usepbo = video_config.pbo; + m_usepbo = video_config.pbo; if (!shown_video_info) { - if(sdl->m_usepbo) + if(m_usepbo) osd_printf_verbose("OpenGL: pixel buffers supported\n"); else osd_printf_verbose("OpenGL: pixel buffers supported, but disabled\n"); @@ -744,10 +742,10 @@ static int drawogl_window_create(sdl_window_info *window, int width, int height) if (strstr(extstr, "GL_EXT_framebuffer_object")) { - sdl->m_usefbo = 1; + m_usefbo = 1; if (!shown_video_info) { - if(sdl->m_usefbo) + if(m_usefbo) osd_printf_verbose("OpenGL: framebuffer object supported\n"); else osd_printf_verbose("OpenGL: framebuffer object not supported\n"); @@ -760,10 +758,10 @@ static int drawogl_window_create(sdl_window_info *window, int width, int height) strstr(extstr, "GL_ARB_fragment_shader") ) { - sdl->m_useglsl = video_config.glsl; + m_useglsl = video_config.glsl; if (!shown_video_info) { - if(sdl->m_useglsl) + if(m_useglsl) osd_printf_verbose("OpenGL: GLSL supported\n"); else osd_printf_verbose("OpenGL: GLSL supported, but disabled\n"); @@ -777,46 +775,44 @@ static int drawogl_window_create(sdl_window_info *window, int width, int height) if (osd_getenv(SDLENV_VMWARE) != NULL) { - sdl->m_usetexturerect = 1; - sdl->m_texpoweroftwo = 1; + m_usetexturerect = 1; + m_texpoweroftwo = 1; } - glGetIntegerv(GL_MAX_TEXTURE_SIZE, (GLint *)&sdl->m_texture_max_width); - glGetIntegerv(GL_MAX_TEXTURE_SIZE, (GLint *)&sdl->m_texture_max_height); + glGetIntegerv(GL_MAX_TEXTURE_SIZE, (GLint *)&m_texture_max_width); + glGetIntegerv(GL_MAX_TEXTURE_SIZE, (GLint *)&m_texture_max_height); if (!shown_video_info) { - osd_printf_verbose("OpenGL: max texture size %d x %d\n", sdl->m_texture_max_width, sdl->m_texture_max_height); + osd_printf_verbose("OpenGL: max texture size %d x %d\n", m_texture_max_width, m_texture_max_height); } shown_video_info = 1; - sdl->m_init_context = 0; + m_init_context = 0; return 0; } //============================================================ -// drawogl_window_resize +// sdl_info::resize //============================================================ -static void drawogl_window_resize(sdl_window_info *window, int width, int height) +void sdl_info_ogl::resize(int width, int height) { - sdl_info *sdl = (sdl_info *) window->m_dxdata; - #if (SDLMAME_SDL2) - //SDL_GL_MakeCurrent(window->sdl_window, sdl->gl_context_id); - SDL_SetWindowSize(window->m_sdl_window, width, height); - SDL_GetWindowSize(window->m_sdl_window, &window->m_width, &window->m_height); - sdl->m_blittimer = 3; + //SDL_GL_MakeCurrent(window().sdl_window, gl_context_id); + SDL_SetWindowSize(window().m_sdl_window, width, height); + SDL_GetWindowSize(window().m_sdl_window, &window().m_width, &window().m_height); + m_blittimer = 3; #else - SDL_FreeSurface(sdl->sdlsurf); + SDL_FreeSurface(sdlsurf); - sdl->sdlsurf = SDL_SetVideoMode(m_width, m_height, 0, - SDL_SWSURFACE | SDL_ANYFORMAT | sdl->m_extra_flags); + sdlsurf = SDL_SetVideoMode(width, height, 0, + SDL_SWSURFACE | SDL_ANYFORMAT | m_extra_flags); - window->m_width = sdl->sdlsurf->w; - window->m_height = sdl->sdlsurf->h; + window().m_width = sdlsurf->w; + window().m_height = sdlsurf->h; #endif - sdl->m_init_context = 1; + m_init_context = 1; } @@ -824,64 +820,61 @@ static void drawogl_window_resize(sdl_window_info *window, int width, int height // drawsdl_xy_to_render_target //============================================================ -static int drawogl_xy_to_render_target(sdl_window_info *window, int x, int y, int *xt, int *yt) +int sdl_info_ogl::xy_to_render_target(int x, int y, int *xt, int *yt) { - sdl_info *sdl =(sdl_info *) window->m_dxdata; - - *xt = x - sdl->m_last_hofs; - *yt = y - sdl->m_last_vofs; - if (*xt<0 || *xt >= window->m_blitwidth) + *xt = x - m_last_hofs; + *yt = y - m_last_vofs; + if (*xt<0 || *xt >= window().m_blitwidth) return 0; - if (*yt<0 || *yt >= window->m_blitheight) + if (*yt<0 || *yt >= window().m_blitheight) return 0; return 1; } //============================================================ -// drawogl_window_get_primitives +// sdl_info::get_primitives //============================================================ -static void drawogl_set_target_bounds(sdl_window_info *window) +void sdl_info_ogl::set_target_bounds() { - window->m_target->set_bounds(window->m_blitwidth, window->m_blitheight, window->monitor()->aspect()); + window().m_target->set_bounds(window().m_blitwidth, window().m_blitheight, window().monitor()->aspect()); } //============================================================ // loadGLExtensions //============================================================ -static void loadGLExtensions(sdl_window_info *window) +void sdl_info_ogl::loadGLExtensions() { - sdl_info *sdl = (sdl_info *) window->m_dxdata; static int _once = 1; - // sdl->usevbo=FALSE; // You may want to switch VBO and PBO off, by uncommenting this statement - // sdl->usepbo=FALSE; // You may want to switch PBO off, by uncommenting this statement - // sdl->useglsl=FALSE; // You may want to switch GLSL off, by uncommenting this statement + // usevbo=FALSE; // You may want to switch VBO and PBO off, by uncommenting this statement + // usepbo=FALSE; // You may want to switch PBO off, by uncommenting this statement + // useglsl=FALSE; // You may want to switch GLSL off, by uncommenting this statement - if (! sdl->m_usevbo) + if (! m_usevbo) { - if(sdl->m_usepbo) // should never ever happen ;-) + if(m_usepbo) // should never ever happen ;-) { if (_once) { osd_printf_warning("OpenGL: PBO not supported, no VBO support. (sdlmame error)\n"); } - sdl->m_usepbo=FALSE; + m_usepbo=FALSE; } - if(sdl->m_useglsl) // should never ever happen ;-) + if(m_useglsl) // should never ever happen ;-) { if (_once) { osd_printf_warning("OpenGL: GLSL not supported, no VBO support. (sdlmame error)\n"); } - sdl->m_useglsl=FALSE; + m_useglsl=FALSE; } } // Get Pointers To The GL Functions // VBO: - if( sdl->m_usevbo ) + if( m_usevbo ) { pfn_glGenBuffers = (PFNGLGENBUFFERSPROC) SDL_GL_GetProcAddress("glGenBuffers"); pfn_glDeleteBuffers = (PFNGLDELETEBUFFERSPROC) SDL_GL_GetProcAddress("glDeleteBuffers"); @@ -890,13 +883,13 @@ static void loadGLExtensions(sdl_window_info *window) pfn_glBufferSubData = (PFNGLBUFFERSUBDATAPROC) SDL_GL_GetProcAddress("glBufferSubData"); } // PBO: - if ( sdl->m_usepbo ) + if ( m_usepbo ) { pfn_glMapBuffer = (PFNGLMAPBUFFERPROC) SDL_GL_GetProcAddress("glMapBuffer"); pfn_glUnmapBuffer= (PFNGLUNMAPBUFFERPROC) SDL_GL_GetProcAddress("glUnmapBuffer"); } // FBO: - if ( sdl->m_usefbo ) + if ( m_usefbo ) { pfn_glIsFramebuffer = (PFNGLISFRAMEBUFFEREXTPROC) SDL_GL_GetProcAddress("glIsFramebufferEXT"); pfn_glBindFramebuffer = (PFNGLBINDFRAMEBUFFEREXTPROC) SDL_GL_GetProcAddress("glBindFramebufferEXT"); @@ -906,12 +899,12 @@ static void loadGLExtensions(sdl_window_info *window) pfn_glFramebufferTexture2D = (PFNGLFRAMEBUFFERTEXTURE2DEXTPROC) SDL_GL_GetProcAddress("glFramebufferTexture2DEXT"); } - if ( sdl->m_usevbo && + if ( m_usevbo && ( !pfn_glGenBuffers || !pfn_glDeleteBuffers || !pfn_glBindBuffer || !pfn_glBufferData || !pfn_glBufferSubData ) ) { - sdl->m_usepbo=FALSE; + m_usepbo=FALSE; if (_once) { osd_printf_warning("OpenGL: VBO not supported, missing: "); @@ -937,19 +930,19 @@ static void loadGLExtensions(sdl_window_info *window) } osd_printf_warning("\n"); } - if ( sdl->m_usevbo ) + if ( m_usevbo ) { if (_once) { osd_printf_warning("OpenGL: PBO not supported, no VBO support.\n"); } - sdl->m_usepbo=FALSE; + m_usepbo=FALSE; } } - if ( sdl->m_usepbo && ( !pfn_glMapBuffer || !pfn_glUnmapBuffer ) ) + if ( m_usepbo && ( !pfn_glMapBuffer || !pfn_glUnmapBuffer ) ) { - sdl->m_usepbo=FALSE; + m_usepbo=FALSE; if (_once) { osd_printf_warning("OpenGL: PBO not supported, missing: "); @@ -965,12 +958,12 @@ static void loadGLExtensions(sdl_window_info *window) } } - if ( sdl->m_usefbo && + if ( m_usefbo && ( !pfn_glIsFramebuffer || !pfn_glBindFramebuffer || !pfn_glDeleteFramebuffers || !pfn_glGenFramebuffers || !pfn_glCheckFramebufferStatus || !pfn_glFramebufferTexture2D )) { - sdl->m_usefbo=FALSE; + m_usefbo=FALSE; if (_once) { osd_printf_warning("OpenGL: FBO not supported, missing: "); @@ -1004,7 +997,7 @@ static void loadGLExtensions(sdl_window_info *window) if (_once) { - if ( sdl->m_usevbo ) + if ( m_usevbo ) { osd_printf_verbose("OpenGL: VBO supported\n"); } @@ -1013,7 +1006,7 @@ static void loadGLExtensions(sdl_window_info *window) osd_printf_warning("OpenGL: VBO not supported\n"); } - if ( sdl->m_usepbo ) + if ( m_usepbo ) { osd_printf_verbose("OpenGL: PBO supported\n"); } @@ -1022,7 +1015,7 @@ static void loadGLExtensions(sdl_window_info *window) osd_printf_warning("OpenGL: PBO not supported\n"); } - if ( sdl->m_usefbo ) + if ( m_usefbo ) { osd_printf_verbose("OpenGL: FBO supported\n"); } @@ -1032,7 +1025,7 @@ static void loadGLExtensions(sdl_window_info *window) } } - if ( sdl->m_useglsl ) + if ( m_useglsl ) { #ifdef GL_ARB_multitexture pfn_glActiveTexture = (PFNGLACTIVETEXTUREARBPROC) SDL_GL_GetProcAddress("glActiveTextureARB"); @@ -1045,16 +1038,16 @@ static void loadGLExtensions(sdl_window_info *window) { osd_printf_warning("OpenGL: GLSL disabled, glActiveTexture(ARB) not supported\n"); } - sdl->m_useglsl = 0; + m_useglsl = 0; } } - if ( sdl->m_useglsl ) + if ( m_useglsl ) { - sdl->m_glsl = glsl_shader_init(); - sdl->m_useglsl = (sdl->m_glsl != NULL ? 1 : 0); + m_glsl = glsl_shader_init(); + m_useglsl = (m_glsl != NULL ? 1 : 0); - if ( ! sdl->m_useglsl ) + if ( ! m_useglsl ) { if (_once) { @@ -1063,11 +1056,11 @@ static void loadGLExtensions(sdl_window_info *window) } } - if ( sdl->m_useglsl ) + if ( m_useglsl ) { - if ( window->m_prescale != 1 ) + if ( window().m_prescale != 1 ) { - sdl->m_useglsl = 0; + m_useglsl = 0; if (_once) { osd_printf_warning("OpenGL: GLSL supported, but disabled due to: prescale !=1 \n"); @@ -1075,17 +1068,17 @@ static void loadGLExtensions(sdl_window_info *window) } } - if ( sdl->m_useglsl ) + if ( m_useglsl ) { int i; video_config.filter = FALSE; glsl_shader_feature = GLSL_SHADER_FEAT_PLAIN; - sdl->m_glsl_program_num = 0; - sdl->m_glsl_program_mb2sc = 0; + m_glsl_program_num = 0; + m_glsl_program_mb2sc = 0; for(i=0; im_usefbo && sdl->m_glsl_program_num==1 ) + if ( !m_usefbo && m_glsl_program_num==1 ) { if (_once) { @@ -1094,7 +1087,7 @@ static void loadGLExtensions(sdl_window_info *window) break; } - if ( glsl_shader_add_mamebm(sdl->m_glsl, video_config.glsl_shader_mamebm[i], sdl->m_glsl_program_num) ) + if ( glsl_shader_add_mamebm(m_glsl, video_config.glsl_shader_mamebm[i], m_glsl_program_num) ) { osd_printf_error("OpenGL: GLSL loading mame bitmap shader %d failed (%s)\n", i, video_config.glsl_shader_mamebm[i]); @@ -1103,22 +1096,22 @@ static void loadGLExtensions(sdl_window_info *window) if (_once) { osd_printf_verbose("OpenGL: GLSL using mame bitmap shader filter %d: '%s'\n", - sdl->m_glsl_program_num, video_config.glsl_shader_mamebm[i]); + m_glsl_program_num, video_config.glsl_shader_mamebm[i]); } - sdl->m_glsl_program_mb2sc = sdl->m_glsl_program_num; // the last mame_bitmap (mb) shader does it. - sdl->m_glsl_program_num++; + m_glsl_program_mb2sc = m_glsl_program_num; // the last mame_bitmap (mb) shader does it. + m_glsl_program_num++; } } - if ( video_config.glsl_shader_scrn_num > 0 && sdl->m_glsl_program_num==0 ) + if ( video_config.glsl_shader_scrn_num > 0 && m_glsl_program_num==0 ) { osd_printf_verbose("OpenGL: GLSL cannot use screen bitmap shader without bitmap shader\n"); } - for(i=0; sdl->m_usefbo && sdl->m_glsl_program_num>0 && i0 && im_glsl, video_config.glsl_shader_scrn[i], - sdl->m_glsl_program_num-1-sdl->m_glsl_program_mb2sc) ) + if ( glsl_shader_add_scrn(m_glsl, video_config.glsl_shader_scrn[i], + m_glsl_program_num-1-m_glsl_program_mb2sc) ) { osd_printf_error("OpenGL: GLSL loading screen bitmap shader %d failed (%s)\n", i, video_config.glsl_shader_scrn[i]); @@ -1126,24 +1119,24 @@ static void loadGLExtensions(sdl_window_info *window) if (_once) { osd_printf_verbose("OpenGL: GLSL using screen bitmap shader filter %d: '%s'\n", - sdl->m_glsl_program_num, video_config.glsl_shader_scrn[i]); + m_glsl_program_num, video_config.glsl_shader_scrn[i]); } - sdl->m_glsl_program_num++; + m_glsl_program_num++; } } - if ( 0==sdl->m_glsl_program_num && + if ( 0==m_glsl_program_num && 0 <= video_config.glsl_filter && video_config.glsl_filter < GLSL_SHADER_FEAT_INT_NUMBER ) { - sdl->m_glsl_program_mb2sc = sdl->m_glsl_program_num; // the last mame_bitmap (mb) shader does it. - sdl->m_glsl_program_num++; + m_glsl_program_mb2sc = m_glsl_program_num; // the last mame_bitmap (mb) shader does it. + m_glsl_program_num++; glsl_shader_feature = video_config.glsl_filter; if (_once) { osd_printf_verbose("OpenGL: GLSL using shader filter '%s', idx: %d, num %d (vid filter: %d)\n", glsl_shader_get_filter_name_mamebm(glsl_shader_feature), - glsl_shader_feature, sdl->m_glsl_program_num, video_config.filter); + glsl_shader_feature, m_glsl_program_num, video_config.filter); } } @@ -1158,12 +1151,11 @@ static void loadGLExtensions(sdl_window_info *window) } //============================================================ -// drawogl_window_draw +// sdl_info::draw //============================================================ -static int drawogl_window_draw(sdl_window_info *window, UINT32 dc, int update) +int sdl_info_ogl::draw(UINT32 dc, int update) { - sdl_info *sdl = (sdl_info *) window->m_dxdata; render_primitive *prim; texture_info *texture=NULL; float vofs, hofs; @@ -1176,22 +1168,22 @@ static int drawogl_window_draw(sdl_window_info *window, UINT32 dc, int update) } #if (SDLMAME_SDL2) - SDL_GL_MakeCurrent(window->m_sdl_window, sdl->m_gl_context_id); + SDL_GL_MakeCurrent(window().m_sdl_window, m_gl_context_id); #else - if (!sdl->m_init_context) + if (!m_init_context) { - screen_device_iterator myiter(window->machine().root_device()); + screen_device_iterator myiter(window().machine().root_device()); for (screen = myiter.first(); screen != NULL; screen = myiter.next()) { - if (window->index() == 0) + if (window().index() == 0) { - if ((screen->m_width() != window->screen_width) || (screen->m_height() != window->screen_height)) + if ((screen->width() != window().m_screen_width) || (screen->height() != window().m_screen_height)) { - window->screen_width = screen->m_width(); - window->screen_height = screen->m_height(); + window().m_screen_width = screen->width(); + window().m_screen_height = screen->height(); // force all textures to be regenerated - drawogl_destroy_all_textures(window); + destroy_all_textures(); } break; } @@ -1199,7 +1191,7 @@ static int drawogl_window_draw(sdl_window_info *window, UINT32 dc, int update) } #endif - if (sdl->m_init_context) + if (m_init_context) { // do some one-time OpenGL setup #if (SDLMAME_SDL2) @@ -1217,10 +1209,10 @@ static int drawogl_window_draw(sdl_window_info *window, UINT32 dc, int update) // figure out if we're vector scrnum = is_vector = 0; - screen_device_iterator iter(window->machine().root_device()); + screen_device_iterator iter(window().machine().root_device()); for (screen = iter.first(); screen != NULL; screen = iter.next()) { - if (scrnum == window->index()) + if (scrnum == window().index()) { is_vector = (screen->screen_type() == SCREEN_TYPE_VECTOR) ? 1 : 0; break; @@ -1232,27 +1224,27 @@ static int drawogl_window_draw(sdl_window_info *window, UINT32 dc, int update) } // only clear if the geometry changes (and for 2 frames afterward to clear double and triple buffers) - if ((sdl->m_blittimer > 0) || (is_vector)) + if ((m_blittimer > 0) || (is_vector)) { glClear(GL_COLOR_BUFFER_BIT); - sdl->m_blittimer--; + m_blittimer--; } - if ( !sdl->m_initialized || - window->m_width!= sdl->m_surf_w || window->m_height!= sdl->m_surf_h ) + if ( !m_initialized || + window().m_width!= m_surf_w || window().m_height!= m_surf_h ) { - if ( !sdl->m_initialized ) + if ( !m_initialized ) { - loadGLExtensions(window); + loadGLExtensions(); } - sdl->m_surf_w=window->m_width; - sdl->m_surf_h=window->m_height; + m_surf_w=window().m_width; + m_surf_h=window().m_height; // we're doing nothing 3d, so the Z-buffer is currently not interesting glDisable(GL_DEPTH_TEST); - if (window->machine().options().antialias()) + if (window().machine().options().antialias()) { // enable antialiasing for lines glEnable(GL_LINE_SMOOTH); @@ -1272,7 +1264,7 @@ static int drawogl_window_draw(sdl_window_info *window, UINT32 dc, int update) // enable blending glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - sdl->m_last_blendmode = BLENDMODE_ALPHA; + m_last_blendmode = BLENDMODE_ALPHA; // set lines and points just barely above normal size to get proper results glLineWidth(video_config.beamwidth); @@ -1288,19 +1280,19 @@ static int drawogl_window_draw(sdl_window_info *window, UINT32 dc, int update) // |_________| // (0,h) (w,h) - glViewport(0.0, 0.0, (GLsizei)window->m_width, (GLsizei)window->m_height); + glViewport(0.0, 0.0, (GLsizei)window().m_width, (GLsizei)window().m_height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); - glOrtho(0.0, (GLdouble)window->m_width, (GLdouble)window->m_height, 0.0, 0.0, -1.0); + glOrtho(0.0, (GLdouble)window().m_width, (GLdouble)window().m_height, 0.0, 0.0, -1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); - if ( ! sdl->m_initialized ) + if ( ! m_initialized ) { glEnableClientState(GL_VERTEX_ARRAY); - glVertexPointer(2, GL_FLOAT, 0, sdl->m_texVerticex); // no VBO, since it's too volatile + glVertexPointer(2, GL_FLOAT, 0, m_texVerticex); // no VBO, since it's too volatile - sdl->m_initialized = 1; + m_initialized = 1; } } @@ -1311,34 +1303,34 @@ static int drawogl_window_draw(sdl_window_info *window, UINT32 dc, int update) { int ch, cw; - if ((window->fullscreen()) && (!video_config.switchres)) + if ((window().fullscreen()) && (!video_config.switchres)) { - ch = window->monitor()->center_height(); - cw = window->monitor()->center_width(); + ch = window().monitor()->center_height(); + cw = window().monitor()->center_width(); } else { - ch = window->m_height; - cw = window->m_width; + ch = window().m_height; + cw = window().m_width; } if (video_config.centerv) { - vofs = (ch - window->m_blitheight) / 2.0f; + vofs = (ch - window().m_blitheight) / 2.0f; } if (video_config.centerh) { - hofs = (cw - window->m_blitwidth) / 2.0f; + hofs = (cw - window().m_blitwidth) / 2.0f; } } - sdl->m_last_hofs = hofs; - sdl->m_last_vofs = vofs; + m_last_hofs = hofs; + m_last_vofs = vofs; - window->m_primlist->acquire_lock(); + window().m_primlist->acquire_lock(); // now draw - for (prim = window->m_primlist->first(); prim != NULL; prim = prim->next()) + for (prim = window().m_primlist->first(); prim != NULL; prim = prim->next()) { int i; @@ -1366,7 +1358,7 @@ static int drawogl_window_draw(sdl_window_info *window, UINT32 dc, int update) if ( pendingPrimitive==GL_NO_PRIMITIVE ) { - set_blendmode(sdl, PRIMFLAG_GET_BLENDMODE(prim->flags)); + set_blendmode(PRIMFLAG_GET_BLENDMODE(prim->flags)); } glColor4f(prim->color.r, prim->color.g, prim->color.b, prim->color.a); @@ -1486,59 +1478,59 @@ static int drawogl_window_draw(sdl_window_info *window, UINT32 dc, int update) glColor4f(prim->color.r, prim->color.g, prim->color.b, prim->color.a); - set_blendmode(sdl, PRIMFLAG_GET_BLENDMODE(prim->flags)); + set_blendmode(PRIMFLAG_GET_BLENDMODE(prim->flags)); - texture = texture_update(window, prim, 0); + texture = texture_update(prim, 0); if ( texture && texture->type==TEXTURE_TYPE_SHADER ) { - for(i=0; im_glsl_program_num; i++) + for(i=0; im_glsl_program_mb2sc ) + if ( i==m_glsl_program_mb2sc ) { - // i==sdl->glsl_program_mb2sc -> transformation mamebm->scrn - sdl->m_texVerticex[0]=prim->bounds.x0 + hofs; - sdl->m_texVerticex[1]=prim->bounds.y0 + vofs; - sdl->m_texVerticex[2]=prim->bounds.x1 + hofs; - sdl->m_texVerticex[3]=prim->bounds.y0 + vofs; - sdl->m_texVerticex[4]=prim->bounds.x1 + hofs; - sdl->m_texVerticex[5]=prim->bounds.y1 + vofs; - sdl->m_texVerticex[6]=prim->bounds.x0 + hofs; - sdl->m_texVerticex[7]=prim->bounds.y1 + vofs; + // i==glsl_program_mb2sc -> transformation mamebm->scrn + m_texVerticex[0]=prim->bounds.x0 + hofs; + m_texVerticex[1]=prim->bounds.y0 + vofs; + m_texVerticex[2]=prim->bounds.x1 + hofs; + m_texVerticex[3]=prim->bounds.y0 + vofs; + m_texVerticex[4]=prim->bounds.x1 + hofs; + m_texVerticex[5]=prim->bounds.y1 + vofs; + m_texVerticex[6]=prim->bounds.x0 + hofs; + m_texVerticex[7]=prim->bounds.y1 + vofs; } else { // 1:1 tex coord CCW (0/0) (1/0) (1/1) (0/1) on texture dimensions - sdl->m_texVerticex[0]=(GLfloat)0.0; - sdl->m_texVerticex[1]=(GLfloat)0.0; - sdl->m_texVerticex[2]=(GLfloat)window->m_width; - sdl->m_texVerticex[3]=(GLfloat)0.0; - sdl->m_texVerticex[4]=(GLfloat)window->m_width; - sdl->m_texVerticex[5]=(GLfloat)window->m_height; - sdl->m_texVerticex[6]=(GLfloat)0.0; - sdl->m_texVerticex[7]=(GLfloat)window->m_height; + m_texVerticex[0]=(GLfloat)0.0; + m_texVerticex[1]=(GLfloat)0.0; + m_texVerticex[2]=(GLfloat)window().m_width; + m_texVerticex[3]=(GLfloat)0.0; + m_texVerticex[4]=(GLfloat)window().m_width; + m_texVerticex[5]=(GLfloat)window().m_height; + m_texVerticex[6]=(GLfloat)0.0; + m_texVerticex[7]=(GLfloat)window().m_height; } if(i>0) // first fetch already done { - texture = texture_update(window, prim, i); + texture = texture_update(prim, i); } glDrawArrays(GL_QUADS, 0, 4); } } else { - sdl->m_texVerticex[0]=prim->bounds.x0 + hofs; - sdl->m_texVerticex[1]=prim->bounds.y0 + vofs; - sdl->m_texVerticex[2]=prim->bounds.x1 + hofs; - sdl->m_texVerticex[3]=prim->bounds.y0 + vofs; - sdl->m_texVerticex[4]=prim->bounds.x1 + hofs; - sdl->m_texVerticex[5]=prim->bounds.y1 + vofs; - sdl->m_texVerticex[6]=prim->bounds.x0 + hofs; - sdl->m_texVerticex[7]=prim->bounds.y1 + vofs; + m_texVerticex[0]=prim->bounds.x0 + hofs; + m_texVerticex[1]=prim->bounds.y0 + vofs; + m_texVerticex[2]=prim->bounds.x1 + hofs; + m_texVerticex[3]=prim->bounds.y0 + vofs; + m_texVerticex[4]=prim->bounds.x1 + hofs; + m_texVerticex[5]=prim->bounds.y1 + vofs; + m_texVerticex[6]=prim->bounds.x0 + hofs; + m_texVerticex[7]=prim->bounds.y1 + vofs; glDrawArrays(GL_QUADS, 0, 4); } if ( texture ) { - texture_disable(sdl, texture); + texture_disable(texture); texture=NULL; } break; @@ -1554,13 +1546,13 @@ static int drawogl_window_draw(sdl_window_info *window, UINT32 dc, int update) pendingPrimitive=GL_NO_PRIMITIVE; } - window->m_primlist->release_lock(); - sdl->m_init_context = 0; + window().m_primlist->release_lock(); + m_init_context = 0; #if (!SDLMAME_SDL2) SDL_GL_SwapBuffers(); #else - SDL_GL_SwapWindow(window->m_sdl_window); + SDL_GL_SwapWindow(window().m_sdl_window); #endif return 0; } @@ -1626,34 +1618,26 @@ static void drawogl_exit(void) } //============================================================ -// drawogl_window_destroy +// sdl_info::destroy //============================================================ -static void drawogl_window_destroy(sdl_window_info *window) +void sdl_info_ogl::destroy() { - sdl_info *sdl = (sdl_info *) window->m_dxdata; - - // skip if nothing - if (sdl == NULL) - return; // free the memory in the window - drawogl_destroy_all_textures(window); + destroy_all_textures(); #if (SDLMAME_SDL2) - SDL_GL_DeleteContext(sdl->m_gl_context_id); - SDL_DestroyWindow(window->m_sdl_window); + SDL_GL_DeleteContext(m_gl_context_id); + SDL_DestroyWindow(window().m_sdl_window); #else - if (sdl->sdlsurf) + if (sdlsurf) { - SDL_FreeSurface(sdl->sdlsurf); - sdl->sdlsurf = NULL; + SDL_FreeSurface(sdlsurf); + sdlsurf = NULL; } #endif - - global_free(sdl); - window->m_dxdata = NULL; } //============================================================ @@ -1667,7 +1651,7 @@ static void drawogl_window_destroy(sdl_window_info *window) // we also don't want to use PBO's in the case of nocopy==TRUE, // since we now might have GLSL shaders - this decision simplifies out life ;-) // -static void texture_compute_type_subroutine(sdl_info *sdl, const render_texinfo *texsource, texture_info *texture, UINT32 flags) +void sdl_info_ogl::texture_compute_type_subroutine(const render_texinfo *texsource, texture_info *texture, UINT32 flags) { texture->type = TEXTURE_TYPE_NONE; texture->nocopy = FALSE; @@ -1676,17 +1660,17 @@ static void texture_compute_type_subroutine(sdl_info *sdl, const render_texinfo !PRIMFLAG_GET_SCREENTEX(flags)) { texture->type = TEXTURE_TYPE_PLAIN; - texture->texTarget = (sdl->m_usetexturerect)?GL_TEXTURE_RECTANGLE_ARB:GL_TEXTURE_2D; - texture->texpow2 = (sdl->m_usetexturerect)?0:sdl->m_texpoweroftwo; + texture->texTarget = (m_usetexturerect)?GL_TEXTURE_RECTANGLE_ARB:GL_TEXTURE_2D; + texture->texpow2 = (m_usetexturerect)?0:m_texpoweroftwo; } - if ( texture->type == TEXTURE_TYPE_NONE && sdl->m_useglsl && + if ( texture->type == TEXTURE_TYPE_NONE && m_useglsl && texture->xprescale == 1 && texture->yprescale == 1 && - texsource->rowpixels <= sdl->m_texture_max_width ) + texsource->rowpixels <= m_texture_max_width ) { texture->type = TEXTURE_TYPE_SHADER; texture->texTarget = GL_TEXTURE_2D; - texture->texpow2 = sdl->m_texpoweroftwo; + texture->texpow2 = m_texpoweroftwo; } // determine if we can skip the copy step @@ -1695,24 +1679,24 @@ static void texture_compute_type_subroutine(sdl_info *sdl, const render_texinfo !texture_copy_properties[texture->format][SDL_TEXFORMAT_SRC_HAS_PALETTE] && texture->xprescale == 1 && texture->yprescale == 1 && !texture->borderpix && !texsource->palette() && - texsource->rowpixels <= sdl->m_texture_max_width ) + texsource->rowpixels <= m_texture_max_width ) { texture->nocopy = TRUE; } if( texture->type == TEXTURE_TYPE_NONE && - sdl->m_usepbo && !texture->nocopy ) + m_usepbo && !texture->nocopy ) { texture->type = TEXTURE_TYPE_DYNAMIC; - texture->texTarget = (sdl->m_usetexturerect)?GL_TEXTURE_RECTANGLE_ARB:GL_TEXTURE_2D; - texture->texpow2 = (sdl->m_usetexturerect)?0:sdl->m_texpoweroftwo; + texture->texTarget = (m_usetexturerect)?GL_TEXTURE_RECTANGLE_ARB:GL_TEXTURE_2D; + texture->texpow2 = (m_usetexturerect)?0:m_texpoweroftwo; } if( texture->type == TEXTURE_TYPE_NONE ) { texture->type = TEXTURE_TYPE_SURFACE; - texture->texTarget = (sdl->m_usetexturerect)?GL_TEXTURE_RECTANGLE_ARB:GL_TEXTURE_2D; - texture->texpow2 = (sdl->m_usetexturerect)?0:sdl->m_texpoweroftwo; + texture->texTarget = (m_usetexturerect)?GL_TEXTURE_RECTANGLE_ARB:GL_TEXTURE_2D; + texture->texpow2 = (m_usetexturerect)?0:m_texpoweroftwo; } } @@ -1721,11 +1705,10 @@ INLINE int get_valid_pow2_value(int v, int needPow2) return (needPow2)?gl_round_to_pow2(v):v; } -static void texture_compute_size_subroutine(sdl_window_info *window, texture_info *texture, UINT32 flags, +void sdl_info_ogl::texture_compute_size_subroutine(texture_info *texture, UINT32 flags, UINT32 width, UINT32 height, int* p_width, int* p_height, int* p_width_create, int* p_height_create) { - sdl_info *sdl = (sdl_info *) window->m_dxdata; int width_create; int height_create; @@ -1746,12 +1729,12 @@ static void texture_compute_size_subroutine(sdl_window_info *window, texture_inf } // don't prescale above max texture size - while (texture->xprescale > 1 && width_create * texture->xprescale > sdl->m_texture_max_width) + while (texture->xprescale > 1 && width_create * texture->xprescale > m_texture_max_width) texture->xprescale--; - while (texture->yprescale > 1 && height_create * texture->yprescale > sdl->m_texture_max_height) + while (texture->yprescale > 1 && height_create * texture->yprescale > m_texture_max_height) texture->yprescale--; - if (PRIMFLAG_GET_SCREENTEX(flags) && (texture->xprescale != window->m_prescale || texture->yprescale != window->m_prescale)) - osd_printf_warning("SDL: adjusting prescale from %dx%d to %dx%d\n", window->m_prescale, window->m_prescale, texture->xprescale, texture->yprescale); + if (PRIMFLAG_GET_SCREENTEX(flags) && (texture->xprescale != window().m_prescale || texture->yprescale != window().m_prescale)) + osd_printf_warning("SDL: adjusting prescale from %dx%d to %dx%d\n", window().m_prescale, window().m_prescale, texture->xprescale, texture->yprescale); width *= texture->xprescale; height *= texture->yprescale; @@ -1773,9 +1756,8 @@ static void texture_compute_size_subroutine(sdl_window_info *window, texture_inf *p_height_create=height_create; } -static void texture_compute_size_type(sdl_window_info *window, const render_texinfo *texsource, texture_info *texture, UINT32 flags) +void sdl_info_ogl::texture_compute_size_type(const render_texinfo *texsource, texture_info *texture, UINT32 flags) { - sdl_info *sdl = (sdl_info *) window->m_dxdata; int finalheight, finalwidth; int finalheight_create, finalwidth_create; @@ -1786,30 +1768,30 @@ static void texture_compute_size_type(sdl_window_info *window, const render_texi texture->borderpix = 0; // don't border the screen right now, there's a bug } - texture_compute_type_subroutine(sdl, texsource, texture, flags); + texture_compute_type_subroutine(texsource, texture, flags); - texture_compute_size_subroutine(window, texture, flags, texsource->width, texsource->height, + texture_compute_size_subroutine(texture, flags, texsource->width, texsource->height, &finalwidth, &finalheight, &finalwidth_create, &finalheight_create); // if we added pixels for the border, and that just barely pushed us over, take it back if (texture->borderpix && - ((finalwidth > sdl->m_texture_max_width && finalwidth - 2 <= sdl->m_texture_max_width) || - (finalheight > sdl->m_texture_max_height && finalheight - 2 <= sdl->m_texture_max_height))) + ((finalwidth > m_texture_max_width && finalwidth - 2 <= m_texture_max_width) || + (finalheight > m_texture_max_height && finalheight - 2 <= m_texture_max_height))) { texture->borderpix = FALSE; - texture_compute_type_subroutine(sdl, texsource, texture, flags); + texture_compute_type_subroutine(texsource, texture, flags); - texture_compute_size_subroutine(window, texture, flags, texsource->width, texsource->height, + texture_compute_size_subroutine(texture, flags, texsource->width, texsource->height, &finalwidth, &finalheight, &finalwidth_create, &finalheight_create); } // if we're above the max width/height, do what? - if (finalwidth_create > sdl->m_texture_max_width || finalheight_create > sdl->m_texture_max_height) + if (finalwidth_create > m_texture_max_width || finalheight_create > m_texture_max_height) { static int printed = FALSE; if (!printed) - 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); + 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); printed = TRUE; } @@ -1831,7 +1813,7 @@ static void texture_compute_size_type(sdl_window_info *window, const render_texi (int)texture_copy_properties[texture->format][SDL_TEXFORMAT_SRC_EQUALS_DEST], (int)texture_copy_properties[texture->format][SDL_TEXFORMAT_SRC_HAS_PALETTE], texture->xprescale, texture->yprescale, - texture->borderpix, texsource->rowpixels, finalwidth, sdl->m_texture_max_width, + texture->borderpix, texsource->rowpixels, finalwidth, m_texture_max_width, (int)sizeof(UINT32) ); } @@ -1927,23 +1909,21 @@ static int texture_fbo_create(UINT32 text_unit, UINT32 text_name, UINT32 fbo_nam return 0; } -static int texture_shader_create(sdl_window_info *window, - const render_texinfo *texsource, texture_info *texture, UINT32 flags) +int sdl_info_ogl::texture_shader_create(const render_texinfo *texsource, texture_info *texture, UINT32 flags) { - sdl_info *sdl = (sdl_info *) window->m_dxdata; int uniform_location; int i; - int surf_w_pow2 = get_valid_pow2_value (window->m_blitwidth, texture->texpow2); - int surf_h_pow2 = get_valid_pow2_value (window->m_blitheight, texture->texpow2); + int surf_w_pow2 = get_valid_pow2_value (window().m_blitwidth, texture->texpow2); + int surf_h_pow2 = get_valid_pow2_value (window().m_blitheight, texture->texpow2); assert ( texture->type==TEXTURE_TYPE_SHADER ); GL_CHECK_ERROR_QUIET(); - if( sdl->m_glsl_program_num > 1 ) + if( m_glsl_program_num > 1 ) { // multipass mode - assert(sdl->m_usefbo); + assert(m_usefbo); // GL_TEXTURE3 GLSL Uniforms texture->mpass_dest_idx = 0; @@ -1951,50 +1931,50 @@ static int texture_shader_create(sdl_window_info *window, texture->mpass_textureunit[1] = GL_TEXTURE2; } - for(i=0; im_glsl_program_num; i++) + for(i=0; im_glsl_program_mb2sc ) + if ( i<=m_glsl_program_mb2sc ) { - sdl->m_glsl_program[i] = glsl_shader_get_program_mamebm(glsl_shader_feature, i); + m_glsl_program[i] = glsl_shader_get_program_mamebm(glsl_shader_feature, i); } else { - sdl->m_glsl_program[i] = glsl_shader_get_program_scrn(i-1-sdl->m_glsl_program_mb2sc); + m_glsl_program[i] = glsl_shader_get_program_scrn(i-1-m_glsl_program_mb2sc); } - pfn_glUseProgramObjectARB(sdl->m_glsl_program[i]); + pfn_glUseProgramObjectARB(m_glsl_program[i]); - if ( i<=sdl->m_glsl_program_mb2sc ) + if ( i<=m_glsl_program_mb2sc ) { // GL_TEXTURE0 GLSL Uniforms - uniform_location = pfn_glGetUniformLocationARB(sdl->m_glsl_program[i], "color_texture"); + uniform_location = pfn_glGetUniformLocationARB(m_glsl_program[i], "color_texture"); pfn_glUniform1iARB(uniform_location, 0); GL_CHECK_ERROR_NORMAL(); } { GLfloat color_texture_sz[2] = { (GLfloat)texture->rawwidth, (GLfloat)texture->rawheight }; - uniform_location = pfn_glGetUniformLocationARB(sdl->m_glsl_program[i], "color_texture_sz"); + uniform_location = pfn_glGetUniformLocationARB(m_glsl_program[i], "color_texture_sz"); pfn_glUniform2fvARB(uniform_location, 1, &(color_texture_sz[0])); GL_CHECK_ERROR_NORMAL(); } GLfloat color_texture_pow2_sz[2] = { (GLfloat)texture->rawwidth_create, (GLfloat)texture->rawheight_create }; - uniform_location = pfn_glGetUniformLocationARB(sdl->m_glsl_program[i], "color_texture_pow2_sz"); + uniform_location = pfn_glGetUniformLocationARB(m_glsl_program[i], "color_texture_pow2_sz"); pfn_glUniform2fvARB(uniform_location, 1, &(color_texture_pow2_sz[0])); GL_CHECK_ERROR_NORMAL(); - GLfloat screen_texture_sz[2] = { (GLfloat)window->m_blitwidth, (GLfloat)window->m_blitheight }; - uniform_location = pfn_glGetUniformLocationARB(sdl->m_glsl_program[i], "screen_texture_sz"); + GLfloat screen_texture_sz[2] = { (GLfloat)window().m_blitwidth, (GLfloat)window().m_blitheight }; + uniform_location = pfn_glGetUniformLocationARB(m_glsl_program[i], "screen_texture_sz"); pfn_glUniform2fvARB(uniform_location, 1, &(screen_texture_sz[0])); GL_CHECK_ERROR_NORMAL(); GLfloat screen_texture_pow2_sz[2] = { (GLfloat)surf_w_pow2, (GLfloat)surf_h_pow2 }; - uniform_location = pfn_glGetUniformLocationARB(sdl->m_glsl_program[i], "screen_texture_pow2_sz"); + uniform_location = pfn_glGetUniformLocationARB(m_glsl_program[i], "screen_texture_pow2_sz"); pfn_glUniform2fvARB(uniform_location, 1, &(screen_texture_pow2_sz[0])); GL_CHECK_ERROR_NORMAL(); } - pfn_glUseProgramObjectARB(sdl->m_glsl_program[0]); // start with 1st shader + pfn_glUseProgramObjectARB(m_glsl_program[0]); // start with 1st shader - if( sdl->m_glsl_program_num > 1 ) + if( m_glsl_program_num > 1 ) { // multipass mode // GL_TEXTURE2/GL_TEXTURE3 @@ -2018,7 +1998,7 @@ static int texture_shader_create(sdl_window_info *window, texture->rawwidth, texture->rawheight, texture->rawwidth_create, texture->rawheight_create); } - if( sdl->m_glsl_program_num > 1 && sdl->m_glsl_program_mb2sc < sdl->m_glsl_program_num - 1 ) + if( m_glsl_program_num > 1 && m_glsl_program_mb2sc < m_glsl_program_num - 1 ) { // multipass mode // GL_TEXTURE2/GL_TEXTURE3 @@ -2037,7 +2017,7 @@ static int texture_shader_create(sdl_window_info *window, } osd_printf_verbose("GL texture: mpass screen-bmp 2x %dx%d (pow2 %dx%d)\n", - window->m_width, window->m_height, surf_w_pow2, surf_h_pow2); + window().m_width, window().m_height, surf_w_pow2, surf_h_pow2); } // GL_TEXTURE0 @@ -2102,9 +2082,8 @@ static int texture_shader_create(sdl_window_info *window, return 0; } -static texture_info *texture_create(sdl_window_info *window, const render_texinfo *texsource, UINT32 flags) +texture_info *sdl_info_ogl::texture_create(const render_texinfo *texsource, UINT32 flags) { - sdl_info *sdl = (sdl_info *) window->m_dxdata; texture_info *texture; // allocate a new texture @@ -2117,8 +2096,8 @@ static texture_info *texture_create(sdl_window_info *window, const render_texinf texture->texinfo.seqid = -1; // force set data if (PRIMFLAG_GET_SCREENTEX(flags)) { - texture->xprescale = window->m_prescale; - texture->yprescale = window->m_prescale; + texture->xprescale = window().m_prescale; + texture->yprescale = window().m_prescale; } else { @@ -2169,18 +2148,18 @@ static texture_info *texture_create(sdl_window_info *window, const render_texinf } // compute the size - texture_compute_size_type(window, texsource, texture, flags); + texture_compute_size_type(texsource, texture, flags); texture->pbo=0; - if ( texture->type != TEXTURE_TYPE_SHADER && sdl->m_useglsl) + if ( texture->type != TEXTURE_TYPE_SHADER && m_useglsl) { pfn_glUseProgramObjectARB(0); // back to fixed function pipeline } if ( texture->type==TEXTURE_TYPE_SHADER ) { - if ( texture_shader_create(window, texsource, texture, flags) ) + if ( texture_shader_create(texsource, texture, flags) ) { global_free(texture); return NULL; @@ -2237,7 +2216,7 @@ static texture_info *texture_create(sdl_window_info *window, const render_texinf if ( texture->type == TEXTURE_TYPE_DYNAMIC ) { - assert(sdl->m_usepbo); + assert(m_usepbo); // create the PBO pfn_glGenBuffers(1, (GLuint *)&texture->pbo); @@ -2257,21 +2236,21 @@ static texture_info *texture_create(sdl_window_info *window, const render_texinf } // add us to the texture list - if (sdl->m_texhash[texture->hash] == NULL) - sdl->m_texhash[texture->hash] = texture; + if (m_texhash[texture->hash] == NULL) + m_texhash[texture->hash] = texture; else { int i; for (i = HASH_SIZE; i < HASH_SIZE + OVERFLOW_SIZE; i++) - if (sdl->m_texhash[i] == NULL) + if (m_texhash[i] == NULL) { - sdl->m_texhash[i] = texture; + m_texhash[i] = texture; break; } assert_always(i < HASH_SIZE + OVERFLOW_SIZE, "texture hash exhausted ..."); } - if(sdl->m_usevbo) + if(m_usevbo) { // Generate And Bind The Texture Coordinate Buffer pfn_glGenBuffers( 1, &(texture->texCoordBufferName) ); @@ -2696,12 +2675,12 @@ static int compare_texture_primitive(const texture_info *texture, const render_p return 0; } -static texture_info *texture_find(sdl_info *sdl, const render_primitive *prim) +texture_info *sdl_info_ogl::texture_find(const render_primitive *prim) { HashT texhash = texture_compute_hash(&prim->texture, prim->flags); texture_info *texture; - texture = sdl->m_texhash[texhash]; + texture = m_texhash[texhash]; if (texture != NULL) { int i; @@ -2709,7 +2688,7 @@ static texture_info *texture_find(sdl_info *sdl, const render_primitive *prim) return texture; for (i=HASH_SIZE; im_texhash[i]; + texture = m_texhash[i]; if (texture != NULL && compare_texture_primitive(texture, prim)) return texture; } @@ -2721,16 +2700,14 @@ static texture_info *texture_find(sdl_info *sdl, const render_primitive *prim) // texture_update //============================================================ -static void texture_coord_update(sdl_window_info *window, - texture_info *texture, const render_primitive *prim, int shaderIdx) +void sdl_info_ogl::texture_coord_update(texture_info *texture, const render_primitive *prim, int shaderIdx) { - sdl_info *sdl = (sdl_info *) window->m_dxdata; float ustart = 0.0f, ustop = 0.0f; // beginning/ending U coordinates float vstart = 0.0f, vstop = 0.0f; // beginning/ending V coordinates float du, dv; if ( texture->type != TEXTURE_TYPE_SHADER || - ( texture->type == TEXTURE_TYPE_SHADER && shaderIdx<=sdl->m_glsl_program_mb2sc ) ) + ( texture->type == TEXTURE_TYPE_SHADER && shaderIdx<=m_glsl_program_mb2sc ) ) { // compute the U/V scale factors if (texture->borderpix) @@ -2748,13 +2725,13 @@ static void texture_coord_update(sdl_window_info *window, vstop = (float)(prim->texture.height*texture->yprescale) / (float)texture->rawheight_create; } } - else if ( texture->type == TEXTURE_TYPE_SHADER && shaderIdx>sdl->m_glsl_program_mb2sc ) + else if ( texture->type == TEXTURE_TYPE_SHADER && shaderIdx>m_glsl_program_mb2sc ) { - int surf_w_pow2 = get_valid_pow2_value (window->m_width, texture->texpow2); - int surf_h_pow2 = get_valid_pow2_value (window->m_height, texture->texpow2); + int surf_w_pow2 = get_valid_pow2_value (window().m_width, texture->texpow2); + int surf_h_pow2 = get_valid_pow2_value (window().m_height, texture->texpow2); - ustop = (float)(window->m_width) / (float)surf_w_pow2; - vstop = (float)(window->m_height) / (float)surf_h_pow2; + ustop = (float)(window().m_width) / (float)surf_w_pow2; + vstop = (float)(window().m_height) / (float)surf_h_pow2; } else { @@ -2772,7 +2749,7 @@ static void texture_coord_update(sdl_window_info *window, dv *= (float)texture->rawheight; } - if ( texture->type == TEXTURE_TYPE_SHADER && shaderIdx!=sdl->m_glsl_program_mb2sc ) + if ( texture->type == TEXTURE_TYPE_SHADER && shaderIdx!=m_glsl_program_mb2sc ) { // 1:1 tex coord CCW (0/0) (1/0) (1/1) (0/1) // we must go CW here due to the mame bitmap order @@ -2799,7 +2776,7 @@ static void texture_coord_update(sdl_window_info *window, } } -static void texture_mpass_flip(sdl_info *sdl, texture_info *texture, int shaderIdx) +void sdl_info_ogl::texture_mpass_flip(texture_info *texture, int shaderIdx) { UINT32 mpass_src_idx = texture->mpass_dest_idx; @@ -2808,13 +2785,13 @@ static void texture_mpass_flip(sdl_info *sdl, texture_info *texture, int shaderI if ( shaderIdx>0 ) { int uniform_location; - uniform_location = pfn_glGetUniformLocationARB(sdl->m_glsl_program[shaderIdx], "mpass_texture"); + uniform_location = pfn_glGetUniformLocationARB(m_glsl_program[shaderIdx], "mpass_texture"); pfn_glUniform1iARB(uniform_location, texture->mpass_textureunit[mpass_src_idx]-GL_TEXTURE0); GL_CHECK_ERROR_NORMAL(); } pfn_glActiveTexture(texture->mpass_textureunit[mpass_src_idx]); - if ( shaderIdx<=sdl->m_glsl_program_mb2sc ) + if ( shaderIdx<=m_glsl_program_mb2sc ) { glBindTexture(texture->texTarget, texture->mpass_texture_mamebm[mpass_src_idx]); } @@ -2827,9 +2804,9 @@ static void texture_mpass_flip(sdl_info *sdl, texture_info *texture, int shaderI pfn_glActiveTexture(texture->mpass_textureunit[texture->mpass_dest_idx]); - if ( shaderIdxm_glsl_program_num-1 ) + if ( shaderIdx=sdl->m_glsl_program_mb2sc ) + if ( shaderIdx>=m_glsl_program_mb2sc ) { glBindTexture(texture->texTarget, texture->mpass_texture_scrn[texture->mpass_dest_idx]); pfn_glBindFramebuffer(GL_FRAMEBUFFER_EXT, texture->mpass_fbo_scrn[texture->mpass_dest_idx]); @@ -2846,10 +2823,10 @@ static void texture_mpass_flip(sdl_info *sdl, texture_info *texture, int shaderI GL_CHECK_ERROR_NORMAL(); glViewport(0.0, 0.0, (GLsizei)texture->rawwidth, (GLsizei)texture->rawheight); } - else if ( shaderIdx==sdl->m_glsl_program_mb2sc ) + else if ( shaderIdx==m_glsl_program_mb2sc ) { - assert ( sdl->m_glsl_program_mb2sc < sdl->m_glsl_program_num-1 ); - glPopAttrib(); // glViewport(0.0, 0.0, (GLsizei)window->width, (GLsizei)window->height) + assert ( m_glsl_program_mb2sc < m_glsl_program_num-1 ); + glPopAttrib(); // glViewport(0.0, 0.0, (GLsizei)window().width, (GLsizei)window().height) GL_CHECK_ERROR_NORMAL(); } glClear(GL_COLOR_BUFFER_BIT); // make sure the whole texture is redrawn .. @@ -2859,9 +2836,9 @@ static void texture_mpass_flip(sdl_info *sdl, texture_info *texture, int shaderI glBindTexture(texture->texTarget, 0); pfn_glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0); - if ( sdl->m_glsl_program_mb2sc == sdl->m_glsl_program_num-1 ) + if ( m_glsl_program_mb2sc == m_glsl_program_num-1 ) { - glPopAttrib(); // glViewport(0.0, 0.0, (GLsizei)window->width, (GLsizei)window->height) + glPopAttrib(); // glViewport(0.0, 0.0, (GLsizei)window().width, (GLsizei)window().height) GL_CHECK_ERROR_NORMAL(); } @@ -2870,19 +2847,18 @@ static void texture_mpass_flip(sdl_info *sdl, texture_info *texture, int shaderI } } -static void texture_shader_update(sdl_window_info *window, texture_info *texture, int shaderIdx) +void sdl_info_ogl::texture_shader_update(texture_info *texture, int shaderIdx) { - sdl_info *sdl = (sdl_info *) window->m_dxdata; int uniform_location, scrnum; render_container *container; GLfloat vid_attributes[4]; scrnum = 0; container = (render_container *)NULL; - screen_device_iterator iter(window->machine().root_device()); + screen_device_iterator iter(window().machine().root_device()); for (screen_device *screen = iter.first(); screen != NULL; screen = iter.next()) { - if (scrnum == window->m_start_viewscreen) + if (scrnum == window().m_start_viewscreen) { container = &screen->container(); } @@ -2896,16 +2872,16 @@ static void texture_shader_update(sdl_window_info *window, texture_info *texture container->get_user_settings(settings); //FIXME: Intended behaviour #if 1 - vid_attributes[0] = window->machine().options().gamma(); - vid_attributes[1] = window->machine().options().contrast(); - vid_attributes[2] = window->machine().options().brightness(); + vid_attributes[0] = window().machine().options().gamma(); + vid_attributes[1] = window().machine().options().contrast(); + vid_attributes[2] = window().machine().options().brightness(); #else vid_attributes[0] = settings.gamma; vid_attributes[1] = settings.contrast; vid_attributes[2] = settings.brightness; #endif vid_attributes[3] = 0.0f; - uniform_location = pfn_glGetUniformLocationARB(sdl->m_glsl_program[shaderIdx], "vid_attributes"); + uniform_location = pfn_glGetUniformLocationARB(m_glsl_program[shaderIdx], "vid_attributes"); pfn_glUniform4fvARB(uniform_location, 1, &(vid_attributes[shaderIdx])); if ( GL_CHECK_ERROR_QUIET() ) { osd_printf_verbose("GLSL: could not set 'vid_attributes' for shader prog idx %d\n", shaderIdx); @@ -2913,30 +2889,29 @@ static void texture_shader_update(sdl_window_info *window, texture_info *texture } else { - osd_printf_verbose("GLSL: could not get render container for screen %d\n", window->m_start_viewscreen); + osd_printf_verbose("GLSL: could not get render container for screen %d\n", window().m_start_viewscreen); } } -static texture_info * texture_update(sdl_window_info *window, const render_primitive *prim, int shaderIdx) +texture_info * sdl_info_ogl::texture_update(const render_primitive *prim, int shaderIdx) { - sdl_info *sdl = (sdl_info *) window->m_dxdata; - texture_info *texture = texture_find(sdl, prim); + texture_info *texture = texture_find(prim); int texBound = 0; // if we didn't find one, create a new texture if (texture == NULL && prim->texture.base != NULL) { - texture = texture_create(window, &prim->texture, prim->flags); + texture = texture_create(&prim->texture, prim->flags); } else if (texture != NULL) { if ( texture->type == TEXTURE_TYPE_SHADER ) { - pfn_glUseProgramObjectARB(sdl->m_glsl_program[shaderIdx]); // back to our shader + pfn_glUseProgramObjectARB(m_glsl_program[shaderIdx]); // back to our shader } else if ( texture->type == TEXTURE_TYPE_DYNAMIC ) { - assert ( sdl->m_usepbo ) ; + assert ( m_usepbo ) ; pfn_glBindBuffer( GL_PIXEL_UNPACK_BUFFER_ARB, texture->pbo); glEnable(texture->texTarget); } @@ -2950,10 +2925,10 @@ static texture_info * texture_update(sdl_window_info *window, const render_primi { if ( texture->type == TEXTURE_TYPE_SHADER ) { - texture_shader_update(window, texture, shaderIdx); - if ( sdl->m_glsl_program_num>1 ) + texture_shader_update(texture, shaderIdx); + if ( m_glsl_program_num>1 ) { - texture_mpass_flip(sdl, texture, shaderIdx); + texture_mpass_flip(texture, shaderIdx); } } @@ -2972,10 +2947,10 @@ static texture_info * texture_update(sdl_window_info *window, const render_primi if (!texBound) { glBindTexture(texture->texTarget, texture->texture); } - texture_coord_update(window, texture, prim, shaderIdx); + texture_coord_update(texture, prim, shaderIdx); glEnableClientState(GL_TEXTURE_COORD_ARRAY); - if(sdl->m_usevbo) + if(m_usevbo) { pfn_glBindBuffer( GL_ARRAY_BUFFER_ARB, texture->texCoordBufferName ); // Load The Data @@ -2991,11 +2966,11 @@ static texture_info * texture_update(sdl_window_info *window, const render_primi return texture; } -static void texture_disable(sdl_info *sdl, texture_info * texture) +void sdl_info_ogl::texture_disable(texture_info * texture) { if ( texture->type == TEXTURE_TYPE_SHADER ) { - assert ( sdl->m_useglsl ); + assert ( m_useglsl ); pfn_glUseProgramObjectARB(0); // back to fixed function pipeline } else if ( texture->type == TEXTURE_TYPE_DYNAMIC ) { @@ -3006,102 +2981,98 @@ static void texture_disable(sdl_info *sdl, texture_info * texture) } } -static void texture_all_disable(sdl_info *sdl) +void sdl_info_ogl::texture_all_disable() { - if ( sdl->m_useglsl ) + if ( m_useglsl ) { pfn_glUseProgramObjectARB(0); // back to fixed function pipeline pfn_glActiveTexture(GL_TEXTURE3); glBindTexture(GL_TEXTURE_2D, 0); - if ( sdl->m_usefbo ) pfn_glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0); + if ( m_usefbo ) pfn_glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0); pfn_glActiveTexture(GL_TEXTURE2); glBindTexture(GL_TEXTURE_2D, 0); - if ( sdl->m_usefbo ) pfn_glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0); + if ( m_usefbo ) pfn_glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0); pfn_glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, 0); - if ( sdl->m_usefbo ) pfn_glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0); + if ( m_usefbo ) pfn_glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0); pfn_glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, 0); - if ( sdl->m_usefbo ) pfn_glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0); + if ( m_usefbo ) pfn_glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0); } glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0); - if(sdl->m_usetexturerect) + if(m_usetexturerect) { glDisable(GL_TEXTURE_RECTANGLE_ARB); } glDisable(GL_TEXTURE_2D); glDisableClientState(GL_TEXTURE_COORD_ARRAY); - if(sdl->m_usevbo) + if(m_usevbo) { pfn_glBindBuffer( GL_ARRAY_BUFFER_ARB, 0); // unbind .. } - if ( sdl->m_usepbo ) + if ( m_usepbo ) { pfn_glBindBuffer( GL_PIXEL_UNPACK_BUFFER_ARB, 0); } } -static void drawogl_destroy_all_textures(sdl_window_info *window) +void sdl_info_ogl::destroy_all_textures() { - sdl_info *sdl = (sdl_info *) window->m_dxdata; texture_info *texture = NULL; int lock=FALSE; int i; - if (sdl == NULL) - return; - - if ( !sdl->m_initialized ) + if ( !m_initialized ) return; #if (SDLMAME_SDL2) - SDL_GL_MakeCurrent(window->m_sdl_window, sdl->m_gl_context_id); + SDL_GL_MakeCurrent(window().m_sdl_window, m_gl_context_id); #endif - if(window->m_primlist) + if(window().m_primlist) { lock=TRUE; - window->m_primlist->acquire_lock(); + window().m_primlist->acquire_lock(); } glFinish(); - texture_all_disable(sdl); + texture_all_disable(); glFinish(); glDisableClientState(GL_VERTEX_ARRAY); i=0; while (im_texhash[i]; - sdl->m_texhash[i] = NULL; + texture = m_texhash[i]; + m_texhash[i] = NULL; if (texture != NULL) { - if(sdl->m_usevbo) + if(m_usevbo) { pfn_glDeleteBuffers( 1, &(texture->texCoordBufferName) ); texture->texCoordBufferName=0; } - if(sdl->m_usepbo && texture->pbo) + if(m_usepbo && texture->pbo) { pfn_glDeleteBuffers( 1, (GLuint *)&(texture->pbo) ); texture->pbo=0; } - if( sdl->m_glsl_program_num > 1 ) + if( m_glsl_program_num > 1 ) { - assert(sdl->m_usefbo); + assert(m_usefbo); pfn_glDeleteFramebuffers(2, (GLuint *)&texture->mpass_fbo_mamebm[0]); glDeleteTextures(2, (GLuint *)&texture->mpass_texture_mamebm[0]); } - if ( sdl->m_glsl_program_mb2sc < sdl->m_glsl_program_num - 1 ) + if ( m_glsl_program_mb2sc < m_glsl_program_num - 1 ) { - assert(sdl->m_usefbo); + assert(m_usefbo); pfn_glDeleteFramebuffers(2, (GLuint *)&texture->mpass_fbo_scrn[0]); glDeleteTextures(2, (GLuint *)&texture->mpass_texture_scrn[0]); } @@ -3117,26 +3088,24 @@ static void drawogl_destroy_all_textures(sdl_window_info *window) } i++; } - if ( sdl->m_useglsl ) + if ( m_useglsl ) { - glsl_shader_free(sdl->m_glsl); - sdl->m_glsl = NULL; + glsl_shader_free(m_glsl); + m_glsl = NULL; } - sdl->m_initialized = 0; + m_initialized = 0; if (lock) - window->m_primlist->release_lock(); + window().m_primlist->release_lock(); } //============================================================ // TEXCOPY FUNCS //============================================================ -static void drawogl_window_clear(sdl_window_info *window) +void sdl_info_ogl::clear() { - sdl_info *sdl = (sdl_info *) window->m_dxdata; - - //FIXME: Handled in drawogl_window_draw as well - sdl->m_blittimer = 3; + //FIXME: Handled in sdl_info::draw as well + m_blittimer = 3; } diff --git a/src/osd/sdl/drawsdl.c b/src/osd/sdl/drawsdl.c index 6da3c92b63b..dcc656c419e 100644 --- a/src/osd/sdl/drawsdl.c +++ b/src/osd/sdl/drawsdl.c @@ -46,8 +46,52 @@ struct sdl_scale_mode; #endif /* sdl_info is the information about SDL for the current screen */ -struct sdl_info +class sdl_info : public osd_renderer { +public: + + sdl_info(sdl_window_info *w) + : osd_renderer(w), + m_blittimer(0), + m_extra_flags(0), + + #if (SDLMAME_SDL2) + m_sdl_renderer(NULL), + m_texture_id(NULL), + #else + m_sdlsurf(NULL), + m_yuvsurf(NULL), + #endif + m_yuv_lookup(NULL), + m_yuv_bitmap(NULL), + m_hw_scale_width(0), + m_hw_scale_height(0), + m_last_hofs(0), + m_last_vofs(0), + m_old_blitwidth(0), + m_old_blitheight(0) + { } + + /* virtual */ int create(int width, int height); + /* virtual */ void resize(int width, int height); + /* virtual */ int draw(UINT32 dc, int update); + /* virtual */ void set_target_bounds(); + /* virtual */ int xy_to_render_target(int x, int y, int *xt, int *yt); + /* virtual */ void destroy_all_textures(); + /* virtual */ void destroy(); + /* virtual */ void clear(); + + void yuv_init(); +#if (SDLMAME_SDL2) + void setup_texture(int tempwidth, int tempheight); +#endif + void yuv_lookup_set(unsigned int pen, unsigned char red, + unsigned char green, unsigned char blue); + +#if (!SDLMAME_SDL2) + void yuv_overlay_init(); +#endif + INT32 m_blittimer; UINT32 m_extra_flags; @@ -101,23 +145,9 @@ struct sdl_scale_mode // core functions static void drawsdl_exit(void); -static void drawsdl_attach(sdl_draw_info *info, sdl_window_info *window); -static int drawsdl_window_create(sdl_window_info *window, int width, int height); -static void drawsdl_window_resize(sdl_window_info *window, int width, int height); -static void drawsdl_window_destroy(sdl_window_info *window); -static void drawsdl_set_target_bounds(sdl_window_info *window); -static int drawsdl_window_draw(sdl_window_info *window, UINT32 dc, int update); -static void drawsdl_destroy_all_textures(sdl_window_info *window); -static void drawsdl_window_clear(sdl_window_info *window); -static int drawsdl_xy_to_render_target(sdl_window_info *window, int x, int y, int *xt, int *yt); - -#if (SDLMAME_SDL2) -static void setup_texture(sdl_window_info *window, int tempwidth, int tempheight); -#endif // YUV overlays -static void drawsdl_yuv_init(sdl_info *sdl); static void yuv_RGB_to_YV12(UINT16 *bitmap, sdl_info *sdl, UINT8 *ptr, int pitch); static void yuv_RGB_to_YV12X2(UINT16 *bitmap, sdl_info *sdl, UINT8 *ptr, int pitch); static void yuv_RGB_to_YUY2(UINT16 *bitmap, sdl_info *sdl, UINT8 *ptr, int pitch); @@ -190,11 +220,17 @@ int drawsdl_scale_mode(const char *s) // drawsdl_init //============================================================ +static osd_renderer *drawsdl_create(sdl_window_info *window) +{ + return global_alloc(sdl_info(window)); +} + + int drawsdl_init(sdl_draw_info *callbacks) { // fill in the callbacks + callbacks->create = drawsdl_create; callbacks->exit = drawsdl_exit; - callbacks->attach = drawsdl_attach; if (SDLMAME_SDL2) osd_printf_verbose("Using SDL multi-window soft driver (SDL 2.0+)\n"); @@ -212,28 +248,11 @@ static void drawsdl_exit(void) { } -//============================================================ -// drawsdl_attach -//============================================================ - -static void drawsdl_attach(sdl_draw_info *info, sdl_window_info *window) -{ - // fill in the callbacks - window->create = drawsdl_window_create; - window->resize = drawsdl_window_resize; - window->set_target_bounds = drawsdl_set_target_bounds; - window->draw = drawsdl_window_draw; - window->destroy = drawsdl_window_destroy; - window->destroy_all_textures = drawsdl_destroy_all_textures; - window->clear = drawsdl_window_clear; - window->xy_to_render_target = drawsdl_xy_to_render_target; -} - //============================================================ // drawsdl_destroy_all_textures //============================================================ -static void drawsdl_destroy_all_textures(sdl_window_info *window) +void sdl_info::destroy_all_textures() { /* nothing to be done in soft mode */ } @@ -243,51 +262,50 @@ static void drawsdl_destroy_all_textures(sdl_window_info *window) //============================================================ #if (SDLMAME_SDL2) -static void setup_texture(sdl_window_info *window, int tempwidth, int tempheight) +void sdl_info::setup_texture(int tempwidth, int tempheight) { - sdl_info *sdl = (sdl_info *) window->m_dxdata; const sdl_scale_mode *sdl_sm = &scale_modes[video_config.scale_mode]; SDL_DisplayMode mode; UINT32 fmt; // Determine preferred pixelformat and set up yuv if necessary - SDL_GetCurrentDisplayMode(window->monitor()->handle(), &mode); + SDL_GetCurrentDisplayMode(window().monitor()->handle(), &mode); - if (sdl->m_yuv_bitmap) + if (m_yuv_bitmap) { - global_free_array(sdl->m_yuv_bitmap); - sdl->m_yuv_bitmap = NULL; + global_free_array(m_yuv_bitmap); + m_yuv_bitmap = NULL; } if (sdl_sm->is_scale) { - window->m_target->compute_minimum_size(sdl->m_hw_scale_width, sdl->m_hw_scale_height); + window().m_target->compute_minimum_size(m_hw_scale_width, m_hw_scale_height); if (video_config.prescale) { - sdl->m_hw_scale_width *= video_config.prescale; - sdl->m_hw_scale_height *= video_config.prescale; + m_hw_scale_width *= video_config.prescale; + m_hw_scale_height *= video_config.prescale; /* This must be a multiple of 2 */ - sdl->m_hw_scale_width = (sdl->m_hw_scale_width + 1) & ~1; + m_hw_scale_width = (m_hw_scale_width + 1) & ~1; } } if (sdl_sm->is_yuv) - sdl->m_yuv_bitmap = global_alloc_array(UINT16, sdl->m_hw_scale_width * sdl->m_hw_scale_height); + m_yuv_bitmap = global_alloc_array(UINT16, m_hw_scale_width * m_hw_scale_height); fmt = (sdl_sm->pixel_format ? sdl_sm->pixel_format : mode.format); if (sdl_sm->is_scale) { - int w = sdl->m_hw_scale_width * sdl_sm->mult_w; - int h = sdl->m_hw_scale_height * sdl_sm->mult_h; + int w = m_hw_scale_width * sdl_sm->mult_w; + int h = m_hw_scale_height * sdl_sm->mult_h; - sdl->m_texture_id = SDL_CreateTexture(sdl->m_sdl_renderer, fmt, SDL_TEXTUREACCESS_STREAMING, w, h); + m_texture_id = SDL_CreateTexture(m_sdl_renderer, fmt, SDL_TEXTUREACCESS_STREAMING, w, h); } else { - sdl->m_texture_id = SDL_CreateTexture(sdl->m_sdl_renderer,fmt, SDL_TEXTUREACCESS_STREAMING, + m_texture_id = SDL_CreateTexture(m_sdl_renderer,fmt, SDL_TEXTUREACCESS_STREAMING, tempwidth, tempheight); } } @@ -298,13 +316,12 @@ static void setup_texture(sdl_window_info *window, int tempwidth, int tempheight //============================================================ #if (!SDLMAME_SDL2) -static void yuv_overlay_init(sdl_window_info *window) +void sdl_info::yuv_overlay_init() { - sdl_info *sdl = (sdl_info *) window->m_dxdata; const sdl_scale_mode *sdl_sm = &scale_modes[video_config.scale_mode]; int minimum_width, minimum_height; - window->m_target->compute_minimum_size(minimum_width, minimum_height); + window().m_target->compute_minimum_size(minimum_width, minimum_height); if (video_config.prescale) { @@ -312,37 +329,37 @@ static void yuv_overlay_init(sdl_window_info *window) minimum_height *= video_config.prescale; } - if (sdl->yuvsurf != NULL) + if (m_yuvsurf != NULL) { - SDL_FreeYUVOverlay(sdl->yuvsurf); - sdl->yuvsurf = NULL; + SDL_FreeYUVOverlay(m_yuvsurf); + m_yuvsurf = NULL; } - if (sdl->m_yuv_bitmap != NULL) + if (m_yuv_bitmap != NULL) { - global_free_array(sdl->m_yuv_bitmap); + global_free_array(m_yuv_bitmap); } osd_printf_verbose("SDL: Creating %d x %d YUV-Overlay ...\n", minimum_width, minimum_height); - sdl->m_yuv_bitmap = global_alloc_array(UINT16, minimum_width*minimum_height); + m_yuv_bitmap = global_alloc_array(UINT16, minimum_width*minimum_height); - sdl->yuvsurf = SDL_CreateYUVOverlay(minimum_width * sdl_sm->mult_w, minimum_height * sdl_sm->mult_h, - sdl_sm->pixel_format, sdl->sdlsurf); + m_yuvsurf = SDL_CreateYUVOverlay(minimum_width * sdl_sm->mult_w, minimum_height * sdl_sm->mult_h, + sdl_sm->pixel_format, m_sdlsurf); - if ( sdl->yuvsurf == NULL ) { + if ( m_yuvsurf == NULL ) { osd_printf_error("SDL: Couldn't create SDL_yuv_overlay: %s\n", SDL_GetError()); //return 1; } - sdl->m_hw_scale_width = minimum_width; - sdl->m_hw_scale_height = minimum_height; + m_hw_scale_width = minimum_width; + m_hw_scale_height = minimum_height; if (!shown_video_info) { osd_printf_verbose("YUV Mode : %s\n", sdl_sm->name); osd_printf_verbose("YUV Overlay Size : %d x %d\n", minimum_width, minimum_height); - osd_printf_verbose("YUV Acceleration : %s\n", sdl->yuvsurf->hw_overlay ? "Hardware" : "Software"); + osd_printf_verbose("YUV Acceleration : %s\n", m_yuvsurf->hw_overlay ? "Hardware" : "Software"); shown_video_info = 1; } } @@ -353,7 +370,7 @@ static void yuv_overlay_init(sdl_window_info *window) //============================================================ #if (SDLMAME_SDL2) -static void drawsdl_show_info(sdl_window_info *window, struct SDL_RendererInfo *render_info) +static void drawsdl_show_info(struct SDL_RendererInfo *render_info) { #define RF_ENTRY(x) {x, #x } static struct { @@ -385,67 +402,60 @@ static void drawsdl_show_info(sdl_window_info *window, struct SDL_RendererInfo * // drawsdl_window_create //============================================================ -static int drawsdl_window_create(sdl_window_info *window, int width, int height) +int sdl_info::create(int width, int height) { - sdl_info *sdl; const sdl_scale_mode *sm = &scale_modes[video_config.scale_mode]; - // allocate memory for our structures - sdl = (sdl_info *) osd_malloc(sizeof(sdl_info)); - memset(sdl, 0, sizeof(sdl_info)); - - window->m_dxdata = sdl; - #if (SDLMAME_SDL2) /* set hints ... */ SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, sm->sdl_scale_mode); - sdl->m_extra_flags = (window->fullscreen() ? + m_extra_flags = (window().fullscreen() ? SDL_WINDOW_BORDERLESS | SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_MOUSE_FOCUS | SDL_WINDOW_INPUT_GRABBED : SDL_WINDOW_RESIZABLE); - window->m_sdl_window = SDL_CreateWindow(window->m_title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, - width, height, sdl->m_extra_flags); + window().m_sdl_window = SDL_CreateWindow(window().m_title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, + width, height, m_extra_flags); - if (window->fullscreen() && video_config.switchres) + if (window().fullscreen() && video_config.switchres) { SDL_DisplayMode mode; - SDL_GetCurrentDisplayMode(window->monitor()->handle(), &mode); + SDL_GetCurrentDisplayMode(window().monitor()->handle(), &mode); mode.w = width; mode.h = height; - if (window->m_refresh) - mode.refresh_rate = window->m_refresh; - SDL_SetWindowDisplayMode(window->m_sdl_window, &mode); // Try to set mode + if (window().m_refresh) + mode.refresh_rate = window().m_refresh; + SDL_SetWindowDisplayMode(window().m_sdl_window, &mode); // Try to set mode } else - SDL_SetWindowDisplayMode(window->m_sdl_window, NULL); // Use desktop + SDL_SetWindowDisplayMode(window().m_sdl_window, NULL); // Use desktop - SDL_ShowWindow(window->m_sdl_window); + SDL_ShowWindow(window().m_sdl_window); - SDL_SetWindowFullscreen(window->m_sdl_window, (SDL_bool) window->fullscreen()); - SDL_GetWindowSize(window->m_sdl_window, &window->m_width, &window->m_height); - SDL_RaiseWindow(window->m_sdl_window); + SDL_SetWindowFullscreen(window().m_sdl_window, (SDL_bool) window().fullscreen()); + SDL_GetWindowSize(window().m_sdl_window, &window().m_width, &window().m_height); + SDL_RaiseWindow(window().m_sdl_window); /* FIXME: Bug in SDL 1.3 */ - if (window->fullscreen()) - SDL_SetWindowGrab(window->m_sdl_window, SDL_TRUE); + if (window().fullscreen()) + SDL_SetWindowGrab(window().m_sdl_window, SDL_TRUE); // create a texture if (video_config.waitvsync) - sdl->m_sdl_renderer = SDL_CreateRenderer(window->m_sdl_window, -1, /*SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTDISCARD |*/ SDL_RENDERER_PRESENTVSYNC); + m_sdl_renderer = SDL_CreateRenderer(window().m_sdl_window, -1, /*SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTDISCARD |*/ SDL_RENDERER_PRESENTVSYNC); else - sdl->m_sdl_renderer = SDL_CreateRenderer(window->m_sdl_window, -1, /*SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTDISCARD*/ 0); + m_sdl_renderer = SDL_CreateRenderer(window().m_sdl_window, -1, /*SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTDISCARD*/ 0); - //SDL_SelectRenderer(window->sdl_window); + //SDL_SelectRenderer(window().sdl_window); { struct SDL_RendererInfo render_info; - SDL_GetRendererInfo(sdl->m_sdl_renderer, &render_info); - drawsdl_show_info(window, &render_info); + SDL_GetRendererInfo(m_sdl_renderer, &render_info); + drawsdl_show_info(&render_info); // Check scale mode @@ -465,31 +475,31 @@ static int drawsdl_window_create(sdl_window_info *window, int width, int height) } } - setup_texture(window, width, height); + setup_texture(width, height); #else - sdl->m_extra_flags = (window->fullscreen() ? SDL_FULLSCREEN : SDL_RESIZABLE); + m_extra_flags = (window().fullscreen() ? SDL_FULLSCREEN : SDL_RESIZABLE); - sdl->m_extra_flags |= sm->m_extra_flags; + m_extra_flags |= sm->m_extra_flags; - sdl->sdlsurf = SDL_SetVideoMode(m_width, m_height, - 0, SDL_SWSURFACE | SDL_ANYFORMAT | sdl->m_extra_flags); + m_sdlsurf = SDL_SetVideoMode(width, height, + 0, SDL_SWSURFACE | SDL_ANYFORMAT | m_extra_flags); - if (!sdl->sdlsurf) + if (!m_sdlsurf) return 1; - window->m_width = sdl->sdlsurf->w; - window->m_height = sdl->sdlsurf->h; + window().m_width = m_sdlsurf->w; + window().m_height = m_sdlsurf->h; if (sm->is_yuv) - yuv_overlay_init(window); + yuv_overlay_init(); // set the window title - SDL_WM_SetCaption(window->m_title, "SDLMAME"); + SDL_WM_SetCaption(window().m_title, "SDLMAME"); #endif - sdl->m_yuv_lookup = NULL; - sdl->m_blittimer = 0; + m_yuv_lookup = NULL; + m_blittimer = 0; - drawsdl_yuv_init(sdl); + yuv_init(); return 0; } @@ -497,34 +507,32 @@ static int drawsdl_window_create(sdl_window_info *window, int width, int height) // drawsdl_window_resize //============================================================ -static void drawsdl_window_resize(sdl_window_info *window, int width, int height) +void sdl_info::resize(int width, int height) { #if (!SDLMAME_SDL2) const sdl_scale_mode *sdl_sm = &scale_modes[video_config.scale_mode]; #endif #if (SDLMAME_SDL2) - SDL_SetWindowSize(window->m_sdl_window, width, height); - SDL_GetWindowSize(window->m_sdl_window, &window->m_width, &window->m_height); + SDL_SetWindowSize(window().m_sdl_window, width, height); + SDL_GetWindowSize(window().m_sdl_window, &window().m_width, &window().m_height); #else - sdl_info *sdl = (sdl_info *) window->m_dxdata; - - if (sdl->yuvsurf != NULL) + if (m_yuvsurf != NULL) { - SDL_FreeYUVOverlay(sdl->yuvsurf); - sdl->yuvsurf = NULL; + SDL_FreeYUVOverlay(m_yuvsurf); + m_yuvsurf = NULL; } - SDL_FreeSurface(sdl->sdlsurf); + SDL_FreeSurface(m_sdlsurf); //printf("SetVideoMode %d %d\n", wp->resize_new_width, wp->resize_new_height); - sdl->sdlsurf = SDL_SetVideoMode(m_width, m_height, 0, - SDL_SWSURFACE | SDL_ANYFORMAT | sdl->m_extra_flags); - window->m_width = sdl->sdlsurf->w; - window->m_height = sdl->sdlsurf->h; + m_sdlsurf = SDL_SetVideoMode(width, height, 0, + SDL_SWSURFACE | SDL_ANYFORMAT | m_extra_flags); + window().m_width = m_sdlsurf->w; + window().m_height = m_sdlsurf->h; if (sdl_sm->is_yuv) { - yuv_overlay_init(window); + yuv_overlay_init(); } #endif @@ -535,81 +543,71 @@ static void drawsdl_window_resize(sdl_window_info *window, int width, int height // drawsdl_window_destroy //============================================================ -static void drawsdl_window_destroy(sdl_window_info *window) +void sdl_info::destroy() { - sdl_info *sdl = (sdl_info *) window->m_dxdata; - - // skip if nothing - if (sdl == NULL) - return; #if (SDLMAME_SDL2) - //SDL_SelectRenderer(window->sdl_window); - SDL_DestroyTexture(sdl->m_texture_id); - //SDL_DestroyRenderer(window->sdl_window); - SDL_DestroyWindow(window->m_sdl_window); + //SDL_SelectRenderer(window().sdl_window); + SDL_DestroyTexture(m_texture_id); + //SDL_DestroyRenderer(window().sdl_window); + SDL_DestroyWindow(window().m_sdl_window); #else - if (sdl->yuvsurf != NULL) + if (m_yuvsurf != NULL) { - SDL_FreeYUVOverlay(sdl->yuvsurf); - sdl->yuvsurf = NULL; + SDL_FreeYUVOverlay(m_yuvsurf); + m_yuvsurf = NULL; } - if (sdl->sdlsurf) + if (m_sdlsurf) { - SDL_FreeSurface(sdl->sdlsurf); - sdl->sdlsurf = NULL; + SDL_FreeSurface(m_sdlsurf); + m_sdlsurf = NULL; } #endif // free the memory in the window - if (sdl->m_yuv_lookup != NULL) + if (m_yuv_lookup != NULL) { - global_free_array(sdl->m_yuv_lookup); - sdl->m_yuv_lookup = NULL; + global_free_array(m_yuv_lookup); + m_yuv_lookup = NULL; } - if (sdl->m_yuv_bitmap != NULL) + if (m_yuv_bitmap != NULL) { - global_free_array(sdl->m_yuv_bitmap); - sdl->m_yuv_bitmap = NULL; + global_free_array(m_yuv_bitmap); + m_yuv_bitmap = NULL; } - osd_free(sdl); - window->m_dxdata = NULL; } //============================================================ // drawsdl_window_clear //============================================================ -static void drawsdl_window_clear(sdl_window_info *window) +void sdl_info::clear() { - sdl_info *sdl = (sdl_info *) window->m_dxdata; - - sdl->m_blittimer = 3; + m_blittimer = 3; } //============================================================ // drawsdl_xy_to_render_target //============================================================ -static int drawsdl_xy_to_render_target(sdl_window_info *window, int x, int y, int *xt, int *yt) +int sdl_info::xy_to_render_target(int x, int y, int *xt, int *yt) { - sdl_info *sdl = (sdl_info *) window->m_dxdata; const sdl_scale_mode *sm = &scale_modes[video_config.scale_mode]; - *xt = x - sdl->m_last_hofs; - *yt = y - sdl->m_last_vofs; - if (*xt<0 || *xt >= window->m_blitwidth) + *xt = x - m_last_hofs; + *yt = y - m_last_vofs; + if (*xt<0 || *xt >= window().m_blitwidth) return 0; - if (*yt<0 || *xt >= window->m_blitheight) + if (*yt<0 || *xt >= window().m_blitheight) return 0; if (!sm->is_scale) { return 1; } /* Rescale */ - *xt = (*xt * sdl->m_hw_scale_width) / window->m_blitwidth; - *yt = (*yt * sdl->m_hw_scale_height) / window->m_blitheight; + *xt = (*xt * m_hw_scale_width) / window().m_blitwidth; + *yt = (*yt * m_hw_scale_height) / window().m_blitheight; return 1; } @@ -617,24 +615,22 @@ static int drawsdl_xy_to_render_target(sdl_window_info *window, int x, int y, in // drawsdl_window_get_primitives //============================================================ -static void drawsdl_set_target_bounds(sdl_window_info *window) +void sdl_info::set_target_bounds() { - sdl_info *sdl = (sdl_info *) window->m_dxdata; const sdl_scale_mode *sm = &scale_modes[video_config.scale_mode]; if (!sm->is_scale) - window->m_target->set_bounds(window->m_blitwidth, window->m_blitheight, window->monitor()->aspect()); + window().m_target->set_bounds(window().m_blitwidth, window().m_blitheight, window().monitor()->aspect()); else - window->m_target->set_bounds(sdl->m_hw_scale_width, sdl->m_hw_scale_height); + window().m_target->set_bounds(m_hw_scale_width, m_hw_scale_height); } //============================================================ // drawsdl_window_draw //============================================================ -static int drawsdl_window_draw(sdl_window_info *window, UINT32 dc, int update) +int sdl_info::draw(UINT32 dc, int update) { - sdl_info *sdl = (sdl_info *) window->m_dxdata; const sdl_scale_mode *sm = &scale_modes[video_config.scale_mode]; UINT8 *surfptr; INT32 pitch; @@ -650,100 +646,97 @@ static int drawsdl_window_draw(sdl_window_info *window, UINT32 dc, int update) return 0; } - // if we haven't been created, just punt - if (sdl == NULL) - return 1; - // lock it if we need it #if (!SDLMAME_SDL2) - pitch = sdl->sdlsurf->pitch; - bpp = sdl->sdlsurf->format->BytesPerPixel; - rmask = sdl->sdlsurf->format->Rmask; - gmask = sdl->sdlsurf->format->Gmask; - bmask = sdl->sdlsurf->format->Bmask; -// amask = sdl->sdlsurf->format->Amask; + pitch = m_sdlsurf->pitch; + bpp = m_sdlsurf->format->BytesPerPixel; + rmask = m_sdlsurf->format->Rmask; + gmask = m_sdlsurf->format->Gmask; + bmask = m_sdlsurf->format->Bmask; +// amask = sdlsurf->format->Amask; - if (window->m_blitwidth != sdl->m_old_blitwidth || window->m_blitheight != sdl->m_old_blitheight) + if (window().m_blitwidth != m_old_blitwidth || window().m_blitheight != m_old_blitheight) { if (sm->is_yuv) - yuv_overlay_init(window); - sdl->m_old_blitwidth = window->m_blitwidth; - sdl->m_old_blitheight = window->m_blitheight; - sdl->m_blittimer = 3; + yuv_overlay_init(); + m_old_blitwidth = window().m_blitwidth; + m_old_blitheight = window().m_blitheight; + m_blittimer = 3; } - if (SDL_MUSTLOCK(sdl->sdlsurf)) SDL_LockSurface(sdl->sdlsurf); - // Clear if necessary + if (SDL_MUSTLOCK(m_sdlsurf)) + SDL_LockSurface(m_sdlsurf); - if (sdl->m_blittimer > 0) + // Clear if necessary + if (m_blittimer > 0) { - memset(sdl->sdlsurf->pixels, 0, window->m_height * sdl->sdlsurf->pitch); - sdl->m_blittimer--; + memset(m_sdlsurf->pixels, 0, window().m_height * m_sdlsurf->pitch); + m_blittimer--; } if (sm->is_yuv) { - SDL_LockYUVOverlay(sdl->yuvsurf); - surfptr = sdl->yuvsurf->pixels[0]; // (UINT8 *) sdl->m_yuv_bitmap; - pitch = sdl->yuvsurf->pitches[0]; // (UINT8 *) sdl->m_yuv_bitmap; + SDL_LockYUVOverlay(m_yuvsurf); + surfptr = m_yuvsurf->pixels[0]; // (UINT8 *) m_yuv_bitmap; + pitch = m_yuvsurf->pitches[0]; // (UINT8 *) m_yuv_bitmap; } else - surfptr = (UINT8 *)sdl->sdlsurf->pixels; + surfptr = (UINT8 *)m_sdlsurf->pixels; #else - //SDL_SelectRenderer(window->sdl_window); + //SDL_SelectRenderer(window().sdl_window); - if (window->m_blitwidth != sdl->m_old_blitwidth || window->m_blitheight != sdl->m_old_blitheight) + if (window().m_blitwidth != m_old_blitwidth || window().m_blitheight != m_old_blitheight) { - SDL_RenderSetViewport(sdl->m_sdl_renderer, NULL); + SDL_RenderSetViewport(m_sdl_renderer, NULL); - SDL_DestroyTexture(sdl->m_texture_id); - setup_texture(window, window->m_blitwidth, window->m_blitheight); - sdl->m_old_blitwidth = window->m_blitwidth; - sdl->m_old_blitheight = window->m_blitheight; - sdl->m_blittimer = 3; + SDL_DestroyTexture(m_texture_id); + setup_texture(window().m_blitwidth, window().m_blitheight); + m_old_blitwidth = window().m_blitwidth; + m_old_blitheight = window().m_blitheight; + m_blittimer = 3; } { Uint32 format; int access, w, h; - SDL_QueryTexture(sdl->m_texture_id, &format, &access, &w, &h); + SDL_QueryTexture(m_texture_id, &format, &access, &w, &h); SDL_PixelFormatEnumToMasks(format, &bpp, &rmask, &gmask, &bmask, &amask); bpp = bpp / 8; /* convert to bytes per pixels */ } // Clear if necessary - if (sdl->m_blittimer > 0) + if (m_blittimer > 0) { /* SDL Underlays need alpha = 0 ! */ - SDL_SetRenderDrawColor(sdl->m_sdl_renderer,0,0,0,0); - SDL_RenderFillRect(sdl->m_sdl_renderer,NULL); + SDL_SetRenderDrawColor(m_sdl_renderer,0,0,0,0); + SDL_RenderFillRect(m_sdl_renderer,NULL); //SDL_RenderFill(0,0,0,0 /*255*/,NULL); - sdl->m_blittimer--; + m_blittimer--; } - SDL_LockTexture(sdl->m_texture_id, NULL, (void **) &surfptr, &pitch); + SDL_LockTexture(m_texture_id, NULL, (void **) &surfptr, &pitch); #endif // get ready to center the image vofs = hofs = 0; - blitwidth = window->m_blitwidth; - blitheight = window->m_blitheight; + blitwidth = window().m_blitwidth; + blitheight = window().m_blitheight; // figure out what coordinate system to use for centering - in window mode it's always the // SDL surface size. in fullscreen the surface covers all monitors, so center according to // the first one only - if ((window->fullscreen()) && (!video_config.switchres)) + if ((window().fullscreen()) && (!video_config.switchres)) { - ch = window->monitor()->center_height(); - cw = window->monitor()->center_width(); + ch = window().monitor()->center_height(); + cw = window().monitor()->center_width(); } else { - ch = window->m_height; - cw = window->m_width; + ch = window().m_height; + cw = window().m_width; } // do not crash if the window's smaller than the blit area @@ -753,7 +746,7 @@ static int drawsdl_window_draw(sdl_window_info *window, UINT32 dc, int update) } else if (video_config.centerv) { - vofs = (ch - window->m_blitheight) / 2; + vofs = (ch - window().m_blitheight) / 2; } if (blitwidth > cw) @@ -762,13 +755,13 @@ static int drawsdl_window_draw(sdl_window_info *window, UINT32 dc, int update) } else if (video_config.centerh) { - hofs = (cw - window->m_blitwidth) / 2; + hofs = (cw - window().m_blitwidth) / 2; } - sdl->m_last_hofs = hofs; - sdl->m_last_vofs = vofs; + m_last_hofs = hofs; + m_last_vofs = vofs; - window->m_primlist->acquire_lock(); + window().m_primlist->acquire_lock(); // render to it if (!sm->is_yuv) @@ -785,29 +778,29 @@ static int drawsdl_window_draw(sdl_window_info *window, UINT32 dc, int update) } else { - mamewidth = sdl->m_hw_scale_width; - mameheight = sdl->m_hw_scale_height; + mamewidth = m_hw_scale_width; + mameheight = m_hw_scale_height; } switch (rmask) { case 0x0000ff00: - software_renderer::draw_primitives(*window->m_primlist, surfptr, mamewidth, mameheight, pitch / 4); + software_renderer::draw_primitives(*window().m_primlist, surfptr, mamewidth, mameheight, pitch / 4); break; case 0x00ff0000: - software_renderer::draw_primitives(*window->m_primlist, surfptr, mamewidth, mameheight, pitch / 4); + software_renderer::draw_primitives(*window().m_primlist, surfptr, mamewidth, mameheight, pitch / 4); break; case 0x000000ff: - software_renderer::draw_primitives(*window->m_primlist, surfptr, mamewidth, mameheight, pitch / 4); + software_renderer::draw_primitives(*window().m_primlist, surfptr, mamewidth, mameheight, pitch / 4); break; case 0xf800: - software_renderer::draw_primitives(*window->m_primlist, surfptr, mamewidth, mameheight, pitch / 2); + software_renderer::draw_primitives(*window().m_primlist, surfptr, mamewidth, mameheight, pitch / 2); break; case 0x7c00: - software_renderer::draw_primitives(*window->m_primlist, surfptr, mamewidth, mameheight, pitch / 2); + software_renderer::draw_primitives(*window().m_primlist, surfptr, mamewidth, mameheight, pitch / 2); break; default: @@ -817,34 +810,34 @@ static int drawsdl_window_draw(sdl_window_info *window, UINT32 dc, int update) } else { - assert (sdl->m_yuv_bitmap != NULL); + assert (m_yuv_bitmap != NULL); assert (surfptr != NULL); - software_renderer::draw_primitives(*window->m_primlist, sdl->m_yuv_bitmap, sdl->m_hw_scale_width, sdl->m_hw_scale_height, sdl->m_hw_scale_width); - sm->yuv_blit((UINT16 *)sdl->m_yuv_bitmap, sdl, surfptr, pitch); + software_renderer::draw_primitives(*window().m_primlist, m_yuv_bitmap, m_hw_scale_width, m_hw_scale_height, m_hw_scale_width); + sm->yuv_blit((UINT16 *)m_yuv_bitmap, this, surfptr, pitch); } - window->m_primlist->release_lock(); + window().m_primlist->release_lock(); // unlock and flip #if (!SDLMAME_SDL2) - if (SDL_MUSTLOCK(sdl->sdlsurf)) SDL_UnlockSurface(sdl->sdlsurf); + if (SDL_MUSTLOCK(m_sdlsurf)) SDL_UnlockSurface(m_sdlsurf); if (!sm->is_yuv) { - SDL_Flip(sdl->sdlsurf); + SDL_Flip(m_sdlsurf); } else { SDL_Rect r; - SDL_UnlockYUVOverlay(sdl->yuvsurf); - r.x=hofs; - r.y=vofs; - r.w=m_blitwidth; - r.h=m_blitheight; - SDL_DisplayYUVOverlay(sdl->yuvsurf, &r); + SDL_UnlockYUVOverlay(m_yuvsurf); + r.x = hofs; + r.y = vofs; + r.w = blitwidth; + r.h = blitheight; + SDL_DisplayYUVOverlay(m_yuvsurf, &r); } #else - SDL_UnlockTexture(sdl->m_texture_id); + SDL_UnlockTexture(m_texture_id); { SDL_Rect r; @@ -852,10 +845,10 @@ static int drawsdl_window_draw(sdl_window_info *window, UINT32 dc, int update) r.y=vofs; r.w=blitwidth; r.h=blitheight; - //printf("blitwidth %d %d - %d %d\n", blitwidth, blitheight, window->width, window->height); - //SDL_UpdateTexture(sdl->sdltex, NULL, sdl->sdlsurf->pixels, pitch); - SDL_RenderCopy(sdl->m_sdl_renderer,sdl->m_texture_id, NULL, &r); - SDL_RenderPresent(sdl->m_sdl_renderer); + //printf("blitwidth %d %d - %d %d\n", blitwidth, blitheight, window().width, window().height); + //SDL_UpdateTexture(sdltex, NULL, sdlsurf->pixels, pitch); + SDL_RenderCopy(m_sdl_renderer,m_texture_id, NULL, &r); + SDL_RenderPresent(m_sdl_renderer); } #endif return 0; @@ -901,7 +894,7 @@ static int drawsdl_window_draw(sdl_window_info *window, UINT32 dc, int update) #define YMASK (Y1MASK|Y2MASK) #define UVMASK (UMASK|VMASK) -static void yuv_lookup_set(sdl_info *sdl, unsigned int pen, unsigned char red, +void sdl_info::yuv_lookup_set(unsigned int pen, unsigned char red, unsigned char green, unsigned char blue) { UINT32 y,u,v; @@ -910,20 +903,20 @@ static void yuv_lookup_set(sdl_info *sdl, unsigned int pen, unsigned char red, /* Storing this data in YUYV order simplifies using the data for YUY2, both with and without smoothing... */ - sdl->m_yuv_lookup[pen]=(y<m_yuv_lookup == NULL) - sdl->m_yuv_lookup = global_alloc_array(UINT32, 65536); + if (m_yuv_lookup == NULL) + m_yuv_lookup = global_alloc_array(UINT32, 65536); for (r = 0; r < 32; r++) for (g = 0; g < 32; g++) for (b = 0; b < 32; b++) { int idx = (r << 10) | (g << 5) | b; - yuv_lookup_set(sdl, idx, + yuv_lookup_set(idx, (r << 3) | (r >> 2), (g << 3) | (g >> 2), (b << 3) | (b >> 2)); diff --git a/src/osd/sdl/input.c b/src/osd/sdl/input.c index 88e49ade7f4..0fdb881fb9a 100644 --- a/src/osd/sdl/input.c +++ b/src/osd/sdl/input.c @@ -1859,7 +1859,7 @@ void sdlinput_poll(running_machine &machine) int cx, cy; osd_ticks_t click = osd_ticks() * 1000 / osd_ticks_per_second(); sdl_window_info *window = GET_FOCUS_WINDOW(&event.button); - if (window != NULL && window->xy_to_render_target(window, event.button.x,event.button.y, &cx, &cy) ) + if (window != NULL && window->renderer().xy_to_render_target(event.button.x,event.button.y, &cx, &cy) ) { ui_input_push_mouse_down_event(machine, window->m_target, cx, cy); // FIXME Parameter ? @@ -1893,7 +1893,7 @@ void sdlinput_poll(running_machine &machine) int cx, cy; sdl_window_info *window = GET_FOCUS_WINDOW(&event.button); - if (window != NULL && window->xy_to_render_target(window, event.button.x,event.button.y, &cx, &cy) ) + if (window != NULL && window->renderer().xy_to_render_target(event.button.x,event.button.y, &cx, &cy) ) { ui_input_push_mouse_up_event(machine, window->m_target, cx, cy); } @@ -1918,7 +1918,7 @@ void sdlinput_poll(running_machine &machine) int cx=-1, cy=-1; sdl_window_info *window = GET_FOCUS_WINDOW(&event.motion); - if (window != NULL && window->xy_to_render_target(window, event.motion.x, event.motion.y, &cx, &cy) ) + if (window != NULL && window->renderer().xy_to_render_target(event.motion.x, event.motion.y, &cx, &cy) ) ui_input_push_mouse_move_event(machine, window->m_target, cx, cy); } break; diff --git a/src/osd/sdl/window.c b/src/osd/sdl/window.c index 06475b06424..b03655912b1 100644 --- a/src/osd/sdl/window.c +++ b/src/osd/sdl/window.c @@ -483,8 +483,8 @@ static OSDWORK_CALLBACK( sdlwindow_resize_wt ) ASSERT_WINDOW_THREAD(); - window->destroy_all_textures(window); - window->resize(window, wp->new_width(), wp->new_height()); + window->renderer().destroy_all_textures(); + window->renderer().resize(wp->new_width(), wp->new_height()); window->blit_surface_size(wp->new_width(), wp->new_height()); @@ -517,7 +517,7 @@ static OSDWORK_CALLBACK( sdlwindow_clear_surface_wt ) ASSERT_WINDOW_THREAD(); - window->clear(window); + window->renderer().clear(); osd_free(wp); return NULL; } @@ -558,7 +558,7 @@ static OSDWORK_CALLBACK( sdlwindow_toggle_full_screen_wt ) window->m_windowed_height = window->m_height; } - window->destroy(window); + window->renderer().destroy(); sdlinput_release_keys(wp->machine()); // toggle the window mode @@ -582,7 +582,7 @@ static OSDWORK_CALLBACK( destroy_all_textures_wt ) sdl_window_info *window = wp->window(); - window->destroy_all_textures(window); + window->renderer().destroy_all_textures(); osd_free(wp); return NULL; @@ -722,7 +722,7 @@ int sdlwindow_video_window_create(running_machine &machine, int index, sdl_monit *last_window_ptr = window; last_window_ptr = &window->m_next; - draw.attach(&draw, window); + window->set_renderer(draw.create(window)); // create an event that we can use to skip blitting window->m_rendered_event = osd_event_alloc(FALSE, TRUE); @@ -781,7 +781,7 @@ static OSDWORK_CALLBACK( sdlwindow_video_window_destroy_wt ) ASSERT_WINDOW_THREAD(); // free the textures etc - window->destroy(window); + window->renderer().destroy(); // release all keys ... sdlinput_release_keys(wp->machine()); @@ -1027,7 +1027,7 @@ void sdl_window_info::video_window_update(running_machine &machine) } // ensure the target bounds are up-to-date, and then get the primitives - set_target_bounds(this); + renderer().set_target_bounds(); render_primitive_list &primlist = m_target->get_primitives(); @@ -1116,7 +1116,7 @@ static OSDWORK_CALLBACK( complete_create_wt ) } // initialize the drawing backend - if (window->create(window, tempwidth, tempheight)) + if (window->renderer().create(tempwidth, tempheight)) return (void *) &result[1]; // Make sure we have a consistent state @@ -1147,7 +1147,7 @@ static void measure_fps(sdl_window_info *window, UINT32 dc, int update) t0 = osd_ticks(); - window->draw(window, dc, update); + window->renderer().draw(dc, update); frames++; currentTime = osd_ticks(); @@ -1198,7 +1198,7 @@ static OSDWORK_CALLBACK( draw_video_contents_wt ) if( video_config.perftest ) measure_fps(window, dc, update); else - window->draw(window, dc, update); + window->renderer().draw(dc, update); } /* all done, ready for next */ diff --git a/src/osd/sdl/window.h b/src/osd/sdl/window.h index cdf3cc08a8d..d9284c95e21 100644 --- a/src/osd/sdl/window.h +++ b/src/osd/sdl/window.h @@ -40,13 +40,15 @@ public: osd_renderer(sdl_window_info *window) : m_window(window) { } + virtual ~osd_renderer() { } + sdl_window_info &window() { return *m_window; } virtual int create(int width, int height) = 0; virtual void resize(int width, int height) = 0; virtual int draw(UINT32 dc, int update) = 0; virtual void set_target_bounds() = 0; - virtual int y_to_render_target(int x, int y, int *xt, int *yt) = 0; + virtual int xy_to_render_target(int x, int y, int *xt, int *yt) = 0; virtual void destroy_all_textures() = 0; virtual void destroy() = 0; virtual void clear() = 0; @@ -62,7 +64,7 @@ public: int index, const sdl_window_config *config) : m_next(NULL), m_minwidth(0), m_minheight(0), m_startmaximized(0), - m_rendered_event(0), m_target(0), m_primlist(NULL), m_dxdata(NULL), + m_rendered_event(0), m_target(0), m_primlist(NULL), m_width(0), m_height(0), m_blitwidth(0), m_blitheight(0), m_start_viewscreen(0), #if (SDLMAME_SDL2) @@ -71,7 +73,7 @@ public: m_resize_height(0), m_last_resize(0), #else - screen_width(0), screen_height(0), + m_screen_width(0), m_screen_height(0), #endif m_machine(a_machine), m_monitor(a_monitor), m_fullscreen(0), m_index(0) { @@ -89,15 +91,18 @@ public: m_windowed_height = config->height; } + ~sdl_window_info() + { + global_free(m_renderer); + } + void video_window_update(running_machine &machine); - //void blit_surface_size(int window_width, int window_height); void toggle_full_screen(running_machine &machine); void modify_prescale(running_machine &machine, int dir); void window_resize(INT32 width, INT32 height); void window_clear(); void video_window_destroy(running_machine &machine); - //void pick_best_mode(int *fswidth, int *fsheight); void get_min_bounds(int *window_width, int *window_height, int constrain); void get_max_bounds(int *window_width, int *window_height, int constrain); @@ -111,17 +116,7 @@ public: void pick_best_mode(int *fswidth, int *fsheight); int index() const { return m_index; } -#if 1 - // Draw Callbacks - int (*create)(sdl_window_info *window, int m_width, int m_height); - void (*resize)(sdl_window_info *window, int m_width, int m_height); - int (*draw)(sdl_window_info *window, UINT32 dc, int update); - void (*set_target_bounds)(sdl_window_info *window); - int (*xy_to_render_target)(sdl_window_info *window, int x, int y, int *xt, int *yt); - void (*destroy_all_textures)(sdl_window_info *window); - void (*destroy)(sdl_window_info *window); - void (*clear)(sdl_window_info *window); -#endif + osd_renderer &renderer() { return *m_renderer; } // Pointer to next window sdl_window_info * m_next; @@ -143,9 +138,6 @@ public: render_target * m_target; render_primitive_list *m_primlist; - // drawing data - void * m_dxdata; - // cache of physical m_width and m_height int m_width; int m_height; @@ -171,6 +163,10 @@ public: int m_screen_height; #endif + void set_renderer(osd_renderer *renderer) + { + m_renderer = renderer; + } private: void constrain_to_aspect_ratio(int *window_width, int *window_height, int adjustment); @@ -186,8 +182,8 @@ private: struct sdl_draw_info { + osd_renderer *(*create)(sdl_window_info *window); void (*exit)(void); - void (*attach)(sdl_draw_info *info, sdl_window_info *window); }; //============================================================