trunk/src/osd/sdl/draw13.c
| r243304 | r243305 | |
| 79 | 79 | // Textures |
| 80 | 80 | //============================================================ |
| 81 | 81 | |
| 82 | | struct sdl_info13; |
| 82 | class sdl_info13; |
| 83 | 83 | struct copy_info_t; |
| 84 | 84 | |
| 85 | 85 | /* texture_info holds information about a texture */ |
| r243304 | r243305 | |
| 139 | 139 | #include "blit13.h" |
| 140 | 140 | |
| 141 | 141 | /* sdl_info is the information about SDL for the current screen */ |
| 142 | | struct sdl_info13 |
| 142 | class sdl_info13 : public osd_renderer |
| 143 | 143 | { |
| 144 | | sdl_info13() |
| 145 | | : m_blittimer(0), m_renderer(NULL), |
| 144 | public: |
| 145 | sdl_info13(sdl_window_info *w) |
| 146 | : osd_renderer(w), m_blittimer(0), m_renderer(NULL), |
| 146 | 147 | m_hofs(0), m_vofs(0), |
| 147 | 148 | m_resize_pending(0), m_resize_width(0), m_resize_height(0), |
| 148 | 149 | m_last_blit_time(0), m_last_blit_pixels(0) |
| 149 | 150 | {} |
| 150 | 151 | |
| 152 | /* virtual */ int create(int width, int height); |
| 153 | /* virtual */ void resize(int width, int height); |
| 154 | /* virtual */ int draw(UINT32 dc, int update); |
| 155 | /* virtual */ void set_target_bounds(); |
| 156 | /* virtual */ int xy_to_render_target(int x, int y, int *xt, int *yt); |
| 157 | /* virtual */ void destroy_all_textures(); |
| 158 | /* virtual */ void destroy(); |
| 159 | /* virtual */ void clear(); |
| 160 | |
| 151 | 161 | void render_quad(texture_info *texture, const render_primitive *prim, const int x, const int y); |
| 152 | 162 | |
| 153 | 163 | texture_info *texture_find(const render_primitive &prim, const quad_setup_data &setup); |
| r243304 | r243305 | |
| 198 | 208 | // core functions |
| 199 | 209 | |
| 200 | 210 | static void drawsdl2_exit(void); |
| 201 | | static void drawsdl2_attach(sdl_draw_info *info, sdl_window_info *window); |
| 202 | | static int drawsdl2_window_create(sdl_window_info *window, int width, int height); |
| 203 | | static void drawsdl2_window_resize(sdl_window_info *window, int width, int height); |
| 204 | | static void drawsdl2_window_destroy(sdl_window_info *window); |
| 205 | | static int drawsdl2_window_draw(sdl_window_info *window, UINT32 dc, int update); |
| 206 | | static void drawsdl2_set_target_bounds(sdl_window_info *window); |
| 207 | | static void drawsdl2_destroy_all_textures(sdl_window_info *window); |
| 208 | | static void drawsdl2_window_clear(sdl_window_info *window); |
| 209 | | static int drawsdl2_xy_to_render_target(sdl_window_info *window, int x, int y, int *xt, int *yt); |
| 210 | 211 | |
| 211 | 212 | //============================================================ |
| 212 | 213 | // STATIC VARIABLES |
| r243304 | r243305 | |
| 483 | 484 | } |
| 484 | 485 | } |
| 485 | 486 | |
| 487 | static osd_renderer *drawsdl2_create(sdl_window_info *window) |
| 488 | { |
| 489 | return global_alloc(sdl_info13(window)); |
| 490 | } |
| 491 | |
| 486 | 492 | // FIXME: machine only used to access options. |
| 487 | 493 | int drawsdl2_init(running_machine &machine, sdl_draw_info *callbacks) |
| 488 | 494 | { |
| r243304 | r243305 | |
| 490 | 496 | |
| 491 | 497 | // fill in the callbacks |
| 492 | 498 | callbacks->exit = drawsdl2_exit; |
| 493 | | callbacks->attach = drawsdl2_attach; |
| 499 | callbacks->create = drawsdl2_create; |
| 494 | 500 | |
| 495 | 501 | osd_printf_verbose("Using SDL native texturing driver (SDL 2.0+)\n"); |
| 496 | 502 | |
| r243304 | r243305 | |
| 550 | 556 | } |
| 551 | 557 | |
| 552 | 558 | //============================================================ |
| 553 | | // drawsdl2_attach |
| 559 | // sdl_info13::create |
| 554 | 560 | //============================================================ |
| 555 | 561 | |
| 556 | | static void drawsdl2_attach(sdl_draw_info *info, sdl_window_info *window) |
| 562 | int sdl_info13::create(int width, int height) |
| 557 | 563 | { |
| 558 | | // fill in the callbacks |
| 559 | | window->create = drawsdl2_window_create; |
| 560 | | window->resize = drawsdl2_window_resize; |
| 561 | | window->set_target_bounds = drawsdl2_set_target_bounds; |
| 562 | | window->draw = drawsdl2_window_draw; |
| 563 | | window->destroy = drawsdl2_window_destroy; |
| 564 | | window->destroy_all_textures = drawsdl2_destroy_all_textures; |
| 565 | | window->clear = drawsdl2_window_clear; |
| 566 | | window->xy_to_render_target = drawsdl2_xy_to_render_target; |
| 567 | | } |
| 568 | | |
| 569 | | //============================================================ |
| 570 | | // drawsdl2_window_create |
| 571 | | //============================================================ |
| 572 | | |
| 573 | | static int drawsdl2_window_create(sdl_window_info *window, int width, int height) |
| 574 | | { |
| 575 | | // allocate memory for our structures |
| 576 | | sdl_info13 *sdl = global_alloc(sdl_info13); |
| 577 | | |
| 578 | 564 | /* FIXME: On Ubuntu and potentially other Linux OS you should use |
| 579 | 565 | * to disable panning. This has to be done before every invocation of mame. |
| 580 | 566 | * |
| r243304 | r243305 | |
| 582 | 568 | * |
| 583 | 569 | */ |
| 584 | 570 | |
| 585 | | osd_printf_verbose("Enter drawsdl2_window_create\n"); |
| 571 | osd_printf_verbose("Enter sdl_info13::create\n"); |
| 586 | 572 | |
| 587 | | window->m_dxdata = sdl; |
| 588 | | |
| 589 | | UINT32 extra_flags = (window->fullscreen() ? |
| 573 | UINT32 extra_flags = (window().fullscreen() ? |
| 590 | 574 | SDL_WINDOW_BORDERLESS | SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_FULLSCREEN : SDL_WINDOW_RESIZABLE); |
| 591 | 575 | |
| 592 | 576 | #if defined(SDLMAME_WIN32) |
| 593 | 577 | SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, "0"); |
| 594 | 578 | #endif |
| 595 | 579 | // create the SDL window |
| 596 | | window->m_sdl_window = SDL_CreateWindow(window->m_title, |
| 597 | | window->monitor()->position_size().x, window->monitor()->position_size().y, |
| 580 | window().m_sdl_window = SDL_CreateWindow(window().m_title, |
| 581 | window().monitor()->position_size().x, window().monitor()->position_size().y, |
| 598 | 582 | width, height, extra_flags); |
| 599 | 583 | |
| 600 | | if (window->fullscreen() && video_config.switchres) |
| 584 | if (window().fullscreen() && video_config.switchres) |
| 601 | 585 | { |
| 602 | 586 | SDL_DisplayMode mode; |
| 603 | | //SDL_GetCurrentDisplayMode(window->monitor()->handle, &mode); |
| 604 | | SDL_GetWindowDisplayMode(window->m_sdl_window, &mode); |
| 605 | | sdl->m_original_mode = mode; |
| 587 | //SDL_GetCurrentDisplayMode(window().monitor()->handle, &mode); |
| 588 | SDL_GetWindowDisplayMode(window().m_sdl_window, &mode); |
| 589 | m_original_mode = mode; |
| 606 | 590 | mode.w = width; |
| 607 | 591 | mode.h = height; |
| 608 | | if (window->m_refresh) |
| 609 | | mode.refresh_rate = window->m_refresh; |
| 592 | if (window().m_refresh) |
| 593 | mode.refresh_rate = window().m_refresh; |
| 610 | 594 | #if 0 |
| 611 | | if (window->depth) |
| 595 | if (window().depth) |
| 612 | 596 | { |
| 613 | | switch (window->depth) |
| 597 | switch (window().depth) |
| 614 | 598 | { |
| 615 | 599 | case 15: |
| 616 | 600 | mode.format = SDL_PIXELFORMAT_RGB555; |
| r243304 | r243305 | |
| 625 | 609 | mode.format = SDL_PIXELFORMAT_RGB888; |
| 626 | 610 | break; |
| 627 | 611 | default: |
| 628 | | osd_printf_warning("Ignoring depth %d\n", window->depth); |
| 612 | osd_printf_warning("Ignoring depth %d\n", window().depth); |
| 629 | 613 | } |
| 630 | 614 | } |
| 631 | 615 | #endif |
| 632 | 616 | |
| 633 | | SDL_SetWindowDisplayMode(window->m_sdl_window, &mode); // Try to set mode |
| 617 | SDL_SetWindowDisplayMode(window().m_sdl_window, &mode); // Try to set mode |
| 634 | 618 | #ifndef SDLMAME_WIN32 |
| 635 | 619 | /* FIXME: Warp the mouse to 0,0 in case a virtual desktop resolution |
| 636 | 620 | * is in place after the mode switch - which will most likely be the case |
| 637 | 621 | * This is a hack to work around a deficiency in SDL2 |
| 638 | 622 | */ |
| 639 | | SDL_WarpMouseInWindow(window->m_sdl_window, 1, 1); |
| 623 | SDL_WarpMouseInWindow(window().m_sdl_window, 1, 1); |
| 640 | 624 | #endif |
| 641 | 625 | } |
| 642 | 626 | else |
| 643 | 627 | { |
| 644 | | //SDL_SetWindowDisplayMode(window->sdl_window, NULL); // Use desktop |
| 628 | //SDL_SetWindowDisplayMode(window().sdl_window, NULL); // Use desktop |
| 645 | 629 | } |
| 646 | 630 | // create renderer |
| 647 | 631 | |
| 648 | 632 | if (video_config.waitvsync) |
| 649 | | sdl->m_renderer = SDL_CreateRenderer(window->m_sdl_window, -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED); |
| 633 | m_renderer = SDL_CreateRenderer(window().m_sdl_window, -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED); |
| 650 | 634 | else |
| 651 | | sdl->m_renderer = SDL_CreateRenderer(window->m_sdl_window, -1, SDL_RENDERER_ACCELERATED); |
| 635 | m_renderer = SDL_CreateRenderer(window().m_sdl_window, -1, SDL_RENDERER_ACCELERATED); |
| 652 | 636 | |
| 653 | | if (!sdl->m_renderer) |
| 637 | if (!m_renderer) |
| 654 | 638 | { |
| 655 | 639 | fatalerror("Error on creating renderer: %s\n", SDL_GetError()); |
| 656 | 640 | } |
| 657 | 641 | |
| 658 | | //SDL_SelectRenderer(window->sdl_window); |
| 659 | | SDL_ShowWindow(window->m_sdl_window); |
| 660 | | //SDL_SetWindowFullscreen(window->window_id, window->fullscreen); |
| 661 | | SDL_RaiseWindow(window->m_sdl_window); |
| 642 | //SDL_SelectRenderer(window().sdl_window); |
| 643 | SDL_ShowWindow(window().m_sdl_window); |
| 644 | //SDL_SetWindowFullscreen(window().window_id, window().fullscreen); |
| 645 | SDL_RaiseWindow(window().m_sdl_window); |
| 662 | 646 | |
| 663 | | SDL_GetWindowSize(window->m_sdl_window, &window->m_width, &window->m_height); |
| 647 | SDL_GetWindowSize(window().m_sdl_window, &window().m_width, &window().m_height); |
| 664 | 648 | |
| 665 | | sdl->m_blittimer = 3; |
| 649 | m_blittimer = 3; |
| 666 | 650 | |
| 667 | | SDL_RenderPresent(sdl->m_renderer); |
| 668 | | osd_printf_verbose("Leave drawsdl2_window_create\n"); |
| 651 | SDL_RenderPresent(m_renderer); |
| 652 | osd_printf_verbose("Leave sdl_info13::create\n"); |
| 669 | 653 | return 0; |
| 670 | 654 | } |
| 671 | 655 | |
| 672 | 656 | //============================================================ |
| 673 | | // drawsdl2_window_resize |
| 657 | // sdl_info13::resize |
| 674 | 658 | //============================================================ |
| 675 | 659 | |
| 676 | | static void drawsdl2_window_resize(sdl_window_info *window, int width, int height) |
| 660 | void sdl_info13::resize(int width, int height) |
| 677 | 661 | { |
| 678 | | sdl_info13 *sdl = (sdl_info13 *) window->m_dxdata; |
| 662 | m_resize_pending = 1; |
| 663 | m_resize_height = height; |
| 664 | m_resize_width = width; |
| 679 | 665 | |
| 680 | | sdl->m_resize_pending = 1; |
| 681 | | sdl->m_resize_height = height; |
| 682 | | sdl->m_resize_width = width; |
| 666 | window().m_width = width; |
| 667 | window().m_height = height; |
| 683 | 668 | |
| 684 | | window->m_width = width; |
| 685 | | window->m_height = height; |
| 669 | m_blittimer = 3; |
| 686 | 670 | |
| 687 | | sdl->m_blittimer = 3; |
| 688 | | |
| 689 | 671 | } |
| 690 | 672 | |
| 691 | 673 | //============================================================ |
| 692 | 674 | // drawsdl_xy_to_render_target |
| 693 | 675 | //============================================================ |
| 694 | 676 | |
| 695 | | static int drawsdl2_xy_to_render_target(sdl_window_info *window, int x, int y, int *xt, int *yt) |
| 677 | int sdl_info13::xy_to_render_target(int x, int y, int *xt, int *yt) |
| 696 | 678 | { |
| 697 | | sdl_info13 *sdl = (sdl_info13 *) window->m_dxdata; |
| 698 | 679 | |
| 699 | | *xt = x - sdl->m_hofs; |
| 700 | | *yt = y - sdl->m_vofs; |
| 701 | | if (*xt<0 || *xt >= window->m_blitwidth) |
| 680 | *xt = x - m_hofs; |
| 681 | *yt = y - m_vofs; |
| 682 | if (*xt<0 || *xt >= window().m_blitwidth) |
| 702 | 683 | return 0; |
| 703 | | if (*yt<0 || *yt >= window->m_blitheight) |
| 684 | if (*yt<0 || *yt >= window().m_blitheight) |
| 704 | 685 | return 0; |
| 705 | 686 | return 1; |
| 706 | 687 | } |
| 707 | 688 | |
| 708 | 689 | //============================================================ |
| 709 | | // drawsdl2_window_get_primitives |
| 690 | // sdl_info13::get_primitives |
| 710 | 691 | //============================================================ |
| 711 | 692 | |
| 712 | | static void drawsdl2_set_target_bounds(sdl_window_info *window) |
| 693 | void sdl_info13::set_target_bounds() |
| 713 | 694 | { |
| 714 | | window->m_target->set_bounds(window->m_blitwidth, window->m_blitheight, window->monitor()->aspect()); |
| 695 | window().m_target->set_bounds(window().m_blitwidth, window().m_blitheight, window().monitor()->aspect()); |
| 715 | 696 | } |
| 716 | 697 | |
| 717 | 698 | //============================================================ |
| 718 | | // drawsdl2_window_draw |
| 699 | // sdl_info13::draw |
| 719 | 700 | //============================================================ |
| 720 | 701 | |
| 721 | | static int drawsdl2_window_draw(sdl_window_info *window, UINT32 dc, int update) |
| 702 | int sdl_info13::draw(UINT32 dc, int update) |
| 722 | 703 | { |
| 723 | | sdl_info13 *sdl = (sdl_info13 *) window->m_dxdata; |
| 724 | 704 | render_primitive *prim; |
| 725 | 705 | texture_info *texture=NULL; |
| 726 | 706 | float vofs, hofs; |
| r243304 | r243305 | |
| 731 | 711 | return 0; |
| 732 | 712 | } |
| 733 | 713 | |
| 734 | | if (sdl->m_resize_pending) |
| 714 | if (m_resize_pending) |
| 735 | 715 | { |
| 736 | | SDL_SetWindowSize(window->m_sdl_window, sdl->m_resize_width, sdl->m_resize_height); |
| 737 | | SDL_GetWindowSize(window->m_sdl_window, &window->m_width, &window->m_height); |
| 738 | | sdl->m_resize_pending = 0; |
| 739 | | SDL_RenderSetViewport(sdl->m_renderer, NULL); |
| 740 | | //sdlvideo_monitor_refresh(window->monitor()); |
| 716 | SDL_SetWindowSize(window().m_sdl_window, m_resize_width, m_resize_height); |
| 717 | SDL_GetWindowSize(window().m_sdl_window, &window().m_width, &window().m_height); |
| 718 | m_resize_pending = 0; |
| 719 | SDL_RenderSetViewport(m_renderer, NULL); |
| 720 | //sdlvideo_monitor_refresh(window().monitor()); |
| 741 | 721 | |
| 742 | 722 | } |
| 743 | 723 | |
| 744 | | //SDL_SelectRenderer(window->sdl_window); |
| 724 | //SDL_SelectRenderer(window().sdl_window); |
| 745 | 725 | |
| 746 | | if (sdl->m_blittimer > 0) |
| 726 | if (m_blittimer > 0) |
| 747 | 727 | { |
| 748 | 728 | /* SDL Underlays need alpha = 0 ! */ |
| 749 | | SDL_SetRenderDrawBlendMode(sdl->m_renderer, SDL_BLENDMODE_NONE); |
| 729 | SDL_SetRenderDrawBlendMode(m_renderer, SDL_BLENDMODE_NONE); |
| 750 | 730 | //SDL_SetRenderDrawColor(0,0,0,255); |
| 751 | | SDL_SetRenderDrawColor(sdl->m_renderer, 0,0,0,0); |
| 752 | | SDL_RenderFillRect(sdl->m_renderer, NULL); |
| 753 | | sdl->m_blittimer--; |
| 731 | SDL_SetRenderDrawColor(m_renderer, 0,0,0,0); |
| 732 | SDL_RenderFillRect(m_renderer, NULL); |
| 733 | m_blittimer--; |
| 754 | 734 | } |
| 755 | 735 | |
| 756 | 736 | // compute centering parameters |
| r243304 | r243305 | |
| 760 | 740 | { |
| 761 | 741 | int ch, cw; |
| 762 | 742 | |
| 763 | | if ((window->fullscreen()) && (!video_config.switchres)) |
| 743 | if ((window().fullscreen()) && (!video_config.switchres)) |
| 764 | 744 | { |
| 765 | | ch = window->monitor()->center_height(); |
| 766 | | cw = window->monitor()->center_width(); |
| 745 | ch = window().monitor()->center_height(); |
| 746 | cw = window().monitor()->center_width(); |
| 767 | 747 | } |
| 768 | 748 | else |
| 769 | 749 | { |
| 770 | | ch = window->m_height; |
| 771 | | cw = window->m_width; |
| 750 | ch = window().m_height; |
| 751 | cw = window().m_width; |
| 772 | 752 | } |
| 773 | 753 | |
| 774 | 754 | if (video_config.centerv) |
| 775 | 755 | { |
| 776 | | vofs = (ch - window->m_blitheight) / 2.0f; |
| 756 | vofs = (ch - window().m_blitheight) / 2.0f; |
| 777 | 757 | } |
| 778 | 758 | if (video_config.centerh) |
| 779 | 759 | { |
| 780 | | hofs = (cw - window->m_blitwidth) / 2.0f; |
| 760 | hofs = (cw - window().m_blitwidth) / 2.0f; |
| 781 | 761 | } |
| 782 | 762 | } |
| 783 | 763 | |
| 784 | | sdl->m_hofs = hofs; |
| 785 | | sdl->m_vofs = vofs; |
| 764 | m_hofs = hofs; |
| 765 | m_vofs = vofs; |
| 786 | 766 | |
| 787 | | window->m_primlist->acquire_lock(); |
| 767 | window().m_primlist->acquire_lock(); |
| 788 | 768 | |
| 789 | 769 | // now draw |
| 790 | | for (prim = window->m_primlist->first(); prim != NULL; prim = prim->next()) |
| 770 | for (prim = window().m_primlist->first(); prim != NULL; prim = prim->next()) |
| 791 | 771 | { |
| 792 | 772 | Uint8 sr, sg, sb, sa; |
| 793 | 773 | |
| r243304 | r243305 | |
| 799 | 779 | sb = (int)(255.0f * prim->color.b); |
| 800 | 780 | sa = (int)(255.0f * prim->color.a); |
| 801 | 781 | |
| 802 | | SDL_SetRenderDrawBlendMode(sdl->m_renderer, map_blendmode(PRIMFLAG_GET_BLENDMODE(prim->flags))); |
| 803 | | SDL_SetRenderDrawColor(sdl->m_renderer, sr, sg, sb, sa); |
| 804 | | SDL_RenderDrawLine(sdl->m_renderer, prim->bounds.x0 + hofs, prim->bounds.y0 + vofs, |
| 782 | SDL_SetRenderDrawBlendMode(m_renderer, map_blendmode(PRIMFLAG_GET_BLENDMODE(prim->flags))); |
| 783 | SDL_SetRenderDrawColor(m_renderer, sr, sg, sb, sa); |
| 784 | SDL_RenderDrawLine(m_renderer, prim->bounds.x0 + hofs, prim->bounds.y0 + vofs, |
| 805 | 785 | prim->bounds.x1 + hofs, prim->bounds.y1 + vofs); |
| 806 | 786 | break; |
| 807 | 787 | case render_primitive::QUAD: |
| 808 | | texture = sdl->texture_update(*prim); |
| 788 | texture = texture_update(*prim); |
| 809 | 789 | if (texture) |
| 810 | 790 | blit_pixels += (texture->raw_height() * texture->raw_width()); |
| 811 | | sdl->render_quad(texture, prim, |
| 791 | render_quad(texture, prim, |
| 812 | 792 | round_nearest(hofs + prim->bounds.x0), |
| 813 | 793 | round_nearest(vofs + prim->bounds.y0)); |
| 814 | 794 | break; |
| r243304 | r243305 | |
| 817 | 797 | } |
| 818 | 798 | } |
| 819 | 799 | |
| 820 | | window->m_primlist->release_lock(); |
| 800 | window().m_primlist->release_lock(); |
| 821 | 801 | |
| 822 | | sdl->m_last_blit_pixels = blit_pixels; |
| 823 | | sdl->m_last_blit_time = -osd_ticks(); |
| 824 | | SDL_RenderPresent(sdl->m_renderer); |
| 825 | | sdl->m_last_blit_time += osd_ticks(); |
| 802 | m_last_blit_pixels = blit_pixels; |
| 803 | m_last_blit_time = -osd_ticks(); |
| 804 | SDL_RenderPresent(m_renderer); |
| 805 | m_last_blit_time += osd_ticks(); |
| 826 | 806 | |
| 827 | 807 | return 0; |
| 828 | 808 | } |
| 829 | 809 | |
| 830 | 810 | |
| 831 | 811 | //============================================================ |
| 832 | | // drawsdl2_window_clear |
| 812 | // sdl_info13::clear |
| 833 | 813 | //============================================================ |
| 834 | 814 | |
| 835 | | static void drawsdl2_window_clear(sdl_window_info *window) |
| 815 | void sdl_info13::clear() |
| 836 | 816 | { |
| 837 | | sdl_info13 *sdl = (sdl_info13 *) window->m_dxdata; |
| 838 | | |
| 839 | | sdl->m_blittimer = 2; |
| 817 | m_blittimer = 2; |
| 840 | 818 | } |
| 841 | 819 | |
| 842 | 820 | |
| 843 | 821 | //============================================================ |
| 844 | | // drawsdl2_window_destroy |
| 822 | // sdl_info13::destroy |
| 845 | 823 | //============================================================ |
| 846 | 824 | |
| 847 | | static void drawsdl2_window_destroy(sdl_window_info *window) |
| 825 | void sdl_info13::destroy() |
| 848 | 826 | { |
| 849 | | sdl_info13 *sdl = (sdl_info13 *) window->m_dxdata; |
| 850 | | |
| 851 | | // skip if nothing |
| 852 | | if (sdl == NULL) |
| 853 | | return; |
| 854 | | |
| 855 | 827 | // free the memory in the window |
| 856 | 828 | |
| 857 | | drawsdl2_destroy_all_textures(window); |
| 829 | destroy_all_textures(); |
| 858 | 830 | |
| 859 | | if (window->fullscreen() && video_config.switchres) |
| 831 | if (window().fullscreen() && video_config.switchres) |
| 860 | 832 | { |
| 861 | | SDL_SetWindowFullscreen(window->m_sdl_window, 0); // Try to set mode |
| 862 | | SDL_SetWindowDisplayMode(window->m_sdl_window, &sdl->m_original_mode); // Try to set mode |
| 863 | | SDL_SetWindowFullscreen(window->m_sdl_window, SDL_WINDOW_FULLSCREEN); // Try to set mode |
| 833 | SDL_SetWindowFullscreen(window().m_sdl_window, 0); // Try to set mode |
| 834 | SDL_SetWindowDisplayMode(window().m_sdl_window, &m_original_mode); // Try to set mode |
| 835 | SDL_SetWindowFullscreen(window().m_sdl_window, SDL_WINDOW_FULLSCREEN); // Try to set mode |
| 864 | 836 | } |
| 865 | 837 | |
| 866 | | SDL_DestroyWindow(window->m_sdl_window); |
| 838 | SDL_DestroyWindow(window().m_sdl_window); |
| 867 | 839 | |
| 868 | | global_free(sdl); |
| 869 | | window->m_dxdata = NULL; |
| 870 | 840 | } |
| 871 | 841 | |
| 872 | 842 | //============================================================ |
| r243304 | r243305 | |
| 1188 | 1158 | } |
| 1189 | 1159 | |
| 1190 | 1160 | |
| 1191 | | static void drawsdl2_destroy_all_textures(sdl_window_info *window) |
| 1161 | void sdl_info13::destroy_all_textures() |
| 1192 | 1162 | { |
| 1193 | | sdl_info13 *sdl = (sdl_info13 *) window->m_dxdata; |
| 1194 | | |
| 1195 | | if (sdl == NULL) |
| 1196 | | return; |
| 1197 | | |
| 1198 | | if(window->m_primlist) |
| 1163 | if(window().m_primlist) |
| 1199 | 1164 | { |
| 1200 | | window->m_primlist->acquire_lock(); |
| 1201 | | sdl->m_texlist.reset(); |
| 1202 | | window->m_primlist->release_lock(); |
| 1165 | window().m_primlist->acquire_lock(); |
| 1166 | m_texlist.reset(); |
| 1167 | window().m_primlist->release_lock(); |
| 1203 | 1168 | } |
| 1204 | 1169 | else |
| 1205 | | sdl->m_texlist.reset(); |
| 1170 | m_texlist.reset(); |
| 1206 | 1171 | } |
trunk/src/osd/sdl/drawogl.c
| r243304 | r243305 | |
| 215 | 215 | }; |
| 216 | 216 | |
| 217 | 217 | /* sdl_info is the information about SDL for the current screen */ |
| 218 | | struct sdl_info |
| 218 | class sdl_info_ogl : public osd_renderer |
| 219 | 219 | { |
| 220 | | sdl_info() |
| 221 | | : m_blittimer(0), m_extra_flags(0), |
| 220 | public: |
| 221 | sdl_info_ogl(sdl_window_info *window) |
| 222 | : osd_renderer(window), m_blittimer(0), m_extra_flags(0), |
| 222 | 223 | #if (SDLMAME_SDL2) |
| 223 | 224 | m_gl_context_id(0), |
| 224 | 225 | #else |
| r243304 | r243305 | |
| 247 | 248 | m_texVerticex[i] = 0.0f; |
| 248 | 249 | } |
| 249 | 250 | |
| 251 | /* virtual */ int create(int width, int height); |
| 252 | /* virtual */ void resize(int width, int height); |
| 253 | /* virtual */ int draw(UINT32 dc, int update); |
| 254 | /* virtual */ void set_target_bounds(); |
| 255 | /* virtual */ int xy_to_render_target(int x, int y, int *xt, int *yt); |
| 256 | /* virtual */ void destroy_all_textures(); |
| 257 | /* virtual */ void destroy(); |
| 258 | /* virtual */ void clear(); |
| 259 | |
| 260 | void loadGLExtensions(); |
| 261 | void set_blendmode(int blendmode); |
| 262 | void texture_compute_type_subroutine(const render_texinfo *texsource, texture_info *texture, UINT32 flags); |
| 263 | void texture_compute_size_subroutine(texture_info *texture, UINT32 flags, |
| 264 | UINT32 width, UINT32 height, |
| 265 | int* p_width, int* p_height, int* p_width_create, int* p_height_create); |
| 266 | void texture_compute_size_type(const render_texinfo *texsource, texture_info *texture, UINT32 flags); |
| 267 | texture_info *texture_create(const render_texinfo *texsource, UINT32 flags); |
| 268 | int texture_shader_create(const render_texinfo *texsource, texture_info *texture, UINT32 flags); |
| 269 | texture_info *texture_find(const render_primitive *prim); |
| 270 | void texture_coord_update(texture_info *texture, const render_primitive *prim, int shaderIdx); |
| 271 | void texture_mpass_flip(texture_info *texture, int shaderIdx); |
| 272 | void texture_shader_update(texture_info *texture, int shaderIdx); |
| 273 | texture_info * texture_update(const render_primitive *prim, int shaderIdx); |
| 274 | void texture_disable(texture_info * texture); |
| 275 | void texture_all_disable(); |
| 276 | |
| 250 | 277 | INT32 m_blittimer; |
| 251 | 278 | UINT32 m_extra_flags; |
| 252 | 279 | |
| r243304 | r243305 | |
| 327 | 354 | return (h >> 8) % HASH_SIZE; |
| 328 | 355 | } |
| 329 | 356 | |
| 330 | | INLINE void set_blendmode(sdl_info *sdl, int blendmode) |
| 357 | void sdl_info_ogl::set_blendmode(int blendmode) |
| 331 | 358 | { |
| 332 | 359 | // try to minimize texture state changes |
| 333 | | if (blendmode != sdl->m_last_blendmode) |
| 360 | if (blendmode != m_last_blendmode) |
| 334 | 361 | { |
| 335 | 362 | switch (blendmode) |
| 336 | 363 | { |
| r243304 | r243305 | |
| 351 | 378 | break; |
| 352 | 379 | } |
| 353 | 380 | |
| 354 | | sdl->m_last_blendmode = blendmode; |
| 381 | m_last_blendmode = blendmode; |
| 355 | 382 | } |
| 356 | 383 | } |
| 357 | 384 | |
| r243304 | r243305 | |
| 362 | 389 | // core functions |
| 363 | 390 | |
| 364 | 391 | static void drawogl_exit(void); |
| 365 | | static void drawogl_attach(sdl_draw_info *info, sdl_window_info *window); |
| 366 | | static int drawogl_window_create(sdl_window_info *window, int width, int height); |
| 367 | | static void drawogl_window_resize(sdl_window_info *window, int width, int height); |
| 368 | | static void drawogl_window_destroy(sdl_window_info *window); |
| 369 | | static int drawogl_window_draw(sdl_window_info *window, UINT32 dc, int update); |
| 370 | | static void drawogl_set_target_bounds(sdl_window_info *window); |
| 371 | | static void drawogl_destroy_all_textures(sdl_window_info *window); |
| 372 | | static void drawogl_window_clear(sdl_window_info *window); |
| 373 | | static int drawogl_xy_to_render_target(sdl_window_info *window, int x, int y, int *xt, int *yt); |
| 374 | 392 | static void load_gl_lib(running_machine &machine); |
| 375 | 393 | |
| 376 | 394 | |
| r243304 | r243305 | |
| 408 | 426 | //============================================================ |
| 409 | 427 | |
| 410 | 428 | static void texture_set_data(texture_info *texture, const render_texinfo *texsource, UINT32 flags); |
| 411 | | static texture_info *texture_create(sdl_window_info *window, const render_texinfo *texsource, UINT32 flags); |
| 412 | | static texture_info *texture_find(sdl_info *sdl, const render_primitive *prim); |
| 413 | | static texture_info * texture_update(sdl_window_info *window, const render_primitive *prim, int shaderIdx); |
| 414 | | static void texture_all_disable(sdl_info *sdl); |
| 415 | | static void texture_disable(sdl_info *sdl, texture_info * texture); |
| 416 | 429 | |
| 417 | 430 | //============================================================ |
| 418 | 431 | // Static Variables |
| r243304 | r243305 | |
| 425 | 438 | // drawogl_init |
| 426 | 439 | //============================================================ |
| 427 | 440 | |
| 441 | static osd_renderer *drawogl_create(sdl_window_info *window) |
| 442 | { |
| 443 | return global_alloc(sdl_info_ogl(window)); |
| 444 | } |
| 445 | |
| 428 | 446 | int drawogl_init(running_machine &machine, sdl_draw_info *callbacks) |
| 429 | 447 | { |
| 430 | 448 | // fill in the callbacks |
| 431 | 449 | callbacks->exit = drawogl_exit; |
| 432 | | callbacks->attach = drawogl_attach; |
| 450 | callbacks->create = drawogl_create; |
| 433 | 451 | |
| 434 | 452 | dll_loaded = 0; |
| 435 | 453 | |
| r243304 | r243305 | |
| 449 | 467 | // drawogl_attach |
| 450 | 468 | //============================================================ |
| 451 | 469 | |
| 452 | | static void drawogl_attach(sdl_draw_info *info, sdl_window_info *window) |
| 453 | | { |
| 454 | | // fill in the callbacks |
| 455 | | window->create = drawogl_window_create; |
| 456 | | window->resize = drawogl_window_resize; |
| 457 | | window->set_target_bounds = drawogl_set_target_bounds; |
| 458 | | window->draw = drawogl_window_draw; |
| 459 | | window->destroy = drawogl_window_destroy; |
| 460 | | window->destroy_all_textures = drawogl_destroy_all_textures; |
| 461 | | window->clear = drawogl_window_clear; |
| 462 | | window->xy_to_render_target = drawogl_xy_to_render_target; |
| 463 | | } |
| 464 | | |
| 465 | | |
| 466 | 470 | //============================================================ |
| 467 | 471 | // Load the OGL function addresses |
| 468 | 472 | //============================================================ |
| r243304 | r243305 | |
| 525 | 529 | } |
| 526 | 530 | |
| 527 | 531 | //============================================================ |
| 528 | | // drawogl_window_create |
| 532 | // sdl_info::create |
| 529 | 533 | //============================================================ |
| 530 | 534 | |
| 531 | | static int drawogl_window_create(sdl_window_info *window, int width, int height) |
| 535 | int sdl_info_ogl::create(int width, int height) |
| 532 | 536 | { |
| 533 | | sdl_info *sdl; |
| 534 | 537 | char *extstr; |
| 535 | 538 | char *vendor; |
| 536 | 539 | int has_and_allow_texturerect = 0; |
| 537 | 540 | |
| 538 | | // allocate memory for our structures |
| 539 | | sdl = global_alloc(sdl_info); |
| 540 | | |
| 541 | | window->m_dxdata = sdl; |
| 542 | | |
| 543 | 541 | #if (SDLMAME_SDL2) |
| 544 | | sdl->m_extra_flags = (window->fullscreen() ? |
| 542 | m_extra_flags = (window().fullscreen() ? |
| 545 | 543 | SDL_WINDOW_BORDERLESS | SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_FULLSCREEN : SDL_WINDOW_RESIZABLE); |
| 546 | | sdl->m_extra_flags |= SDL_WINDOW_OPENGL; |
| 544 | m_extra_flags |= SDL_WINDOW_OPENGL; |
| 547 | 545 | |
| 548 | 546 | SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); |
| 549 | 547 | |
| r243304 | r243305 | |
| 555 | 553 | */ |
| 556 | 554 | |
| 557 | 555 | //Moved into init |
| 558 | | //load_gl_lib(window->machine()); |
| 556 | //load_gl_lib(window().machine()); |
| 559 | 557 | |
| 560 | 558 | // create the SDL window |
| 561 | | window->m_sdl_window = SDL_CreateWindow(window->m_title, |
| 562 | | window->monitor()->position_size().x, window->monitor()->position_size().y, |
| 563 | | width, height, sdl->m_extra_flags); |
| 559 | window().m_sdl_window = SDL_CreateWindow(window().m_title, |
| 560 | window().monitor()->position_size().x, window().monitor()->position_size().y, |
| 561 | width, height, m_extra_flags); |
| 564 | 562 | |
| 565 | | if (!window->m_sdl_window ) |
| 563 | if (!window().m_sdl_window ) |
| 566 | 564 | { |
| 567 | 565 | osd_printf_error("OpenGL not supported on this driver: %s\n", SDL_GetError()); |
| 568 | 566 | return 1; |
| 569 | 567 | } |
| 570 | 568 | |
| 571 | | if (window->fullscreen() && video_config.switchres) |
| 569 | if (window().fullscreen() && video_config.switchres) |
| 572 | 570 | { |
| 573 | 571 | SDL_DisplayMode mode; |
| 574 | | SDL_GetCurrentDisplayMode(window->monitor()->handle(), &mode); |
| 572 | SDL_GetCurrentDisplayMode(window().monitor()->handle(), &mode); |
| 575 | 573 | mode.w = width; |
| 576 | 574 | mode.h = height; |
| 577 | | if (window->m_refresh) |
| 578 | | mode.refresh_rate = window->m_refresh; |
| 579 | | SDL_SetWindowDisplayMode(window->m_sdl_window, &mode); // Try to set mode |
| 575 | if (window().m_refresh) |
| 576 | mode.refresh_rate = window().m_refresh; |
| 577 | SDL_SetWindowDisplayMode(window().m_sdl_window, &mode); // Try to set mode |
| 580 | 578 | } |
| 581 | 579 | else |
| 582 | | SDL_SetWindowDisplayMode(window->m_sdl_window, NULL); // Use desktop |
| 580 | SDL_SetWindowDisplayMode(window().m_sdl_window, NULL); // Use desktop |
| 583 | 581 | |
| 584 | | SDL_ShowWindow(window->m_sdl_window); |
| 585 | | //SDL_SetWindowFullscreen(window->sdl_window, window->fullscreen); |
| 586 | | SDL_RaiseWindow(window->m_sdl_window); |
| 587 | | SDL_GetWindowSize(window->m_sdl_window, &window->m_width, &window->m_height); |
| 582 | SDL_ShowWindow(window().m_sdl_window); |
| 583 | //SDL_SetWindowFullscreen(window().sdl_window, window().fullscreen); |
| 584 | SDL_RaiseWindow(window().m_sdl_window); |
| 585 | SDL_GetWindowSize(window().m_sdl_window, &window().m_width, &window().m_height); |
| 588 | 586 | |
| 589 | | sdl->m_gl_context_id = SDL_GL_CreateContext(window->m_sdl_window); |
| 590 | | if (!sdl->m_gl_context_id) |
| 587 | m_gl_context_id = SDL_GL_CreateContext(window().m_sdl_window); |
| 588 | if (!m_gl_context_id) |
| 591 | 589 | { |
| 592 | 590 | osd_printf_error("OpenGL not supported on this driver: %s\n", SDL_GetError()); |
| 593 | 591 | return 1; |
| r243304 | r243305 | |
| 596 | 594 | SDL_GL_SetSwapInterval(video_config.waitvsync ? 2 : 0); |
| 597 | 595 | |
| 598 | 596 | #else |
| 599 | | sdl->m_extra_flags = (window->fullscreen() ? SDL_FULLSCREEN : SDL_RESIZABLE); |
| 600 | | sdl->m_extra_flags |= SDL_OPENGL | SDL_DOUBLEBUF; |
| 597 | m_extra_flags = (window().fullscreen() ? SDL_FULLSCREEN : SDL_RESIZABLE); |
| 598 | m_extra_flags |= SDL_OPENGL | SDL_DOUBLEBUF; |
| 601 | 599 | |
| 602 | 600 | SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); |
| 603 | 601 | #if (SDL_VERSION_ATLEAST(1,2,10)) && (!defined(SDLMAME_EMSCRIPTEN)) |
| 604 | 602 | SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, video_config.waitvsync ? 1 : 0); |
| 605 | 603 | #endif |
| 606 | 604 | |
| 607 | | load_gl_lib(window->machine()); |
| 605 | load_gl_lib(window().machine()); |
| 608 | 606 | |
| 609 | 607 | // create the SDL surface (which creates the window in windowed mode) |
| 610 | | sdl->sdlsurf = SDL_SetVideoMode(m_width, m_height, |
| 611 | | 0, SDL_SWSURFACE | SDL_ANYFORMAT | sdl->m_extra_flags); |
| 608 | sdlsurf = SDL_SetVideoMode(width, height, |
| 609 | 0, SDL_SWSURFACE | SDL_ANYFORMAT | m_extra_flags); |
| 612 | 610 | |
| 613 | | if (!sdl->sdlsurf) |
| 611 | if (!sdlsurf) |
| 614 | 612 | return 1; |
| 615 | 613 | |
| 616 | | window->m_width = sdl->sdlsurf->w; |
| 617 | | window->m_height = sdl->sdlsurf->h; |
| 614 | window().m_width = sdlsurf->w; |
| 615 | window().m_height = sdlsurf->h; |
| 618 | 616 | |
| 619 | | window->screen_width = 0; |
| 620 | | window->screen_height = 0; |
| 617 | window().m_screen_width = 0; |
| 618 | window().m_screen_height = 0; |
| 621 | 619 | |
| 622 | | if ( (video_config.mode == VIDEO_MODE_OPENGL) && !(sdl->sdlsurf->flags & SDL_OPENGL) ) |
| 620 | if ( (video_config.mode == VIDEO_MODE_OPENGL) && !(sdlsurf->flags & SDL_OPENGL) ) |
| 623 | 621 | { |
| 624 | 622 | osd_printf_error("OpenGL not supported on this driver!\n"); |
| 625 | 623 | return 1; |
| 626 | 624 | } |
| 627 | 625 | |
| 628 | 626 | // set the window title |
| 629 | | SDL_WM_SetCaption(window->m_title, "SDLMAME"); |
| 627 | SDL_WM_SetCaption(window().m_title, "SDLMAME"); |
| 630 | 628 | |
| 631 | 629 | #endif |
| 632 | | sdl->m_blittimer = 0; |
| 633 | | sdl->m_surf_w = 0; |
| 634 | | sdl->m_surf_h = 0; |
| 630 | m_blittimer = 0; |
| 631 | m_surf_w = 0; |
| 632 | m_surf_h = 0; |
| 635 | 633 | |
| 636 | | sdl->m_initialized = 0; |
| 634 | m_initialized = 0; |
| 637 | 635 | |
| 638 | 636 | // in case any textures try to come up before these are validated, |
| 639 | 637 | // OpenGL guarantees all implementations can handle something this size. |
| 640 | | sdl->m_texture_max_width = 64; |
| 641 | | sdl->m_texture_max_height = 64; |
| 638 | m_texture_max_width = 64; |
| 639 | m_texture_max_height = 64; |
| 642 | 640 | |
| 643 | 641 | /* load any GL function addresses |
| 644 | 642 | * this must be done here because we need a context |
| r243304 | r243305 | |
| 656 | 654 | osd_printf_verbose("OpenGL: %s\nOpenGL: %s\nOpenGL: %s\n", vendor, (char *)glGetString(GL_RENDERER), (char *)glGetString(GL_VERSION)); |
| 657 | 655 | } |
| 658 | 656 | |
| 659 | | sdl->m_usetexturerect = 0; |
| 660 | | sdl->m_texpoweroftwo = 1; |
| 661 | | sdl->m_usevbo = 0; |
| 662 | | sdl->m_usepbo = 0; |
| 663 | | sdl->m_usefbo = 0; |
| 664 | | sdl->m_useglsl = 0; |
| 657 | m_usetexturerect = 0; |
| 658 | m_texpoweroftwo = 1; |
| 659 | m_usevbo = 0; |
| 660 | m_usepbo = 0; |
| 661 | m_usefbo = 0; |
| 662 | m_useglsl = 0; |
| 665 | 663 | |
| 666 | 664 | if ( video_config.allowtexturerect && |
| 667 | 665 | ( strstr(extstr, "GL_ARB_texture_rectangle") || strstr(extstr, "GL_EXT_texture_rectangle") ) |
| r243304 | r243305 | |
| 681 | 679 | { |
| 682 | 680 | osd_printf_verbose("OpenGL: non-power-of-2 textures supported (new method)\n"); |
| 683 | 681 | } |
| 684 | | sdl->m_texpoweroftwo = 0; |
| 682 | m_texpoweroftwo = 0; |
| 685 | 683 | } |
| 686 | 684 | else |
| 687 | 685 | { |
| r243304 | r243305 | |
| 692 | 690 | { |
| 693 | 691 | osd_printf_verbose("OpenGL: non-power-of-2 textures supported (old method)\n"); |
| 694 | 692 | } |
| 695 | | sdl->m_usetexturerect = 1; |
| 693 | m_usetexturerect = 1; |
| 696 | 694 | } |
| 697 | 695 | else |
| 698 | 696 | { |
| r243304 | r243305 | |
| 705 | 703 | |
| 706 | 704 | if (strstr(extstr, "GL_ARB_vertex_buffer_object")) |
| 707 | 705 | { |
| 708 | | sdl->m_usevbo = video_config.vbo; |
| 706 | m_usevbo = video_config.vbo; |
| 709 | 707 | if (!shown_video_info) |
| 710 | 708 | { |
| 711 | | if(sdl->m_usevbo) |
| 709 | if(m_usevbo) |
| 712 | 710 | osd_printf_verbose("OpenGL: vertex buffer supported\n"); |
| 713 | 711 | else |
| 714 | 712 | osd_printf_verbose("OpenGL: vertex buffer supported, but disabled\n"); |
| r243304 | r243305 | |
| 717 | 715 | |
| 718 | 716 | if (strstr(extstr, "GL_ARB_pixel_buffer_object")) |
| 719 | 717 | { |
| 720 | | if( sdl->m_usevbo ) |
| 718 | if( m_usevbo ) |
| 721 | 719 | { |
| 722 | | sdl->m_usepbo = video_config.pbo; |
| 720 | m_usepbo = video_config.pbo; |
| 723 | 721 | if (!shown_video_info) |
| 724 | 722 | { |
| 725 | | if(sdl->m_usepbo) |
| 723 | if(m_usepbo) |
| 726 | 724 | osd_printf_verbose("OpenGL: pixel buffers supported\n"); |
| 727 | 725 | else |
| 728 | 726 | osd_printf_verbose("OpenGL: pixel buffers supported, but disabled\n"); |
| r243304 | r243305 | |
| 744 | 742 | |
| 745 | 743 | if (strstr(extstr, "GL_EXT_framebuffer_object")) |
| 746 | 744 | { |
| 747 | | sdl->m_usefbo = 1; |
| 745 | m_usefbo = 1; |
| 748 | 746 | if (!shown_video_info) |
| 749 | 747 | { |
| 750 | | if(sdl->m_usefbo) |
| 748 | if(m_usefbo) |
| 751 | 749 | osd_printf_verbose("OpenGL: framebuffer object supported\n"); |
| 752 | 750 | else |
| 753 | 751 | osd_printf_verbose("OpenGL: framebuffer object not supported\n"); |
| r243304 | r243305 | |
| 760 | 758 | strstr(extstr, "GL_ARB_fragment_shader") |
| 761 | 759 | ) |
| 762 | 760 | { |
| 763 | | sdl->m_useglsl = video_config.glsl; |
| 761 | m_useglsl = video_config.glsl; |
| 764 | 762 | if (!shown_video_info) |
| 765 | 763 | { |
| 766 | | if(sdl->m_useglsl) |
| 764 | if(m_useglsl) |
| 767 | 765 | osd_printf_verbose("OpenGL: GLSL supported\n"); |
| 768 | 766 | else |
| 769 | 767 | osd_printf_verbose("OpenGL: GLSL supported, but disabled\n"); |
| r243304 | r243305 | |
| 777 | 775 | |
| 778 | 776 | if (osd_getenv(SDLENV_VMWARE) != NULL) |
| 779 | 777 | { |
| 780 | | sdl->m_usetexturerect = 1; |
| 781 | | sdl->m_texpoweroftwo = 1; |
| 778 | m_usetexturerect = 1; |
| 779 | m_texpoweroftwo = 1; |
| 782 | 780 | } |
| 783 | | glGetIntegerv(GL_MAX_TEXTURE_SIZE, (GLint *)&sdl->m_texture_max_width); |
| 784 | | glGetIntegerv(GL_MAX_TEXTURE_SIZE, (GLint *)&sdl->m_texture_max_height); |
| 781 | glGetIntegerv(GL_MAX_TEXTURE_SIZE, (GLint *)&m_texture_max_width); |
| 782 | glGetIntegerv(GL_MAX_TEXTURE_SIZE, (GLint *)&m_texture_max_height); |
| 785 | 783 | if (!shown_video_info) |
| 786 | 784 | { |
| 787 | | osd_printf_verbose("OpenGL: max texture size %d x %d\n", sdl->m_texture_max_width, sdl->m_texture_max_height); |
| 785 | osd_printf_verbose("OpenGL: max texture size %d x %d\n", m_texture_max_width, m_texture_max_height); |
| 788 | 786 | } |
| 789 | 787 | |
| 790 | 788 | shown_video_info = 1; |
| 791 | 789 | |
| 792 | | sdl->m_init_context = 0; |
| 790 | m_init_context = 0; |
| 793 | 791 | |
| 794 | 792 | return 0; |
| 795 | 793 | } |
| 796 | 794 | |
| 797 | 795 | //============================================================ |
| 798 | | // drawogl_window_resize |
| 796 | // sdl_info::resize |
| 799 | 797 | //============================================================ |
| 800 | 798 | |
| 801 | | static void drawogl_window_resize(sdl_window_info *window, int width, int height) |
| 799 | void sdl_info_ogl::resize(int width, int height) |
| 802 | 800 | { |
| 803 | | sdl_info *sdl = (sdl_info *) window->m_dxdata; |
| 804 | | |
| 805 | 801 | #if (SDLMAME_SDL2) |
| 806 | | //SDL_GL_MakeCurrent(window->sdl_window, sdl->gl_context_id); |
| 807 | | SDL_SetWindowSize(window->m_sdl_window, width, height); |
| 808 | | SDL_GetWindowSize(window->m_sdl_window, &window->m_width, &window->m_height); |
| 809 | | sdl->m_blittimer = 3; |
| 802 | //SDL_GL_MakeCurrent(window().sdl_window, gl_context_id); |
| 803 | SDL_SetWindowSize(window().m_sdl_window, width, height); |
| 804 | SDL_GetWindowSize(window().m_sdl_window, &window().m_width, &window().m_height); |
| 805 | m_blittimer = 3; |
| 810 | 806 | #else |
| 811 | | SDL_FreeSurface(sdl->sdlsurf); |
| 807 | SDL_FreeSurface(sdlsurf); |
| 812 | 808 | |
| 813 | | sdl->sdlsurf = SDL_SetVideoMode(m_width, m_height, 0, |
| 814 | | SDL_SWSURFACE | SDL_ANYFORMAT | sdl->m_extra_flags); |
| 809 | sdlsurf = SDL_SetVideoMode(width, height, 0, |
| 810 | SDL_SWSURFACE | SDL_ANYFORMAT | m_extra_flags); |
| 815 | 811 | |
| 816 | | window->m_width = sdl->sdlsurf->w; |
| 817 | | window->m_height = sdl->sdlsurf->h; |
| 812 | window().m_width = sdlsurf->w; |
| 813 | window().m_height = sdlsurf->h; |
| 818 | 814 | #endif |
| 819 | | sdl->m_init_context = 1; |
| 815 | m_init_context = 1; |
| 820 | 816 | |
| 821 | 817 | } |
| 822 | 818 | |
| r243304 | r243305 | |
| 824 | 820 | // drawsdl_xy_to_render_target |
| 825 | 821 | //============================================================ |
| 826 | 822 | |
| 827 | | static int drawogl_xy_to_render_target(sdl_window_info *window, int x, int y, int *xt, int *yt) |
| 823 | int sdl_info_ogl::xy_to_render_target(int x, int y, int *xt, int *yt) |
| 828 | 824 | { |
| 829 | | sdl_info *sdl =(sdl_info *) window->m_dxdata; |
| 830 | | |
| 831 | | *xt = x - sdl->m_last_hofs; |
| 832 | | *yt = y - sdl->m_last_vofs; |
| 833 | | if (*xt<0 || *xt >= window->m_blitwidth) |
| 825 | *xt = x - m_last_hofs; |
| 826 | *yt = y - m_last_vofs; |
| 827 | if (*xt<0 || *xt >= window().m_blitwidth) |
| 834 | 828 | return 0; |
| 835 | | if (*yt<0 || *yt >= window->m_blitheight) |
| 829 | if (*yt<0 || *yt >= window().m_blitheight) |
| 836 | 830 | return 0; |
| 837 | 831 | return 1; |
| 838 | 832 | } |
| 839 | 833 | |
| 840 | 834 | //============================================================ |
| 841 | | // drawogl_window_get_primitives |
| 835 | // sdl_info::get_primitives |
| 842 | 836 | //============================================================ |
| 843 | 837 | |
| 844 | | static void drawogl_set_target_bounds(sdl_window_info *window) |
| 838 | void sdl_info_ogl::set_target_bounds() |
| 845 | 839 | { |
| 846 | | window->m_target->set_bounds(window->m_blitwidth, window->m_blitheight, window->monitor()->aspect()); |
| 840 | window().m_target->set_bounds(window().m_blitwidth, window().m_blitheight, window().monitor()->aspect()); |
| 847 | 841 | } |
| 848 | 842 | |
| 849 | 843 | //============================================================ |
| 850 | 844 | // loadGLExtensions |
| 851 | 845 | //============================================================ |
| 852 | 846 | |
| 853 | | static void loadGLExtensions(sdl_window_info *window) |
| 847 | void sdl_info_ogl::loadGLExtensions() |
| 854 | 848 | { |
| 855 | | sdl_info *sdl = (sdl_info *) window->m_dxdata; |
| 856 | 849 | static int _once = 1; |
| 857 | 850 | |
| 858 | | // sdl->usevbo=FALSE; // You may want to switch VBO and PBO off, by uncommenting this statement |
| 859 | | // sdl->usepbo=FALSE; // You may want to switch PBO off, by uncommenting this statement |
| 860 | | // sdl->useglsl=FALSE; // You may want to switch GLSL off, by uncommenting this statement |
| 851 | // usevbo=FALSE; // You may want to switch VBO and PBO off, by uncommenting this statement |
| 852 | // usepbo=FALSE; // You may want to switch PBO off, by uncommenting this statement |
| 853 | // useglsl=FALSE; // You may want to switch GLSL off, by uncommenting this statement |
| 861 | 854 | |
| 862 | | if (! sdl->m_usevbo) |
| 855 | if (! m_usevbo) |
| 863 | 856 | { |
| 864 | | if(sdl->m_usepbo) // should never ever happen ;-) |
| 857 | if(m_usepbo) // should never ever happen ;-) |
| 865 | 858 | { |
| 866 | 859 | if (_once) |
| 867 | 860 | { |
| 868 | 861 | osd_printf_warning("OpenGL: PBO not supported, no VBO support. (sdlmame error)\n"); |
| 869 | 862 | } |
| 870 | | sdl->m_usepbo=FALSE; |
| 863 | m_usepbo=FALSE; |
| 871 | 864 | } |
| 872 | | if(sdl->m_useglsl) // should never ever happen ;-) |
| 865 | if(m_useglsl) // should never ever happen ;-) |
| 873 | 866 | { |
| 874 | 867 | if (_once) |
| 875 | 868 | { |
| 876 | 869 | osd_printf_warning("OpenGL: GLSL not supported, no VBO support. (sdlmame error)\n"); |
| 877 | 870 | } |
| 878 | | sdl->m_useglsl=FALSE; |
| 871 | m_useglsl=FALSE; |
| 879 | 872 | } |
| 880 | 873 | } |
| 881 | 874 | |
| 882 | 875 | // Get Pointers To The GL Functions |
| 883 | 876 | // VBO: |
| 884 | | if( sdl->m_usevbo ) |
| 877 | if( m_usevbo ) |
| 885 | 878 | { |
| 886 | 879 | pfn_glGenBuffers = (PFNGLGENBUFFERSPROC) SDL_GL_GetProcAddress("glGenBuffers"); |
| 887 | 880 | pfn_glDeleteBuffers = (PFNGLDELETEBUFFERSPROC) SDL_GL_GetProcAddress("glDeleteBuffers"); |
| r243304 | r243305 | |
| 890 | 883 | pfn_glBufferSubData = (PFNGLBUFFERSUBDATAPROC) SDL_GL_GetProcAddress("glBufferSubData"); |
| 891 | 884 | } |
| 892 | 885 | // PBO: |
| 893 | | if ( sdl->m_usepbo ) |
| 886 | if ( m_usepbo ) |
| 894 | 887 | { |
| 895 | 888 | pfn_glMapBuffer = (PFNGLMAPBUFFERPROC) SDL_GL_GetProcAddress("glMapBuffer"); |
| 896 | 889 | pfn_glUnmapBuffer= (PFNGLUNMAPBUFFERPROC) SDL_GL_GetProcAddress("glUnmapBuffer"); |
| 897 | 890 | } |
| 898 | 891 | // FBO: |
| 899 | | if ( sdl->m_usefbo ) |
| 892 | if ( m_usefbo ) |
| 900 | 893 | { |
| 901 | 894 | pfn_glIsFramebuffer = (PFNGLISFRAMEBUFFEREXTPROC) SDL_GL_GetProcAddress("glIsFramebufferEXT"); |
| 902 | 895 | pfn_glBindFramebuffer = (PFNGLBINDFRAMEBUFFEREXTPROC) SDL_GL_GetProcAddress("glBindFramebufferEXT"); |
| r243304 | r243305 | |
| 906 | 899 | pfn_glFramebufferTexture2D = (PFNGLFRAMEBUFFERTEXTURE2DEXTPROC) SDL_GL_GetProcAddress("glFramebufferTexture2DEXT"); |
| 907 | 900 | } |
| 908 | 901 | |
| 909 | | if ( sdl->m_usevbo && |
| 902 | if ( m_usevbo && |
| 910 | 903 | ( !pfn_glGenBuffers || !pfn_glDeleteBuffers || |
| 911 | 904 | !pfn_glBindBuffer || !pfn_glBufferData || !pfn_glBufferSubData |
| 912 | 905 | ) ) |
| 913 | 906 | { |
| 914 | | sdl->m_usepbo=FALSE; |
| 907 | m_usepbo=FALSE; |
| 915 | 908 | if (_once) |
| 916 | 909 | { |
| 917 | 910 | osd_printf_warning("OpenGL: VBO not supported, missing: "); |
| r243304 | r243305 | |
| 937 | 930 | } |
| 938 | 931 | osd_printf_warning("\n"); |
| 939 | 932 | } |
| 940 | | if ( sdl->m_usevbo ) |
| 933 | if ( m_usevbo ) |
| 941 | 934 | { |
| 942 | 935 | if (_once) |
| 943 | 936 | { |
| 944 | 937 | osd_printf_warning("OpenGL: PBO not supported, no VBO support.\n"); |
| 945 | 938 | } |
| 946 | | sdl->m_usepbo=FALSE; |
| 939 | m_usepbo=FALSE; |
| 947 | 940 | } |
| 948 | 941 | } |
| 949 | 942 | |
| 950 | | if ( sdl->m_usepbo && ( !pfn_glMapBuffer || !pfn_glUnmapBuffer ) ) |
| 943 | if ( m_usepbo && ( !pfn_glMapBuffer || !pfn_glUnmapBuffer ) ) |
| 951 | 944 | { |
| 952 | | sdl->m_usepbo=FALSE; |
| 945 | m_usepbo=FALSE; |
| 953 | 946 | if (_once) |
| 954 | 947 | { |
| 955 | 948 | osd_printf_warning("OpenGL: PBO not supported, missing: "); |
| r243304 | r243305 | |
| 965 | 958 | } |
| 966 | 959 | } |
| 967 | 960 | |
| 968 | | if ( sdl->m_usefbo && |
| 961 | if ( m_usefbo && |
| 969 | 962 | ( !pfn_glIsFramebuffer || !pfn_glBindFramebuffer || !pfn_glDeleteFramebuffers || |
| 970 | 963 | !pfn_glGenFramebuffers || !pfn_glCheckFramebufferStatus || !pfn_glFramebufferTexture2D |
| 971 | 964 | )) |
| 972 | 965 | { |
| 973 | | sdl->m_usefbo=FALSE; |
| 966 | m_usefbo=FALSE; |
| 974 | 967 | if (_once) |
| 975 | 968 | { |
| 976 | 969 | osd_printf_warning("OpenGL: FBO not supported, missing: "); |
| r243304 | r243305 | |
| 1004 | 997 | |
| 1005 | 998 | if (_once) |
| 1006 | 999 | { |
| 1007 | | if ( sdl->m_usevbo ) |
| 1000 | if ( m_usevbo ) |
| 1008 | 1001 | { |
| 1009 | 1002 | osd_printf_verbose("OpenGL: VBO supported\n"); |
| 1010 | 1003 | } |
| r243304 | r243305 | |
| 1013 | 1006 | osd_printf_warning("OpenGL: VBO not supported\n"); |
| 1014 | 1007 | } |
| 1015 | 1008 | |
| 1016 | | if ( sdl->m_usepbo ) |
| 1009 | if ( m_usepbo ) |
| 1017 | 1010 | { |
| 1018 | 1011 | osd_printf_verbose("OpenGL: PBO supported\n"); |
| 1019 | 1012 | } |
| r243304 | r243305 | |
| 1022 | 1015 | osd_printf_warning("OpenGL: PBO not supported\n"); |
| 1023 | 1016 | } |
| 1024 | 1017 | |
| 1025 | | if ( sdl->m_usefbo ) |
| 1018 | if ( m_usefbo ) |
| 1026 | 1019 | { |
| 1027 | 1020 | osd_printf_verbose("OpenGL: FBO supported\n"); |
| 1028 | 1021 | } |
| r243304 | r243305 | |
| 1032 | 1025 | } |
| 1033 | 1026 | } |
| 1034 | 1027 | |
| 1035 | | if ( sdl->m_useglsl ) |
| 1028 | if ( m_useglsl ) |
| 1036 | 1029 | { |
| 1037 | 1030 | #ifdef GL_ARB_multitexture |
| 1038 | 1031 | pfn_glActiveTexture = (PFNGLACTIVETEXTUREARBPROC) SDL_GL_GetProcAddress("glActiveTextureARB"); |
| r243304 | r243305 | |
| 1045 | 1038 | { |
| 1046 | 1039 | osd_printf_warning("OpenGL: GLSL disabled, glActiveTexture(ARB) not supported\n"); |
| 1047 | 1040 | } |
| 1048 | | sdl->m_useglsl = 0; |
| 1041 | m_useglsl = 0; |
| 1049 | 1042 | } |
| 1050 | 1043 | } |
| 1051 | 1044 | |
| 1052 | | if ( sdl->m_useglsl ) |
| 1045 | if ( m_useglsl ) |
| 1053 | 1046 | { |
| 1054 | | sdl->m_glsl = glsl_shader_init(); |
| 1055 | | sdl->m_useglsl = (sdl->m_glsl != NULL ? 1 : 0); |
| 1047 | m_glsl = glsl_shader_init(); |
| 1048 | m_useglsl = (m_glsl != NULL ? 1 : 0); |
| 1056 | 1049 | |
| 1057 | | if ( ! sdl->m_useglsl ) |
| 1050 | if ( ! m_useglsl ) |
| 1058 | 1051 | { |
| 1059 | 1052 | if (_once) |
| 1060 | 1053 | { |
| r243304 | r243305 | |
| 1063 | 1056 | } |
| 1064 | 1057 | } |
| 1065 | 1058 | |
| 1066 | | if ( sdl->m_useglsl ) |
| 1059 | if ( m_useglsl ) |
| 1067 | 1060 | { |
| 1068 | | if ( window->m_prescale != 1 ) |
| 1061 | if ( window().m_prescale != 1 ) |
| 1069 | 1062 | { |
| 1070 | | sdl->m_useglsl = 0; |
| 1063 | m_useglsl = 0; |
| 1071 | 1064 | if (_once) |
| 1072 | 1065 | { |
| 1073 | 1066 | osd_printf_warning("OpenGL: GLSL supported, but disabled due to: prescale !=1 \n"); |
| r243304 | r243305 | |
| 1075 | 1068 | } |
| 1076 | 1069 | } |
| 1077 | 1070 | |
| 1078 | | if ( sdl->m_useglsl ) |
| 1071 | if ( m_useglsl ) |
| 1079 | 1072 | { |
| 1080 | 1073 | int i; |
| 1081 | 1074 | video_config.filter = FALSE; |
| 1082 | 1075 | glsl_shader_feature = GLSL_SHADER_FEAT_PLAIN; |
| 1083 | | sdl->m_glsl_program_num = 0; |
| 1084 | | sdl->m_glsl_program_mb2sc = 0; |
| 1076 | m_glsl_program_num = 0; |
| 1077 | m_glsl_program_mb2sc = 0; |
| 1085 | 1078 | |
| 1086 | 1079 | for(i=0; i<video_config.glsl_shader_mamebm_num; i++) |
| 1087 | 1080 | { |
| 1088 | | if ( !sdl->m_usefbo && sdl->m_glsl_program_num==1 ) |
| 1081 | if ( !m_usefbo && m_glsl_program_num==1 ) |
| 1089 | 1082 | { |
| 1090 | 1083 | if (_once) |
| 1091 | 1084 | { |
| r243304 | r243305 | |
| 1094 | 1087 | break; |
| 1095 | 1088 | } |
| 1096 | 1089 | |
| 1097 | | if ( glsl_shader_add_mamebm(sdl->m_glsl, video_config.glsl_shader_mamebm[i], sdl->m_glsl_program_num) ) |
| 1090 | if ( glsl_shader_add_mamebm(m_glsl, video_config.glsl_shader_mamebm[i], m_glsl_program_num) ) |
| 1098 | 1091 | { |
| 1099 | 1092 | osd_printf_error("OpenGL: GLSL loading mame bitmap shader %d failed (%s)\n", |
| 1100 | 1093 | i, video_config.glsl_shader_mamebm[i]); |
| r243304 | r243305 | |
| 1103 | 1096 | if (_once) |
| 1104 | 1097 | { |
| 1105 | 1098 | osd_printf_verbose("OpenGL: GLSL using mame bitmap shader filter %d: '%s'\n", |
| 1106 | | sdl->m_glsl_program_num, video_config.glsl_shader_mamebm[i]); |
| 1099 | m_glsl_program_num, video_config.glsl_shader_mamebm[i]); |
| 1107 | 1100 | } |
| 1108 | | sdl->m_glsl_program_mb2sc = sdl->m_glsl_program_num; // the last mame_bitmap (mb) shader does it. |
| 1109 | | sdl->m_glsl_program_num++; |
| 1101 | m_glsl_program_mb2sc = m_glsl_program_num; // the last mame_bitmap (mb) shader does it. |
| 1102 | m_glsl_program_num++; |
| 1110 | 1103 | } |
| 1111 | 1104 | } |
| 1112 | 1105 | |
| 1113 | | if ( video_config.glsl_shader_scrn_num > 0 && sdl->m_glsl_program_num==0 ) |
| 1106 | if ( video_config.glsl_shader_scrn_num > 0 && m_glsl_program_num==0 ) |
| 1114 | 1107 | { |
| 1115 | 1108 | osd_printf_verbose("OpenGL: GLSL cannot use screen bitmap shader without bitmap shader\n"); |
| 1116 | 1109 | } |
| 1117 | 1110 | |
| 1118 | | for(i=0; sdl->m_usefbo && sdl->m_glsl_program_num>0 && i<video_config.glsl_shader_scrn_num; i++) |
| 1111 | for(i=0; m_usefbo && m_glsl_program_num>0 && i<video_config.glsl_shader_scrn_num; i++) |
| 1119 | 1112 | { |
| 1120 | | if ( glsl_shader_add_scrn(sdl->m_glsl, video_config.glsl_shader_scrn[i], |
| 1121 | | sdl->m_glsl_program_num-1-sdl->m_glsl_program_mb2sc) ) |
| 1113 | if ( glsl_shader_add_scrn(m_glsl, video_config.glsl_shader_scrn[i], |
| 1114 | m_glsl_program_num-1-m_glsl_program_mb2sc) ) |
| 1122 | 1115 | { |
| 1123 | 1116 | osd_printf_error("OpenGL: GLSL loading screen bitmap shader %d failed (%s)\n", |
| 1124 | 1117 | i, video_config.glsl_shader_scrn[i]); |
| r243304 | r243305 | |
| 1126 | 1119 | if (_once) |
| 1127 | 1120 | { |
| 1128 | 1121 | osd_printf_verbose("OpenGL: GLSL using screen bitmap shader filter %d: '%s'\n", |
| 1129 | | sdl->m_glsl_program_num, video_config.glsl_shader_scrn[i]); |
| 1122 | m_glsl_program_num, video_config.glsl_shader_scrn[i]); |
| 1130 | 1123 | } |
| 1131 | | sdl->m_glsl_program_num++; |
| 1124 | m_glsl_program_num++; |
| 1132 | 1125 | } |
| 1133 | 1126 | } |
| 1134 | 1127 | |
| 1135 | | if ( 0==sdl->m_glsl_program_num && |
| 1128 | if ( 0==m_glsl_program_num && |
| 1136 | 1129 | 0 <= video_config.glsl_filter && video_config.glsl_filter < GLSL_SHADER_FEAT_INT_NUMBER ) |
| 1137 | 1130 | { |
| 1138 | | sdl->m_glsl_program_mb2sc = sdl->m_glsl_program_num; // the last mame_bitmap (mb) shader does it. |
| 1139 | | sdl->m_glsl_program_num++; |
| 1131 | m_glsl_program_mb2sc = m_glsl_program_num; // the last mame_bitmap (mb) shader does it. |
| 1132 | m_glsl_program_num++; |
| 1140 | 1133 | glsl_shader_feature = video_config.glsl_filter; |
| 1141 | 1134 | |
| 1142 | 1135 | if (_once) |
| 1143 | 1136 | { |
| 1144 | 1137 | osd_printf_verbose("OpenGL: GLSL using shader filter '%s', idx: %d, num %d (vid filter: %d)\n", |
| 1145 | 1138 | glsl_shader_get_filter_name_mamebm(glsl_shader_feature), |
| 1146 | | glsl_shader_feature, sdl->m_glsl_program_num, video_config.filter); |
| 1139 | glsl_shader_feature, m_glsl_program_num, video_config.filter); |
| 1147 | 1140 | } |
| 1148 | 1141 | } |
| 1149 | 1142 | |
| r243304 | r243305 | |
| 1158 | 1151 | } |
| 1159 | 1152 | |
| 1160 | 1153 | //============================================================ |
| 1161 | | // drawogl_window_draw |
| 1154 | // sdl_info::draw |
| 1162 | 1155 | //============================================================ |
| 1163 | 1156 | |
| 1164 | | static int drawogl_window_draw(sdl_window_info *window, UINT32 dc, int update) |
| 1157 | int sdl_info_ogl::draw(UINT32 dc, int update) |
| 1165 | 1158 | { |
| 1166 | | sdl_info *sdl = (sdl_info *) window->m_dxdata; |
| 1167 | 1159 | render_primitive *prim; |
| 1168 | 1160 | texture_info *texture=NULL; |
| 1169 | 1161 | float vofs, hofs; |
| r243304 | r243305 | |
| 1176 | 1168 | } |
| 1177 | 1169 | |
| 1178 | 1170 | #if (SDLMAME_SDL2) |
| 1179 | | SDL_GL_MakeCurrent(window->m_sdl_window, sdl->m_gl_context_id); |
| 1171 | SDL_GL_MakeCurrent(window().m_sdl_window, m_gl_context_id); |
| 1180 | 1172 | #else |
| 1181 | | if (!sdl->m_init_context) |
| 1173 | if (!m_init_context) |
| 1182 | 1174 | { |
| 1183 | | screen_device_iterator myiter(window->machine().root_device()); |
| 1175 | screen_device_iterator myiter(window().machine().root_device()); |
| 1184 | 1176 | for (screen = myiter.first(); screen != NULL; screen = myiter.next()) |
| 1185 | 1177 | { |
| 1186 | | if (window->index() == 0) |
| 1178 | if (window().index() == 0) |
| 1187 | 1179 | { |
| 1188 | | if ((screen->m_width() != window->screen_width) || (screen->m_height() != window->screen_height)) |
| 1180 | if ((screen->width() != window().m_screen_width) || (screen->height() != window().m_screen_height)) |
| 1189 | 1181 | { |
| 1190 | | window->screen_width = screen->m_width(); |
| 1191 | | window->screen_height = screen->m_height(); |
| 1182 | window().m_screen_width = screen->width(); |
| 1183 | window().m_screen_height = screen->height(); |
| 1192 | 1184 | |
| 1193 | 1185 | // force all textures to be regenerated |
| 1194 | | drawogl_destroy_all_textures(window); |
| 1186 | destroy_all_textures(); |
| 1195 | 1187 | } |
| 1196 | 1188 | break; |
| 1197 | 1189 | } |
| r243304 | r243305 | |
| 1199 | 1191 | } |
| 1200 | 1192 | #endif |
| 1201 | 1193 | |
| 1202 | | if (sdl->m_init_context) |
| 1194 | if (m_init_context) |
| 1203 | 1195 | { |
| 1204 | 1196 | // do some one-time OpenGL setup |
| 1205 | 1197 | #if (SDLMAME_SDL2) |
| r243304 | r243305 | |
| 1217 | 1209 | |
| 1218 | 1210 | // figure out if we're vector |
| 1219 | 1211 | scrnum = is_vector = 0; |
| 1220 | | screen_device_iterator iter(window->machine().root_device()); |
| 1212 | screen_device_iterator iter(window().machine().root_device()); |
| 1221 | 1213 | for (screen = iter.first(); screen != NULL; screen = iter.next()) |
| 1222 | 1214 | { |
| 1223 | | if (scrnum == window->index()) |
| 1215 | if (scrnum == window().index()) |
| 1224 | 1216 | { |
| 1225 | 1217 | is_vector = (screen->screen_type() == SCREEN_TYPE_VECTOR) ? 1 : 0; |
| 1226 | 1218 | break; |
| r243304 | r243305 | |
| 1232 | 1224 | } |
| 1233 | 1225 | |
| 1234 | 1226 | // only clear if the geometry changes (and for 2 frames afterward to clear double and triple buffers) |
| 1235 | | if ((sdl->m_blittimer > 0) || (is_vector)) |
| 1227 | if ((m_blittimer > 0) || (is_vector)) |
| 1236 | 1228 | { |
| 1237 | 1229 | glClear(GL_COLOR_BUFFER_BIT); |
| 1238 | | sdl->m_blittimer--; |
| 1230 | m_blittimer--; |
| 1239 | 1231 | } |
| 1240 | 1232 | |
| 1241 | | if ( !sdl->m_initialized || |
| 1242 | | window->m_width!= sdl->m_surf_w || window->m_height!= sdl->m_surf_h ) |
| 1233 | if ( !m_initialized || |
| 1234 | window().m_width!= m_surf_w || window().m_height!= m_surf_h ) |
| 1243 | 1235 | { |
| 1244 | | if ( !sdl->m_initialized ) |
| 1236 | if ( !m_initialized ) |
| 1245 | 1237 | { |
| 1246 | | loadGLExtensions(window); |
| 1238 | loadGLExtensions(); |
| 1247 | 1239 | } |
| 1248 | 1240 | |
| 1249 | | sdl->m_surf_w=window->m_width; |
| 1250 | | sdl->m_surf_h=window->m_height; |
| 1241 | m_surf_w=window().m_width; |
| 1242 | m_surf_h=window().m_height; |
| 1251 | 1243 | |
| 1252 | 1244 | // we're doing nothing 3d, so the Z-buffer is currently not interesting |
| 1253 | 1245 | glDisable(GL_DEPTH_TEST); |
| 1254 | 1246 | |
| 1255 | | if (window->machine().options().antialias()) |
| 1247 | if (window().machine().options().antialias()) |
| 1256 | 1248 | { |
| 1257 | 1249 | // enable antialiasing for lines |
| 1258 | 1250 | glEnable(GL_LINE_SMOOTH); |
| r243304 | r243305 | |
| 1272 | 1264 | // enable blending |
| 1273 | 1265 | glEnable(GL_BLEND); |
| 1274 | 1266 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
| 1275 | | sdl->m_last_blendmode = BLENDMODE_ALPHA; |
| 1267 | m_last_blendmode = BLENDMODE_ALPHA; |
| 1276 | 1268 | |
| 1277 | 1269 | // set lines and points just barely above normal size to get proper results |
| 1278 | 1270 | glLineWidth(video_config.beamwidth); |
| r243304 | r243305 | |
| 1288 | 1280 | // |_________| |
| 1289 | 1281 | // (0,h) (w,h) |
| 1290 | 1282 | |
| 1291 | | glViewport(0.0, 0.0, (GLsizei)window->m_width, (GLsizei)window->m_height); |
| 1283 | glViewport(0.0, 0.0, (GLsizei)window().m_width, (GLsizei)window().m_height); |
| 1292 | 1284 | glMatrixMode(GL_PROJECTION); |
| 1293 | 1285 | glLoadIdentity(); |
| 1294 | | glOrtho(0.0, (GLdouble)window->m_width, (GLdouble)window->m_height, 0.0, 0.0, -1.0); |
| 1286 | glOrtho(0.0, (GLdouble)window().m_width, (GLdouble)window().m_height, 0.0, 0.0, -1.0); |
| 1295 | 1287 | glMatrixMode(GL_MODELVIEW); |
| 1296 | 1288 | glLoadIdentity(); |
| 1297 | 1289 | |
| 1298 | | if ( ! sdl->m_initialized ) |
| 1290 | if ( ! m_initialized ) |
| 1299 | 1291 | { |
| 1300 | 1292 | glEnableClientState(GL_VERTEX_ARRAY); |
| 1301 | | glVertexPointer(2, GL_FLOAT, 0, sdl->m_texVerticex); // no VBO, since it's too volatile |
| 1293 | glVertexPointer(2, GL_FLOAT, 0, m_texVerticex); // no VBO, since it's too volatile |
| 1302 | 1294 | |
| 1303 | | sdl->m_initialized = 1; |
| 1295 | m_initialized = 1; |
| 1304 | 1296 | } |
| 1305 | 1297 | } |
| 1306 | 1298 | |
| r243304 | r243305 | |
| 1311 | 1303 | { |
| 1312 | 1304 | int ch, cw; |
| 1313 | 1305 | |
| 1314 | | if ((window->fullscreen()) && (!video_config.switchres)) |
| 1306 | if ((window().fullscreen()) && (!video_config.switchres)) |
| 1315 | 1307 | { |
| 1316 | | ch = window->monitor()->center_height(); |
| 1317 | | cw = window->monitor()->center_width(); |
| 1308 | ch = window().monitor()->center_height(); |
| 1309 | cw = window().monitor()->center_width(); |
| 1318 | 1310 | } |
| 1319 | 1311 | else |
| 1320 | 1312 | { |
| 1321 | | ch = window->m_height; |
| 1322 | | cw = window->m_width; |
| 1313 | ch = window().m_height; |
| 1314 | cw = window().m_width; |
| 1323 | 1315 | } |
| 1324 | 1316 | |
| 1325 | 1317 | if (video_config.centerv) |
| 1326 | 1318 | { |
| 1327 | | vofs = (ch - window->m_blitheight) / 2.0f; |
| 1319 | vofs = (ch - window().m_blitheight) / 2.0f; |
| 1328 | 1320 | } |
| 1329 | 1321 | if (video_config.centerh) |
| 1330 | 1322 | { |
| 1331 | | hofs = (cw - window->m_blitwidth) / 2.0f; |
| 1323 | hofs = (cw - window().m_blitwidth) / 2.0f; |
| 1332 | 1324 | } |
| 1333 | 1325 | } |
| 1334 | 1326 | |
| 1335 | | sdl->m_last_hofs = hofs; |
| 1336 | | sdl->m_last_vofs = vofs; |
| 1327 | m_last_hofs = hofs; |
| 1328 | m_last_vofs = vofs; |
| 1337 | 1329 | |
| 1338 | | window->m_primlist->acquire_lock(); |
| 1330 | window().m_primlist->acquire_lock(); |
| 1339 | 1331 | |
| 1340 | 1332 | // now draw |
| 1341 | | for (prim = window->m_primlist->first(); prim != NULL; prim = prim->next()) |
| 1333 | for (prim = window().m_primlist->first(); prim != NULL; prim = prim->next()) |
| 1342 | 1334 | { |
| 1343 | 1335 | int i; |
| 1344 | 1336 | |
| r243304 | r243305 | |
| 1366 | 1358 | |
| 1367 | 1359 | if ( pendingPrimitive==GL_NO_PRIMITIVE ) |
| 1368 | 1360 | { |
| 1369 | | set_blendmode(sdl, PRIMFLAG_GET_BLENDMODE(prim->flags)); |
| 1361 | set_blendmode(PRIMFLAG_GET_BLENDMODE(prim->flags)); |
| 1370 | 1362 | } |
| 1371 | 1363 | |
| 1372 | 1364 | glColor4f(prim->color.r, prim->color.g, prim->color.b, prim->color.a); |
| r243304 | r243305 | |
| 1486 | 1478 | |
| 1487 | 1479 | glColor4f(prim->color.r, prim->color.g, prim->color.b, prim->color.a); |
| 1488 | 1480 | |
| 1489 | | set_blendmode(sdl, PRIMFLAG_GET_BLENDMODE(prim->flags)); |
| 1481 | set_blendmode(PRIMFLAG_GET_BLENDMODE(prim->flags)); |
| 1490 | 1482 | |
| 1491 | | texture = texture_update(window, prim, 0); |
| 1483 | texture = texture_update(prim, 0); |
| 1492 | 1484 | |
| 1493 | 1485 | if ( texture && texture->type==TEXTURE_TYPE_SHADER ) |
| 1494 | 1486 | { |
| 1495 | | for(i=0; i<sdl->m_glsl_program_num; i++) |
| 1487 | for(i=0; i<m_glsl_program_num; i++) |
| 1496 | 1488 | { |
| 1497 | | if ( i==sdl->m_glsl_program_mb2sc ) |
| 1489 | if ( i==m_glsl_program_mb2sc ) |
| 1498 | 1490 | { |
| 1499 | | // i==sdl->glsl_program_mb2sc -> transformation mamebm->scrn |
| 1500 | | sdl->m_texVerticex[0]=prim->bounds.x0 + hofs; |
| 1501 | | sdl->m_texVerticex[1]=prim->bounds.y0 + vofs; |
| 1502 | | sdl->m_texVerticex[2]=prim->bounds.x1 + hofs; |
| 1503 | | sdl->m_texVerticex[3]=prim->bounds.y0 + vofs; |
| 1504 | | sdl->m_texVerticex[4]=prim->bounds.x1 + hofs; |
| 1505 | | sdl->m_texVerticex[5]=prim->bounds.y1 + vofs; |
| 1506 | | sdl->m_texVerticex[6]=prim->bounds.x0 + hofs; |
| 1507 | | sdl->m_texVerticex[7]=prim->bounds.y1 + vofs; |
| 1491 | // i==glsl_program_mb2sc -> transformation mamebm->scrn |
| 1492 | m_texVerticex[0]=prim->bounds.x0 + hofs; |
| 1493 | m_texVerticex[1]=prim->bounds.y0 + vofs; |
| 1494 | m_texVerticex[2]=prim->bounds.x1 + hofs; |
| 1495 | m_texVerticex[3]=prim->bounds.y0 + vofs; |
| 1496 | m_texVerticex[4]=prim->bounds.x1 + hofs; |
| 1497 | m_texVerticex[5]=prim->bounds.y1 + vofs; |
| 1498 | m_texVerticex[6]=prim->bounds.x0 + hofs; |
| 1499 | m_texVerticex[7]=prim->bounds.y1 + vofs; |
| 1508 | 1500 | } else { |
| 1509 | 1501 | // 1:1 tex coord CCW (0/0) (1/0) (1/1) (0/1) on texture dimensions |
| 1510 | | sdl->m_texVerticex[0]=(GLfloat)0.0; |
| 1511 | | sdl->m_texVerticex[1]=(GLfloat)0.0; |
| 1512 | | sdl->m_texVerticex[2]=(GLfloat)window->m_width; |
| 1513 | | sdl->m_texVerticex[3]=(GLfloat)0.0; |
| 1514 | | sdl->m_texVerticex[4]=(GLfloat)window->m_width; |
| 1515 | | sdl->m_texVerticex[5]=(GLfloat)window->m_height; |
| 1516 | | sdl->m_texVerticex[6]=(GLfloat)0.0; |
| 1517 | | sdl->m_texVerticex[7]=(GLfloat)window->m_height; |
| 1502 | m_texVerticex[0]=(GLfloat)0.0; |
| 1503 | m_texVerticex[1]=(GLfloat)0.0; |
| 1504 | m_texVerticex[2]=(GLfloat)window().m_width; |
| 1505 | m_texVerticex[3]=(GLfloat)0.0; |
| 1506 | m_texVerticex[4]=(GLfloat)window().m_width; |
| 1507 | m_texVerticex[5]=(GLfloat)window().m_height; |
| 1508 | m_texVerticex[6]=(GLfloat)0.0; |
| 1509 | m_texVerticex[7]=(GLfloat)window().m_height; |
| 1518 | 1510 | } |
| 1519 | 1511 | |
| 1520 | 1512 | if(i>0) // first fetch already done |
| 1521 | 1513 | { |
| 1522 | | texture = texture_update(window, prim, i); |
| 1514 | texture = texture_update(prim, i); |
| 1523 | 1515 | } |
| 1524 | 1516 | glDrawArrays(GL_QUADS, 0, 4); |
| 1525 | 1517 | } |
| 1526 | 1518 | } else { |
| 1527 | | sdl->m_texVerticex[0]=prim->bounds.x0 + hofs; |
| 1528 | | sdl->m_texVerticex[1]=prim->bounds.y0 + vofs; |
| 1529 | | sdl->m_texVerticex[2]=prim->bounds.x1 + hofs; |
| 1530 | | sdl->m_texVerticex[3]=prim->bounds.y0 + vofs; |
| 1531 | | sdl->m_texVerticex[4]=prim->bounds.x1 + hofs; |
| 1532 | | sdl->m_texVerticex[5]=prim->bounds.y1 + vofs; |
| 1533 | | sdl->m_texVerticex[6]=prim->bounds.x0 + hofs; |
| 1534 | | sdl->m_texVerticex[7]=prim->bounds.y1 + vofs; |
| 1519 | m_texVerticex[0]=prim->bounds.x0 + hofs; |
| 1520 | m_texVerticex[1]=prim->bounds.y0 + vofs; |
| 1521 | m_texVerticex[2]=prim->bounds.x1 + hofs; |
| 1522 | m_texVerticex[3]=prim->bounds.y0 + vofs; |
| 1523 | m_texVerticex[4]=prim->bounds.x1 + hofs; |
| 1524 | m_texVerticex[5]=prim->bounds.y1 + vofs; |
| 1525 | m_texVerticex[6]=prim->bounds.x0 + hofs; |
| 1526 | m_texVerticex[7]=prim->bounds.y1 + vofs; |
| 1535 | 1527 | |
| 1536 | 1528 | glDrawArrays(GL_QUADS, 0, 4); |
| 1537 | 1529 | } |
| 1538 | 1530 | |
| 1539 | 1531 | if ( texture ) |
| 1540 | 1532 | { |
| 1541 | | texture_disable(sdl, texture); |
| 1533 | texture_disable(texture); |
| 1542 | 1534 | texture=NULL; |
| 1543 | 1535 | } |
| 1544 | 1536 | break; |
| r243304 | r243305 | |
| 1554 | 1546 | pendingPrimitive=GL_NO_PRIMITIVE; |
| 1555 | 1547 | } |
| 1556 | 1548 | |
| 1557 | | window->m_primlist->release_lock(); |
| 1558 | | sdl->m_init_context = 0; |
| 1549 | window().m_primlist->release_lock(); |
| 1550 | m_init_context = 0; |
| 1559 | 1551 | |
| 1560 | 1552 | #if (!SDLMAME_SDL2) |
| 1561 | 1553 | SDL_GL_SwapBuffers(); |
| 1562 | 1554 | #else |
| 1563 | | SDL_GL_SwapWindow(window->m_sdl_window); |
| 1555 | SDL_GL_SwapWindow(window().m_sdl_window); |
| 1564 | 1556 | #endif |
| 1565 | 1557 | return 0; |
| 1566 | 1558 | } |
| r243304 | r243305 | |
| 1626 | 1618 | } |
| 1627 | 1619 | |
| 1628 | 1620 | //============================================================ |
| 1629 | | // drawogl_window_destroy |
| 1621 | // sdl_info::destroy |
| 1630 | 1622 | //============================================================ |
| 1631 | 1623 | |
| 1632 | | static void drawogl_window_destroy(sdl_window_info *window) |
| 1624 | void sdl_info_ogl::destroy() |
| 1633 | 1625 | { |
| 1634 | | sdl_info *sdl = (sdl_info *) window->m_dxdata; |
| 1635 | 1626 | |
| 1636 | | // skip if nothing |
| 1637 | | if (sdl == NULL) |
| 1638 | | return; |
| 1639 | | |
| 1640 | 1627 | // free the memory in the window |
| 1641 | 1628 | |
| 1642 | | drawogl_destroy_all_textures(window); |
| 1629 | destroy_all_textures(); |
| 1643 | 1630 | |
| 1644 | 1631 | #if (SDLMAME_SDL2) |
| 1645 | | SDL_GL_DeleteContext(sdl->m_gl_context_id); |
| 1646 | | SDL_DestroyWindow(window->m_sdl_window); |
| 1632 | SDL_GL_DeleteContext(m_gl_context_id); |
| 1633 | SDL_DestroyWindow(window().m_sdl_window); |
| 1647 | 1634 | #else |
| 1648 | | if (sdl->sdlsurf) |
| 1635 | if (sdlsurf) |
| 1649 | 1636 | { |
| 1650 | | SDL_FreeSurface(sdl->sdlsurf); |
| 1651 | | sdl->sdlsurf = NULL; |
| 1637 | SDL_FreeSurface(sdlsurf); |
| 1638 | sdlsurf = NULL; |
| 1652 | 1639 | } |
| 1653 | 1640 | #endif |
| 1654 | | |
| 1655 | | global_free(sdl); |
| 1656 | | window->m_dxdata = NULL; |
| 1657 | 1641 | } |
| 1658 | 1642 | |
| 1659 | 1643 | //============================================================ |
| r243304 | r243305 | |
| 1667 | 1651 | // we also don't want to use PBO's in the case of nocopy==TRUE, |
| 1668 | 1652 | // since we now might have GLSL shaders - this decision simplifies out life ;-) |
| 1669 | 1653 | // |
| 1670 | | static void texture_compute_type_subroutine(sdl_info *sdl, const render_texinfo *texsource, texture_info *texture, UINT32 flags) |
| 1654 | void sdl_info_ogl::texture_compute_type_subroutine(const render_texinfo *texsource, texture_info *texture, UINT32 flags) |
| 1671 | 1655 | { |
| 1672 | 1656 | texture->type = TEXTURE_TYPE_NONE; |
| 1673 | 1657 | texture->nocopy = FALSE; |
| r243304 | r243305 | |
| 1676 | 1660 | !PRIMFLAG_GET_SCREENTEX(flags)) |
| 1677 | 1661 | { |
| 1678 | 1662 | texture->type = TEXTURE_TYPE_PLAIN; |
| 1679 | | texture->texTarget = (sdl->m_usetexturerect)?GL_TEXTURE_RECTANGLE_ARB:GL_TEXTURE_2D; |
| 1680 | | texture->texpow2 = (sdl->m_usetexturerect)?0:sdl->m_texpoweroftwo; |
| 1663 | texture->texTarget = (m_usetexturerect)?GL_TEXTURE_RECTANGLE_ARB:GL_TEXTURE_2D; |
| 1664 | texture->texpow2 = (m_usetexturerect)?0:m_texpoweroftwo; |
| 1681 | 1665 | } |
| 1682 | 1666 | |
| 1683 | | if ( texture->type == TEXTURE_TYPE_NONE && sdl->m_useglsl && |
| 1667 | if ( texture->type == TEXTURE_TYPE_NONE && m_useglsl && |
| 1684 | 1668 | texture->xprescale == 1 && texture->yprescale == 1 && |
| 1685 | | texsource->rowpixels <= sdl->m_texture_max_width ) |
| 1669 | texsource->rowpixels <= m_texture_max_width ) |
| 1686 | 1670 | { |
| 1687 | 1671 | texture->type = TEXTURE_TYPE_SHADER; |
| 1688 | 1672 | texture->texTarget = GL_TEXTURE_2D; |
| 1689 | | texture->texpow2 = sdl->m_texpoweroftwo; |
| 1673 | texture->texpow2 = m_texpoweroftwo; |
| 1690 | 1674 | } |
| 1691 | 1675 | |
| 1692 | 1676 | // determine if we can skip the copy step |
| r243304 | r243305 | |
| 1695 | 1679 | !texture_copy_properties[texture->format][SDL_TEXFORMAT_SRC_HAS_PALETTE] && |
| 1696 | 1680 | texture->xprescale == 1 && texture->yprescale == 1 && |
| 1697 | 1681 | !texture->borderpix && !texsource->palette() && |
| 1698 | | texsource->rowpixels <= sdl->m_texture_max_width ) |
| 1682 | texsource->rowpixels <= m_texture_max_width ) |
| 1699 | 1683 | { |
| 1700 | 1684 | texture->nocopy = TRUE; |
| 1701 | 1685 | } |
| 1702 | 1686 | |
| 1703 | 1687 | if( texture->type == TEXTURE_TYPE_NONE && |
| 1704 | | sdl->m_usepbo && !texture->nocopy ) |
| 1688 | m_usepbo && !texture->nocopy ) |
| 1705 | 1689 | { |
| 1706 | 1690 | texture->type = TEXTURE_TYPE_DYNAMIC; |
| 1707 | | texture->texTarget = (sdl->m_usetexturerect)?GL_TEXTURE_RECTANGLE_ARB:GL_TEXTURE_2D; |
| 1708 | | texture->texpow2 = (sdl->m_usetexturerect)?0:sdl->m_texpoweroftwo; |
| 1691 | texture->texTarget = (m_usetexturerect)?GL_TEXTURE_RECTANGLE_ARB:GL_TEXTURE_2D; |
| 1692 | texture->texpow2 = (m_usetexturerect)?0:m_texpoweroftwo; |
| 1709 | 1693 | } |
| 1710 | 1694 | |
| 1711 | 1695 | if( texture->type == TEXTURE_TYPE_NONE ) |
| 1712 | 1696 | { |
| 1713 | 1697 | texture->type = TEXTURE_TYPE_SURFACE; |
| 1714 | | texture->texTarget = (sdl->m_usetexturerect)?GL_TEXTURE_RECTANGLE_ARB:GL_TEXTURE_2D; |
| 1715 | | texture->texpow2 = (sdl->m_usetexturerect)?0:sdl->m_texpoweroftwo; |
| 1698 | texture->texTarget = (m_usetexturerect)?GL_TEXTURE_RECTANGLE_ARB:GL_TEXTURE_2D; |
| 1699 | texture->texpow2 = (m_usetexturerect)?0:m_texpoweroftwo; |
| 1716 | 1700 | } |
| 1717 | 1701 | } |
| 1718 | 1702 | |
| r243304 | r243305 | |
| 1721 | 1705 | return (needPow2)?gl_round_to_pow2(v):v; |
| 1722 | 1706 | } |
| 1723 | 1707 | |
| 1724 | | static void texture_compute_size_subroutine(sdl_window_info *window, texture_info *texture, UINT32 flags, |
| 1708 | void sdl_info_ogl::texture_compute_size_subroutine(texture_info *texture, UINT32 flags, |
| 1725 | 1709 | UINT32 width, UINT32 height, |
| 1726 | 1710 | int* p_width, int* p_height, int* p_width_create, int* p_height_create) |
| 1727 | 1711 | { |
| 1728 | | sdl_info *sdl = (sdl_info *) window->m_dxdata; |
| 1729 | 1712 | int width_create; |
| 1730 | 1713 | int height_create; |
| 1731 | 1714 | |
| r243304 | r243305 | |
| 1746 | 1729 | } |
| 1747 | 1730 | |
| 1748 | 1731 | // don't prescale above max texture size |
| 1749 | | while (texture->xprescale > 1 && width_create * texture->xprescale > sdl->m_texture_max_width) |
| 1732 | while (texture->xprescale > 1 && width_create * texture->xprescale > m_texture_max_width) |
| 1750 | 1733 | texture->xprescale--; |
| 1751 | | while (texture->yprescale > 1 && height_create * texture->yprescale > sdl->m_texture_max_height) |
| 1734 | while (texture->yprescale > 1 && height_create * texture->yprescale > m_texture_max_height) |
| 1752 | 1735 | texture->yprescale--; |
| 1753 | | if (PRIMFLAG_GET_SCREENTEX(flags) && (texture->xprescale != window->m_prescale || texture->yprescale != window->m_prescale)) |
| 1754 | | osd_printf_warning("SDL: adjusting prescale from %dx%d to %dx%d\n", window->m_prescale, window->m_prescale, texture->xprescale, texture->yprescale); |
| 1736 | if (PRIMFLAG_GET_SCREENTEX(flags) && (texture->xprescale != window().m_prescale || texture->yprescale != window().m_prescale)) |
| 1737 | osd_printf_warning("SDL: adjusting prescale from %dx%d to %dx%d\n", window().m_prescale, window().m_prescale, texture->xprescale, texture->yprescale); |
| 1755 | 1738 | |
| 1756 | 1739 | width *= texture->xprescale; |
| 1757 | 1740 | height *= texture->yprescale; |
| r243304 | r243305 | |
| 1773 | 1756 | *p_height_create=height_create; |
| 1774 | 1757 | } |
| 1775 | 1758 | |
| 1776 | | static void texture_compute_size_type(sdl_window_info *window, const render_texinfo *texsource, texture_info *texture, UINT32 flags) |
| 1759 | void sdl_info_ogl::texture_compute_size_type(const render_texinfo *texsource, texture_info *texture, UINT32 flags) |
| 1777 | 1760 | { |
| 1778 | | sdl_info *sdl = (sdl_info *) window->m_dxdata; |
| 1779 | 1761 | int finalheight, finalwidth; |
| 1780 | 1762 | int finalheight_create, finalwidth_create; |
| 1781 | 1763 | |
| r243304 | r243305 | |
| 1786 | 1768 | texture->borderpix = 0; // don't border the screen right now, there's a bug |
| 1787 | 1769 | } |
| 1788 | 1770 | |
| 1789 | | texture_compute_type_subroutine(sdl, texsource, texture, flags); |
| 1771 | texture_compute_type_subroutine(texsource, texture, flags); |
| 1790 | 1772 | |
| 1791 | | texture_compute_size_subroutine(window, texture, flags, texsource->width, texsource->height, |
| 1773 | texture_compute_size_subroutine(texture, flags, texsource->width, texsource->height, |
| 1792 | 1774 | &finalwidth, &finalheight, &finalwidth_create, &finalheight_create); |
| 1793 | 1775 | |
| 1794 | 1776 | // if we added pixels for the border, and that just barely pushed us over, take it back |
| 1795 | 1777 | if (texture->borderpix && |
| 1796 | | ((finalwidth > sdl->m_texture_max_width && finalwidth - 2 <= sdl->m_texture_max_width) || |
| 1797 | | (finalheight > sdl->m_texture_max_height && finalheight - 2 <= sdl->m_texture_max_height))) |
| 1778 | ((finalwidth > m_texture_max_width && finalwidth - 2 <= m_texture_max_width) || |
| 1779 | (finalheight > m_texture_max_height && finalheight - 2 <= m_texture_max_height))) |
| 1798 | 1780 | { |
| 1799 | 1781 | texture->borderpix = FALSE; |
| 1800 | 1782 | |
| 1801 | | texture_compute_type_subroutine(sdl, texsource, texture, flags); |
| 1783 | texture_compute_type_subroutine(texsource, texture, flags); |
| 1802 | 1784 | |
| 1803 | | texture_compute_size_subroutine(window, texture, flags, texsource->width, texsource->height, |
| 1785 | texture_compute_size_subroutine(texture, flags, texsource->width, texsource->height, |
| 1804 | 1786 | &finalwidth, &finalheight, &finalwidth_create, &finalheight_create); |
| 1805 | 1787 | } |
| 1806 | 1788 | |
| 1807 | 1789 | // if we're above the max width/height, do what? |
| 1808 | | if (finalwidth_create > sdl->m_texture_max_width || finalheight_create > sdl->m_texture_max_height) |
| 1790 | if (finalwidth_create > m_texture_max_width || finalheight_create > m_texture_max_height) |
| 1809 | 1791 | { |
| 1810 | 1792 | static int printed = FALSE; |
| 1811 | 1793 | if (!printed) |
| 1812 | | osd_printf_warning("Texture too big! (wanted: %dx%d, max is %dx%d)\n", finalwidth_create, finalheight_create, sdl->m_texture_max_width, sdl->m_texture_max_height); |
| 1794 | osd_printf_warning("Texture too big! (wanted: %dx%d, max is %dx%d)\n", finalwidth_create, finalheight_create, m_texture_max_width, m_texture_max_height); |
| 1813 | 1795 | printed = TRUE; |
| 1814 | 1796 | } |
| 1815 | 1797 | |
| r243304 | r243305 | |
| 1831 | 1813 | (int)texture_copy_properties[texture->format][SDL_TEXFORMAT_SRC_EQUALS_DEST], |
| 1832 | 1814 | (int)texture_copy_properties[texture->format][SDL_TEXFORMAT_SRC_HAS_PALETTE], |
| 1833 | 1815 | texture->xprescale, texture->yprescale, |
| 1834 | | texture->borderpix, texsource->rowpixels, finalwidth, sdl->m_texture_max_width, |
| 1816 | texture->borderpix, texsource->rowpixels, finalwidth, m_texture_max_width, |
| 1835 | 1817 | (int)sizeof(UINT32) |
| 1836 | 1818 | ); |
| 1837 | 1819 | } |
| r243304 | r243305 | |
| 1927 | 1909 | return 0; |
| 1928 | 1910 | } |
| 1929 | 1911 | |
| 1930 | | static int texture_shader_create(sdl_window_info *window, |
| 1931 | | const render_texinfo *texsource, texture_info *texture, UINT32 flags) |
| 1912 | int sdl_info_ogl::texture_shader_create(const render_texinfo *texsource, texture_info *texture, UINT32 flags) |
| 1932 | 1913 | { |
| 1933 | | sdl_info *sdl = (sdl_info *) window->m_dxdata; |
| 1934 | 1914 | int uniform_location; |
| 1935 | 1915 | int i; |
| 1936 | | int surf_w_pow2 = get_valid_pow2_value (window->m_blitwidth, texture->texpow2); |
| 1937 | | int surf_h_pow2 = get_valid_pow2_value (window->m_blitheight, texture->texpow2); |
| 1916 | int surf_w_pow2 = get_valid_pow2_value (window().m_blitwidth, texture->texpow2); |
| 1917 | int surf_h_pow2 = get_valid_pow2_value (window().m_blitheight, texture->texpow2); |
| 1938 | 1918 | |
| 1939 | 1919 | assert ( texture->type==TEXTURE_TYPE_SHADER ); |
| 1940 | 1920 | |
| 1941 | 1921 | GL_CHECK_ERROR_QUIET(); |
| 1942 | 1922 | |
| 1943 | | if( sdl->m_glsl_program_num > 1 ) |
| 1923 | if( m_glsl_program_num > 1 ) |
| 1944 | 1924 | { |
| 1945 | 1925 | // multipass mode |
| 1946 | | assert(sdl->m_usefbo); |
| 1926 | assert(m_usefbo); |
| 1947 | 1927 | |
| 1948 | 1928 | // GL_TEXTURE3 GLSL Uniforms |
| 1949 | 1929 | texture->mpass_dest_idx = 0; |
| r243304 | r243305 | |
| 1951 | 1931 | texture->mpass_textureunit[1] = GL_TEXTURE2; |
| 1952 | 1932 | } |
| 1953 | 1933 | |
| 1954 | | for(i=0; i<sdl->m_glsl_program_num; i++) |
| 1934 | for(i=0; i<m_glsl_program_num; i++) |
| 1955 | 1935 | { |
| 1956 | | if ( i<=sdl->m_glsl_program_mb2sc ) |
| 1936 | if ( i<=m_glsl_program_mb2sc ) |
| 1957 | 1937 | { |
| 1958 | | sdl->m_glsl_program[i] = glsl_shader_get_program_mamebm(glsl_shader_feature, i); |
| 1938 | m_glsl_program[i] = glsl_shader_get_program_mamebm(glsl_shader_feature, i); |
| 1959 | 1939 | } else { |
| 1960 | | sdl->m_glsl_program[i] = glsl_shader_get_program_scrn(i-1-sdl->m_glsl_program_mb2sc); |
| 1940 | m_glsl_program[i] = glsl_shader_get_program_scrn(i-1-m_glsl_program_mb2sc); |
| 1961 | 1941 | } |
| 1962 | | pfn_glUseProgramObjectARB(sdl->m_glsl_program[i]); |
| 1942 | pfn_glUseProgramObjectARB(m_glsl_program[i]); |
| 1963 | 1943 | |
| 1964 | | if ( i<=sdl->m_glsl_program_mb2sc ) |
| 1944 | if ( i<=m_glsl_program_mb2sc ) |
| 1965 | 1945 | { |
| 1966 | 1946 | // GL_TEXTURE0 GLSL Uniforms |
| 1967 | | uniform_location = pfn_glGetUniformLocationARB(sdl->m_glsl_program[i], "color_texture"); |
| 1947 | uniform_location = pfn_glGetUniformLocationARB(m_glsl_program[i], "color_texture"); |
| 1968 | 1948 | pfn_glUniform1iARB(uniform_location, 0); |
| 1969 | 1949 | GL_CHECK_ERROR_NORMAL(); |
| 1970 | 1950 | } |
| 1971 | 1951 | |
| 1972 | 1952 | { |
| 1973 | 1953 | GLfloat color_texture_sz[2] = { (GLfloat)texture->rawwidth, (GLfloat)texture->rawheight }; |
| 1974 | | uniform_location = pfn_glGetUniformLocationARB(sdl->m_glsl_program[i], "color_texture_sz"); |
| 1954 | uniform_location = pfn_glGetUniformLocationARB(m_glsl_program[i], "color_texture_sz"); |
| 1975 | 1955 | pfn_glUniform2fvARB(uniform_location, 1, &(color_texture_sz[0])); |
| 1976 | 1956 | GL_CHECK_ERROR_NORMAL(); |
| 1977 | 1957 | } |
| 1978 | 1958 | |
| 1979 | 1959 | GLfloat color_texture_pow2_sz[2] = { (GLfloat)texture->rawwidth_create, (GLfloat)texture->rawheight_create }; |
| 1980 | | uniform_location = pfn_glGetUniformLocationARB(sdl->m_glsl_program[i], "color_texture_pow2_sz"); |
| 1960 | uniform_location = pfn_glGetUniformLocationARB(m_glsl_program[i], "color_texture_pow2_sz"); |
| 1981 | 1961 | pfn_glUniform2fvARB(uniform_location, 1, &(color_texture_pow2_sz[0])); |
| 1982 | 1962 | GL_CHECK_ERROR_NORMAL(); |
| 1983 | 1963 | |
| 1984 | | GLfloat screen_texture_sz[2] = { (GLfloat)window->m_blitwidth, (GLfloat)window->m_blitheight }; |
| 1985 | | uniform_location = pfn_glGetUniformLocationARB(sdl->m_glsl_program[i], "screen_texture_sz"); |
| 1964 | GLfloat screen_texture_sz[2] = { (GLfloat)window().m_blitwidth, (GLfloat)window().m_blitheight }; |
| 1965 | uniform_location = pfn_glGetUniformLocationARB(m_glsl_program[i], "screen_texture_sz"); |
| 1986 | 1966 | pfn_glUniform2fvARB(uniform_location, 1, &(screen_texture_sz[0])); |
| 1987 | 1967 | GL_CHECK_ERROR_NORMAL(); |
| 1988 | 1968 | |
| 1989 | 1969 | GLfloat screen_texture_pow2_sz[2] = { (GLfloat)surf_w_pow2, (GLfloat)surf_h_pow2 }; |
| 1990 | | uniform_location = pfn_glGetUniformLocationARB(sdl->m_glsl_program[i], "screen_texture_pow2_sz"); |
| 1970 | uniform_location = pfn_glGetUniformLocationARB(m_glsl_program[i], "screen_texture_pow2_sz"); |
| 1991 | 1971 | pfn_glUniform2fvARB(uniform_location, 1, &(screen_texture_pow2_sz[0])); |
| 1992 | 1972 | GL_CHECK_ERROR_NORMAL(); |
| 1993 | 1973 | } |
| 1994 | 1974 | |
| 1995 | | pfn_glUseProgramObjectARB(sdl->m_glsl_program[0]); // start with 1st shader |
| 1975 | pfn_glUseProgramObjectARB(m_glsl_program[0]); // start with 1st shader |
| 1996 | 1976 | |
| 1997 | | if( sdl->m_glsl_program_num > 1 ) |
| 1977 | if( m_glsl_program_num > 1 ) |
| 1998 | 1978 | { |
| 1999 | 1979 | // multipass mode |
| 2000 | 1980 | // GL_TEXTURE2/GL_TEXTURE3 |
| r243304 | r243305 | |
| 2018 | 1998 | texture->rawwidth, texture->rawheight, texture->rawwidth_create, texture->rawheight_create); |
| 2019 | 1999 | } |
| 2020 | 2000 | |
| 2021 | | if( sdl->m_glsl_program_num > 1 && sdl->m_glsl_program_mb2sc < sdl->m_glsl_program_num - 1 ) |
| 2001 | if( m_glsl_program_num > 1 && m_glsl_program_mb2sc < m_glsl_program_num - 1 ) |
| 2022 | 2002 | { |
| 2023 | 2003 | // multipass mode |
| 2024 | 2004 | // GL_TEXTURE2/GL_TEXTURE3 |
| r243304 | r243305 | |
| 2037 | 2017 | } |
| 2038 | 2018 | |
| 2039 | 2019 | osd_printf_verbose("GL texture: mpass screen-bmp 2x %dx%d (pow2 %dx%d)\n", |
| 2040 | | window->m_width, window->m_height, surf_w_pow2, surf_h_pow2); |
| 2020 | window().m_width, window().m_height, surf_w_pow2, surf_h_pow2); |
| 2041 | 2021 | } |
| 2042 | 2022 | |
| 2043 | 2023 | // GL_TEXTURE0 |
| r243304 | r243305 | |
| 2102 | 2082 | return 0; |
| 2103 | 2083 | } |
| 2104 | 2084 | |
| 2105 | | static texture_info *texture_create(sdl_window_info *window, const render_texinfo *texsource, UINT32 flags) |
| 2085 | texture_info *sdl_info_ogl::texture_create(const render_texinfo *texsource, UINT32 flags) |
| 2106 | 2086 | { |
| 2107 | | sdl_info *sdl = (sdl_info *) window->m_dxdata; |
| 2108 | 2087 | texture_info *texture; |
| 2109 | 2088 | |
| 2110 | 2089 | // allocate a new texture |
| r243304 | r243305 | |
| 2117 | 2096 | texture->texinfo.seqid = -1; // force set data |
| 2118 | 2097 | if (PRIMFLAG_GET_SCREENTEX(flags)) |
| 2119 | 2098 | { |
| 2120 | | texture->xprescale = window->m_prescale; |
| 2121 | | texture->yprescale = window->m_prescale; |
| 2099 | texture->xprescale = window().m_prescale; |
| 2100 | texture->yprescale = window().m_prescale; |
| 2122 | 2101 | } |
| 2123 | 2102 | else |
| 2124 | 2103 | { |
| r243304 | r243305 | |
| 2169 | 2148 | } |
| 2170 | 2149 | |
| 2171 | 2150 | // compute the size |
| 2172 | | texture_compute_size_type(window, texsource, texture, flags); |
| 2151 | texture_compute_size_type(texsource, texture, flags); |
| 2173 | 2152 | |
| 2174 | 2153 | texture->pbo=0; |
| 2175 | 2154 | |
| 2176 | | if ( texture->type != TEXTURE_TYPE_SHADER && sdl->m_useglsl) |
| 2155 | if ( texture->type != TEXTURE_TYPE_SHADER && m_useglsl) |
| 2177 | 2156 | { |
| 2178 | 2157 | pfn_glUseProgramObjectARB(0); // back to fixed function pipeline |
| 2179 | 2158 | } |
| 2180 | 2159 | |
| 2181 | 2160 | if ( texture->type==TEXTURE_TYPE_SHADER ) |
| 2182 | 2161 | { |
| 2183 | | if ( texture_shader_create(window, texsource, texture, flags) ) |
| 2162 | if ( texture_shader_create(texsource, texture, flags) ) |
| 2184 | 2163 | { |
| 2185 | 2164 | global_free(texture); |
| 2186 | 2165 | return NULL; |
| r243304 | r243305 | |
| 2237 | 2216 | |
| 2238 | 2217 | if ( texture->type == TEXTURE_TYPE_DYNAMIC ) |
| 2239 | 2218 | { |
| 2240 | | assert(sdl->m_usepbo); |
| 2219 | assert(m_usepbo); |
| 2241 | 2220 | |
| 2242 | 2221 | // create the PBO |
| 2243 | 2222 | pfn_glGenBuffers(1, (GLuint *)&texture->pbo); |
| r243304 | r243305 | |
| 2257 | 2236 | } |
| 2258 | 2237 | |
| 2259 | 2238 | // add us to the texture list |
| 2260 | | if (sdl->m_texhash[texture->hash] == NULL) |
| 2261 | | sdl->m_texhash[texture->hash] = texture; |
| 2239 | if (m_texhash[texture->hash] == NULL) |
| 2240 | m_texhash[texture->hash] = texture; |
| 2262 | 2241 | else |
| 2263 | 2242 | { |
| 2264 | 2243 | int i; |
| 2265 | 2244 | for (i = HASH_SIZE; i < HASH_SIZE + OVERFLOW_SIZE; i++) |
| 2266 | | if (sdl->m_texhash[i] == NULL) |
| 2245 | if (m_texhash[i] == NULL) |
| 2267 | 2246 | { |
| 2268 | | sdl->m_texhash[i] = texture; |
| 2247 | m_texhash[i] = texture; |
| 2269 | 2248 | break; |
| 2270 | 2249 | } |
| 2271 | 2250 | assert_always(i < HASH_SIZE + OVERFLOW_SIZE, "texture hash exhausted ..."); |
| 2272 | 2251 | } |
| 2273 | 2252 | |
| 2274 | | if(sdl->m_usevbo) |
| 2253 | if(m_usevbo) |
| 2275 | 2254 | { |
| 2276 | 2255 | // Generate And Bind The Texture Coordinate Buffer |
| 2277 | 2256 | pfn_glGenBuffers( 1, &(texture->texCoordBufferName) ); |
| r243304 | r243305 | |
| 2696 | 2675 | return 0; |
| 2697 | 2676 | } |
| 2698 | 2677 | |
| 2699 | | static texture_info *texture_find(sdl_info *sdl, const render_primitive *prim) |
| 2678 | texture_info *sdl_info_ogl::texture_find(const render_primitive *prim) |
| 2700 | 2679 | { |
| 2701 | 2680 | HashT texhash = texture_compute_hash(&prim->texture, prim->flags); |
| 2702 | 2681 | texture_info *texture; |
| 2703 | 2682 | |
| 2704 | | texture = sdl->m_texhash[texhash]; |
| 2683 | texture = m_texhash[texhash]; |
| 2705 | 2684 | if (texture != NULL) |
| 2706 | 2685 | { |
| 2707 | 2686 | int i; |
| r243304 | r243305 | |
| 2709 | 2688 | return texture; |
| 2710 | 2689 | for (i=HASH_SIZE; i<HASH_SIZE + OVERFLOW_SIZE; i++) |
| 2711 | 2690 | { |
| 2712 | | texture = sdl->m_texhash[i]; |
| 2691 | texture = m_texhash[i]; |
| 2713 | 2692 | if (texture != NULL && compare_texture_primitive(texture, prim)) |
| 2714 | 2693 | return texture; |
| 2715 | 2694 | } |
| r243304 | r243305 | |
| 2721 | 2700 | // texture_update |
| 2722 | 2701 | //============================================================ |
| 2723 | 2702 | |
| 2724 | | static void texture_coord_update(sdl_window_info *window, |
| 2725 | | texture_info *texture, const render_primitive *prim, int shaderIdx) |
| 2703 | void sdl_info_ogl::texture_coord_update(texture_info *texture, const render_primitive *prim, int shaderIdx) |
| 2726 | 2704 | { |
| 2727 | | sdl_info *sdl = (sdl_info *) window->m_dxdata; |
| 2728 | 2705 | float ustart = 0.0f, ustop = 0.0f; // beginning/ending U coordinates |
| 2729 | 2706 | float vstart = 0.0f, vstop = 0.0f; // beginning/ending V coordinates |
| 2730 | 2707 | float du, dv; |
| 2731 | 2708 | |
| 2732 | 2709 | if ( texture->type != TEXTURE_TYPE_SHADER || |
| 2733 | | ( texture->type == TEXTURE_TYPE_SHADER && shaderIdx<=sdl->m_glsl_program_mb2sc ) ) |
| 2710 | ( texture->type == TEXTURE_TYPE_SHADER && shaderIdx<=m_glsl_program_mb2sc ) ) |
| 2734 | 2711 | { |
| 2735 | 2712 | // compute the U/V scale factors |
| 2736 | 2713 | if (texture->borderpix) |
| r243304 | r243305 | |
| 2748 | 2725 | vstop = (float)(prim->texture.height*texture->yprescale) / (float)texture->rawheight_create; |
| 2749 | 2726 | } |
| 2750 | 2727 | } |
| 2751 | | else if ( texture->type == TEXTURE_TYPE_SHADER && shaderIdx>sdl->m_glsl_program_mb2sc ) |
| 2728 | else if ( texture->type == TEXTURE_TYPE_SHADER && shaderIdx>m_glsl_program_mb2sc ) |
| 2752 | 2729 | { |
| 2753 | | int surf_w_pow2 = get_valid_pow2_value (window->m_width, texture->texpow2); |
| 2754 | | int surf_h_pow2 = get_valid_pow2_value (window->m_height, texture->texpow2); |
| 2730 | int surf_w_pow2 = get_valid_pow2_value (window().m_width, texture->texpow2); |
| 2731 | int surf_h_pow2 = get_valid_pow2_value (window().m_height, texture->texpow2); |
| 2755 | 2732 | |
| 2756 | | ustop = (float)(window->m_width) / (float)surf_w_pow2; |
| 2757 | | vstop = (float)(window->m_height) / (float)surf_h_pow2; |
| 2733 | ustop = (float)(window().m_width) / (float)surf_w_pow2; |
| 2734 | vstop = (float)(window().m_height) / (float)surf_h_pow2; |
| 2758 | 2735 | } |
| 2759 | 2736 | else |
| 2760 | 2737 | { |
| r243304 | r243305 | |
| 2772 | 2749 | dv *= (float)texture->rawheight; |
| 2773 | 2750 | } |
| 2774 | 2751 | |
| 2775 | | if ( texture->type == TEXTURE_TYPE_SHADER && shaderIdx!=sdl->m_glsl_program_mb2sc ) |
| 2752 | if ( texture->type == TEXTURE_TYPE_SHADER && shaderIdx!=m_glsl_program_mb2sc ) |
| 2776 | 2753 | { |
| 2777 | 2754 | // 1:1 tex coord CCW (0/0) (1/0) (1/1) (0/1) |
| 2778 | 2755 | // we must go CW here due to the mame bitmap order |
| r243304 | r243305 | |
| 2799 | 2776 | } |
| 2800 | 2777 | } |
| 2801 | 2778 | |
| 2802 | | static void texture_mpass_flip(sdl_info *sdl, texture_info *texture, int shaderIdx) |
| 2779 | void sdl_info_ogl::texture_mpass_flip(texture_info *texture, int shaderIdx) |
| 2803 | 2780 | { |
| 2804 | 2781 | UINT32 mpass_src_idx = texture->mpass_dest_idx; |
| 2805 | 2782 | |
| r243304 | r243305 | |
| 2808 | 2785 | if ( shaderIdx>0 ) |
| 2809 | 2786 | { |
| 2810 | 2787 | int uniform_location; |
| 2811 | | uniform_location = pfn_glGetUniformLocationARB(sdl->m_glsl_program[shaderIdx], "mpass_texture"); |
| 2788 | uniform_location = pfn_glGetUniformLocationARB(m_glsl_program[shaderIdx], "mpass_texture"); |
| 2812 | 2789 | pfn_glUniform1iARB(uniform_location, texture->mpass_textureunit[mpass_src_idx]-GL_TEXTURE0); |
| 2813 | 2790 | GL_CHECK_ERROR_NORMAL(); |
| 2814 | 2791 | } |
| 2815 | 2792 | |
| 2816 | 2793 | pfn_glActiveTexture(texture->mpass_textureunit[mpass_src_idx]); |
| 2817 | | if ( shaderIdx<=sdl->m_glsl_program_mb2sc ) |
| 2794 | if ( shaderIdx<=m_glsl_program_mb2sc ) |
| 2818 | 2795 | { |
| 2819 | 2796 | glBindTexture(texture->texTarget, texture->mpass_texture_mamebm[mpass_src_idx]); |
| 2820 | 2797 | } |
| r243304 | r243305 | |
| 2827 | 2804 | |
| 2828 | 2805 | pfn_glActiveTexture(texture->mpass_textureunit[texture->mpass_dest_idx]); |
| 2829 | 2806 | |
| 2830 | | if ( shaderIdx<sdl->m_glsl_program_num-1 ) |
| 2807 | if ( shaderIdx<m_glsl_program_num-1 ) |
| 2831 | 2808 | { |
| 2832 | | if ( shaderIdx>=sdl->m_glsl_program_mb2sc ) |
| 2809 | if ( shaderIdx>=m_glsl_program_mb2sc ) |
| 2833 | 2810 | { |
| 2834 | 2811 | glBindTexture(texture->texTarget, texture->mpass_texture_scrn[texture->mpass_dest_idx]); |
| 2835 | 2812 | pfn_glBindFramebuffer(GL_FRAMEBUFFER_EXT, texture->mpass_fbo_scrn[texture->mpass_dest_idx]); |
| r243304 | r243305 | |
| 2846 | 2823 | GL_CHECK_ERROR_NORMAL(); |
| 2847 | 2824 | glViewport(0.0, 0.0, (GLsizei)texture->rawwidth, (GLsizei)texture->rawheight); |
| 2848 | 2825 | } |
| 2849 | | else if ( shaderIdx==sdl->m_glsl_program_mb2sc ) |
| 2826 | else if ( shaderIdx==m_glsl_program_mb2sc ) |
| 2850 | 2827 | { |
| 2851 | | assert ( sdl->m_glsl_program_mb2sc < sdl->m_glsl_program_num-1 ); |
| 2852 | | glPopAttrib(); // glViewport(0.0, 0.0, (GLsizei)window->width, (GLsizei)window->height) |
| 2828 | assert ( m_glsl_program_mb2sc < m_glsl_program_num-1 ); |
| 2829 | glPopAttrib(); // glViewport(0.0, 0.0, (GLsizei)window().width, (GLsizei)window().height) |
| 2853 | 2830 | GL_CHECK_ERROR_NORMAL(); |
| 2854 | 2831 | } |
| 2855 | 2832 | glClear(GL_COLOR_BUFFER_BIT); // make sure the whole texture is redrawn .. |
| r243304 | r243305 | |
| 2859 | 2836 | glBindTexture(texture->texTarget, 0); |
| 2860 | 2837 | pfn_glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0); |
| 2861 | 2838 | |
| 2862 | | if ( sdl->m_glsl_program_mb2sc == sdl->m_glsl_program_num-1 ) |
| 2839 | if ( m_glsl_program_mb2sc == m_glsl_program_num-1 ) |
| 2863 | 2840 | { |
| 2864 | | glPopAttrib(); // glViewport(0.0, 0.0, (GLsizei)window->width, (GLsizei)window->height) |
| 2841 | glPopAttrib(); // glViewport(0.0, 0.0, (GLsizei)window().width, (GLsizei)window().height) |
| 2865 | 2842 | GL_CHECK_ERROR_NORMAL(); |
| 2866 | 2843 | } |
| 2867 | 2844 | |
| r243304 | r243305 | |
| 2870 | 2847 | } |
| 2871 | 2848 | } |
| 2872 | 2849 | |
| 2873 | | static void texture_shader_update(sdl_window_info *window, texture_info *texture, int shaderIdx) |
| 2850 | void sdl_info_ogl::texture_shader_update(texture_info *texture, int shaderIdx) |
| 2874 | 2851 | { |
| 2875 | | sdl_info *sdl = (sdl_info *) window->m_dxdata; |
| 2876 | 2852 | int uniform_location, scrnum; |
| 2877 | 2853 | render_container *container; |
| 2878 | 2854 | GLfloat vid_attributes[4]; |
| 2879 | 2855 | |
| 2880 | 2856 | scrnum = 0; |
| 2881 | 2857 | container = (render_container *)NULL; |
| 2882 | | screen_device_iterator iter(window->machine().root_device()); |
| 2858 | screen_device_iterator iter(window().machine().root_device()); |
| 2883 | 2859 | for (screen_device *screen = iter.first(); screen != NULL; screen = iter.next()) |
| 2884 | 2860 | { |
| 2885 | | if (scrnum == window->m_start_viewscreen) |
| 2861 | if (scrnum == window().m_start_viewscreen) |
| 2886 | 2862 | { |
| 2887 | 2863 | container = &screen->container(); |
| 2888 | 2864 | } |
| r243304 | r243305 | |
| 2896 | 2872 | container->get_user_settings(settings); |
| 2897 | 2873 | //FIXME: Intended behaviour |
| 2898 | 2874 | #if 1 |
| 2899 | | vid_attributes[0] = window->machine().options().gamma(); |
| 2900 | | vid_attributes[1] = window->machine().options().contrast(); |
| 2901 | | vid_attributes[2] = window->machine().options().brightness(); |
| 2875 | vid_attributes[0] = window().machine().options().gamma(); |
| 2876 | vid_attributes[1] = window().machine().options().contrast(); |
| 2877 | vid_attributes[2] = window().machine().options().brightness(); |
| 2902 | 2878 | #else |
| 2903 | 2879 | vid_attributes[0] = settings.gamma; |
| 2904 | 2880 | vid_attributes[1] = settings.contrast; |
| 2905 | 2881 | vid_attributes[2] = settings.brightness; |
| 2906 | 2882 | #endif |
| 2907 | 2883 | vid_attributes[3] = 0.0f; |
| 2908 | | uniform_location = pfn_glGetUniformLocationARB(sdl->m_glsl_program[shaderIdx], "vid_attributes"); |
| 2884 | uniform_location = pfn_glGetUniformLocationARB(m_glsl_program[shaderIdx], "vid_attributes"); |
| 2909 | 2885 | pfn_glUniform4fvARB(uniform_location, 1, &(vid_attributes[shaderIdx])); |
| 2910 | 2886 | if ( GL_CHECK_ERROR_QUIET() ) { |
| 2911 | 2887 | osd_printf_verbose("GLSL: could not set 'vid_attributes' for shader prog idx %d\n", shaderIdx); |
| r243304 | r243305 | |
| 2913 | 2889 | } |
| 2914 | 2890 | else |
| 2915 | 2891 | { |
| 2916 | | osd_printf_verbose("GLSL: could not get render container for screen %d\n", window->m_start_viewscreen); |
| 2892 | osd_printf_verbose("GLSL: could not get render container for screen %d\n", window().m_start_viewscreen); |
| 2917 | 2893 | } |
| 2918 | 2894 | } |
| 2919 | 2895 | |
| 2920 | | static texture_info * texture_update(sdl_window_info *window, const render_primitive *prim, int shaderIdx) |
| 2896 | texture_info * sdl_info_ogl::texture_update(const render_primitive *prim, int shaderIdx) |
| 2921 | 2897 | { |
| 2922 | | sdl_info *sdl = (sdl_info *) window->m_dxdata; |
| 2923 | | texture_info *texture = texture_find(sdl, prim); |
| 2898 | texture_info *texture = texture_find(prim); |
| 2924 | 2899 | int texBound = 0; |
| 2925 | 2900 | |
| 2926 | 2901 | // if we didn't find one, create a new texture |
| 2927 | 2902 | if (texture == NULL && prim->texture.base != NULL) |
| 2928 | 2903 | { |
| 2929 | | texture = texture_create(window, &prim->texture, prim->flags); |
| 2904 | texture = texture_create(&prim->texture, prim->flags); |
| 2930 | 2905 | } |
| 2931 | 2906 | else if (texture != NULL) |
| 2932 | 2907 | { |
| 2933 | 2908 | if ( texture->type == TEXTURE_TYPE_SHADER ) |
| 2934 | 2909 | { |
| 2935 | | pfn_glUseProgramObjectARB(sdl->m_glsl_program[shaderIdx]); // back to our shader |
| 2910 | pfn_glUseProgramObjectARB(m_glsl_program[shaderIdx]); // back to our shader |
| 2936 | 2911 | } |
| 2937 | 2912 | else if ( texture->type == TEXTURE_TYPE_DYNAMIC ) |
| 2938 | 2913 | { |
| 2939 | | assert ( sdl->m_usepbo ) ; |
| 2914 | assert ( m_usepbo ) ; |
| 2940 | 2915 | pfn_glBindBuffer( GL_PIXEL_UNPACK_BUFFER_ARB, texture->pbo); |
| 2941 | 2916 | glEnable(texture->texTarget); |
| 2942 | 2917 | } |
| r243304 | r243305 | |
| 2950 | 2925 | { |
| 2951 | 2926 | if ( texture->type == TEXTURE_TYPE_SHADER ) |
| 2952 | 2927 | { |
| 2953 | | texture_shader_update(window, texture, shaderIdx); |
| 2954 | | if ( sdl->m_glsl_program_num>1 ) |
| 2928 | texture_shader_update(texture, shaderIdx); |
| 2929 | if ( m_glsl_program_num>1 ) |
| 2955 | 2930 | { |
| 2956 | | texture_mpass_flip(sdl, texture, shaderIdx); |
| 2931 | texture_mpass_flip(texture, shaderIdx); |
| 2957 | 2932 | } |
| 2958 | 2933 | } |
| 2959 | 2934 | |
| r243304 | r243305 | |
| 2972 | 2947 | if (!texBound) { |
| 2973 | 2948 | glBindTexture(texture->texTarget, texture->texture); |
| 2974 | 2949 | } |
| 2975 | | texture_coord_update(window, texture, prim, shaderIdx); |
| 2950 | texture_coord_update(texture, prim, shaderIdx); |
| 2976 | 2951 | |
| 2977 | 2952 | glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
| 2978 | | if(sdl->m_usevbo) |
| 2953 | if(m_usevbo) |
| 2979 | 2954 | { |
| 2980 | 2955 | pfn_glBindBuffer( GL_ARRAY_BUFFER_ARB, texture->texCoordBufferName ); |
| 2981 | 2956 | // Load The Data |
| r243304 | r243305 | |
| 2991 | 2966 | return texture; |
| 2992 | 2967 | } |
| 2993 | 2968 | |
| 2994 | | static void texture_disable(sdl_info *sdl, texture_info * texture) |
| 2969 | void sdl_info_ogl::texture_disable(texture_info * texture) |
| 2995 | 2970 | { |
| 2996 | 2971 | if ( texture->type == TEXTURE_TYPE_SHADER ) |
| 2997 | 2972 | { |
| 2998 | | assert ( sdl->m_useglsl ); |
| 2973 | assert ( m_useglsl ); |
| 2999 | 2974 | pfn_glUseProgramObjectARB(0); // back to fixed function pipeline |
| 3000 | 2975 | } else if ( texture->type == TEXTURE_TYPE_DYNAMIC ) |
| 3001 | 2976 | { |
| r243304 | r243305 | |
| 3006 | 2981 | } |
| 3007 | 2982 | } |
| 3008 | 2983 | |
| 3009 | | static void texture_all_disable(sdl_info *sdl) |
| 2984 | void sdl_info_ogl::texture_all_disable() |
| 3010 | 2985 | { |
| 3011 | | if ( sdl->m_useglsl ) |
| 2986 | if ( m_useglsl ) |
| 3012 | 2987 | { |
| 3013 | 2988 | pfn_glUseProgramObjectARB(0); // back to fixed function pipeline |
| 3014 | 2989 | |
| 3015 | 2990 | pfn_glActiveTexture(GL_TEXTURE3); |
| 3016 | 2991 | glBindTexture(GL_TEXTURE_2D, 0); |
| 3017 | | if ( sdl->m_usefbo ) pfn_glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0); |
| 2992 | if ( m_usefbo ) pfn_glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0); |
| 3018 | 2993 | pfn_glActiveTexture(GL_TEXTURE2); |
| 3019 | 2994 | glBindTexture(GL_TEXTURE_2D, 0); |
| 3020 | | if ( sdl->m_usefbo ) pfn_glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0); |
| 2995 | if ( m_usefbo ) pfn_glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0); |
| 3021 | 2996 | pfn_glActiveTexture(GL_TEXTURE1); |
| 3022 | 2997 | glBindTexture(GL_TEXTURE_2D, 0); |
| 3023 | | if ( sdl->m_usefbo ) pfn_glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0); |
| 2998 | if ( m_usefbo ) pfn_glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0); |
| 3024 | 2999 | pfn_glActiveTexture(GL_TEXTURE0); |
| 3025 | 3000 | glBindTexture(GL_TEXTURE_2D, 0); |
| 3026 | | if ( sdl->m_usefbo ) pfn_glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0); |
| 3001 | if ( m_usefbo ) pfn_glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0); |
| 3027 | 3002 | } |
| 3028 | 3003 | glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0); |
| 3029 | 3004 | |
| 3030 | | if(sdl->m_usetexturerect) |
| 3005 | if(m_usetexturerect) |
| 3031 | 3006 | { |
| 3032 | 3007 | glDisable(GL_TEXTURE_RECTANGLE_ARB); |
| 3033 | 3008 | } |
| 3034 | 3009 | glDisable(GL_TEXTURE_2D); |
| 3035 | 3010 | |
| 3036 | 3011 | glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
| 3037 | | if(sdl->m_usevbo) |
| 3012 | if(m_usevbo) |
| 3038 | 3013 | { |
| 3039 | 3014 | pfn_glBindBuffer( GL_ARRAY_BUFFER_ARB, 0); // unbind .. |
| 3040 | 3015 | } |
| 3041 | | if ( sdl->m_usepbo ) |
| 3016 | if ( m_usepbo ) |
| 3042 | 3017 | { |
| 3043 | 3018 | pfn_glBindBuffer( GL_PIXEL_UNPACK_BUFFER_ARB, 0); |
| 3044 | 3019 | } |
| 3045 | 3020 | } |
| 3046 | 3021 | |
| 3047 | | static void drawogl_destroy_all_textures(sdl_window_info *window) |
| 3022 | void sdl_info_ogl::destroy_all_textures() |
| 3048 | 3023 | { |
| 3049 | | sdl_info *sdl = (sdl_info *) window->m_dxdata; |
| 3050 | 3024 | texture_info *texture = NULL; |
| 3051 | 3025 | int lock=FALSE; |
| 3052 | 3026 | int i; |
| 3053 | 3027 | |
| 3054 | | if (sdl == NULL) |
| 3028 | if ( !m_initialized ) |
| 3055 | 3029 | return; |
| 3056 | 3030 | |
| 3057 | | if ( !sdl->m_initialized ) |
| 3058 | | return; |
| 3059 | | |
| 3060 | 3031 | #if (SDLMAME_SDL2) |
| 3061 | | SDL_GL_MakeCurrent(window->m_sdl_window, sdl->m_gl_context_id); |
| 3032 | SDL_GL_MakeCurrent(window().m_sdl_window, m_gl_context_id); |
| 3062 | 3033 | #endif |
| 3063 | 3034 | |
| 3064 | | if(window->m_primlist) |
| 3035 | if(window().m_primlist) |
| 3065 | 3036 | { |
| 3066 | 3037 | lock=TRUE; |
| 3067 | | window->m_primlist->acquire_lock(); |
| 3038 | window().m_primlist->acquire_lock(); |
| 3068 | 3039 | } |
| 3069 | 3040 | |
| 3070 | 3041 | glFinish(); |
| 3071 | 3042 | |
| 3072 | | texture_all_disable(sdl); |
| 3043 | texture_all_disable(); |
| 3073 | 3044 | glFinish(); |
| 3074 | 3045 | glDisableClientState(GL_VERTEX_ARRAY); |
| 3075 | 3046 | |
| 3076 | 3047 | i=0; |
| 3077 | 3048 | while (i<HASH_SIZE+OVERFLOW_SIZE) |
| 3078 | 3049 | { |
| 3079 | | texture = sdl->m_texhash[i]; |
| 3080 | | sdl->m_texhash[i] = NULL; |
| 3050 | texture = m_texhash[i]; |
| 3051 | m_texhash[i] = NULL; |
| 3081 | 3052 | if (texture != NULL) |
| 3082 | 3053 | { |
| 3083 | | if(sdl->m_usevbo) |
| 3054 | if(m_usevbo) |
| 3084 | 3055 | { |
| 3085 | 3056 | pfn_glDeleteBuffers( 1, &(texture->texCoordBufferName) ); |
| 3086 | 3057 | texture->texCoordBufferName=0; |
| 3087 | 3058 | } |
| 3088 | 3059 | |
| 3089 | | if(sdl->m_usepbo && texture->pbo) |
| 3060 | if(m_usepbo && texture->pbo) |
| 3090 | 3061 | { |
| 3091 | 3062 | pfn_glDeleteBuffers( 1, (GLuint *)&(texture->pbo) ); |
| 3092 | 3063 | texture->pbo=0; |
| 3093 | 3064 | } |
| 3094 | 3065 | |
| 3095 | | if( sdl->m_glsl_program_num > 1 ) |
| 3066 | if( m_glsl_program_num > 1 ) |
| 3096 | 3067 | { |
| 3097 | | assert(sdl->m_usefbo); |
| 3068 | assert(m_usefbo); |
| 3098 | 3069 | pfn_glDeleteFramebuffers(2, (GLuint *)&texture->mpass_fbo_mamebm[0]); |
| 3099 | 3070 | glDeleteTextures(2, (GLuint *)&texture->mpass_texture_mamebm[0]); |
| 3100 | 3071 | } |
| 3101 | 3072 | |
| 3102 | | if ( sdl->m_glsl_program_mb2sc < sdl->m_glsl_program_num - 1 ) |
| 3073 | if ( m_glsl_program_mb2sc < m_glsl_program_num - 1 ) |
| 3103 | 3074 | { |
| 3104 | | assert(sdl->m_usefbo); |
| 3075 | assert(m_usefbo); |
| 3105 | 3076 | pfn_glDeleteFramebuffers(2, (GLuint *)&texture->mpass_fbo_scrn[0]); |
| 3106 | 3077 | glDeleteTextures(2, (GLuint *)&texture->mpass_texture_scrn[0]); |
| 3107 | 3078 | } |
| r243304 | r243305 | |
| 3117 | 3088 | } |
| 3118 | 3089 | i++; |
| 3119 | 3090 | } |
| 3120 | | if ( sdl->m_useglsl ) |
| 3091 | if ( m_useglsl ) |
| 3121 | 3092 | { |
| 3122 | | glsl_shader_free(sdl->m_glsl); |
| 3123 | | sdl->m_glsl = NULL; |
| 3093 | glsl_shader_free(m_glsl); |
| 3094 | m_glsl = NULL; |
| 3124 | 3095 | } |
| 3125 | 3096 | |
| 3126 | | sdl->m_initialized = 0; |
| 3097 | m_initialized = 0; |
| 3127 | 3098 | |
| 3128 | 3099 | if (lock) |
| 3129 | | window->m_primlist->release_lock(); |
| 3100 | window().m_primlist->release_lock(); |
| 3130 | 3101 | } |
| 3131 | 3102 | |
| 3132 | 3103 | //============================================================ |
| 3133 | 3104 | // TEXCOPY FUNCS |
| 3134 | 3105 | //============================================================ |
| 3135 | 3106 | |
| 3136 | | static void drawogl_window_clear(sdl_window_info *window) |
| 3107 | void sdl_info_ogl::clear() |
| 3137 | 3108 | { |
| 3138 | | sdl_info *sdl = (sdl_info *) window->m_dxdata; |
| 3139 | | |
| 3140 | | //FIXME: Handled in drawogl_window_draw as well |
| 3141 | | sdl->m_blittimer = 3; |
| 3109 | //FIXME: Handled in sdl_info::draw as well |
| 3110 | m_blittimer = 3; |
| 3142 | 3111 | } |
trunk/src/osd/sdl/drawsdl.c
| r243304 | r243305 | |
| 46 | 46 | #endif |
| 47 | 47 | |
| 48 | 48 | /* sdl_info is the information about SDL for the current screen */ |
| 49 | | struct sdl_info |
| 49 | class sdl_info : public osd_renderer |
| 50 | 50 | { |
| 51 | public: |
| 52 | |
| 53 | sdl_info(sdl_window_info *w) |
| 54 | : osd_renderer(w), |
| 55 | m_blittimer(0), |
| 56 | m_extra_flags(0), |
| 57 | |
| 58 | #if (SDLMAME_SDL2) |
| 59 | m_sdl_renderer(NULL), |
| 60 | m_texture_id(NULL), |
| 61 | #else |
| 62 | m_sdlsurf(NULL), |
| 63 | m_yuvsurf(NULL), |
| 64 | #endif |
| 65 | m_yuv_lookup(NULL), |
| 66 | m_yuv_bitmap(NULL), |
| 67 | m_hw_scale_width(0), |
| 68 | m_hw_scale_height(0), |
| 69 | m_last_hofs(0), |
| 70 | m_last_vofs(0), |
| 71 | m_old_blitwidth(0), |
| 72 | m_old_blitheight(0) |
| 73 | { } |
| 74 | |
| 75 | /* virtual */ int create(int width, int height); |
| 76 | /* virtual */ void resize(int width, int height); |
| 77 | /* virtual */ int draw(UINT32 dc, int update); |
| 78 | /* virtual */ void set_target_bounds(); |
| 79 | /* virtual */ int xy_to_render_target(int x, int y, int *xt, int *yt); |
| 80 | /* virtual */ void destroy_all_textures(); |
| 81 | /* virtual */ void destroy(); |
| 82 | /* virtual */ void clear(); |
| 83 | |
| 84 | void yuv_init(); |
| 85 | #if (SDLMAME_SDL2) |
| 86 | void setup_texture(int tempwidth, int tempheight); |
| 87 | #endif |
| 88 | void yuv_lookup_set(unsigned int pen, unsigned char red, |
| 89 | unsigned char green, unsigned char blue); |
| 90 | |
| 91 | #if (!SDLMAME_SDL2) |
| 92 | void yuv_overlay_init(); |
| 93 | #endif |
| 94 | |
| 51 | 95 | INT32 m_blittimer; |
| 52 | 96 | UINT32 m_extra_flags; |
| 53 | 97 | |
| r243304 | r243305 | |
| 101 | 145 | |
| 102 | 146 | // core functions |
| 103 | 147 | static void drawsdl_exit(void); |
| 104 | | static void drawsdl_attach(sdl_draw_info *info, sdl_window_info *window); |
| 105 | | static int drawsdl_window_create(sdl_window_info *window, int width, int height); |
| 106 | | static void drawsdl_window_resize(sdl_window_info *window, int width, int height); |
| 107 | | static void drawsdl_window_destroy(sdl_window_info *window); |
| 108 | | static void drawsdl_set_target_bounds(sdl_window_info *window); |
| 109 | | static int drawsdl_window_draw(sdl_window_info *window, UINT32 dc, int update); |
| 110 | | static void drawsdl_destroy_all_textures(sdl_window_info *window); |
| 111 | | static void drawsdl_window_clear(sdl_window_info *window); |
| 112 | | static int drawsdl_xy_to_render_target(sdl_window_info *window, int x, int y, int *xt, int *yt); |
| 113 | 148 | |
| 114 | | #if (SDLMAME_SDL2) |
| 115 | | static void setup_texture(sdl_window_info *window, int tempwidth, int tempheight); |
| 116 | | #endif |
| 117 | | |
| 118 | 149 | // YUV overlays |
| 119 | 150 | |
| 120 | | static void drawsdl_yuv_init(sdl_info *sdl); |
| 121 | 151 | static void yuv_RGB_to_YV12(UINT16 *bitmap, sdl_info *sdl, UINT8 *ptr, int pitch); |
| 122 | 152 | static void yuv_RGB_to_YV12X2(UINT16 *bitmap, sdl_info *sdl, UINT8 *ptr, int pitch); |
| 123 | 153 | static void yuv_RGB_to_YUY2(UINT16 *bitmap, sdl_info *sdl, UINT8 *ptr, int pitch); |
| r243304 | r243305 | |
| 190 | 220 | // drawsdl_init |
| 191 | 221 | //============================================================ |
| 192 | 222 | |
| 223 | static osd_renderer *drawsdl_create(sdl_window_info *window) |
| 224 | { |
| 225 | return global_alloc(sdl_info(window)); |
| 226 | } |
| 227 | |
| 228 | |
| 193 | 229 | int drawsdl_init(sdl_draw_info *callbacks) |
| 194 | 230 | { |
| 195 | 231 | // fill in the callbacks |
| 232 | callbacks->create = drawsdl_create; |
| 196 | 233 | callbacks->exit = drawsdl_exit; |
| 197 | | callbacks->attach = drawsdl_attach; |
| 198 | 234 | |
| 199 | 235 | if (SDLMAME_SDL2) |
| 200 | 236 | osd_printf_verbose("Using SDL multi-window soft driver (SDL 2.0+)\n"); |
| r243304 | r243305 | |
| 213 | 249 | } |
| 214 | 250 | |
| 215 | 251 | //============================================================ |
| 216 | | // drawsdl_attach |
| 217 | | //============================================================ |
| 218 | | |
| 219 | | static void drawsdl_attach(sdl_draw_info *info, sdl_window_info *window) |
| 220 | | { |
| 221 | | // fill in the callbacks |
| 222 | | window->create = drawsdl_window_create; |
| 223 | | window->resize = drawsdl_window_resize; |
| 224 | | window->set_target_bounds = drawsdl_set_target_bounds; |
| 225 | | window->draw = drawsdl_window_draw; |
| 226 | | window->destroy = drawsdl_window_destroy; |
| 227 | | window->destroy_all_textures = drawsdl_destroy_all_textures; |
| 228 | | window->clear = drawsdl_window_clear; |
| 229 | | window->xy_to_render_target = drawsdl_xy_to_render_target; |
| 230 | | } |
| 231 | | |
| 232 | | //============================================================ |
| 233 | 252 | // drawsdl_destroy_all_textures |
| 234 | 253 | //============================================================ |
| 235 | 254 | |
| 236 | | static void drawsdl_destroy_all_textures(sdl_window_info *window) |
| 255 | void sdl_info::destroy_all_textures() |
| 237 | 256 | { |
| 238 | 257 | /* nothing to be done in soft mode */ |
| 239 | 258 | } |
| r243304 | r243305 | |
| 243 | 262 | //============================================================ |
| 244 | 263 | |
| 245 | 264 | #if (SDLMAME_SDL2) |
| 246 | | static void setup_texture(sdl_window_info *window, int tempwidth, int tempheight) |
| 265 | void sdl_info::setup_texture(int tempwidth, int tempheight) |
| 247 | 266 | { |
| 248 | | sdl_info *sdl = (sdl_info *) window->m_dxdata; |
| 249 | 267 | const sdl_scale_mode *sdl_sm = &scale_modes[video_config.scale_mode]; |
| 250 | 268 | SDL_DisplayMode mode; |
| 251 | 269 | UINT32 fmt; |
| 252 | 270 | |
| 253 | 271 | // Determine preferred pixelformat and set up yuv if necessary |
| 254 | | SDL_GetCurrentDisplayMode(window->monitor()->handle(), &mode); |
| 272 | SDL_GetCurrentDisplayMode(window().monitor()->handle(), &mode); |
| 255 | 273 | |
| 256 | | if (sdl->m_yuv_bitmap) |
| 274 | if (m_yuv_bitmap) |
| 257 | 275 | { |
| 258 | | global_free_array(sdl->m_yuv_bitmap); |
| 259 | | sdl->m_yuv_bitmap = NULL; |
| 276 | global_free_array(m_yuv_bitmap); |
| 277 | m_yuv_bitmap = NULL; |
| 260 | 278 | } |
| 261 | 279 | |
| 262 | 280 | if (sdl_sm->is_scale) |
| 263 | 281 | { |
| 264 | | window->m_target->compute_minimum_size(sdl->m_hw_scale_width, sdl->m_hw_scale_height); |
| 282 | window().m_target->compute_minimum_size(m_hw_scale_width, m_hw_scale_height); |
| 265 | 283 | if (video_config.prescale) |
| 266 | 284 | { |
| 267 | | sdl->m_hw_scale_width *= video_config.prescale; |
| 268 | | sdl->m_hw_scale_height *= video_config.prescale; |
| 285 | m_hw_scale_width *= video_config.prescale; |
| 286 | m_hw_scale_height *= video_config.prescale; |
| 269 | 287 | |
| 270 | 288 | /* This must be a multiple of 2 */ |
| 271 | | sdl->m_hw_scale_width = (sdl->m_hw_scale_width + 1) & ~1; |
| 289 | m_hw_scale_width = (m_hw_scale_width + 1) & ~1; |
| 272 | 290 | } |
| 273 | 291 | } |
| 274 | 292 | |
| 275 | 293 | if (sdl_sm->is_yuv) |
| 276 | | sdl->m_yuv_bitmap = global_alloc_array(UINT16, sdl->m_hw_scale_width * sdl->m_hw_scale_height); |
| 294 | m_yuv_bitmap = global_alloc_array(UINT16, m_hw_scale_width * m_hw_scale_height); |
| 277 | 295 | |
| 278 | 296 | fmt = (sdl_sm->pixel_format ? sdl_sm->pixel_format : mode.format); |
| 279 | 297 | |
| 280 | 298 | if (sdl_sm->is_scale) |
| 281 | 299 | { |
| 282 | | int w = sdl->m_hw_scale_width * sdl_sm->mult_w; |
| 283 | | int h = sdl->m_hw_scale_height * sdl_sm->mult_h; |
| 300 | int w = m_hw_scale_width * sdl_sm->mult_w; |
| 301 | int h = m_hw_scale_height * sdl_sm->mult_h; |
| 284 | 302 | |
| 285 | | sdl->m_texture_id = SDL_CreateTexture(sdl->m_sdl_renderer, fmt, SDL_TEXTUREACCESS_STREAMING, w, h); |
| 303 | m_texture_id = SDL_CreateTexture(m_sdl_renderer, fmt, SDL_TEXTUREACCESS_STREAMING, w, h); |
| 286 | 304 | |
| 287 | 305 | } |
| 288 | 306 | else |
| 289 | 307 | { |
| 290 | | sdl->m_texture_id = SDL_CreateTexture(sdl->m_sdl_renderer,fmt, SDL_TEXTUREACCESS_STREAMING, |
| 308 | m_texture_id = SDL_CreateTexture(m_sdl_renderer,fmt, SDL_TEXTUREACCESS_STREAMING, |
| 291 | 309 | tempwidth, tempheight); |
| 292 | 310 | } |
| 293 | 311 | } |
| r243304 | r243305 | |
| 298 | 316 | //============================================================ |
| 299 | 317 | |
| 300 | 318 | #if (!SDLMAME_SDL2) |
| 301 | | static void yuv_overlay_init(sdl_window_info *window) |
| 319 | void sdl_info::yuv_overlay_init() |
| 302 | 320 | { |
| 303 | | sdl_info *sdl = (sdl_info *) window->m_dxdata; |
| 304 | 321 | const sdl_scale_mode *sdl_sm = &scale_modes[video_config.scale_mode]; |
| 305 | 322 | int minimum_width, minimum_height; |
| 306 | 323 | |
| 307 | | window->m_target->compute_minimum_size(minimum_width, minimum_height); |
| 324 | window().m_target->compute_minimum_size(minimum_width, minimum_height); |
| 308 | 325 | |
| 309 | 326 | if (video_config.prescale) |
| 310 | 327 | { |
| r243304 | r243305 | |
| 312 | 329 | minimum_height *= video_config.prescale; |
| 313 | 330 | } |
| 314 | 331 | |
| 315 | | if (sdl->yuvsurf != NULL) |
| 332 | if (m_yuvsurf != NULL) |
| 316 | 333 | { |
| 317 | | SDL_FreeYUVOverlay(sdl->yuvsurf); |
| 318 | | sdl->yuvsurf = NULL; |
| 334 | SDL_FreeYUVOverlay(m_yuvsurf); |
| 335 | m_yuvsurf = NULL; |
| 319 | 336 | } |
| 320 | 337 | |
| 321 | | if (sdl->m_yuv_bitmap != NULL) |
| 338 | if (m_yuv_bitmap != NULL) |
| 322 | 339 | { |
| 323 | | global_free_array(sdl->m_yuv_bitmap); |
| 340 | global_free_array(m_yuv_bitmap); |
| 324 | 341 | } |
| 325 | 342 | |
| 326 | 343 | osd_printf_verbose("SDL: Creating %d x %d YUV-Overlay ...\n", minimum_width, minimum_height); |
| 327 | 344 | |
| 328 | | sdl->m_yuv_bitmap = global_alloc_array(UINT16, minimum_width*minimum_height); |
| 345 | m_yuv_bitmap = global_alloc_array(UINT16, minimum_width*minimum_height); |
| 329 | 346 | |
| 330 | | sdl->yuvsurf = SDL_CreateYUVOverlay(minimum_width * sdl_sm->mult_w, minimum_height * sdl_sm->mult_h, |
| 331 | | sdl_sm->pixel_format, sdl->sdlsurf); |
| 347 | m_yuvsurf = SDL_CreateYUVOverlay(minimum_width * sdl_sm->mult_w, minimum_height * sdl_sm->mult_h, |
| 348 | sdl_sm->pixel_format, m_sdlsurf); |
| 332 | 349 | |
| 333 | | if ( sdl->yuvsurf == NULL ) { |
| 350 | if ( m_yuvsurf == NULL ) { |
| 334 | 351 | osd_printf_error("SDL: Couldn't create SDL_yuv_overlay: %s\n", SDL_GetError()); |
| 335 | 352 | //return 1; |
| 336 | 353 | } |
| 337 | 354 | |
| 338 | | sdl->m_hw_scale_width = minimum_width; |
| 339 | | sdl->m_hw_scale_height = minimum_height; |
| 355 | m_hw_scale_width = minimum_width; |
| 356 | m_hw_scale_height = minimum_height; |
| 340 | 357 | |
| 341 | 358 | if (!shown_video_info) |
| 342 | 359 | { |
| 343 | 360 | osd_printf_verbose("YUV Mode : %s\n", sdl_sm->name); |
| 344 | 361 | osd_printf_verbose("YUV Overlay Size : %d x %d\n", minimum_width, minimum_height); |
| 345 | | osd_printf_verbose("YUV Acceleration : %s\n", sdl->yuvsurf->hw_overlay ? "Hardware" : "Software"); |
| 362 | osd_printf_verbose("YUV Acceleration : %s\n", m_yuvsurf->hw_overlay ? "Hardware" : "Software"); |
| 346 | 363 | shown_video_info = 1; |
| 347 | 364 | } |
| 348 | 365 | } |
| r243304 | r243305 | |
| 353 | 370 | //============================================================ |
| 354 | 371 | |
| 355 | 372 | #if (SDLMAME_SDL2) |
| 356 | | static void drawsdl_show_info(sdl_window_info *window, struct SDL_RendererInfo *render_info) |
| 373 | static void drawsdl_show_info(struct SDL_RendererInfo *render_info) |
| 357 | 374 | { |
| 358 | 375 | #define RF_ENTRY(x) {x, #x } |
| 359 | 376 | static struct { |
| r243304 | r243305 | |
| 385 | 402 | // drawsdl_window_create |
| 386 | 403 | //============================================================ |
| 387 | 404 | |
| 388 | | static int drawsdl_window_create(sdl_window_info *window, int width, int height) |
| 405 | int sdl_info::create(int width, int height) |
| 389 | 406 | { |
| 390 | | sdl_info *sdl; |
| 391 | 407 | const sdl_scale_mode *sm = &scale_modes[video_config.scale_mode]; |
| 392 | 408 | |
| 393 | | // allocate memory for our structures |
| 394 | | sdl = (sdl_info *) osd_malloc(sizeof(sdl_info)); |
| 395 | | memset(sdl, 0, sizeof(sdl_info)); |
| 396 | | |
| 397 | | window->m_dxdata = sdl; |
| 398 | | |
| 399 | 409 | #if (SDLMAME_SDL2) |
| 400 | 410 | |
| 401 | 411 | /* set hints ... */ |
| 402 | 412 | |
| 403 | 413 | SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, sm->sdl_scale_mode); |
| 404 | 414 | |
| 405 | | sdl->m_extra_flags = (window->fullscreen() ? |
| 415 | m_extra_flags = (window().fullscreen() ? |
| 406 | 416 | SDL_WINDOW_BORDERLESS | SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_MOUSE_FOCUS |
| 407 | 417 | | SDL_WINDOW_INPUT_GRABBED : SDL_WINDOW_RESIZABLE); |
| 408 | 418 | |
| 409 | | window->m_sdl_window = SDL_CreateWindow(window->m_title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, |
| 410 | | width, height, sdl->m_extra_flags); |
| 419 | window().m_sdl_window = SDL_CreateWindow(window().m_title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, |
| 420 | width, height, m_extra_flags); |
| 411 | 421 | |
| 412 | | if (window->fullscreen() && video_config.switchres) |
| 422 | if (window().fullscreen() && video_config.switchres) |
| 413 | 423 | { |
| 414 | 424 | SDL_DisplayMode mode; |
| 415 | | SDL_GetCurrentDisplayMode(window->monitor()->handle(), &mode); |
| 425 | SDL_GetCurrentDisplayMode(window().monitor()->handle(), &mode); |
| 416 | 426 | mode.w = width; |
| 417 | 427 | mode.h = height; |
| 418 | | if (window->m_refresh) |
| 419 | | mode.refresh_rate = window->m_refresh; |
| 420 | | SDL_SetWindowDisplayMode(window->m_sdl_window, &mode); // Try to set mode |
| 428 | if (window().m_refresh) |
| 429 | mode.refresh_rate = window().m_refresh; |
| 430 | SDL_SetWindowDisplayMode(window().m_sdl_window, &mode); // Try to set mode |
| 421 | 431 | } |
| 422 | 432 | else |
| 423 | | SDL_SetWindowDisplayMode(window->m_sdl_window, NULL); // Use desktop |
| 433 | SDL_SetWindowDisplayMode(window().m_sdl_window, NULL); // Use desktop |
| 424 | 434 | |
| 425 | | SDL_ShowWindow(window->m_sdl_window); |
| 435 | SDL_ShowWindow(window().m_sdl_window); |
| 426 | 436 | |
| 427 | | SDL_SetWindowFullscreen(window->m_sdl_window, (SDL_bool) window->fullscreen()); |
| 428 | | SDL_GetWindowSize(window->m_sdl_window, &window->m_width, &window->m_height); |
| 429 | | SDL_RaiseWindow(window->m_sdl_window); |
| 437 | SDL_SetWindowFullscreen(window().m_sdl_window, (SDL_bool) window().fullscreen()); |
| 438 | SDL_GetWindowSize(window().m_sdl_window, &window().m_width, &window().m_height); |
| 439 | SDL_RaiseWindow(window().m_sdl_window); |
| 430 | 440 | |
| 431 | 441 | /* FIXME: Bug in SDL 1.3 */ |
| 432 | | if (window->fullscreen()) |
| 433 | | SDL_SetWindowGrab(window->m_sdl_window, SDL_TRUE); |
| 442 | if (window().fullscreen()) |
| 443 | SDL_SetWindowGrab(window().m_sdl_window, SDL_TRUE); |
| 434 | 444 | |
| 435 | 445 | // create a texture |
| 436 | 446 | |
| 437 | 447 | if (video_config.waitvsync) |
| 438 | | sdl->m_sdl_renderer = SDL_CreateRenderer(window->m_sdl_window, -1, /*SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTDISCARD |*/ SDL_RENDERER_PRESENTVSYNC); |
| 448 | m_sdl_renderer = SDL_CreateRenderer(window().m_sdl_window, -1, /*SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTDISCARD |*/ SDL_RENDERER_PRESENTVSYNC); |
| 439 | 449 | else |
| 440 | | sdl->m_sdl_renderer = SDL_CreateRenderer(window->m_sdl_window, -1, /*SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTDISCARD*/ 0); |
| 450 | m_sdl_renderer = SDL_CreateRenderer(window().m_sdl_window, -1, /*SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTDISCARD*/ 0); |
| 441 | 451 | |
| 442 | | //SDL_SelectRenderer(window->sdl_window); |
| 452 | //SDL_SelectRenderer(window().sdl_window); |
| 443 | 453 | |
| 444 | 454 | { |
| 445 | 455 | struct SDL_RendererInfo render_info; |
| 446 | 456 | |
| 447 | | SDL_GetRendererInfo(sdl->m_sdl_renderer, &render_info); |
| 448 | | drawsdl_show_info(window, &render_info); |
| 457 | SDL_GetRendererInfo(m_sdl_renderer, &render_info); |
| 458 | drawsdl_show_info(&render_info); |
| 449 | 459 | |
| 450 | 460 | // Check scale mode |
| 451 | 461 | |
| r243304 | r243305 | |
| 465 | 475 | } |
| 466 | 476 | } |
| 467 | 477 | |
| 468 | | setup_texture(window, width, height); |
| 478 | setup_texture(width, height); |
| 469 | 479 | #else |
| 470 | | sdl->m_extra_flags = (window->fullscreen() ? SDL_FULLSCREEN : SDL_RESIZABLE); |
| 480 | m_extra_flags = (window().fullscreen() ? SDL_FULLSCREEN : SDL_RESIZABLE); |
| 471 | 481 | |
| 472 | | sdl->m_extra_flags |= sm->m_extra_flags; |
| 482 | m_extra_flags |= sm->m_extra_flags; |
| 473 | 483 | |
| 474 | | sdl->sdlsurf = SDL_SetVideoMode(m_width, m_height, |
| 475 | | 0, SDL_SWSURFACE | SDL_ANYFORMAT | sdl->m_extra_flags); |
| 484 | m_sdlsurf = SDL_SetVideoMode(width, height, |
| 485 | 0, SDL_SWSURFACE | SDL_ANYFORMAT | m_extra_flags); |
| 476 | 486 | |
| 477 | | if (!sdl->sdlsurf) |
| 487 | if (!m_sdlsurf) |
| 478 | 488 | return 1; |
| 479 | 489 | |
| 480 | | window->m_width = sdl->sdlsurf->w; |
| 481 | | window->m_height = sdl->sdlsurf->h; |
| 490 | window().m_width = m_sdlsurf->w; |
| 491 | window().m_height = m_sdlsurf->h; |
| 482 | 492 | |
| 483 | 493 | if (sm->is_yuv) |
| 484 | | yuv_overlay_init(window); |
| 494 | yuv_overlay_init(); |
| 485 | 495 | |
| 486 | 496 | // set the window title |
| 487 | | SDL_WM_SetCaption(window->m_title, "SDLMAME"); |
| 497 | SDL_WM_SetCaption(window().m_title, "SDLMAME"); |
| 488 | 498 | #endif |
| 489 | | sdl->m_yuv_lookup = NULL; |
| 490 | | sdl->m_blittimer = 0; |
| 499 | m_yuv_lookup = NULL; |
| 500 | m_blittimer = 0; |
| 491 | 501 | |
| 492 | | drawsdl_yuv_init(sdl); |
| 502 | yuv_init(); |
| 493 | 503 | return 0; |
| 494 | 504 | } |
| 495 | 505 | |
| r243304 | r243305 | |
| 497 | 507 | // drawsdl_window_resize |
| 498 | 508 | //============================================================ |
| 499 | 509 | |
| 500 | | static void drawsdl_window_resize(sdl_window_info *window, int width, int height) |
| 510 | void sdl_info::resize(int width, int height) |
| 501 | 511 | { |
| 502 | 512 | #if (!SDLMAME_SDL2) |
| 503 | 513 | const sdl_scale_mode *sdl_sm = &scale_modes[video_config.scale_mode]; |
| 504 | 514 | #endif |
| 505 | 515 | #if (SDLMAME_SDL2) |
| 506 | | SDL_SetWindowSize(window->m_sdl_window, width, height); |
| 507 | | SDL_GetWindowSize(window->m_sdl_window, &window->m_width, &window->m_height); |
| 516 | SDL_SetWindowSize(window().m_sdl_window, width, height); |
| 517 | SDL_GetWindowSize(window().m_sdl_window, &window().m_width, &window().m_height); |
| 508 | 518 | |
| 509 | 519 | #else |
| 510 | | sdl_info *sdl = (sdl_info *) window->m_dxdata; |
| 511 | | |
| 512 | | if (sdl->yuvsurf != NULL) |
| 520 | if (m_yuvsurf != NULL) |
| 513 | 521 | { |
| 514 | | SDL_FreeYUVOverlay(sdl->yuvsurf); |
| 515 | | sdl->yuvsurf = NULL; |
| 522 | SDL_FreeYUVOverlay(m_yuvsurf); |
| 523 | m_yuvsurf = NULL; |
| 516 | 524 | } |
| 517 | | SDL_FreeSurface(sdl->sdlsurf); |
| 525 | SDL_FreeSurface(m_sdlsurf); |
| 518 | 526 | //printf("SetVideoMode %d %d\n", wp->resize_new_width, wp->resize_new_height); |
| 519 | 527 | |
| 520 | | sdl->sdlsurf = SDL_SetVideoMode(m_width, m_height, 0, |
| 521 | | SDL_SWSURFACE | SDL_ANYFORMAT | sdl->m_extra_flags); |
| 522 | | window->m_width = sdl->sdlsurf->w; |
| 523 | | window->m_height = sdl->sdlsurf->h; |
| 528 | m_sdlsurf = SDL_SetVideoMode(width, height, 0, |
| 529 | SDL_SWSURFACE | SDL_ANYFORMAT | m_extra_flags); |
| 530 | window().m_width = m_sdlsurf->w; |
| 531 | window().m_height = m_sdlsurf->h; |
| 524 | 532 | |
| 525 | 533 | if (sdl_sm->is_yuv) |
| 526 | 534 | { |
| 527 | | yuv_overlay_init(window); |
| 535 | yuv_overlay_init(); |
| 528 | 536 | } |
| 529 | 537 | |
| 530 | 538 | #endif |
| r243304 | r243305 | |
| 535 | 543 | // drawsdl_window_destroy |
| 536 | 544 | //============================================================ |
| 537 | 545 | |
| 538 | | static void drawsdl_window_destroy(sdl_window_info *window) |
| 546 | void sdl_info::destroy() |
| 539 | 547 | { |
| 540 | | sdl_info *sdl = (sdl_info *) window->m_dxdata; |
| 541 | 548 | |
| 542 | | // skip if nothing |
| 543 | | if (sdl == NULL) |
| 544 | | return; |
| 545 | | |
| 546 | 549 | #if (SDLMAME_SDL2) |
| 547 | | //SDL_SelectRenderer(window->sdl_window); |
| 548 | | SDL_DestroyTexture(sdl->m_texture_id); |
| 549 | | //SDL_DestroyRenderer(window->sdl_window); |
| 550 | | SDL_DestroyWindow(window->m_sdl_window); |
| 550 | //SDL_SelectRenderer(window().sdl_window); |
| 551 | SDL_DestroyTexture(m_texture_id); |
| 552 | //SDL_DestroyRenderer(window().sdl_window); |
| 553 | SDL_DestroyWindow(window().m_sdl_window); |
| 551 | 554 | #else |
| 552 | | if (sdl->yuvsurf != NULL) |
| 555 | if (m_yuvsurf != NULL) |
| 553 | 556 | { |
| 554 | | SDL_FreeYUVOverlay(sdl->yuvsurf); |
| 555 | | sdl->yuvsurf = NULL; |
| 557 | SDL_FreeYUVOverlay(m_yuvsurf); |
| 558 | m_yuvsurf = NULL; |
| 556 | 559 | } |
| 557 | 560 | |
| 558 | | if (sdl->sdlsurf) |
| 561 | if (m_sdlsurf) |
| 559 | 562 | { |
| 560 | | SDL_FreeSurface(sdl->sdlsurf); |
| 561 | | sdl->sdlsurf = NULL; |
| 563 | SDL_FreeSurface(m_sdlsurf); |
| 564 | m_sdlsurf = NULL; |
| 562 | 565 | } |
| 563 | 566 | #endif |
| 564 | 567 | // free the memory in the window |
| 565 | 568 | |
| 566 | | if (sdl->m_yuv_lookup != NULL) |
| 569 | if (m_yuv_lookup != NULL) |
| 567 | 570 | { |
| 568 | | global_free_array(sdl->m_yuv_lookup); |
| 569 | | sdl->m_yuv_lookup = NULL; |
| 571 | global_free_array(m_yuv_lookup); |
| 572 | m_yuv_lookup = NULL; |
| 570 | 573 | } |
| 571 | | if (sdl->m_yuv_bitmap != NULL) |
| 574 | if (m_yuv_bitmap != NULL) |
| 572 | 575 | { |
| 573 | | global_free_array(sdl->m_yuv_bitmap); |
| 574 | | sdl->m_yuv_bitmap = NULL; |
| 576 | global_free_array(m_yuv_bitmap); |
| 577 | m_yuv_bitmap = NULL; |
| 575 | 578 | } |
| 576 | | osd_free(sdl); |
| 577 | | window->m_dxdata = NULL; |
| 578 | 579 | } |
| 579 | 580 | |
| 580 | 581 | //============================================================ |
| 581 | 582 | // drawsdl_window_clear |
| 582 | 583 | //============================================================ |
| 583 | 584 | |
| 584 | | static void drawsdl_window_clear(sdl_window_info *window) |
| 585 | void sdl_info::clear() |
| 585 | 586 | { |
| 586 | | sdl_info *sdl = (sdl_info *) window->m_dxdata; |
| 587 | | |
| 588 | | sdl->m_blittimer = 3; |
| 587 | m_blittimer = 3; |
| 589 | 588 | } |
| 590 | 589 | |
| 591 | 590 | //============================================================ |
| 592 | 591 | // drawsdl_xy_to_render_target |
| 593 | 592 | //============================================================ |
| 594 | 593 | |
| 595 | | static int drawsdl_xy_to_render_target(sdl_window_info *window, int x, int y, int *xt, int *yt) |
| 594 | int sdl_info::xy_to_render_target(int x, int y, int *xt, int *yt) |
| 596 | 595 | { |
| 597 | | sdl_info *sdl = (sdl_info *) window->m_dxdata; |
| 598 | 596 | const sdl_scale_mode *sm = &scale_modes[video_config.scale_mode]; |
| 599 | 597 | |
| 600 | | *xt = x - sdl->m_last_hofs; |
| 601 | | *yt = y - sdl->m_last_vofs; |
| 602 | | if (*xt<0 || *xt >= window->m_blitwidth) |
| 598 | *xt = x - m_last_hofs; |
| 599 | *yt = y - m_last_vofs; |
| 600 | if (*xt<0 || *xt >= window().m_blitwidth) |
| 603 | 601 | return 0; |
| 604 | | if (*yt<0 || *xt >= window->m_blitheight) |
| 602 | if (*yt<0 || *xt >= window().m_blitheight) |
| 605 | 603 | return 0; |
| 606 | 604 | if (!sm->is_scale) |
| 607 | 605 | { |
| 608 | 606 | return 1; |
| 609 | 607 | } |
| 610 | 608 | /* Rescale */ |
| 611 | | *xt = (*xt * sdl->m_hw_scale_width) / window->m_blitwidth; |
| 612 | | *yt = (*yt * sdl->m_hw_scale_height) / window->m_blitheight; |
| 609 | *xt = (*xt * m_hw_scale_width) / window().m_blitwidth; |
| 610 | *yt = (*yt * m_hw_scale_height) / window().m_blitheight; |
| 613 | 611 | return 1; |
| 614 | 612 | } |
| 615 | 613 | |
| r243304 | r243305 | |
| 617 | 615 | // drawsdl_window_get_primitives |
| 618 | 616 | //============================================================ |
| 619 | 617 | |
| 620 | | static void drawsdl_set_target_bounds(sdl_window_info *window) |
| 618 | void sdl_info::set_target_bounds() |
| 621 | 619 | { |
| 622 | | sdl_info *sdl = (sdl_info *) window->m_dxdata; |
| 623 | 620 | const sdl_scale_mode *sm = &scale_modes[video_config.scale_mode]; |
| 624 | 621 | |
| 625 | 622 | if (!sm->is_scale) |
| 626 | | window->m_target->set_bounds(window->m_blitwidth, window->m_blitheight, window->monitor()->aspect()); |
| 623 | window().m_target->set_bounds(window().m_blitwidth, window().m_blitheight, window().monitor()->aspect()); |
| 627 | 624 | else |
| 628 | | window->m_target->set_bounds(sdl->m_hw_scale_width, sdl->m_hw_scale_height); |
| 625 | window().m_target->set_bounds(m_hw_scale_width, m_hw_scale_height); |
| 629 | 626 | } |
| 630 | 627 | |
| 631 | 628 | //============================================================ |
| 632 | 629 | // drawsdl_window_draw |
| 633 | 630 | //============================================================ |
| 634 | 631 | |
| 635 | | static int drawsdl_window_draw(sdl_window_info *window, UINT32 dc, int update) |
| 632 | int sdl_info::draw(UINT32 dc, int update) |
| 636 | 633 | { |
| 637 | | sdl_info *sdl = (sdl_info *) window->m_dxdata; |
| 638 | 634 | const sdl_scale_mode *sm = &scale_modes[video_config.scale_mode]; |
| 639 | 635 | UINT8 *surfptr; |
| 640 | 636 | INT32 pitch; |
| r243304 | r243305 | |
| 650 | 646 | return 0; |
| 651 | 647 | } |
| 652 | 648 | |
| 653 | | // if we haven't been created, just punt |
| 654 | | if (sdl == NULL) |
| 655 | | return 1; |
| 656 | | |
| 657 | 649 | // lock it if we need it |
| 658 | 650 | #if (!SDLMAME_SDL2) |
| 659 | 651 | |
| 660 | | pitch = sdl->sdlsurf->pitch; |
| 661 | | bpp = sdl->sdlsurf->format->BytesPerPixel; |
| 662 | | rmask = sdl->sdlsurf->format->Rmask; |
| 663 | | gmask = sdl->sdlsurf->format->Gmask; |
| 664 | | bmask = sdl->sdlsurf->format->Bmask; |
| 665 | | // amask = sdl->sdlsurf->format->Amask; |
| 652 | pitch = m_sdlsurf->pitch; |
| 653 | bpp = m_sdlsurf->format->BytesPerPixel; |
| 654 | rmask = m_sdlsurf->format->Rmask; |
| 655 | gmask = m_sdlsurf->format->Gmask; |
| 656 | bmask = m_sdlsurf->format->Bmask; |
| 657 | // amask = sdlsurf->format->Amask; |
| 666 | 658 | |
| 667 | | if (window->m_blitwidth != sdl->m_old_blitwidth || window->m_blitheight != sdl->m_old_blitheight) |
| 659 | if (window().m_blitwidth != m_old_blitwidth || window().m_blitheight != m_old_blitheight) |
| 668 | 660 | { |
| 669 | 661 | if (sm->is_yuv) |
| 670 | | yuv_overlay_init(window); |
| 671 | | sdl->m_old_blitwidth = window->m_blitwidth; |
| 672 | | sdl->m_old_blitheight = window->m_blitheight; |
| 673 | | sdl->m_blittimer = 3; |
| 662 | yuv_overlay_init(); |
| 663 | m_old_blitwidth = window().m_blitwidth; |
| 664 | m_old_blitheight = window().m_blitheight; |
| 665 | m_blittimer = 3; |
| 674 | 666 | } |
| 675 | 667 | |
| 676 | | if (SDL_MUSTLOCK(sdl->sdlsurf)) SDL_LockSurface(sdl->sdlsurf); |
| 677 | | // Clear if necessary |
| 668 | if (SDL_MUSTLOCK(m_sdlsurf)) |
| 669 | SDL_LockSurface(m_sdlsurf); |
| 678 | 670 | |
| 679 | | if (sdl->m_blittimer > 0) |
| 671 | // Clear if necessary |
| 672 | if (m_blittimer > 0) |
| 680 | 673 | { |
| 681 | | memset(sdl->sdlsurf->pixels, 0, window->m_height * sdl->sdlsurf->pitch); |
| 682 | | sdl->m_blittimer--; |
| 674 | memset(m_sdlsurf->pixels, 0, window().m_height * m_sdlsurf->pitch); |
| 675 | m_blittimer--; |
| 683 | 676 | } |
| 684 | 677 | |
| 685 | 678 | |
| 686 | 679 | if (sm->is_yuv) |
| 687 | 680 | { |
| 688 | | SDL_LockYUVOverlay(sdl->yuvsurf); |
| 689 | | surfptr = sdl->yuvsurf->pixels[0]; // (UINT8 *) sdl->m_yuv_bitmap; |
| 690 | | pitch = sdl->yuvsurf->pitches[0]; // (UINT8 *) sdl->m_yuv_bitmap; |
| 681 | SDL_LockYUVOverlay(m_yuvsurf); |
| 682 | surfptr = m_yuvsurf->pixels[0]; // (UINT8 *) m_yuv_bitmap; |
| 683 | pitch = m_yuvsurf->pitches[0]; // (UINT8 *) m_yuv_bitmap; |
| 691 | 684 | } |
| 692 | 685 | else |
| 693 | | surfptr = (UINT8 *)sdl->sdlsurf->pixels; |
| 686 | surfptr = (UINT8 *)m_sdlsurf->pixels; |
| 694 | 687 | #else |
| 695 | | //SDL_SelectRenderer(window->sdl_window); |
| 688 | //SDL_SelectRenderer(window().sdl_window); |
| 696 | 689 | |
| 697 | | if (window->m_blitwidth != sdl->m_old_blitwidth || window->m_blitheight != sdl->m_old_blitheight) |
| 690 | if (window().m_blitwidth != m_old_blitwidth || window().m_blitheight != m_old_blitheight) |
| 698 | 691 | { |
| 699 | | SDL_RenderSetViewport(sdl->m_sdl_renderer, NULL); |
| 692 | SDL_RenderSetViewport(m_sdl_renderer, NULL); |
| 700 | 693 | |
| 701 | | SDL_DestroyTexture(sdl->m_texture_id); |
| 702 | | setup_texture(window, window->m_blitwidth, window->m_blitheight); |
| 703 | | sdl->m_old_blitwidth = window->m_blitwidth; |
| 704 | | sdl->m_old_blitheight = window->m_blitheight; |
| 705 | | sdl->m_blittimer = 3; |
| 694 | SDL_DestroyTexture(m_texture_id); |
| 695 | setup_texture(window().m_blitwidth, window().m_blitheight); |
| 696 | m_old_blitwidth = window().m_blitwidth; |
| 697 | m_old_blitheight = window().m_blitheight; |
| 698 | m_blittimer = 3; |
| 706 | 699 | } |
| 707 | 700 | |
| 708 | 701 | { |
| 709 | 702 | Uint32 format; |
| 710 | 703 | int access, w, h; |
| 711 | 704 | |
| 712 | | SDL_QueryTexture(sdl->m_texture_id, &format, &access, &w, &h); |
| 705 | SDL_QueryTexture(m_texture_id, &format, &access, &w, &h); |
| 713 | 706 | SDL_PixelFormatEnumToMasks(format, &bpp, &rmask, &gmask, &bmask, &amask); |
| 714 | 707 | bpp = bpp / 8; /* convert to bytes per pixels */ |
| 715 | 708 | } |
| 716 | 709 | |
| 717 | 710 | // Clear if necessary |
| 718 | | if (sdl->m_blittimer > 0) |
| 711 | if (m_blittimer > 0) |
| 719 | 712 | { |
| 720 | 713 | /* SDL Underlays need alpha = 0 ! */ |
| 721 | | SDL_SetRenderDrawColor(sdl->m_sdl_renderer,0,0,0,0); |
| 722 | | SDL_RenderFillRect(sdl->m_sdl_renderer,NULL); |
| 714 | SDL_SetRenderDrawColor(m_sdl_renderer,0,0,0,0); |
| 715 | SDL_RenderFillRect(m_sdl_renderer,NULL); |
| 723 | 716 | //SDL_RenderFill(0,0,0,0 /*255*/,NULL); |
| 724 | | sdl->m_blittimer--; |
| 717 | m_blittimer--; |
| 725 | 718 | } |
| 726 | 719 | |
| 727 | | SDL_LockTexture(sdl->m_texture_id, NULL, (void **) &surfptr, &pitch); |
| 720 | SDL_LockTexture(m_texture_id, NULL, (void **) &surfptr, &pitch); |
| 728 | 721 | |
| 729 | 722 | #endif |
| 730 | 723 | // get ready to center the image |
| 731 | 724 | vofs = hofs = 0; |
| 732 | | blitwidth = window->m_blitwidth; |
| 733 | | blitheight = window->m_blitheight; |
| 725 | blitwidth = window().m_blitwidth; |
| 726 | blitheight = window().m_blitheight; |
| 734 | 727 | |
| 735 | 728 | // figure out what coordinate system to use for centering - in window mode it's always the |
| 736 | 729 | // SDL surface size. in fullscreen the surface covers all monitors, so center according to |
| 737 | 730 | // the first one only |
| 738 | | if ((window->fullscreen()) && (!video_config.switchres)) |
| 731 | if ((window().fullscreen()) && (!video_config.switchres)) |
| 739 | 732 | { |
| 740 | | ch = window->monitor()->center_height(); |
| 741 | | cw = window->monitor()->center_width(); |
| 733 | ch = window().monitor()->center_height(); |
| 734 | cw = window().monitor()->center_width(); |
| 742 | 735 | } |
| 743 | 736 | else |
| 744 | 737 | { |
| 745 | | ch = window->m_height; |
| 746 | | cw = window->m_width; |
| 738 | ch = window().m_height; |
| 739 | cw = window().m_width; |
| 747 | 740 | } |
| 748 | 741 | |
| 749 | 742 | // do not crash if the window's smaller than the blit area |
| r243304 | r243305 | |
| 753 | 746 | } |
| 754 | 747 | else if (video_config.centerv) |
| 755 | 748 | { |
| 756 | | vofs = (ch - window->m_blitheight) / 2; |
| 749 | vofs = (ch - window().m_blitheight) / 2; |
| 757 | 750 | } |
| 758 | 751 | |
| 759 | 752 | if (blitwidth > cw) |
| r243304 | r243305 | |
| 762 | 755 | } |
| 763 | 756 | else if (video_config.centerh) |
| 764 | 757 | { |
| 765 | | hofs = (cw - window->m_blitwidth) / 2; |
| 758 | hofs = (cw - window().m_blitwidth) / 2; |
| 766 | 759 | } |
| 767 | 760 | |
| 768 | | sdl->m_last_hofs = hofs; |
| 769 | | sdl->m_last_vofs = vofs; |
| 761 | m_last_hofs = hofs; |
| 762 | m_last_vofs = vofs; |
| 770 | 763 | |
| 771 | | window->m_primlist->acquire_lock(); |
| 764 | window().m_primlist->acquire_lock(); |
| 772 | 765 | |
| 773 | 766 | // render to it |
| 774 | 767 | if (!sm->is_yuv) |
| r243304 | r243305 | |
| 785 | 778 | } |
| 786 | 779 | else |
| 787 | 780 | { |
| 788 | | mamewidth = sdl->m_hw_scale_width; |
| 789 | | mameheight = sdl->m_hw_scale_height; |
| 781 | mamewidth = m_hw_scale_width; |
| 782 | mameheight = m_hw_scale_height; |
| 790 | 783 | } |
| 791 | 784 | switch (rmask) |
| 792 | 785 | { |
| 793 | 786 | case 0x0000ff00: |
| 794 | | software_renderer<UINT32, 0,0,0, 8,16,24>::draw_primitives(*window->m_primlist, surfptr, mamewidth, mameheight, pitch / 4); |
| 787 | software_renderer<UINT32, 0,0,0, 8,16,24>::draw_primitives(*window().m_primlist, surfptr, mamewidth, mameheight, pitch / 4); |
| 795 | 788 | break; |
| 796 | 789 | |
| 797 | 790 | case 0x00ff0000: |
| 798 | | software_renderer<UINT32, 0,0,0, 16,8,0>::draw_primitives(*window->m_primlist, surfptr, mamewidth, mameheight, pitch / 4); |
| 791 | software_renderer<UINT32, 0,0,0, 16,8,0>::draw_primitives(*window().m_primlist, surfptr, mamewidth, mameheight, pitch / 4); |
| 799 | 792 | break; |
| 800 | 793 | |
| 801 | 794 | case 0x000000ff: |
| 802 | | software_renderer<UINT32, 0,0,0, 0,8,16>::draw_primitives(*window->m_primlist, surfptr, mamewidth, mameheight, pitch / 4); |
| 795 | software_renderer<UINT32, 0,0,0, 0,8,16>::draw_primitives(*window().m_primlist, surfptr, mamewidth, mameheight, pitch / 4); |
| 803 | 796 | break; |
| 804 | 797 | |
| 805 | 798 | case 0xf800: |
| 806 | | software_renderer<UINT16, 3,2,3, 11,5,0>::draw_primitives(*window->m_primlist, surfptr, mamewidth, mameheight, pitch / 2); |
| 799 | software_renderer<UINT16, 3,2,3, 11,5,0>::draw_primitives(*window().m_primlist, surfptr, mamewidth, mameheight, pitch / 2); |
| 807 | 800 | break; |
| 808 | 801 | |
| 809 | 802 | case 0x7c00: |
| 810 | | software_renderer<UINT16, 3,3,3, 10,5,0>::draw_primitives(*window->m_primlist, surfptr, mamewidth, mameheight, pitch / 2); |
| 803 | software_renderer<UINT16, 3,3,3, 10,5,0>::draw_primitives(*window().m_primlist, surfptr, mamewidth, mameheight, pitch / 2); |
| 811 | 804 | break; |
| 812 | 805 | |
| 813 | 806 | default: |
| r243304 | r243305 | |
| 817 | 810 | } |
| 818 | 811 | else |
| 819 | 812 | { |
| 820 | | assert (sdl->m_yuv_bitmap != NULL); |
| 813 | assert (m_yuv_bitmap != NULL); |
| 821 | 814 | assert (surfptr != NULL); |
| 822 | | software_renderer<UINT16, 3,3,3, 10,5,0>::draw_primitives(*window->m_primlist, sdl->m_yuv_bitmap, sdl->m_hw_scale_width, sdl->m_hw_scale_height, sdl->m_hw_scale_width); |
| 823 | | sm->yuv_blit((UINT16 *)sdl->m_yuv_bitmap, sdl, surfptr, pitch); |
| 815 | software_renderer<UINT16, 3,3,3, 10,5,0>::draw_primitives(*window().m_primlist, m_yuv_bitmap, m_hw_scale_width, m_hw_scale_height, m_hw_scale_width); |
| 816 | sm->yuv_blit((UINT16 *)m_yuv_bitmap, this, surfptr, pitch); |
| 824 | 817 | } |
| 825 | 818 | |
| 826 | | window->m_primlist->release_lock(); |
| 819 | window().m_primlist->release_lock(); |
| 827 | 820 | |
| 828 | 821 | // unlock and flip |
| 829 | 822 | #if (!SDLMAME_SDL2) |
| 830 | | if (SDL_MUSTLOCK(sdl->sdlsurf)) SDL_UnlockSurface(sdl->sdlsurf); |
| 823 | if (SDL_MUSTLOCK(m_sdlsurf)) SDL_UnlockSurface(m_sdlsurf); |
| 831 | 824 | if (!sm->is_yuv) |
| 832 | 825 | { |
| 833 | | SDL_Flip(sdl->sdlsurf); |
| 826 | SDL_Flip(m_sdlsurf); |
| 834 | 827 | } |
| 835 | 828 | else |
| 836 | 829 | { |
| 837 | 830 | SDL_Rect r; |
| 838 | 831 | |
| 839 | | SDL_UnlockYUVOverlay(sdl->yuvsurf); |
| 840 | | r.x=hofs; |
| 841 | | r.y=vofs; |
| 842 | | r.w=m_blitwidth; |
| 843 | | r.h=m_blitheight; |
| 844 | | SDL_DisplayYUVOverlay(sdl->yuvsurf, &r); |
| 832 | SDL_UnlockYUVOverlay(m_yuvsurf); |
| 833 | r.x = hofs; |
| 834 | r.y = vofs; |
| 835 | r.w = blitwidth; |
| 836 | r.h = blitheight; |
| 837 | SDL_DisplayYUVOverlay(m_yuvsurf, &r); |
| 845 | 838 | } |
| 846 | 839 | #else |
| 847 | | SDL_UnlockTexture(sdl->m_texture_id); |
| 840 | SDL_UnlockTexture(m_texture_id); |
| 848 | 841 | { |
| 849 | 842 | SDL_Rect r; |
| 850 | 843 | |
| r243304 | r243305 | |
| 852 | 845 | r.y=vofs; |
| 853 | 846 | r.w=blitwidth; |
| 854 | 847 | r.h=blitheight; |
| 855 | | //printf("blitwidth %d %d - %d %d\n", blitwidth, blitheight, window->width, window->height); |
| 856 | | //SDL_UpdateTexture(sdl->sdltex, NULL, sdl->sdlsurf->pixels, pitch); |
| 857 | | SDL_RenderCopy(sdl->m_sdl_renderer,sdl->m_texture_id, NULL, &r); |
| 858 | | SDL_RenderPresent(sdl->m_sdl_renderer); |
| 848 | //printf("blitwidth %d %d - %d %d\n", blitwidth, blitheight, window().width, window().height); |
| 849 | //SDL_UpdateTexture(sdltex, NULL, sdlsurf->pixels, pitch); |
| 850 | SDL_RenderCopy(m_sdl_renderer,m_texture_id, NULL, &r); |
| 851 | SDL_RenderPresent(m_sdl_renderer); |
| 859 | 852 | } |
| 860 | 853 | #endif |
| 861 | 854 | return 0; |
| r243304 | r243305 | |
| 901 | 894 | #define YMASK (Y1MASK|Y2MASK) |
| 902 | 895 | #define UVMASK (UMASK|VMASK) |
| 903 | 896 | |
| 904 | | static void yuv_lookup_set(sdl_info *sdl, unsigned int pen, unsigned char red, |
| 897 | void sdl_info::yuv_lookup_set(unsigned int pen, unsigned char red, |
| 905 | 898 | unsigned char green, unsigned char blue) |
| 906 | 899 | { |
| 907 | 900 | UINT32 y,u,v; |
| r243304 | r243305 | |
| 910 | 903 | |
| 911 | 904 | /* Storing this data in YUYV order simplifies using the data for |
| 912 | 905 | YUY2, both with and without smoothing... */ |
| 913 | | sdl->m_yuv_lookup[pen]=(y<<Y1SHIFT)|(u<<USHIFT)|(y<<Y2SHIFT)|(v<<VSHIFT); |
| 906 | m_yuv_lookup[pen]=(y<<Y1SHIFT)|(u<<USHIFT)|(y<<Y2SHIFT)|(v<<VSHIFT); |
| 914 | 907 | } |
| 915 | 908 | |
| 916 | | static void drawsdl_yuv_init(sdl_info *sdl) |
| 909 | void sdl_info::yuv_init() |
| 917 | 910 | { |
| 918 | 911 | unsigned char r,g,b; |
| 919 | | if (sdl->m_yuv_lookup == NULL) |
| 920 | | sdl->m_yuv_lookup = global_alloc_array(UINT32, 65536); |
| 912 | if (m_yuv_lookup == NULL) |
| 913 | m_yuv_lookup = global_alloc_array(UINT32, 65536); |
| 921 | 914 | for (r = 0; r < 32; r++) |
| 922 | 915 | for (g = 0; g < 32; g++) |
| 923 | 916 | for (b = 0; b < 32; b++) |
| 924 | 917 | { |
| 925 | 918 | int idx = (r << 10) | (g << 5) | b; |
| 926 | | yuv_lookup_set(sdl, idx, |
| 919 | yuv_lookup_set(idx, |
| 927 | 920 | (r << 3) | (r >> 2), |
| 928 | 921 | (g << 3) | (g >> 2), |
| 929 | 922 | (b << 3) | (b >> 2)); |