trunk/src/osd/sdl/draw13.c
| r243307 | r243308 | |
| 144 | 144 | public: |
| 145 | 145 | sdl_info13(sdl_window_info *w) |
| 146 | 146 | : osd_renderer(w), m_blittimer(0), m_renderer(NULL), |
| 147 | | m_hofs(0), m_vofs(0), |
| 147 | m_last_hofs(0), m_last_vofs(0), |
| 148 | 148 | m_resize_pending(0), m_resize_width(0), m_resize_height(0), |
| 149 | 149 | m_last_blit_time(0), m_last_blit_pixels(0) |
| 150 | 150 | {} |
| r243307 | r243308 | |
| 164 | 164 | texture_info *texture_update(const render_primitive &prim); |
| 165 | 165 | |
| 166 | 166 | INT32 m_blittimer; |
| 167 | UINT32 m_extra_flags; |
| 167 | 168 | |
| 168 | 169 | SDL_Renderer * m_renderer; |
| 169 | 170 | simple_list<texture_info> m_texlist; // list of active textures |
| 170 | 171 | |
| 171 | | float m_hofs; |
| 172 | | float m_vofs; |
| 172 | float m_last_hofs; |
| 173 | float m_last_vofs; |
| 173 | 174 | |
| 174 | 175 | // resize information |
| 175 | 176 | |
| r243307 | r243308 | |
| 556 | 557 | } |
| 557 | 558 | |
| 558 | 559 | //============================================================ |
| 559 | | // sdl_info13::create |
| 560 | // sdl_info::create |
| 561 | // a |
| 562 | // a |
| 563 | // a |
| 564 | // a |
| 565 | // a |
| 566 | // a |
| 567 | // a |
| 568 | // a |
| 569 | // a |
| 570 | // a |
| 571 | // a |
| 572 | // a |
| 573 | // a |
| 574 | // a |
| 575 | // a |
| 576 | // a |
| 577 | // a |
| 578 | // a |
| 579 | // a |
| 580 | // a |
| 581 | // a |
| 582 | // a |
| 583 | // a |
| 584 | // a |
| 585 | // a |
| 586 | // a |
| 560 | 587 | //============================================================ |
| 561 | 588 | |
| 562 | 589 | int sdl_info13::create(int width, int height) |
| r243307 | r243308 | |
| 570 | 597 | |
| 571 | 598 | osd_printf_verbose("Enter sdl_info13::create\n"); |
| 572 | 599 | |
| 573 | | UINT32 extra_flags = (window().fullscreen() ? |
| 600 | // create the SDL window |
| 601 | m_extra_flags = (window().fullscreen() ? |
| 574 | 602 | SDL_WINDOW_BORDERLESS | SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_FULLSCREEN : SDL_WINDOW_RESIZABLE); |
| 575 | 603 | |
| 576 | 604 | #if defined(SDLMAME_WIN32) |
| r243307 | r243308 | |
| 579 | 607 | // create the SDL window |
| 580 | 608 | window().m_sdl_window = SDL_CreateWindow(window().m_title, |
| 581 | 609 | window().monitor()->position_size().x, window().monitor()->position_size().y, |
| 582 | | width, height, extra_flags); |
| 610 | width, height, m_extra_flags); |
| 583 | 611 | |
| 612 | if (!window().m_sdl_window ) |
| 613 | { |
| 614 | osd_printf_error("Window creation failed: %s\n", SDL_GetError()); |
| 615 | return 1; |
| 616 | } |
| 617 | |
| 584 | 618 | if (window().fullscreen() && video_config.switchres) |
| 585 | 619 | { |
| 586 | 620 | SDL_DisplayMode mode; |
| r243307 | r243308 | |
| 591 | 625 | mode.h = height; |
| 592 | 626 | if (window().m_refresh) |
| 593 | 627 | mode.refresh_rate = window().m_refresh; |
| 594 | | #if 0 |
| 595 | | if (window().depth) |
| 596 | | { |
| 597 | | switch (window().depth) |
| 598 | | { |
| 599 | | case 15: |
| 600 | | mode.format = SDL_PIXELFORMAT_RGB555; |
| 601 | | break; |
| 602 | | case 16: |
| 603 | | mode.format = SDL_PIXELFORMAT_RGB565; |
| 604 | | break; |
| 605 | | case 24: |
| 606 | | mode.format = SDL_PIXELFORMAT_RGB24; |
| 607 | | break; |
| 608 | | case 32: |
| 609 | | mode.format = SDL_PIXELFORMAT_RGB888; |
| 610 | | break; |
| 611 | | default: |
| 612 | | osd_printf_warning("Ignoring depth %d\n", window().depth); |
| 613 | | } |
| 614 | | } |
| 615 | | #endif |
| 616 | 628 | |
| 617 | 629 | SDL_SetWindowDisplayMode(window().m_sdl_window, &mode); // Try to set mode |
| 618 | 630 | #ifndef SDLMAME_WIN32 |
| r243307 | r243308 | |
| 625 | 637 | } |
| 626 | 638 | else |
| 627 | 639 | { |
| 628 | | //SDL_SetWindowDisplayMode(window().sdl_window, NULL); // Use desktop |
| 640 | //SDL_SetWindowDisplayMode(window().m_sdl_window, NULL); // Use desktop |
| 629 | 641 | } |
| 630 | 642 | // create renderer |
| 631 | 643 | |
| r243307 | r243308 | |
| 640 | 652 | } |
| 641 | 653 | |
| 642 | 654 | //SDL_SelectRenderer(window().sdl_window); |
| 655 | |
| 656 | // show window |
| 657 | |
| 643 | 658 | SDL_ShowWindow(window().m_sdl_window); |
| 644 | | //SDL_SetWindowFullscreen(window().window_id, window().fullscreen); |
| 659 | //SDL_SetWindowFullscreen(window().sdl_window, window().fullscreen); |
| 645 | 660 | SDL_RaiseWindow(window().m_sdl_window); |
| 646 | 661 | |
| 647 | 662 | SDL_GetWindowSize(window().m_sdl_window, &window().m_width, &window().m_height); |
| r243307 | r243308 | |
| 654 | 669 | } |
| 655 | 670 | |
| 656 | 671 | //============================================================ |
| 657 | | // sdl_info13::resize |
| 672 | // sdl_info::resize |
| 658 | 673 | //============================================================ |
| 659 | 674 | |
| 660 | 675 | void sdl_info13::resize(int width, int height) |
| r243307 | r243308 | |
| 677 | 692 | int sdl_info13::xy_to_render_target(int x, int y, int *xt, int *yt) |
| 678 | 693 | { |
| 679 | 694 | |
| 680 | | *xt = x - m_hofs; |
| 681 | | *yt = y - m_vofs; |
| 695 | *xt = x - m_last_hofs; |
| 696 | *yt = y - m_last_vofs; |
| 682 | 697 | if (*xt<0 || *xt >= window().m_blitwidth) |
| 683 | 698 | return 0; |
| 684 | 699 | if (*yt<0 || *yt >= window().m_blitheight) |
| r243307 | r243308 | |
| 687 | 702 | } |
| 688 | 703 | |
| 689 | 704 | //============================================================ |
| 690 | | // sdl_info13::get_primitives |
| 705 | // sdl_info::get_primitives |
| 691 | 706 | //============================================================ |
| 692 | 707 | |
| 693 | 708 | void sdl_info13::set_target_bounds() |
| r243307 | r243308 | |
| 696 | 711 | } |
| 697 | 712 | |
| 698 | 713 | //============================================================ |
| 699 | | // sdl_info13::draw |
| 714 | // sdl_info::draw |
| 700 | 715 | //============================================================ |
| 701 | 716 | |
| 702 | 717 | int sdl_info13::draw(UINT32 dc, int update) |
| r243307 | r243308 | |
| 761 | 776 | } |
| 762 | 777 | } |
| 763 | 778 | |
| 764 | | m_hofs = hofs; |
| 765 | | m_vofs = vofs; |
| 779 | m_last_hofs = hofs; |
| 780 | m_last_vofs = vofs; |
| 766 | 781 | |
| 767 | 782 | window().m_primlist->acquire_lock(); |
| 768 | 783 | |
trunk/src/osd/sdl/drawogl.c
| r243307 | r243308 | |
| 223 | 223 | #if (SDLMAME_SDL2) |
| 224 | 224 | m_gl_context_id(0), |
| 225 | 225 | #else |
| 226 | | sdlsurf(NULL), |
| 226 | m_sdlsurf(NULL), |
| 227 | 227 | #endif |
| 228 | 228 | m_initialized(0), |
| 229 | 229 | m_last_blendmode(0), |
| r243307 | r243308 | |
| 258 | 258 | /* virtual */ void clear(); |
| 259 | 259 | |
| 260 | 260 | void loadGLExtensions(); |
| 261 | void initialize_gl(); |
| 261 | 262 | void set_blendmode(int blendmode); |
| 262 | 263 | void texture_compute_type_subroutine(const render_texinfo *texsource, texture_info *texture, UINT32 flags); |
| 263 | 264 | void texture_compute_size_subroutine(texture_info *texture, UINT32 flags, |
| r243307 | r243308 | |
| 277 | 278 | INT32 m_blittimer; |
| 278 | 279 | UINT32 m_extra_flags; |
| 279 | 280 | |
| 281 | |
| 280 | 282 | #if (SDLMAME_SDL2) |
| 283 | // Original display_mode |
| 284 | SDL_DisplayMode m_original_mode; |
| 285 | |
| 281 | 286 | SDL_GLContext m_gl_context_id; |
| 282 | 287 | #else |
| 283 | 288 | // SDL surface |
| 284 | | SDL_Surface *sdlsurf; |
| 289 | SDL_Surface *m_sdlsurf; |
| 285 | 290 | #endif |
| 286 | 291 | |
| 287 | 292 | int m_initialized; // is everything well initialized, i.e. all GL stuff etc. |
| r243307 | r243308 | |
| 464 | 469 | |
| 465 | 470 | |
| 466 | 471 | //============================================================ |
| 467 | | // drawogl_attach |
| 468 | | //============================================================ |
| 469 | | |
| 470 | | //============================================================ |
| 471 | 472 | // Load the OGL function addresses |
| 472 | 473 | //============================================================ |
| 473 | 474 | |
| r243307 | r243308 | |
| 528 | 529 | #endif |
| 529 | 530 | } |
| 530 | 531 | |
| 531 | | //============================================================ |
| 532 | | // sdl_info::create |
| 533 | | //============================================================ |
| 534 | | |
| 535 | | int sdl_info_ogl::create(int width, int height) |
| 532 | void sdl_info_ogl::initialize_gl() |
| 536 | 533 | { |
| 537 | | char *extstr; |
| 538 | | char *vendor; |
| 539 | 534 | int has_and_allow_texturerect = 0; |
| 540 | 535 | |
| 541 | | #if (SDLMAME_SDL2) |
| 542 | | m_extra_flags = (window().fullscreen() ? |
| 543 | | SDL_WINDOW_BORDERLESS | SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_FULLSCREEN : SDL_WINDOW_RESIZABLE); |
| 544 | | m_extra_flags |= SDL_WINDOW_OPENGL; |
| 536 | char *extstr = (char *)glGetString(GL_EXTENSIONS); |
| 537 | char *vendor = (char *)glGetString(GL_VENDOR); |
| 545 | 538 | |
| 546 | | SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); |
| 547 | | |
| 548 | | /* FIXME: A reminder that gamma is wrong throughout MAME. Currently, SDL2.0 doesn't seem to |
| 549 | | * support the following attribute although my hardware lists GL_ARB_framebuffer_sRGB as an extension. |
| 550 | | * |
| 551 | | * SDL_GL_SetAttribute( SDL_GL_FRAMEBUFFER_SRGB_CAPABLE, 1 ); |
| 552 | | * |
| 553 | | */ |
| 554 | | |
| 555 | | //Moved into init |
| 556 | | //load_gl_lib(window().machine()); |
| 557 | | |
| 558 | | // create the SDL window |
| 559 | | window().m_sdl_window = SDL_CreateWindow(window().m_title, |
| 560 | | window().monitor()->position_size().x, window().monitor()->position_size().y, |
| 561 | | width, height, m_extra_flags); |
| 562 | | |
| 563 | | if (!window().m_sdl_window ) |
| 564 | | { |
| 565 | | osd_printf_error("OpenGL not supported on this driver: %s\n", SDL_GetError()); |
| 566 | | return 1; |
| 567 | | } |
| 568 | | |
| 569 | | if (window().fullscreen() && video_config.switchres) |
| 570 | | { |
| 571 | | SDL_DisplayMode mode; |
| 572 | | SDL_GetCurrentDisplayMode(window().monitor()->handle(), &mode); |
| 573 | | mode.w = width; |
| 574 | | mode.h = height; |
| 575 | | if (window().m_refresh) |
| 576 | | mode.refresh_rate = window().m_refresh; |
| 577 | | SDL_SetWindowDisplayMode(window().m_sdl_window, &mode); // Try to set mode |
| 578 | | } |
| 579 | | else |
| 580 | | SDL_SetWindowDisplayMode(window().m_sdl_window, NULL); // Use desktop |
| 581 | | |
| 582 | | SDL_ShowWindow(window().m_sdl_window); |
| 583 | | //SDL_SetWindowFullscreen(window().sdl_window, window().fullscreen); |
| 584 | | SDL_RaiseWindow(window().m_sdl_window); |
| 585 | | SDL_GetWindowSize(window().m_sdl_window, &window().m_width, &window().m_height); |
| 586 | | |
| 587 | | m_gl_context_id = SDL_GL_CreateContext(window().m_sdl_window); |
| 588 | | if (!m_gl_context_id) |
| 589 | | { |
| 590 | | osd_printf_error("OpenGL not supported on this driver: %s\n", SDL_GetError()); |
| 591 | | return 1; |
| 592 | | } |
| 593 | | |
| 594 | | SDL_GL_SetSwapInterval(video_config.waitvsync ? 2 : 0); |
| 595 | | |
| 596 | | #else |
| 597 | | m_extra_flags = (window().fullscreen() ? SDL_FULLSCREEN : SDL_RESIZABLE); |
| 598 | | m_extra_flags |= SDL_OPENGL | SDL_DOUBLEBUF; |
| 599 | | |
| 600 | | SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); |
| 601 | | #if (SDL_VERSION_ATLEAST(1,2,10)) && (!defined(SDLMAME_EMSCRIPTEN)) |
| 602 | | SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, video_config.waitvsync ? 1 : 0); |
| 603 | | #endif |
| 604 | | |
| 605 | | load_gl_lib(window().machine()); |
| 606 | | |
| 607 | | // create the SDL surface (which creates the window in windowed mode) |
| 608 | | sdlsurf = SDL_SetVideoMode(width, height, |
| 609 | | 0, SDL_SWSURFACE | SDL_ANYFORMAT | m_extra_flags); |
| 610 | | |
| 611 | | if (!sdlsurf) |
| 612 | | return 1; |
| 613 | | |
| 614 | | window().m_width = sdlsurf->w; |
| 615 | | window().m_height = sdlsurf->h; |
| 616 | | |
| 617 | | window().m_screen_width = 0; |
| 618 | | window().m_screen_height = 0; |
| 619 | | |
| 620 | | if ( (video_config.mode == VIDEO_MODE_OPENGL) && !(sdlsurf->flags & SDL_OPENGL) ) |
| 621 | | { |
| 622 | | osd_printf_error("OpenGL not supported on this driver!\n"); |
| 623 | | return 1; |
| 624 | | } |
| 625 | | |
| 626 | | // set the window title |
| 627 | | SDL_WM_SetCaption(window().m_title, "SDLMAME"); |
| 628 | | |
| 629 | | #endif |
| 630 | | m_blittimer = 0; |
| 631 | | m_surf_w = 0; |
| 632 | | m_surf_h = 0; |
| 633 | | |
| 634 | | m_initialized = 0; |
| 635 | | |
| 636 | | // in case any textures try to come up before these are validated, |
| 637 | | // OpenGL guarantees all implementations can handle something this size. |
| 638 | | m_texture_max_width = 64; |
| 639 | | m_texture_max_height = 64; |
| 640 | | |
| 641 | | /* load any GL function addresses |
| 642 | | * this must be done here because we need a context |
| 643 | | */ |
| 644 | | loadgl_functions(); |
| 645 | | |
| 646 | | extstr = (char *)glGetString(GL_EXTENSIONS); |
| 647 | | vendor = (char *)glGetString(GL_VENDOR); |
| 648 | | |
| 649 | 539 | //printf("%s\n", extstr); |
| 650 | 540 | |
| 651 | 541 | // print out the driver info for debugging |
| r243307 | r243308 | |
| 787 | 677 | |
| 788 | 678 | shown_video_info = 1; |
| 789 | 679 | |
| 680 | } |
| 681 | //============================================================ |
| 682 | // sdl_info::create |
| 683 | // a |
| 684 | // a |
| 685 | // a |
| 686 | // a |
| 687 | // a |
| 688 | // a |
| 689 | // a |
| 690 | // a |
| 691 | // a |
| 692 | // a |
| 693 | // a |
| 694 | // a |
| 695 | // a |
| 696 | // a |
| 697 | // a |
| 698 | // a |
| 699 | // a |
| 700 | // a |
| 701 | // a |
| 702 | // a |
| 703 | // a |
| 704 | // a |
| 705 | // a |
| 706 | // a |
| 707 | // a |
| 708 | // a |
| 709 | //============================================================ |
| 710 | |
| 711 | int sdl_info_ogl::create(int width, int height) |
| 712 | { |
| 713 | #if (SDLMAME_SDL2) |
| 714 | |
| 715 | SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); |
| 716 | |
| 717 | /* FIXME: A reminder that gamma is wrong throughout MAME. Currently, SDL2.0 doesn't seem to |
| 718 | * support the following attribute although my hardware lists GL_ARB_framebuffer_sRGB as an extension. |
| 719 | * |
| 720 | * SDL_GL_SetAttribute( SDL_GL_FRAMEBUFFER_SRGB_CAPABLE, 1 ); |
| 721 | * |
| 722 | */ |
| 723 | |
| 724 | osd_printf_verbose("Enter sdl_info_ogl::create\n"); |
| 725 | |
| 726 | // create the SDL window |
| 727 | // soft driver also used | SDL_WINDOW_INPUT_GRABBED | SDL_WINDOW_MOUSE_FOCUS |
| 728 | m_extra_flags = (window().fullscreen() ? |
| 729 | SDL_WINDOW_BORDERLESS | SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_FULLSCREEN : SDL_WINDOW_RESIZABLE); |
| 730 | |
| 731 | m_extra_flags |= SDL_WINDOW_OPENGL; |
| 732 | |
| 733 | |
| 734 | #if defined(SDLMAME_WIN32) |
| 735 | SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, "0"); |
| 736 | #endif |
| 737 | // create the SDL window |
| 738 | window().m_sdl_window = SDL_CreateWindow(window().m_title, |
| 739 | window().monitor()->position_size().x, window().monitor()->position_size().y, |
| 740 | width, height, m_extra_flags); |
| 741 | //window().m_sdl_window = SDL_CreateWindow(window().m_title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, |
| 742 | // width, height, m_extra_flags); |
| 743 | |
| 744 | if (!window().m_sdl_window ) |
| 745 | { |
| 746 | osd_printf_error("OpenGL not supported on this driver: %s\n", SDL_GetError()); |
| 747 | return 1; |
| 748 | } |
| 749 | |
| 750 | if (window().fullscreen() && video_config.switchres) |
| 751 | { |
| 752 | SDL_DisplayMode mode; |
| 753 | //SDL_GetCurrentDisplayMode(window().monitor()->handle, &mode); |
| 754 | SDL_GetWindowDisplayMode(window().m_sdl_window, &mode); |
| 755 | m_original_mode = mode; |
| 756 | mode.w = width; |
| 757 | mode.h = height; |
| 758 | if (window().m_refresh) |
| 759 | mode.refresh_rate = window().m_refresh; |
| 760 | |
| 761 | SDL_SetWindowDisplayMode(window().m_sdl_window, &mode); // Try to set mode |
| 762 | #ifndef SDLMAME_WIN32 |
| 763 | /* FIXME: Warp the mouse to 0,0 in case a virtual desktop resolution |
| 764 | * is in place after the mode switch - which will most likely be the case |
| 765 | * This is a hack to work around a deficiency in SDL2 |
| 766 | */ |
| 767 | SDL_WarpMouseInWindow(window().m_sdl_window, 1, 1); |
| 768 | #endif |
| 769 | } |
| 770 | else |
| 771 | { |
| 772 | //SDL_SetWindowDisplayMode(window().m_sdl_window, NULL); // Use desktop |
| 773 | } |
| 774 | // create renderer |
| 775 | |
| 776 | //SDL_SelectRenderer(window().sdl_window); |
| 777 | |
| 778 | // show window |
| 779 | |
| 780 | SDL_ShowWindow(window().m_sdl_window); |
| 781 | //SDL_SetWindowFullscreen(window().m_sdl_window, window().fullscreen); |
| 782 | SDL_RaiseWindow(window().m_sdl_window); |
| 783 | |
| 784 | SDL_GetWindowSize(window().m_sdl_window, &window().m_width, &window().m_height); |
| 785 | |
| 786 | |
| 787 | m_gl_context_id = SDL_GL_CreateContext(window().m_sdl_window); |
| 788 | if (!m_gl_context_id) |
| 789 | { |
| 790 | osd_printf_error("OpenGL not supported on this driver: %s\n", SDL_GetError()); |
| 791 | return 1; |
| 792 | } |
| 793 | |
| 794 | SDL_GL_SetSwapInterval(video_config.waitvsync ? 2 : 0); |
| 795 | |
| 796 | #else |
| 797 | m_extra_flags = (window().fullscreen() ? SDL_FULLSCREEN : SDL_RESIZABLE); |
| 798 | m_extra_flags |= SDL_OPENGL | SDL_DOUBLEBUF; |
| 799 | |
| 800 | SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); |
| 801 | #if (SDL_VERSION_ATLEAST(1,2,10)) && (!defined(SDLMAME_EMSCRIPTEN)) |
| 802 | SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, video_config.waitvsync ? 1 : 0); |
| 803 | #endif |
| 804 | |
| 805 | load_gl_lib(window().machine()); |
| 806 | |
| 807 | // create the SDL surface (which creates the window in windowed mode) |
| 808 | m_sdlsurf = SDL_SetVideoMode(width, height, |
| 809 | 0, SDL_SWSURFACE | SDL_ANYFORMAT | m_extra_flags); |
| 810 | |
| 811 | if (!m_sdlsurf) |
| 812 | return 1; |
| 813 | |
| 814 | window().m_width = m_sdlsurf->w; |
| 815 | window().m_height = m_sdlsurf->h; |
| 816 | |
| 817 | window().m_screen_width = 0; |
| 818 | window().m_screen_height = 0; |
| 819 | |
| 820 | if ( (video_config.mode == VIDEO_MODE_OPENGL) && !(m_sdlsurf->flags & SDL_OPENGL) ) |
| 821 | { |
| 822 | osd_printf_error("OpenGL not supported on this driver!\n"); |
| 823 | return 1; |
| 824 | } |
| 825 | |
| 826 | // set the window title |
| 827 | SDL_WM_SetCaption(window().m_title, "SDLMAME"); |
| 828 | |
| 829 | #endif |
| 830 | |
| 831 | m_blittimer = 0; |
| 832 | m_surf_w = 0; |
| 833 | m_surf_h = 0; |
| 834 | |
| 835 | m_initialized = 0; |
| 836 | |
| 837 | // in case any textures try to come up before these are validated, |
| 838 | // OpenGL guarantees all implementations can handle something this size. |
| 839 | m_texture_max_width = 64; |
| 840 | m_texture_max_height = 64; |
| 841 | |
| 842 | /* load any GL function addresses |
| 843 | * this must be done here because we need a context |
| 844 | */ |
| 845 | loadgl_functions(); |
| 846 | initialize_gl(); |
| 847 | |
| 848 | |
| 790 | 849 | m_init_context = 0; |
| 791 | 850 | |
| 851 | osd_printf_verbose("Leave sdl_info_ogl::create\n"); |
| 792 | 852 | return 0; |
| 793 | 853 | } |
| 794 | 854 | |
| r243307 | r243308 | |
| 804 | 864 | SDL_GetWindowSize(window().m_sdl_window, &window().m_width, &window().m_height); |
| 805 | 865 | m_blittimer = 3; |
| 806 | 866 | #else |
| 807 | | SDL_FreeSurface(sdlsurf); |
| 867 | SDL_FreeSurface(m_sdlsurf); |
| 808 | 868 | |
| 809 | | sdlsurf = SDL_SetVideoMode(width, height, 0, |
| 869 | m_sdlsurf = SDL_SetVideoMode(width, height, 0, |
| 810 | 870 | SDL_SWSURFACE | SDL_ANYFORMAT | m_extra_flags); |
| 811 | 871 | |
| 812 | | window().m_width = sdlsurf->w; |
| 813 | | window().m_height = sdlsurf->h; |
| 872 | window().m_width = m_sdlsurf->w; |
| 873 | window().m_height = m_sdlsurf->h; |
| 814 | 874 | #endif |
| 815 | 875 | m_init_context = 1; |
| 816 | 876 | |
| r243307 | r243308 | |
| 1151 | 1211 | } |
| 1152 | 1212 | |
| 1153 | 1213 | //============================================================ |
| 1214 | // sdl_info::destroy |
| 1215 | //============================================================ |
| 1216 | |
| 1217 | void sdl_info_ogl::destroy() |
| 1218 | { |
| 1219 | |
| 1220 | // free the memory in the window |
| 1221 | |
| 1222 | destroy_all_textures(); |
| 1223 | |
| 1224 | #if (SDLMAME_SDL2) |
| 1225 | SDL_GL_DeleteContext(m_gl_context_id); |
| 1226 | if (window().fullscreen() && video_config.switchres) |
| 1227 | { |
| 1228 | SDL_SetWindowFullscreen(window().m_sdl_window, 0); // Try to set mode |
| 1229 | SDL_SetWindowDisplayMode(window().m_sdl_window, &m_original_mode); // Try to set mode |
| 1230 | SDL_SetWindowFullscreen(window().m_sdl_window, SDL_WINDOW_FULLSCREEN); // Try to set mode |
| 1231 | } |
| 1232 | |
| 1233 | SDL_DestroyWindow(window().m_sdl_window); |
| 1234 | #else |
| 1235 | if (m_sdlsurf) |
| 1236 | { |
| 1237 | SDL_FreeSurface(m_sdlsurf); |
| 1238 | m_sdlsurf = NULL; |
| 1239 | } |
| 1240 | #endif |
| 1241 | } |
| 1242 | |
| 1243 | //============================================================ |
| 1154 | 1244 | // sdl_info::draw |
| 1155 | 1245 | //============================================================ |
| 1156 | 1246 | |
| r243307 | r243308 | |
| 1618 | 1708 | } |
| 1619 | 1709 | |
| 1620 | 1710 | //============================================================ |
| 1621 | | // sdl_info::destroy |
| 1622 | | //============================================================ |
| 1623 | | |
| 1624 | | void sdl_info_ogl::destroy() |
| 1625 | | { |
| 1626 | | |
| 1627 | | // free the memory in the window |
| 1628 | | |
| 1629 | | destroy_all_textures(); |
| 1630 | | |
| 1631 | | #if (SDLMAME_SDL2) |
| 1632 | | SDL_GL_DeleteContext(m_gl_context_id); |
| 1633 | | SDL_DestroyWindow(window().m_sdl_window); |
| 1634 | | #else |
| 1635 | | if (sdlsurf) |
| 1636 | | { |
| 1637 | | SDL_FreeSurface(sdlsurf); |
| 1638 | | sdlsurf = NULL; |
| 1639 | | } |
| 1640 | | #endif |
| 1641 | | } |
| 1642 | | |
| 1643 | | //============================================================ |
| 1644 | 1711 | // texture_compute_size and type |
| 1645 | 1712 | //============================================================ |
| 1646 | 1713 | |
trunk/src/osd/sdl/drawsdl.c
| r243307 | r243308 | |
| 96 | 96 | UINT32 m_extra_flags; |
| 97 | 97 | |
| 98 | 98 | #if (SDLMAME_SDL2) |
| 99 | // Original display_mode |
| 100 | SDL_DisplayMode m_original_mode; |
| 101 | |
| 99 | 102 | SDL_Renderer *m_sdl_renderer; |
| 100 | 103 | SDL_Texture *m_texture_id; |
| 101 | 104 | #else |
| r243307 | r243308 | |
| 399 | 402 | #endif |
| 400 | 403 | |
| 401 | 404 | //============================================================ |
| 402 | | // drawsdl_window_create |
| 405 | // sdl_info::create |
| 406 | // a |
| 407 | // a |
| 408 | // a |
| 409 | // a |
| 410 | // a |
| 411 | // a |
| 412 | // a |
| 413 | // a |
| 414 | // a |
| 415 | // a |
| 416 | // a |
| 417 | // a |
| 418 | // a |
| 419 | // a |
| 420 | // a |
| 421 | // a |
| 422 | // a |
| 423 | // a |
| 424 | // a |
| 425 | // a |
| 426 | // a |
| 427 | // a |
| 428 | // a |
| 429 | // a |
| 430 | // a |
| 431 | // a |
| 403 | 432 | //============================================================ |
| 404 | 433 | |
| 405 | 434 | int sdl_info::create(int width, int height) |
| r243307 | r243308 | |
| 408 | 437 | |
| 409 | 438 | #if (SDLMAME_SDL2) |
| 410 | 439 | |
| 440 | osd_printf_verbose("Enter sdl_info::create\n"); |
| 441 | |
| 411 | 442 | /* set hints ... */ |
| 412 | | |
| 413 | 443 | SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, sm->sdl_scale_mode); |
| 414 | 444 | |
| 445 | // create the SDL window |
| 446 | // soft driver also used | SDL_WINDOW_INPUT_GRABBED | SDL_WINDOW_MOUSE_FOCUS |
| 415 | 447 | m_extra_flags = (window().fullscreen() ? |
| 416 | | SDL_WINDOW_BORDERLESS | SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_MOUSE_FOCUS |
| 417 | | | SDL_WINDOW_INPUT_GRABBED : SDL_WINDOW_RESIZABLE); |
| 448 | SDL_WINDOW_BORDERLESS | SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_FULLSCREEN : SDL_WINDOW_RESIZABLE); |
| 418 | 449 | |
| 419 | | window().m_sdl_window = SDL_CreateWindow(window().m_title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, |
| 450 | #if defined(SDLMAME_WIN32) |
| 451 | SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, "0"); |
| 452 | #endif |
| 453 | window().m_sdl_window = SDL_CreateWindow(window().m_title, |
| 454 | window().monitor()->position_size().x, window().monitor()->position_size().y, |
| 420 | 455 | width, height, m_extra_flags); |
| 456 | //window().m_sdl_window = SDL_CreateWindow(window().m_title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, |
| 457 | // width, height, m_extra_flags); |
| 421 | 458 | |
| 459 | if (!window().m_sdl_window ) |
| 460 | { |
| 461 | osd_printf_error("Unable to create window: %s\n", SDL_GetError()); |
| 462 | return 1; |
| 463 | } |
| 464 | |
| 422 | 465 | if (window().fullscreen() && video_config.switchres) |
| 423 | 466 | { |
| 424 | 467 | SDL_DisplayMode mode; |
| 425 | | SDL_GetCurrentDisplayMode(window().monitor()->handle(), &mode); |
| 468 | //SDL_GetCurrentDisplayMode(window().monitor()->handle, &mode); |
| 469 | SDL_GetWindowDisplayMode(window().m_sdl_window, &mode); |
| 470 | m_original_mode = mode; |
| 426 | 471 | mode.w = width; |
| 427 | 472 | mode.h = height; |
| 428 | 473 | if (window().m_refresh) |
| 429 | 474 | mode.refresh_rate = window().m_refresh; |
| 475 | |
| 430 | 476 | SDL_SetWindowDisplayMode(window().m_sdl_window, &mode); // Try to set mode |
| 477 | #ifndef SDLMAME_WIN32 |
| 478 | /* FIXME: Warp the mouse to 0,0 in case a virtual desktop resolution |
| 479 | * is in place after the mode switch - which will most likely be the case |
| 480 | * This is a hack to work around a deficiency in SDL2 |
| 481 | */ |
| 482 | SDL_WarpMouseInWindow(window().m_sdl_window, 1, 1); |
| 483 | #endif |
| 431 | 484 | } |
| 432 | 485 | else |
| 433 | | SDL_SetWindowDisplayMode(window().m_sdl_window, NULL); // Use desktop |
| 486 | { |
| 487 | //SDL_SetWindowDisplayMode(window().m_sdl_window, NULL); // Use desktop |
| 488 | } |
| 489 | // create renderer |
| 434 | 490 | |
| 491 | //SDL_SelectRenderer(window().sdl_window); |
| 492 | |
| 493 | // show window |
| 494 | |
| 435 | 495 | SDL_ShowWindow(window().m_sdl_window); |
| 496 | //SDL_SetWindowFullscreen(window().m_sdl_window, window().fullscreen); |
| 497 | SDL_RaiseWindow(window().m_sdl_window); |
| 436 | 498 | |
| 437 | | SDL_SetWindowFullscreen(window().m_sdl_window, (SDL_bool) window().fullscreen()); |
| 438 | 499 | SDL_GetWindowSize(window().m_sdl_window, &window().m_width, &window().m_height); |
| 439 | | SDL_RaiseWindow(window().m_sdl_window); |
| 440 | 500 | |
| 441 | 501 | /* FIXME: Bug in SDL 1.3 */ |
| 442 | 502 | if (window().fullscreen()) |
| r243307 | r243308 | |
| 495 | 555 | |
| 496 | 556 | // set the window title |
| 497 | 557 | SDL_WM_SetCaption(window().m_title, "SDLMAME"); |
| 558 | |
| 498 | 559 | #endif |
| 560 | |
| 499 | 561 | m_yuv_lookup = NULL; |
| 500 | 562 | m_blittimer = 0; |
| 501 | 563 | |
| 502 | 564 | yuv_init(); |
| 565 | osd_printf_verbose("Leave sdl_info::create\n"); |
| 503 | 566 | return 0; |
| 504 | 567 | } |
| 505 | 568 | |
| 506 | 569 | //============================================================ |
| 507 | | // drawsdl_window_resize |
| 570 | // sdl_info::resize |
| 508 | 571 | //============================================================ |
| 509 | 572 | |
| 510 | 573 | void sdl_info::resize(int width, int height) |
| r243307 | r243308 | |
| 523 | 586 | m_yuvsurf = NULL; |
| 524 | 587 | } |
| 525 | 588 | SDL_FreeSurface(m_sdlsurf); |
| 526 | | //printf("SetVideoMode %d %d\n", wp->resize_new_width, wp->resize_new_height); |
| 527 | | |
| 589 | |
| 528 | 590 | m_sdlsurf = SDL_SetVideoMode(width, height, 0, |
| 529 | 591 | SDL_SWSURFACE | SDL_ANYFORMAT | m_extra_flags); |
| 530 | 592 | window().m_width = m_sdlsurf->w; |
| r243307 | r243308 | |
| 540 | 602 | |
| 541 | 603 | |
| 542 | 604 | //============================================================ |
| 543 | | // drawsdl_window_destroy |
| 605 | // sdl_info::destroy |
| 544 | 606 | //============================================================ |
| 545 | 607 | |
| 546 | 608 | void sdl_info::destroy() |
| r243307 | r243308 | |
| 550 | 612 | //SDL_SelectRenderer(window().sdl_window); |
| 551 | 613 | SDL_DestroyTexture(m_texture_id); |
| 552 | 614 | //SDL_DestroyRenderer(window().sdl_window); |
| 615 | if (window().fullscreen() && video_config.switchres) |
| 616 | { |
| 617 | SDL_SetWindowFullscreen(window().m_sdl_window, 0); // Try to set mode |
| 618 | SDL_SetWindowDisplayMode(window().m_sdl_window, &m_original_mode); // Try to set mode |
| 619 | SDL_SetWindowFullscreen(window().m_sdl_window, SDL_WINDOW_FULLSCREEN); // Try to set mode |
| 620 | } |
| 621 | |
| 553 | 622 | SDL_DestroyWindow(window().m_sdl_window); |
| 554 | 623 | #else |
| 555 | 624 | if (m_yuvsurf != NULL) |
| r243307 | r243308 | |
| 579 | 648 | } |
| 580 | 649 | |
| 581 | 650 | //============================================================ |
| 582 | | // drawsdl_window_clear |
| 651 | // sdl_info::draw |
| 583 | 652 | //============================================================ |
| 584 | 653 | |
| 585 | 654 | void sdl_info::clear() |