trunk/src/osd/sdl/drawogl.c
| r243303 | r243304 | |
| 218 | 218 | struct sdl_info |
| 219 | 219 | { |
| 220 | 220 | sdl_info() |
| 221 | | : blittimer(0), extra_flags(0), |
| 221 | : m_blittimer(0), m_extra_flags(0), |
| 222 | 222 | #if (SDLMAME_SDL2) |
| 223 | | gl_context_id(0), |
| 223 | m_gl_context_id(0), |
| 224 | 224 | #else |
| 225 | 225 | sdlsurf(NULL), |
| 226 | 226 | #endif |
| 227 | | initialized(0), |
| 228 | | last_blendmode(0), |
| 229 | | texture_max_width(0), |
| 230 | | texture_max_height(0), |
| 231 | | texpoweroftwo(0), |
| 232 | | usevbo(0), usepbo(0), usefbo(0), useglsl(0), glsl(NULL), |
| 233 | | glsl_program_num(0), |
| 234 | | glsl_program_mb2sc(0), |
| 235 | | usetexturerect(0), |
| 236 | | init_context(0), |
| 237 | | last_hofs(0.0f), |
| 238 | | last_vofs(0.0f), |
| 239 | | surf_w(0), |
| 240 | | surf_h(0) |
| 227 | m_initialized(0), |
| 228 | m_last_blendmode(0), |
| 229 | m_texture_max_width(0), |
| 230 | m_texture_max_height(0), |
| 231 | m_texpoweroftwo(0), |
| 232 | m_usevbo(0), m_usepbo(0), m_usefbo(0), m_useglsl(0), m_glsl(NULL), |
| 233 | m_glsl_program_num(0), |
| 234 | m_glsl_program_mb2sc(0), |
| 235 | m_usetexturerect(0), |
| 236 | m_init_context(0), |
| 237 | m_last_hofs(0.0f), |
| 238 | m_last_vofs(0.0f), |
| 239 | m_surf_w(0), |
| 240 | m_surf_h(0) |
| 241 | 241 | { |
| 242 | 242 | for (int i=0; i < HASH_SIZE + OVERFLOW_SIZE; i++) |
| 243 | | texhash[i] = NULL; |
| 243 | m_texhash[i] = NULL; |
| 244 | 244 | for (int i=0; i < 2*GLSL_SHADER_MAX; i++) |
| 245 | | glsl_program[i] = 0; |
| 245 | m_glsl_program[i] = 0; |
| 246 | 246 | for (int i=0; i < 8; i++) |
| 247 | | texVerticex[i] = 0.0f; |
| 247 | m_texVerticex[i] = 0.0f; |
| 248 | 248 | } |
| 249 | 249 | |
| 250 | | INT32 blittimer; |
| 251 | | UINT32 extra_flags; |
| 250 | INT32 m_blittimer; |
| 251 | UINT32 m_extra_flags; |
| 252 | 252 | |
| 253 | 253 | #if (SDLMAME_SDL2) |
| 254 | | SDL_GLContext gl_context_id; |
| 254 | SDL_GLContext m_gl_context_id; |
| 255 | 255 | #else |
| 256 | 256 | // SDL surface |
| 257 | 257 | SDL_Surface *sdlsurf; |
| 258 | 258 | #endif |
| 259 | 259 | |
| 260 | | int initialized; // is everything well initialized, i.e. all GL stuff etc. |
| 260 | int m_initialized; // is everything well initialized, i.e. all GL stuff etc. |
| 261 | 261 | // 3D info (GL mode only) |
| 262 | | texture_info * texhash[HASH_SIZE + OVERFLOW_SIZE]; |
| 263 | | int last_blendmode; // previous blendmode |
| 264 | | INT32 texture_max_width; // texture maximum width |
| 265 | | INT32 texture_max_height; // texture maximum height |
| 266 | | int texpoweroftwo; // must textures be power-of-2 sized? |
| 267 | | int usevbo; // runtime check if VBO is available |
| 268 | | int usepbo; // runtime check if PBO is available |
| 269 | | int usefbo; // runtime check if FBO is available |
| 270 | | int useglsl; // runtime check if GLSL is available |
| 262 | texture_info * m_texhash[HASH_SIZE + OVERFLOW_SIZE]; |
| 263 | int m_last_blendmode; // previous blendmode |
| 264 | INT32 m_texture_max_width; // texture maximum width |
| 265 | INT32 m_texture_max_height; // texture maximum height |
| 266 | int m_texpoweroftwo; // must textures be power-of-2 sized? |
| 267 | int m_usevbo; // runtime check if VBO is available |
| 268 | int m_usepbo; // runtime check if PBO is available |
| 269 | int m_usefbo; // runtime check if FBO is available |
| 270 | int m_useglsl; // runtime check if GLSL is available |
| 271 | 271 | |
| 272 | | glsl_shader_info *glsl; // glsl_shader_info |
| 272 | glsl_shader_info *m_glsl; // glsl_shader_info |
| 273 | 273 | |
| 274 | | GLhandleARB glsl_program[2*GLSL_SHADER_MAX]; // GLSL programs, or 0 |
| 275 | | int glsl_program_num; // number of GLSL programs |
| 276 | | int glsl_program_mb2sc; // GLSL program idx, which transforms |
| 274 | GLhandleARB m_glsl_program[2*GLSL_SHADER_MAX]; // GLSL programs, or 0 |
| 275 | int m_glsl_program_num; // number of GLSL programs |
| 276 | int m_glsl_program_mb2sc; // GLSL program idx, which transforms |
| 277 | 277 | // the mame-bitmap. screen-bitmap (size/rotation/..) |
| 278 | 278 | // All progs <= glsl_program_mb2sc using the mame bitmap |
| 279 | 279 | // as input, otherwise the screen bitmap. |
| 280 | 280 | // All progs >= glsl_program_mb2sc using the screen bitmap |
| 281 | 281 | // as output, otherwise the mame bitmap. |
| 282 | | int usetexturerect; // use ARB_texture_rectangle for non-power-of-2, general use |
| 282 | int m_usetexturerect; // use ARB_texture_rectangle for non-power-of-2, general use |
| 283 | 283 | |
| 284 | | int init_context; // initialize context before next draw |
| 284 | int m_init_context; // initialize context before next draw |
| 285 | 285 | |
| 286 | | float last_hofs; |
| 287 | | float last_vofs; |
| 286 | float m_last_hofs; |
| 287 | float m_last_vofs; |
| 288 | 288 | |
| 289 | 289 | // Static vars from draogl_window_dra |
| 290 | | INT32 surf_w; |
| 291 | | INT32 surf_h; |
| 292 | | GLfloat texVerticex[8]; |
| 290 | INT32 m_surf_w; |
| 291 | INT32 m_surf_h; |
| 292 | GLfloat m_texVerticex[8]; |
| 293 | 293 | }; |
| 294 | 294 | |
| 295 | 295 | /* line_aa_step is used for drawing antialiased lines */ |
| r243303 | r243304 | |
| 330 | 330 | INLINE void set_blendmode(sdl_info *sdl, int blendmode) |
| 331 | 331 | { |
| 332 | 332 | // try to minimize texture state changes |
| 333 | | if (blendmode != sdl->last_blendmode) |
| 333 | if (blendmode != sdl->m_last_blendmode) |
| 334 | 334 | { |
| 335 | 335 | switch (blendmode) |
| 336 | 336 | { |
| r243303 | r243304 | |
| 351 | 351 | break; |
| 352 | 352 | } |
| 353 | 353 | |
| 354 | | sdl->last_blendmode = blendmode; |
| 354 | sdl->m_last_blendmode = blendmode; |
| 355 | 355 | } |
| 356 | 356 | } |
| 357 | 357 | |
| r243303 | r243304 | |
| 541 | 541 | window->m_dxdata = sdl; |
| 542 | 542 | |
| 543 | 543 | #if (SDLMAME_SDL2) |
| 544 | | sdl->extra_flags = (window->fullscreen() ? |
| 544 | sdl->m_extra_flags = (window->fullscreen() ? |
| 545 | 545 | SDL_WINDOW_BORDERLESS | SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_FULLSCREEN : SDL_WINDOW_RESIZABLE); |
| 546 | | sdl->extra_flags |= SDL_WINDOW_OPENGL; |
| 546 | sdl->m_extra_flags |= SDL_WINDOW_OPENGL; |
| 547 | 547 | |
| 548 | 548 | SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); |
| 549 | 549 | |
| r243303 | r243304 | |
| 560 | 560 | // create the SDL window |
| 561 | 561 | window->m_sdl_window = SDL_CreateWindow(window->m_title, |
| 562 | 562 | window->monitor()->position_size().x, window->monitor()->position_size().y, |
| 563 | | width, height, sdl->extra_flags); |
| 563 | width, height, sdl->m_extra_flags); |
| 564 | 564 | |
| 565 | 565 | if (!window->m_sdl_window ) |
| 566 | 566 | { |
| r243303 | r243304 | |
| 586 | 586 | SDL_RaiseWindow(window->m_sdl_window); |
| 587 | 587 | SDL_GetWindowSize(window->m_sdl_window, &window->m_width, &window->m_height); |
| 588 | 588 | |
| 589 | | sdl->gl_context_id = SDL_GL_CreateContext(window->m_sdl_window); |
| 590 | | if (!sdl->gl_context_id) |
| 589 | sdl->m_gl_context_id = SDL_GL_CreateContext(window->m_sdl_window); |
| 590 | if (!sdl->m_gl_context_id) |
| 591 | 591 | { |
| 592 | 592 | osd_printf_error("OpenGL not supported on this driver: %s\n", SDL_GetError()); |
| 593 | 593 | return 1; |
| r243303 | r243304 | |
| 596 | 596 | SDL_GL_SetSwapInterval(video_config.waitvsync ? 2 : 0); |
| 597 | 597 | |
| 598 | 598 | #else |
| 599 | | sdl->extra_flags = (window->fullscreen() ? SDL_FULLSCREEN : SDL_RESIZABLE); |
| 600 | | sdl->extra_flags |= SDL_OPENGL | SDL_DOUBLEBUF; |
| 599 | sdl->m_extra_flags = (window->fullscreen() ? SDL_FULLSCREEN : SDL_RESIZABLE); |
| 600 | sdl->m_extra_flags |= SDL_OPENGL | SDL_DOUBLEBUF; |
| 601 | 601 | |
| 602 | 602 | SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); |
| 603 | 603 | #if (SDL_VERSION_ATLEAST(1,2,10)) && (!defined(SDLMAME_EMSCRIPTEN)) |
| r243303 | r243304 | |
| 608 | 608 | |
| 609 | 609 | // create the SDL surface (which creates the window in windowed mode) |
| 610 | 610 | sdl->sdlsurf = SDL_SetVideoMode(m_width, m_height, |
| 611 | | 0, SDL_SWSURFACE | SDL_ANYFORMAT | sdl->extra_flags); |
| 611 | 0, SDL_SWSURFACE | SDL_ANYFORMAT | sdl->m_extra_flags); |
| 612 | 612 | |
| 613 | 613 | if (!sdl->sdlsurf) |
| 614 | 614 | return 1; |
| r243303 | r243304 | |
| 629 | 629 | SDL_WM_SetCaption(window->m_title, "SDLMAME"); |
| 630 | 630 | |
| 631 | 631 | #endif |
| 632 | | sdl->blittimer = 0; |
| 633 | | sdl->surf_w = 0; |
| 634 | | sdl->surf_h = 0; |
| 632 | sdl->m_blittimer = 0; |
| 633 | sdl->m_surf_w = 0; |
| 634 | sdl->m_surf_h = 0; |
| 635 | 635 | |
| 636 | | sdl->initialized = 0; |
| 636 | sdl->m_initialized = 0; |
| 637 | 637 | |
| 638 | 638 | // in case any textures try to come up before these are validated, |
| 639 | 639 | // OpenGL guarantees all implementations can handle something this size. |
| 640 | | sdl->texture_max_width = 64; |
| 641 | | sdl->texture_max_height = 64; |
| 640 | sdl->m_texture_max_width = 64; |
| 641 | sdl->m_texture_max_height = 64; |
| 642 | 642 | |
| 643 | 643 | /* load any GL function addresses |
| 644 | 644 | * this must be done here because we need a context |
| r243303 | r243304 | |
| 656 | 656 | osd_printf_verbose("OpenGL: %s\nOpenGL: %s\nOpenGL: %s\n", vendor, (char *)glGetString(GL_RENDERER), (char *)glGetString(GL_VERSION)); |
| 657 | 657 | } |
| 658 | 658 | |
| 659 | | sdl->usetexturerect = 0; |
| 660 | | sdl->texpoweroftwo = 1; |
| 661 | | sdl->usevbo = 0; |
| 662 | | sdl->usepbo = 0; |
| 663 | | sdl->usefbo = 0; |
| 664 | | sdl->useglsl = 0; |
| 659 | sdl->m_usetexturerect = 0; |
| 660 | sdl->m_texpoweroftwo = 1; |
| 661 | sdl->m_usevbo = 0; |
| 662 | sdl->m_usepbo = 0; |
| 663 | sdl->m_usefbo = 0; |
| 664 | sdl->m_useglsl = 0; |
| 665 | 665 | |
| 666 | 666 | if ( video_config.allowtexturerect && |
| 667 | 667 | ( strstr(extstr, "GL_ARB_texture_rectangle") || strstr(extstr, "GL_EXT_texture_rectangle") ) |
| r243303 | r243304 | |
| 681 | 681 | { |
| 682 | 682 | osd_printf_verbose("OpenGL: non-power-of-2 textures supported (new method)\n"); |
| 683 | 683 | } |
| 684 | | sdl->texpoweroftwo = 0; |
| 684 | sdl->m_texpoweroftwo = 0; |
| 685 | 685 | } |
| 686 | 686 | else |
| 687 | 687 | { |
| r243303 | r243304 | |
| 692 | 692 | { |
| 693 | 693 | osd_printf_verbose("OpenGL: non-power-of-2 textures supported (old method)\n"); |
| 694 | 694 | } |
| 695 | | sdl->usetexturerect = 1; |
| 695 | sdl->m_usetexturerect = 1; |
| 696 | 696 | } |
| 697 | 697 | else |
| 698 | 698 | { |
| r243303 | r243304 | |
| 705 | 705 | |
| 706 | 706 | if (strstr(extstr, "GL_ARB_vertex_buffer_object")) |
| 707 | 707 | { |
| 708 | | sdl->usevbo = video_config.vbo; |
| 708 | sdl->m_usevbo = video_config.vbo; |
| 709 | 709 | if (!shown_video_info) |
| 710 | 710 | { |
| 711 | | if(sdl->usevbo) |
| 711 | if(sdl->m_usevbo) |
| 712 | 712 | osd_printf_verbose("OpenGL: vertex buffer supported\n"); |
| 713 | 713 | else |
| 714 | 714 | osd_printf_verbose("OpenGL: vertex buffer supported, but disabled\n"); |
| r243303 | r243304 | |
| 717 | 717 | |
| 718 | 718 | if (strstr(extstr, "GL_ARB_pixel_buffer_object")) |
| 719 | 719 | { |
| 720 | | if( sdl->usevbo ) |
| 720 | if( sdl->m_usevbo ) |
| 721 | 721 | { |
| 722 | | sdl->usepbo = video_config.pbo; |
| 722 | sdl->m_usepbo = video_config.pbo; |
| 723 | 723 | if (!shown_video_info) |
| 724 | 724 | { |
| 725 | | if(sdl->usepbo) |
| 725 | if(sdl->m_usepbo) |
| 726 | 726 | osd_printf_verbose("OpenGL: pixel buffers supported\n"); |
| 727 | 727 | else |
| 728 | 728 | osd_printf_verbose("OpenGL: pixel buffers supported, but disabled\n"); |
| r243303 | r243304 | |
| 744 | 744 | |
| 745 | 745 | if (strstr(extstr, "GL_EXT_framebuffer_object")) |
| 746 | 746 | { |
| 747 | | sdl->usefbo = 1; |
| 747 | sdl->m_usefbo = 1; |
| 748 | 748 | if (!shown_video_info) |
| 749 | 749 | { |
| 750 | | if(sdl->usefbo) |
| 750 | if(sdl->m_usefbo) |
| 751 | 751 | osd_printf_verbose("OpenGL: framebuffer object supported\n"); |
| 752 | 752 | else |
| 753 | 753 | osd_printf_verbose("OpenGL: framebuffer object not supported\n"); |
| r243303 | r243304 | |
| 760 | 760 | strstr(extstr, "GL_ARB_fragment_shader") |
| 761 | 761 | ) |
| 762 | 762 | { |
| 763 | | sdl->useglsl = video_config.glsl; |
| 763 | sdl->m_useglsl = video_config.glsl; |
| 764 | 764 | if (!shown_video_info) |
| 765 | 765 | { |
| 766 | | if(sdl->useglsl) |
| 766 | if(sdl->m_useglsl) |
| 767 | 767 | osd_printf_verbose("OpenGL: GLSL supported\n"); |
| 768 | 768 | else |
| 769 | 769 | osd_printf_verbose("OpenGL: GLSL supported, but disabled\n"); |
| r243303 | r243304 | |
| 777 | 777 | |
| 778 | 778 | if (osd_getenv(SDLENV_VMWARE) != NULL) |
| 779 | 779 | { |
| 780 | | sdl->usetexturerect = 1; |
| 781 | | sdl->texpoweroftwo = 1; |
| 780 | sdl->m_usetexturerect = 1; |
| 781 | sdl->m_texpoweroftwo = 1; |
| 782 | 782 | } |
| 783 | | glGetIntegerv(GL_MAX_TEXTURE_SIZE, (GLint *)&sdl->texture_max_width); |
| 784 | | glGetIntegerv(GL_MAX_TEXTURE_SIZE, (GLint *)&sdl->texture_max_height); |
| 783 | glGetIntegerv(GL_MAX_TEXTURE_SIZE, (GLint *)&sdl->m_texture_max_width); |
| 784 | glGetIntegerv(GL_MAX_TEXTURE_SIZE, (GLint *)&sdl->m_texture_max_height); |
| 785 | 785 | if (!shown_video_info) |
| 786 | 786 | { |
| 787 | | osd_printf_verbose("OpenGL: max texture size %d x %d\n", sdl->texture_max_width, sdl->texture_max_height); |
| 787 | osd_printf_verbose("OpenGL: max texture size %d x %d\n", sdl->m_texture_max_width, sdl->m_texture_max_height); |
| 788 | 788 | } |
| 789 | 789 | |
| 790 | 790 | shown_video_info = 1; |
| 791 | 791 | |
| 792 | | sdl->init_context = 0; |
| 792 | sdl->m_init_context = 0; |
| 793 | 793 | |
| 794 | 794 | return 0; |
| 795 | 795 | } |
| r243303 | r243304 | |
| 806 | 806 | //SDL_GL_MakeCurrent(window->sdl_window, sdl->gl_context_id); |
| 807 | 807 | SDL_SetWindowSize(window->m_sdl_window, width, height); |
| 808 | 808 | SDL_GetWindowSize(window->m_sdl_window, &window->m_width, &window->m_height); |
| 809 | | sdl->blittimer = 3; |
| 809 | sdl->m_blittimer = 3; |
| 810 | 810 | #else |
| 811 | 811 | SDL_FreeSurface(sdl->sdlsurf); |
| 812 | 812 | |
| 813 | 813 | sdl->sdlsurf = SDL_SetVideoMode(m_width, m_height, 0, |
| 814 | | SDL_SWSURFACE | SDL_ANYFORMAT | sdl->extra_flags); |
| 814 | SDL_SWSURFACE | SDL_ANYFORMAT | sdl->m_extra_flags); |
| 815 | 815 | |
| 816 | 816 | window->m_width = sdl->sdlsurf->w; |
| 817 | 817 | window->m_height = sdl->sdlsurf->h; |
| 818 | 818 | #endif |
| 819 | | sdl->init_context = 1; |
| 819 | sdl->m_init_context = 1; |
| 820 | 820 | |
| 821 | 821 | } |
| 822 | 822 | |
| r243303 | r243304 | |
| 828 | 828 | { |
| 829 | 829 | sdl_info *sdl =(sdl_info *) window->m_dxdata; |
| 830 | 830 | |
| 831 | | *xt = x - sdl->last_hofs; |
| 832 | | *yt = y - sdl->last_vofs; |
| 831 | *xt = x - sdl->m_last_hofs; |
| 832 | *yt = y - sdl->m_last_vofs; |
| 833 | 833 | if (*xt<0 || *xt >= window->m_blitwidth) |
| 834 | 834 | return 0; |
| 835 | 835 | if (*yt<0 || *yt >= window->m_blitheight) |
| r243303 | r243304 | |
| 859 | 859 | // sdl->usepbo=FALSE; // You may want to switch PBO off, by uncommenting this statement |
| 860 | 860 | // sdl->useglsl=FALSE; // You may want to switch GLSL off, by uncommenting this statement |
| 861 | 861 | |
| 862 | | if (! sdl->usevbo) |
| 862 | if (! sdl->m_usevbo) |
| 863 | 863 | { |
| 864 | | if(sdl->usepbo) // should never ever happen ;-) |
| 864 | if(sdl->m_usepbo) // should never ever happen ;-) |
| 865 | 865 | { |
| 866 | 866 | if (_once) |
| 867 | 867 | { |
| 868 | 868 | osd_printf_warning("OpenGL: PBO not supported, no VBO support. (sdlmame error)\n"); |
| 869 | 869 | } |
| 870 | | sdl->usepbo=FALSE; |
| 870 | sdl->m_usepbo=FALSE; |
| 871 | 871 | } |
| 872 | | if(sdl->useglsl) // should never ever happen ;-) |
| 872 | if(sdl->m_useglsl) // should never ever happen ;-) |
| 873 | 873 | { |
| 874 | 874 | if (_once) |
| 875 | 875 | { |
| 876 | 876 | osd_printf_warning("OpenGL: GLSL not supported, no VBO support. (sdlmame error)\n"); |
| 877 | 877 | } |
| 878 | | sdl->useglsl=FALSE; |
| 878 | sdl->m_useglsl=FALSE; |
| 879 | 879 | } |
| 880 | 880 | } |
| 881 | 881 | |
| 882 | 882 | // Get Pointers To The GL Functions |
| 883 | 883 | // VBO: |
| 884 | | if( sdl->usevbo ) |
| 884 | if( sdl->m_usevbo ) |
| 885 | 885 | { |
| 886 | 886 | pfn_glGenBuffers = (PFNGLGENBUFFERSPROC) SDL_GL_GetProcAddress("glGenBuffers"); |
| 887 | 887 | pfn_glDeleteBuffers = (PFNGLDELETEBUFFERSPROC) SDL_GL_GetProcAddress("glDeleteBuffers"); |
| r243303 | r243304 | |
| 890 | 890 | pfn_glBufferSubData = (PFNGLBUFFERSUBDATAPROC) SDL_GL_GetProcAddress("glBufferSubData"); |
| 891 | 891 | } |
| 892 | 892 | // PBO: |
| 893 | | if ( sdl->usepbo ) |
| 893 | if ( sdl->m_usepbo ) |
| 894 | 894 | { |
| 895 | 895 | pfn_glMapBuffer = (PFNGLMAPBUFFERPROC) SDL_GL_GetProcAddress("glMapBuffer"); |
| 896 | 896 | pfn_glUnmapBuffer= (PFNGLUNMAPBUFFERPROC) SDL_GL_GetProcAddress("glUnmapBuffer"); |
| 897 | 897 | } |
| 898 | 898 | // FBO: |
| 899 | | if ( sdl->usefbo ) |
| 899 | if ( sdl->m_usefbo ) |
| 900 | 900 | { |
| 901 | 901 | pfn_glIsFramebuffer = (PFNGLISFRAMEBUFFEREXTPROC) SDL_GL_GetProcAddress("glIsFramebufferEXT"); |
| 902 | 902 | pfn_glBindFramebuffer = (PFNGLBINDFRAMEBUFFEREXTPROC) SDL_GL_GetProcAddress("glBindFramebufferEXT"); |
| r243303 | r243304 | |
| 906 | 906 | pfn_glFramebufferTexture2D = (PFNGLFRAMEBUFFERTEXTURE2DEXTPROC) SDL_GL_GetProcAddress("glFramebufferTexture2DEXT"); |
| 907 | 907 | } |
| 908 | 908 | |
| 909 | | if ( sdl->usevbo && |
| 909 | if ( sdl->m_usevbo && |
| 910 | 910 | ( !pfn_glGenBuffers || !pfn_glDeleteBuffers || |
| 911 | 911 | !pfn_glBindBuffer || !pfn_glBufferData || !pfn_glBufferSubData |
| 912 | 912 | ) ) |
| 913 | 913 | { |
| 914 | | sdl->usepbo=FALSE; |
| 914 | sdl->m_usepbo=FALSE; |
| 915 | 915 | if (_once) |
| 916 | 916 | { |
| 917 | 917 | osd_printf_warning("OpenGL: VBO not supported, missing: "); |
| r243303 | r243304 | |
| 937 | 937 | } |
| 938 | 938 | osd_printf_warning("\n"); |
| 939 | 939 | } |
| 940 | | if ( sdl->usevbo ) |
| 940 | if ( sdl->m_usevbo ) |
| 941 | 941 | { |
| 942 | 942 | if (_once) |
| 943 | 943 | { |
| 944 | 944 | osd_printf_warning("OpenGL: PBO not supported, no VBO support.\n"); |
| 945 | 945 | } |
| 946 | | sdl->usepbo=FALSE; |
| 946 | sdl->m_usepbo=FALSE; |
| 947 | 947 | } |
| 948 | 948 | } |
| 949 | 949 | |
| 950 | | if ( sdl->usepbo && ( !pfn_glMapBuffer || !pfn_glUnmapBuffer ) ) |
| 950 | if ( sdl->m_usepbo && ( !pfn_glMapBuffer || !pfn_glUnmapBuffer ) ) |
| 951 | 951 | { |
| 952 | | sdl->usepbo=FALSE; |
| 952 | sdl->m_usepbo=FALSE; |
| 953 | 953 | if (_once) |
| 954 | 954 | { |
| 955 | 955 | osd_printf_warning("OpenGL: PBO not supported, missing: "); |
| r243303 | r243304 | |
| 965 | 965 | } |
| 966 | 966 | } |
| 967 | 967 | |
| 968 | | if ( sdl->usefbo && |
| 968 | if ( sdl->m_usefbo && |
| 969 | 969 | ( !pfn_glIsFramebuffer || !pfn_glBindFramebuffer || !pfn_glDeleteFramebuffers || |
| 970 | 970 | !pfn_glGenFramebuffers || !pfn_glCheckFramebufferStatus || !pfn_glFramebufferTexture2D |
| 971 | 971 | )) |
| 972 | 972 | { |
| 973 | | sdl->usefbo=FALSE; |
| 973 | sdl->m_usefbo=FALSE; |
| 974 | 974 | if (_once) |
| 975 | 975 | { |
| 976 | 976 | osd_printf_warning("OpenGL: FBO not supported, missing: "); |
| r243303 | r243304 | |
| 1004 | 1004 | |
| 1005 | 1005 | if (_once) |
| 1006 | 1006 | { |
| 1007 | | if ( sdl->usevbo ) |
| 1007 | if ( sdl->m_usevbo ) |
| 1008 | 1008 | { |
| 1009 | 1009 | osd_printf_verbose("OpenGL: VBO supported\n"); |
| 1010 | 1010 | } |
| r243303 | r243304 | |
| 1013 | 1013 | osd_printf_warning("OpenGL: VBO not supported\n"); |
| 1014 | 1014 | } |
| 1015 | 1015 | |
| 1016 | | if ( sdl->usepbo ) |
| 1016 | if ( sdl->m_usepbo ) |
| 1017 | 1017 | { |
| 1018 | 1018 | osd_printf_verbose("OpenGL: PBO supported\n"); |
| 1019 | 1019 | } |
| r243303 | r243304 | |
| 1022 | 1022 | osd_printf_warning("OpenGL: PBO not supported\n"); |
| 1023 | 1023 | } |
| 1024 | 1024 | |
| 1025 | | if ( sdl->usefbo ) |
| 1025 | if ( sdl->m_usefbo ) |
| 1026 | 1026 | { |
| 1027 | 1027 | osd_printf_verbose("OpenGL: FBO supported\n"); |
| 1028 | 1028 | } |
| r243303 | r243304 | |
| 1032 | 1032 | } |
| 1033 | 1033 | } |
| 1034 | 1034 | |
| 1035 | | if ( sdl->useglsl ) |
| 1035 | if ( sdl->m_useglsl ) |
| 1036 | 1036 | { |
| 1037 | 1037 | #ifdef GL_ARB_multitexture |
| 1038 | 1038 | pfn_glActiveTexture = (PFNGLACTIVETEXTUREARBPROC) SDL_GL_GetProcAddress("glActiveTextureARB"); |
| r243303 | r243304 | |
| 1045 | 1045 | { |
| 1046 | 1046 | osd_printf_warning("OpenGL: GLSL disabled, glActiveTexture(ARB) not supported\n"); |
| 1047 | 1047 | } |
| 1048 | | sdl->useglsl = 0; |
| 1048 | sdl->m_useglsl = 0; |
| 1049 | 1049 | } |
| 1050 | 1050 | } |
| 1051 | 1051 | |
| 1052 | | if ( sdl->useglsl ) |
| 1052 | if ( sdl->m_useglsl ) |
| 1053 | 1053 | { |
| 1054 | | sdl->glsl = glsl_shader_init(); |
| 1055 | | sdl->useglsl = (sdl->glsl != NULL ? 1 : 0); |
| 1054 | sdl->m_glsl = glsl_shader_init(); |
| 1055 | sdl->m_useglsl = (sdl->m_glsl != NULL ? 1 : 0); |
| 1056 | 1056 | |
| 1057 | | if ( ! sdl->useglsl ) |
| 1057 | if ( ! sdl->m_useglsl ) |
| 1058 | 1058 | { |
| 1059 | 1059 | if (_once) |
| 1060 | 1060 | { |
| r243303 | r243304 | |
| 1063 | 1063 | } |
| 1064 | 1064 | } |
| 1065 | 1065 | |
| 1066 | | if ( sdl->useglsl ) |
| 1066 | if ( sdl->m_useglsl ) |
| 1067 | 1067 | { |
| 1068 | 1068 | if ( window->m_prescale != 1 ) |
| 1069 | 1069 | { |
| 1070 | | sdl->useglsl = 0; |
| 1070 | sdl->m_useglsl = 0; |
| 1071 | 1071 | if (_once) |
| 1072 | 1072 | { |
| 1073 | 1073 | osd_printf_warning("OpenGL: GLSL supported, but disabled due to: prescale !=1 \n"); |
| r243303 | r243304 | |
| 1075 | 1075 | } |
| 1076 | 1076 | } |
| 1077 | 1077 | |
| 1078 | | if ( sdl->useglsl ) |
| 1078 | if ( sdl->m_useglsl ) |
| 1079 | 1079 | { |
| 1080 | 1080 | int i; |
| 1081 | 1081 | video_config.filter = FALSE; |
| 1082 | 1082 | glsl_shader_feature = GLSL_SHADER_FEAT_PLAIN; |
| 1083 | | sdl->glsl_program_num = 0; |
| 1084 | | sdl->glsl_program_mb2sc = 0; |
| 1083 | sdl->m_glsl_program_num = 0; |
| 1084 | sdl->m_glsl_program_mb2sc = 0; |
| 1085 | 1085 | |
| 1086 | 1086 | for(i=0; i<video_config.glsl_shader_mamebm_num; i++) |
| 1087 | 1087 | { |
| 1088 | | if ( !sdl->usefbo && sdl->glsl_program_num==1 ) |
| 1088 | if ( !sdl->m_usefbo && sdl->m_glsl_program_num==1 ) |
| 1089 | 1089 | { |
| 1090 | 1090 | if (_once) |
| 1091 | 1091 | { |
| r243303 | r243304 | |
| 1094 | 1094 | break; |
| 1095 | 1095 | } |
| 1096 | 1096 | |
| 1097 | | if ( glsl_shader_add_mamebm(sdl->glsl, video_config.glsl_shader_mamebm[i], sdl->glsl_program_num) ) |
| 1097 | if ( glsl_shader_add_mamebm(sdl->m_glsl, video_config.glsl_shader_mamebm[i], sdl->m_glsl_program_num) ) |
| 1098 | 1098 | { |
| 1099 | 1099 | osd_printf_error("OpenGL: GLSL loading mame bitmap shader %d failed (%s)\n", |
| 1100 | 1100 | i, video_config.glsl_shader_mamebm[i]); |
| r243303 | r243304 | |
| 1103 | 1103 | if (_once) |
| 1104 | 1104 | { |
| 1105 | 1105 | osd_printf_verbose("OpenGL: GLSL using mame bitmap shader filter %d: '%s'\n", |
| 1106 | | sdl->glsl_program_num, video_config.glsl_shader_mamebm[i]); |
| 1106 | sdl->m_glsl_program_num, video_config.glsl_shader_mamebm[i]); |
| 1107 | 1107 | } |
| 1108 | | sdl->glsl_program_mb2sc = sdl->glsl_program_num; // the last mame_bitmap (mb) shader does it. |
| 1109 | | sdl->glsl_program_num++; |
| 1108 | sdl->m_glsl_program_mb2sc = sdl->m_glsl_program_num; // the last mame_bitmap (mb) shader does it. |
| 1109 | sdl->m_glsl_program_num++; |
| 1110 | 1110 | } |
| 1111 | 1111 | } |
| 1112 | 1112 | |
| 1113 | | if ( video_config.glsl_shader_scrn_num > 0 && sdl->glsl_program_num==0 ) |
| 1113 | if ( video_config.glsl_shader_scrn_num > 0 && sdl->m_glsl_program_num==0 ) |
| 1114 | 1114 | { |
| 1115 | 1115 | osd_printf_verbose("OpenGL: GLSL cannot use screen bitmap shader without bitmap shader\n"); |
| 1116 | 1116 | } |
| 1117 | 1117 | |
| 1118 | | for(i=0; sdl->usefbo && sdl->glsl_program_num>0 && i<video_config.glsl_shader_scrn_num; i++) |
| 1118 | for(i=0; sdl->m_usefbo && sdl->m_glsl_program_num>0 && i<video_config.glsl_shader_scrn_num; i++) |
| 1119 | 1119 | { |
| 1120 | | if ( glsl_shader_add_scrn(sdl->glsl, video_config.glsl_shader_scrn[i], |
| 1121 | | sdl->glsl_program_num-1-sdl->glsl_program_mb2sc) ) |
| 1120 | if ( glsl_shader_add_scrn(sdl->m_glsl, video_config.glsl_shader_scrn[i], |
| 1121 | sdl->m_glsl_program_num-1-sdl->m_glsl_program_mb2sc) ) |
| 1122 | 1122 | { |
| 1123 | 1123 | osd_printf_error("OpenGL: GLSL loading screen bitmap shader %d failed (%s)\n", |
| 1124 | 1124 | i, video_config.glsl_shader_scrn[i]); |
| r243303 | r243304 | |
| 1126 | 1126 | if (_once) |
| 1127 | 1127 | { |
| 1128 | 1128 | osd_printf_verbose("OpenGL: GLSL using screen bitmap shader filter %d: '%s'\n", |
| 1129 | | sdl->glsl_program_num, video_config.glsl_shader_scrn[i]); |
| 1129 | sdl->m_glsl_program_num, video_config.glsl_shader_scrn[i]); |
| 1130 | 1130 | } |
| 1131 | | sdl->glsl_program_num++; |
| 1131 | sdl->m_glsl_program_num++; |
| 1132 | 1132 | } |
| 1133 | 1133 | } |
| 1134 | 1134 | |
| 1135 | | if ( 0==sdl->glsl_program_num && |
| 1135 | if ( 0==sdl->m_glsl_program_num && |
| 1136 | 1136 | 0 <= video_config.glsl_filter && video_config.glsl_filter < GLSL_SHADER_FEAT_INT_NUMBER ) |
| 1137 | 1137 | { |
| 1138 | | sdl->glsl_program_mb2sc = sdl->glsl_program_num; // the last mame_bitmap (mb) shader does it. |
| 1139 | | sdl->glsl_program_num++; |
| 1138 | sdl->m_glsl_program_mb2sc = sdl->m_glsl_program_num; // the last mame_bitmap (mb) shader does it. |
| 1139 | sdl->m_glsl_program_num++; |
| 1140 | 1140 | glsl_shader_feature = video_config.glsl_filter; |
| 1141 | 1141 | |
| 1142 | 1142 | if (_once) |
| 1143 | 1143 | { |
| 1144 | 1144 | osd_printf_verbose("OpenGL: GLSL using shader filter '%s', idx: %d, num %d (vid filter: %d)\n", |
| 1145 | 1145 | glsl_shader_get_filter_name_mamebm(glsl_shader_feature), |
| 1146 | | glsl_shader_feature, sdl->glsl_program_num, video_config.filter); |
| 1146 | glsl_shader_feature, sdl->m_glsl_program_num, video_config.filter); |
| 1147 | 1147 | } |
| 1148 | 1148 | } |
| 1149 | 1149 | |
| r243303 | r243304 | |
| 1176 | 1176 | } |
| 1177 | 1177 | |
| 1178 | 1178 | #if (SDLMAME_SDL2) |
| 1179 | | SDL_GL_MakeCurrent(window->m_sdl_window, sdl->gl_context_id); |
| 1179 | SDL_GL_MakeCurrent(window->m_sdl_window, sdl->m_gl_context_id); |
| 1180 | 1180 | #else |
| 1181 | | if (!sdl->init_context) |
| 1181 | if (!sdl->m_init_context) |
| 1182 | 1182 | { |
| 1183 | 1183 | screen_device_iterator myiter(window->machine().root_device()); |
| 1184 | 1184 | for (screen = myiter.first(); screen != NULL; screen = myiter.next()) |
| r243303 | r243304 | |
| 1199 | 1199 | } |
| 1200 | 1200 | #endif |
| 1201 | 1201 | |
| 1202 | | if (sdl->init_context) |
| 1202 | if (sdl->m_init_context) |
| 1203 | 1203 | { |
| 1204 | 1204 | // do some one-time OpenGL setup |
| 1205 | 1205 | #if (SDLMAME_SDL2) |
| r243303 | r243304 | |
| 1232 | 1232 | } |
| 1233 | 1233 | |
| 1234 | 1234 | // only clear if the geometry changes (and for 2 frames afterward to clear double and triple buffers) |
| 1235 | | if ((sdl->blittimer > 0) || (is_vector)) |
| 1235 | if ((sdl->m_blittimer > 0) || (is_vector)) |
| 1236 | 1236 | { |
| 1237 | 1237 | glClear(GL_COLOR_BUFFER_BIT); |
| 1238 | | sdl->blittimer--; |
| 1238 | sdl->m_blittimer--; |
| 1239 | 1239 | } |
| 1240 | 1240 | |
| 1241 | | if ( !sdl->initialized || |
| 1242 | | window->m_width!= sdl->surf_w || window->m_height!= sdl->surf_h ) |
| 1241 | if ( !sdl->m_initialized || |
| 1242 | window->m_width!= sdl->m_surf_w || window->m_height!= sdl->m_surf_h ) |
| 1243 | 1243 | { |
| 1244 | | if ( !sdl->initialized ) |
| 1244 | if ( !sdl->m_initialized ) |
| 1245 | 1245 | { |
| 1246 | 1246 | loadGLExtensions(window); |
| 1247 | 1247 | } |
| 1248 | 1248 | |
| 1249 | | sdl->surf_w=window->m_width; |
| 1250 | | sdl->surf_h=window->m_height; |
| 1249 | sdl->m_surf_w=window->m_width; |
| 1250 | sdl->m_surf_h=window->m_height; |
| 1251 | 1251 | |
| 1252 | 1252 | // we're doing nothing 3d, so the Z-buffer is currently not interesting |
| 1253 | 1253 | glDisable(GL_DEPTH_TEST); |
| r243303 | r243304 | |
| 1272 | 1272 | // enable blending |
| 1273 | 1273 | glEnable(GL_BLEND); |
| 1274 | 1274 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
| 1275 | | sdl->last_blendmode = BLENDMODE_ALPHA; |
| 1275 | sdl->m_last_blendmode = BLENDMODE_ALPHA; |
| 1276 | 1276 | |
| 1277 | 1277 | // set lines and points just barely above normal size to get proper results |
| 1278 | 1278 | glLineWidth(video_config.beamwidth); |
| r243303 | r243304 | |
| 1295 | 1295 | glMatrixMode(GL_MODELVIEW); |
| 1296 | 1296 | glLoadIdentity(); |
| 1297 | 1297 | |
| 1298 | | if ( ! sdl->initialized ) |
| 1298 | if ( ! sdl->m_initialized ) |
| 1299 | 1299 | { |
| 1300 | 1300 | glEnableClientState(GL_VERTEX_ARRAY); |
| 1301 | | glVertexPointer(2, GL_FLOAT, 0, sdl->texVerticex); // no VBO, since it's too volatile |
| 1301 | glVertexPointer(2, GL_FLOAT, 0, sdl->m_texVerticex); // no VBO, since it's too volatile |
| 1302 | 1302 | |
| 1303 | | sdl->initialized = 1; |
| 1303 | sdl->m_initialized = 1; |
| 1304 | 1304 | } |
| 1305 | 1305 | } |
| 1306 | 1306 | |
| r243303 | r243304 | |
| 1332 | 1332 | } |
| 1333 | 1333 | } |
| 1334 | 1334 | |
| 1335 | | sdl->last_hofs = hofs; |
| 1336 | | sdl->last_vofs = vofs; |
| 1335 | sdl->m_last_hofs = hofs; |
| 1336 | sdl->m_last_vofs = vofs; |
| 1337 | 1337 | |
| 1338 | 1338 | window->m_primlist->acquire_lock(); |
| 1339 | 1339 | |
| r243303 | r243304 | |
| 1492 | 1492 | |
| 1493 | 1493 | if ( texture && texture->type==TEXTURE_TYPE_SHADER ) |
| 1494 | 1494 | { |
| 1495 | | for(i=0; i<sdl->glsl_program_num; i++) |
| 1495 | for(i=0; i<sdl->m_glsl_program_num; i++) |
| 1496 | 1496 | { |
| 1497 | | if ( i==sdl->glsl_program_mb2sc ) |
| 1497 | if ( i==sdl->m_glsl_program_mb2sc ) |
| 1498 | 1498 | { |
| 1499 | 1499 | // i==sdl->glsl_program_mb2sc -> transformation mamebm->scrn |
| 1500 | | sdl->texVerticex[0]=prim->bounds.x0 + hofs; |
| 1501 | | sdl->texVerticex[1]=prim->bounds.y0 + vofs; |
| 1502 | | sdl->texVerticex[2]=prim->bounds.x1 + hofs; |
| 1503 | | sdl->texVerticex[3]=prim->bounds.y0 + vofs; |
| 1504 | | sdl->texVerticex[4]=prim->bounds.x1 + hofs; |
| 1505 | | sdl->texVerticex[5]=prim->bounds.y1 + vofs; |
| 1506 | | sdl->texVerticex[6]=prim->bounds.x0 + hofs; |
| 1507 | | sdl->texVerticex[7]=prim->bounds.y1 + vofs; |
| 1500 | sdl->m_texVerticex[0]=prim->bounds.x0 + hofs; |
| 1501 | sdl->m_texVerticex[1]=prim->bounds.y0 + vofs; |
| 1502 | sdl->m_texVerticex[2]=prim->bounds.x1 + hofs; |
| 1503 | sdl->m_texVerticex[3]=prim->bounds.y0 + vofs; |
| 1504 | sdl->m_texVerticex[4]=prim->bounds.x1 + hofs; |
| 1505 | sdl->m_texVerticex[5]=prim->bounds.y1 + vofs; |
| 1506 | sdl->m_texVerticex[6]=prim->bounds.x0 + hofs; |
| 1507 | sdl->m_texVerticex[7]=prim->bounds.y1 + vofs; |
| 1508 | 1508 | } else { |
| 1509 | 1509 | // 1:1 tex coord CCW (0/0) (1/0) (1/1) (0/1) on texture dimensions |
| 1510 | | sdl->texVerticex[0]=(GLfloat)0.0; |
| 1511 | | sdl->texVerticex[1]=(GLfloat)0.0; |
| 1512 | | sdl->texVerticex[2]=(GLfloat)window->m_width; |
| 1513 | | sdl->texVerticex[3]=(GLfloat)0.0; |
| 1514 | | sdl->texVerticex[4]=(GLfloat)window->m_width; |
| 1515 | | sdl->texVerticex[5]=(GLfloat)window->m_height; |
| 1516 | | sdl->texVerticex[6]=(GLfloat)0.0; |
| 1517 | | sdl->texVerticex[7]=(GLfloat)window->m_height; |
| 1510 | sdl->m_texVerticex[0]=(GLfloat)0.0; |
| 1511 | sdl->m_texVerticex[1]=(GLfloat)0.0; |
| 1512 | sdl->m_texVerticex[2]=(GLfloat)window->m_width; |
| 1513 | sdl->m_texVerticex[3]=(GLfloat)0.0; |
| 1514 | sdl->m_texVerticex[4]=(GLfloat)window->m_width; |
| 1515 | sdl->m_texVerticex[5]=(GLfloat)window->m_height; |
| 1516 | sdl->m_texVerticex[6]=(GLfloat)0.0; |
| 1517 | sdl->m_texVerticex[7]=(GLfloat)window->m_height; |
| 1518 | 1518 | } |
| 1519 | 1519 | |
| 1520 | 1520 | if(i>0) // first fetch already done |
| r243303 | r243304 | |
| 1524 | 1524 | glDrawArrays(GL_QUADS, 0, 4); |
| 1525 | 1525 | } |
| 1526 | 1526 | } else { |
| 1527 | | sdl->texVerticex[0]=prim->bounds.x0 + hofs; |
| 1528 | | sdl->texVerticex[1]=prim->bounds.y0 + vofs; |
| 1529 | | sdl->texVerticex[2]=prim->bounds.x1 + hofs; |
| 1530 | | sdl->texVerticex[3]=prim->bounds.y0 + vofs; |
| 1531 | | sdl->texVerticex[4]=prim->bounds.x1 + hofs; |
| 1532 | | sdl->texVerticex[5]=prim->bounds.y1 + vofs; |
| 1533 | | sdl->texVerticex[6]=prim->bounds.x0 + hofs; |
| 1534 | | sdl->texVerticex[7]=prim->bounds.y1 + vofs; |
| 1527 | sdl->m_texVerticex[0]=prim->bounds.x0 + hofs; |
| 1528 | sdl->m_texVerticex[1]=prim->bounds.y0 + vofs; |
| 1529 | sdl->m_texVerticex[2]=prim->bounds.x1 + hofs; |
| 1530 | sdl->m_texVerticex[3]=prim->bounds.y0 + vofs; |
| 1531 | sdl->m_texVerticex[4]=prim->bounds.x1 + hofs; |
| 1532 | sdl->m_texVerticex[5]=prim->bounds.y1 + vofs; |
| 1533 | sdl->m_texVerticex[6]=prim->bounds.x0 + hofs; |
| 1534 | sdl->m_texVerticex[7]=prim->bounds.y1 + vofs; |
| 1535 | 1535 | |
| 1536 | 1536 | glDrawArrays(GL_QUADS, 0, 4); |
| 1537 | 1537 | } |
| r243303 | r243304 | |
| 1555 | 1555 | } |
| 1556 | 1556 | |
| 1557 | 1557 | window->m_primlist->release_lock(); |
| 1558 | | sdl->init_context = 0; |
| 1558 | sdl->m_init_context = 0; |
| 1559 | 1559 | |
| 1560 | 1560 | #if (!SDLMAME_SDL2) |
| 1561 | 1561 | SDL_GL_SwapBuffers(); |
| r243303 | r243304 | |
| 1642 | 1642 | drawogl_destroy_all_textures(window); |
| 1643 | 1643 | |
| 1644 | 1644 | #if (SDLMAME_SDL2) |
| 1645 | | SDL_GL_DeleteContext(sdl->gl_context_id); |
| 1645 | SDL_GL_DeleteContext(sdl->m_gl_context_id); |
| 1646 | 1646 | SDL_DestroyWindow(window->m_sdl_window); |
| 1647 | 1647 | #else |
| 1648 | 1648 | if (sdl->sdlsurf) |
| r243303 | r243304 | |
| 1676 | 1676 | !PRIMFLAG_GET_SCREENTEX(flags)) |
| 1677 | 1677 | { |
| 1678 | 1678 | texture->type = TEXTURE_TYPE_PLAIN; |
| 1679 | | texture->texTarget = (sdl->usetexturerect)?GL_TEXTURE_RECTANGLE_ARB:GL_TEXTURE_2D; |
| 1680 | | texture->texpow2 = (sdl->usetexturerect)?0:sdl->texpoweroftwo; |
| 1679 | texture->texTarget = (sdl->m_usetexturerect)?GL_TEXTURE_RECTANGLE_ARB:GL_TEXTURE_2D; |
| 1680 | texture->texpow2 = (sdl->m_usetexturerect)?0:sdl->m_texpoweroftwo; |
| 1681 | 1681 | } |
| 1682 | 1682 | |
| 1683 | | if ( texture->type == TEXTURE_TYPE_NONE && sdl->useglsl && |
| 1683 | if ( texture->type == TEXTURE_TYPE_NONE && sdl->m_useglsl && |
| 1684 | 1684 | texture->xprescale == 1 && texture->yprescale == 1 && |
| 1685 | | texsource->rowpixels <= sdl->texture_max_width ) |
| 1685 | texsource->rowpixels <= sdl->m_texture_max_width ) |
| 1686 | 1686 | { |
| 1687 | 1687 | texture->type = TEXTURE_TYPE_SHADER; |
| 1688 | 1688 | texture->texTarget = GL_TEXTURE_2D; |
| 1689 | | texture->texpow2 = sdl->texpoweroftwo; |
| 1689 | texture->texpow2 = sdl->m_texpoweroftwo; |
| 1690 | 1690 | } |
| 1691 | 1691 | |
| 1692 | 1692 | // determine if we can skip the copy step |
| r243303 | r243304 | |
| 1695 | 1695 | !texture_copy_properties[texture->format][SDL_TEXFORMAT_SRC_HAS_PALETTE] && |
| 1696 | 1696 | texture->xprescale == 1 && texture->yprescale == 1 && |
| 1697 | 1697 | !texture->borderpix && !texsource->palette() && |
| 1698 | | texsource->rowpixels <= sdl->texture_max_width ) |
| 1698 | texsource->rowpixels <= sdl->m_texture_max_width ) |
| 1699 | 1699 | { |
| 1700 | 1700 | texture->nocopy = TRUE; |
| 1701 | 1701 | } |
| 1702 | 1702 | |
| 1703 | 1703 | if( texture->type == TEXTURE_TYPE_NONE && |
| 1704 | | sdl->usepbo && !texture->nocopy ) |
| 1704 | sdl->m_usepbo && !texture->nocopy ) |
| 1705 | 1705 | { |
| 1706 | 1706 | texture->type = TEXTURE_TYPE_DYNAMIC; |
| 1707 | | texture->texTarget = (sdl->usetexturerect)?GL_TEXTURE_RECTANGLE_ARB:GL_TEXTURE_2D; |
| 1708 | | texture->texpow2 = (sdl->usetexturerect)?0:sdl->texpoweroftwo; |
| 1707 | texture->texTarget = (sdl->m_usetexturerect)?GL_TEXTURE_RECTANGLE_ARB:GL_TEXTURE_2D; |
| 1708 | texture->texpow2 = (sdl->m_usetexturerect)?0:sdl->m_texpoweroftwo; |
| 1709 | 1709 | } |
| 1710 | 1710 | |
| 1711 | 1711 | if( texture->type == TEXTURE_TYPE_NONE ) |
| 1712 | 1712 | { |
| 1713 | 1713 | texture->type = TEXTURE_TYPE_SURFACE; |
| 1714 | | texture->texTarget = (sdl->usetexturerect)?GL_TEXTURE_RECTANGLE_ARB:GL_TEXTURE_2D; |
| 1715 | | texture->texpow2 = (sdl->usetexturerect)?0:sdl->texpoweroftwo; |
| 1714 | texture->texTarget = (sdl->m_usetexturerect)?GL_TEXTURE_RECTANGLE_ARB:GL_TEXTURE_2D; |
| 1715 | texture->texpow2 = (sdl->m_usetexturerect)?0:sdl->m_texpoweroftwo; |
| 1716 | 1716 | } |
| 1717 | 1717 | } |
| 1718 | 1718 | |
| r243303 | r243304 | |
| 1746 | 1746 | } |
| 1747 | 1747 | |
| 1748 | 1748 | // don't prescale above max texture size |
| 1749 | | while (texture->xprescale > 1 && width_create * texture->xprescale > sdl->texture_max_width) |
| 1749 | while (texture->xprescale > 1 && width_create * texture->xprescale > sdl->m_texture_max_width) |
| 1750 | 1750 | texture->xprescale--; |
| 1751 | | while (texture->yprescale > 1 && height_create * texture->yprescale > sdl->texture_max_height) |
| 1751 | while (texture->yprescale > 1 && height_create * texture->yprescale > sdl->m_texture_max_height) |
| 1752 | 1752 | texture->yprescale--; |
| 1753 | 1753 | if (PRIMFLAG_GET_SCREENTEX(flags) && (texture->xprescale != window->m_prescale || texture->yprescale != window->m_prescale)) |
| 1754 | 1754 | osd_printf_warning("SDL: adjusting prescale from %dx%d to %dx%d\n", window->m_prescale, window->m_prescale, texture->xprescale, texture->yprescale); |
| r243303 | r243304 | |
| 1793 | 1793 | |
| 1794 | 1794 | // if we added pixels for the border, and that just barely pushed us over, take it back |
| 1795 | 1795 | if (texture->borderpix && |
| 1796 | | ((finalwidth > sdl->texture_max_width && finalwidth - 2 <= sdl->texture_max_width) || |
| 1797 | | (finalheight > sdl->texture_max_height && finalheight - 2 <= sdl->texture_max_height))) |
| 1796 | ((finalwidth > sdl->m_texture_max_width && finalwidth - 2 <= sdl->m_texture_max_width) || |
| 1797 | (finalheight > sdl->m_texture_max_height && finalheight - 2 <= sdl->m_texture_max_height))) |
| 1798 | 1798 | { |
| 1799 | 1799 | texture->borderpix = FALSE; |
| 1800 | 1800 | |
| r243303 | r243304 | |
| 1805 | 1805 | } |
| 1806 | 1806 | |
| 1807 | 1807 | // if we're above the max width/height, do what? |
| 1808 | | if (finalwidth_create > sdl->texture_max_width || finalheight_create > sdl->texture_max_height) |
| 1808 | if (finalwidth_create > sdl->m_texture_max_width || finalheight_create > sdl->m_texture_max_height) |
| 1809 | 1809 | { |
| 1810 | 1810 | static int printed = FALSE; |
| 1811 | 1811 | if (!printed) |
| 1812 | | osd_printf_warning("Texture too big! (wanted: %dx%d, max is %dx%d)\n", finalwidth_create, finalheight_create, sdl->texture_max_width, sdl->texture_max_height); |
| 1812 | osd_printf_warning("Texture too big! (wanted: %dx%d, max is %dx%d)\n", finalwidth_create, finalheight_create, sdl->m_texture_max_width, sdl->m_texture_max_height); |
| 1813 | 1813 | printed = TRUE; |
| 1814 | 1814 | } |
| 1815 | 1815 | |
| r243303 | r243304 | |
| 1831 | 1831 | (int)texture_copy_properties[texture->format][SDL_TEXFORMAT_SRC_EQUALS_DEST], |
| 1832 | 1832 | (int)texture_copy_properties[texture->format][SDL_TEXFORMAT_SRC_HAS_PALETTE], |
| 1833 | 1833 | texture->xprescale, texture->yprescale, |
| 1834 | | texture->borderpix, texsource->rowpixels, finalwidth, sdl->texture_max_width, |
| 1834 | texture->borderpix, texsource->rowpixels, finalwidth, sdl->m_texture_max_width, |
| 1835 | 1835 | (int)sizeof(UINT32) |
| 1836 | 1836 | ); |
| 1837 | 1837 | } |
| r243303 | r243304 | |
| 1940 | 1940 | |
| 1941 | 1941 | GL_CHECK_ERROR_QUIET(); |
| 1942 | 1942 | |
| 1943 | | if( sdl->glsl_program_num > 1 ) |
| 1943 | if( sdl->m_glsl_program_num > 1 ) |
| 1944 | 1944 | { |
| 1945 | 1945 | // multipass mode |
| 1946 | | assert(sdl->usefbo); |
| 1946 | assert(sdl->m_usefbo); |
| 1947 | 1947 | |
| 1948 | 1948 | // GL_TEXTURE3 GLSL Uniforms |
| 1949 | 1949 | texture->mpass_dest_idx = 0; |
| r243303 | r243304 | |
| 1951 | 1951 | texture->mpass_textureunit[1] = GL_TEXTURE2; |
| 1952 | 1952 | } |
| 1953 | 1953 | |
| 1954 | | for(i=0; i<sdl->glsl_program_num; i++) |
| 1954 | for(i=0; i<sdl->m_glsl_program_num; i++) |
| 1955 | 1955 | { |
| 1956 | | if ( i<=sdl->glsl_program_mb2sc ) |
| 1956 | if ( i<=sdl->m_glsl_program_mb2sc ) |
| 1957 | 1957 | { |
| 1958 | | sdl->glsl_program[i] = glsl_shader_get_program_mamebm(glsl_shader_feature, i); |
| 1958 | sdl->m_glsl_program[i] = glsl_shader_get_program_mamebm(glsl_shader_feature, i); |
| 1959 | 1959 | } else { |
| 1960 | | sdl->glsl_program[i] = glsl_shader_get_program_scrn(i-1-sdl->glsl_program_mb2sc); |
| 1960 | sdl->m_glsl_program[i] = glsl_shader_get_program_scrn(i-1-sdl->m_glsl_program_mb2sc); |
| 1961 | 1961 | } |
| 1962 | | pfn_glUseProgramObjectARB(sdl->glsl_program[i]); |
| 1962 | pfn_glUseProgramObjectARB(sdl->m_glsl_program[i]); |
| 1963 | 1963 | |
| 1964 | | if ( i<=sdl->glsl_program_mb2sc ) |
| 1964 | if ( i<=sdl->m_glsl_program_mb2sc ) |
| 1965 | 1965 | { |
| 1966 | 1966 | // GL_TEXTURE0 GLSL Uniforms |
| 1967 | | uniform_location = pfn_glGetUniformLocationARB(sdl->glsl_program[i], "color_texture"); |
| 1967 | uniform_location = pfn_glGetUniformLocationARB(sdl->m_glsl_program[i], "color_texture"); |
| 1968 | 1968 | pfn_glUniform1iARB(uniform_location, 0); |
| 1969 | 1969 | GL_CHECK_ERROR_NORMAL(); |
| 1970 | 1970 | } |
| 1971 | 1971 | |
| 1972 | 1972 | { |
| 1973 | 1973 | GLfloat color_texture_sz[2] = { (GLfloat)texture->rawwidth, (GLfloat)texture->rawheight }; |
| 1974 | | uniform_location = pfn_glGetUniformLocationARB(sdl->glsl_program[i], "color_texture_sz"); |
| 1974 | uniform_location = pfn_glGetUniformLocationARB(sdl->m_glsl_program[i], "color_texture_sz"); |
| 1975 | 1975 | pfn_glUniform2fvARB(uniform_location, 1, &(color_texture_sz[0])); |
| 1976 | 1976 | GL_CHECK_ERROR_NORMAL(); |
| 1977 | 1977 | } |
| 1978 | 1978 | |
| 1979 | 1979 | GLfloat color_texture_pow2_sz[2] = { (GLfloat)texture->rawwidth_create, (GLfloat)texture->rawheight_create }; |
| 1980 | | uniform_location = pfn_glGetUniformLocationARB(sdl->glsl_program[i], "color_texture_pow2_sz"); |
| 1980 | uniform_location = pfn_glGetUniformLocationARB(sdl->m_glsl_program[i], "color_texture_pow2_sz"); |
| 1981 | 1981 | pfn_glUniform2fvARB(uniform_location, 1, &(color_texture_pow2_sz[0])); |
| 1982 | 1982 | GL_CHECK_ERROR_NORMAL(); |
| 1983 | 1983 | |
| 1984 | 1984 | GLfloat screen_texture_sz[2] = { (GLfloat)window->m_blitwidth, (GLfloat)window->m_blitheight }; |
| 1985 | | uniform_location = pfn_glGetUniformLocationARB(sdl->glsl_program[i], "screen_texture_sz"); |
| 1985 | uniform_location = pfn_glGetUniformLocationARB(sdl->m_glsl_program[i], "screen_texture_sz"); |
| 1986 | 1986 | pfn_glUniform2fvARB(uniform_location, 1, &(screen_texture_sz[0])); |
| 1987 | 1987 | GL_CHECK_ERROR_NORMAL(); |
| 1988 | 1988 | |
| 1989 | 1989 | GLfloat screen_texture_pow2_sz[2] = { (GLfloat)surf_w_pow2, (GLfloat)surf_h_pow2 }; |
| 1990 | | uniform_location = pfn_glGetUniformLocationARB(sdl->glsl_program[i], "screen_texture_pow2_sz"); |
| 1990 | uniform_location = pfn_glGetUniformLocationARB(sdl->m_glsl_program[i], "screen_texture_pow2_sz"); |
| 1991 | 1991 | pfn_glUniform2fvARB(uniform_location, 1, &(screen_texture_pow2_sz[0])); |
| 1992 | 1992 | GL_CHECK_ERROR_NORMAL(); |
| 1993 | 1993 | } |
| 1994 | 1994 | |
| 1995 | | pfn_glUseProgramObjectARB(sdl->glsl_program[0]); // start with 1st shader |
| 1995 | pfn_glUseProgramObjectARB(sdl->m_glsl_program[0]); // start with 1st shader |
| 1996 | 1996 | |
| 1997 | | if( sdl->glsl_program_num > 1 ) |
| 1997 | if( sdl->m_glsl_program_num > 1 ) |
| 1998 | 1998 | { |
| 1999 | 1999 | // multipass mode |
| 2000 | 2000 | // GL_TEXTURE2/GL_TEXTURE3 |
| r243303 | r243304 | |
| 2018 | 2018 | texture->rawwidth, texture->rawheight, texture->rawwidth_create, texture->rawheight_create); |
| 2019 | 2019 | } |
| 2020 | 2020 | |
| 2021 | | if( sdl->glsl_program_num > 1 && sdl->glsl_program_mb2sc < sdl->glsl_program_num - 1 ) |
| 2021 | if( sdl->m_glsl_program_num > 1 && sdl->m_glsl_program_mb2sc < sdl->m_glsl_program_num - 1 ) |
| 2022 | 2022 | { |
| 2023 | 2023 | // multipass mode |
| 2024 | 2024 | // GL_TEXTURE2/GL_TEXTURE3 |
| r243303 | r243304 | |
| 2173 | 2173 | |
| 2174 | 2174 | texture->pbo=0; |
| 2175 | 2175 | |
| 2176 | | if ( texture->type != TEXTURE_TYPE_SHADER && sdl->useglsl) |
| 2176 | if ( texture->type != TEXTURE_TYPE_SHADER && sdl->m_useglsl) |
| 2177 | 2177 | { |
| 2178 | 2178 | pfn_glUseProgramObjectARB(0); // back to fixed function pipeline |
| 2179 | 2179 | } |
| r243303 | r243304 | |
| 2237 | 2237 | |
| 2238 | 2238 | if ( texture->type == TEXTURE_TYPE_DYNAMIC ) |
| 2239 | 2239 | { |
| 2240 | | assert(sdl->usepbo); |
| 2240 | assert(sdl->m_usepbo); |
| 2241 | 2241 | |
| 2242 | 2242 | // create the PBO |
| 2243 | 2243 | pfn_glGenBuffers(1, (GLuint *)&texture->pbo); |
| r243303 | r243304 | |
| 2257 | 2257 | } |
| 2258 | 2258 | |
| 2259 | 2259 | // add us to the texture list |
| 2260 | | if (sdl->texhash[texture->hash] == NULL) |
| 2261 | | sdl->texhash[texture->hash] = texture; |
| 2260 | if (sdl->m_texhash[texture->hash] == NULL) |
| 2261 | sdl->m_texhash[texture->hash] = texture; |
| 2262 | 2262 | else |
| 2263 | 2263 | { |
| 2264 | 2264 | int i; |
| 2265 | 2265 | for (i = HASH_SIZE; i < HASH_SIZE + OVERFLOW_SIZE; i++) |
| 2266 | | if (sdl->texhash[i] == NULL) |
| 2266 | if (sdl->m_texhash[i] == NULL) |
| 2267 | 2267 | { |
| 2268 | | sdl->texhash[i] = texture; |
| 2268 | sdl->m_texhash[i] = texture; |
| 2269 | 2269 | break; |
| 2270 | 2270 | } |
| 2271 | 2271 | assert_always(i < HASH_SIZE + OVERFLOW_SIZE, "texture hash exhausted ..."); |
| 2272 | 2272 | } |
| 2273 | 2273 | |
| 2274 | | if(sdl->usevbo) |
| 2274 | if(sdl->m_usevbo) |
| 2275 | 2275 | { |
| 2276 | 2276 | // Generate And Bind The Texture Coordinate Buffer |
| 2277 | 2277 | pfn_glGenBuffers( 1, &(texture->texCoordBufferName) ); |
| r243303 | r243304 | |
| 2701 | 2701 | HashT texhash = texture_compute_hash(&prim->texture, prim->flags); |
| 2702 | 2702 | texture_info *texture; |
| 2703 | 2703 | |
| 2704 | | texture = sdl->texhash[texhash]; |
| 2704 | texture = sdl->m_texhash[texhash]; |
| 2705 | 2705 | if (texture != NULL) |
| 2706 | 2706 | { |
| 2707 | 2707 | int i; |
| r243303 | r243304 | |
| 2709 | 2709 | return texture; |
| 2710 | 2710 | for (i=HASH_SIZE; i<HASH_SIZE + OVERFLOW_SIZE; i++) |
| 2711 | 2711 | { |
| 2712 | | texture = sdl->texhash[i]; |
| 2712 | texture = sdl->m_texhash[i]; |
| 2713 | 2713 | if (texture != NULL && compare_texture_primitive(texture, prim)) |
| 2714 | 2714 | return texture; |
| 2715 | 2715 | } |
| r243303 | r243304 | |
| 2730 | 2730 | float du, dv; |
| 2731 | 2731 | |
| 2732 | 2732 | if ( texture->type != TEXTURE_TYPE_SHADER || |
| 2733 | | ( texture->type == TEXTURE_TYPE_SHADER && shaderIdx<=sdl->glsl_program_mb2sc ) ) |
| 2733 | ( texture->type == TEXTURE_TYPE_SHADER && shaderIdx<=sdl->m_glsl_program_mb2sc ) ) |
| 2734 | 2734 | { |
| 2735 | 2735 | // compute the U/V scale factors |
| 2736 | 2736 | if (texture->borderpix) |
| r243303 | r243304 | |
| 2748 | 2748 | vstop = (float)(prim->texture.height*texture->yprescale) / (float)texture->rawheight_create; |
| 2749 | 2749 | } |
| 2750 | 2750 | } |
| 2751 | | else if ( texture->type == TEXTURE_TYPE_SHADER && shaderIdx>sdl->glsl_program_mb2sc ) |
| 2751 | else if ( texture->type == TEXTURE_TYPE_SHADER && shaderIdx>sdl->m_glsl_program_mb2sc ) |
| 2752 | 2752 | { |
| 2753 | 2753 | int surf_w_pow2 = get_valid_pow2_value (window->m_width, texture->texpow2); |
| 2754 | 2754 | int surf_h_pow2 = get_valid_pow2_value (window->m_height, texture->texpow2); |
| r243303 | r243304 | |
| 2772 | 2772 | dv *= (float)texture->rawheight; |
| 2773 | 2773 | } |
| 2774 | 2774 | |
| 2775 | | if ( texture->type == TEXTURE_TYPE_SHADER && shaderIdx!=sdl->glsl_program_mb2sc ) |
| 2775 | if ( texture->type == TEXTURE_TYPE_SHADER && shaderIdx!=sdl->m_glsl_program_mb2sc ) |
| 2776 | 2776 | { |
| 2777 | 2777 | // 1:1 tex coord CCW (0/0) (1/0) (1/1) (0/1) |
| 2778 | 2778 | // we must go CW here due to the mame bitmap order |
| r243303 | r243304 | |
| 2808 | 2808 | if ( shaderIdx>0 ) |
| 2809 | 2809 | { |
| 2810 | 2810 | int uniform_location; |
| 2811 | | uniform_location = pfn_glGetUniformLocationARB(sdl->glsl_program[shaderIdx], "mpass_texture"); |
| 2811 | uniform_location = pfn_glGetUniformLocationARB(sdl->m_glsl_program[shaderIdx], "mpass_texture"); |
| 2812 | 2812 | pfn_glUniform1iARB(uniform_location, texture->mpass_textureunit[mpass_src_idx]-GL_TEXTURE0); |
| 2813 | 2813 | GL_CHECK_ERROR_NORMAL(); |
| 2814 | 2814 | } |
| 2815 | 2815 | |
| 2816 | 2816 | pfn_glActiveTexture(texture->mpass_textureunit[mpass_src_idx]); |
| 2817 | | if ( shaderIdx<=sdl->glsl_program_mb2sc ) |
| 2817 | if ( shaderIdx<=sdl->m_glsl_program_mb2sc ) |
| 2818 | 2818 | { |
| 2819 | 2819 | glBindTexture(texture->texTarget, texture->mpass_texture_mamebm[mpass_src_idx]); |
| 2820 | 2820 | } |
| r243303 | r243304 | |
| 2827 | 2827 | |
| 2828 | 2828 | pfn_glActiveTexture(texture->mpass_textureunit[texture->mpass_dest_idx]); |
| 2829 | 2829 | |
| 2830 | | if ( shaderIdx<sdl->glsl_program_num-1 ) |
| 2830 | if ( shaderIdx<sdl->m_glsl_program_num-1 ) |
| 2831 | 2831 | { |
| 2832 | | if ( shaderIdx>=sdl->glsl_program_mb2sc ) |
| 2832 | if ( shaderIdx>=sdl->m_glsl_program_mb2sc ) |
| 2833 | 2833 | { |
| 2834 | 2834 | glBindTexture(texture->texTarget, texture->mpass_texture_scrn[texture->mpass_dest_idx]); |
| 2835 | 2835 | pfn_glBindFramebuffer(GL_FRAMEBUFFER_EXT, texture->mpass_fbo_scrn[texture->mpass_dest_idx]); |
| r243303 | r243304 | |
| 2846 | 2846 | GL_CHECK_ERROR_NORMAL(); |
| 2847 | 2847 | glViewport(0.0, 0.0, (GLsizei)texture->rawwidth, (GLsizei)texture->rawheight); |
| 2848 | 2848 | } |
| 2849 | | else if ( shaderIdx==sdl->glsl_program_mb2sc ) |
| 2849 | else if ( shaderIdx==sdl->m_glsl_program_mb2sc ) |
| 2850 | 2850 | { |
| 2851 | | assert ( sdl->glsl_program_mb2sc < sdl->glsl_program_num-1 ); |
| 2851 | assert ( sdl->m_glsl_program_mb2sc < sdl->m_glsl_program_num-1 ); |
| 2852 | 2852 | glPopAttrib(); // glViewport(0.0, 0.0, (GLsizei)window->width, (GLsizei)window->height) |
| 2853 | 2853 | GL_CHECK_ERROR_NORMAL(); |
| 2854 | 2854 | } |
| r243303 | r243304 | |
| 2859 | 2859 | glBindTexture(texture->texTarget, 0); |
| 2860 | 2860 | pfn_glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0); |
| 2861 | 2861 | |
| 2862 | | if ( sdl->glsl_program_mb2sc == sdl->glsl_program_num-1 ) |
| 2862 | if ( sdl->m_glsl_program_mb2sc == sdl->m_glsl_program_num-1 ) |
| 2863 | 2863 | { |
| 2864 | 2864 | glPopAttrib(); // glViewport(0.0, 0.0, (GLsizei)window->width, (GLsizei)window->height) |
| 2865 | 2865 | GL_CHECK_ERROR_NORMAL(); |
| r243303 | r243304 | |
| 2905 | 2905 | vid_attributes[2] = settings.brightness; |
| 2906 | 2906 | #endif |
| 2907 | 2907 | vid_attributes[3] = 0.0f; |
| 2908 | | uniform_location = pfn_glGetUniformLocationARB(sdl->glsl_program[shaderIdx], "vid_attributes"); |
| 2908 | uniform_location = pfn_glGetUniformLocationARB(sdl->m_glsl_program[shaderIdx], "vid_attributes"); |
| 2909 | 2909 | pfn_glUniform4fvARB(uniform_location, 1, &(vid_attributes[shaderIdx])); |
| 2910 | 2910 | if ( GL_CHECK_ERROR_QUIET() ) { |
| 2911 | 2911 | osd_printf_verbose("GLSL: could not set 'vid_attributes' for shader prog idx %d\n", shaderIdx); |
| r243303 | r243304 | |
| 2932 | 2932 | { |
| 2933 | 2933 | if ( texture->type == TEXTURE_TYPE_SHADER ) |
| 2934 | 2934 | { |
| 2935 | | pfn_glUseProgramObjectARB(sdl->glsl_program[shaderIdx]); // back to our shader |
| 2935 | pfn_glUseProgramObjectARB(sdl->m_glsl_program[shaderIdx]); // back to our shader |
| 2936 | 2936 | } |
| 2937 | 2937 | else if ( texture->type == TEXTURE_TYPE_DYNAMIC ) |
| 2938 | 2938 | { |
| 2939 | | assert ( sdl->usepbo ) ; |
| 2939 | assert ( sdl->m_usepbo ) ; |
| 2940 | 2940 | pfn_glBindBuffer( GL_PIXEL_UNPACK_BUFFER_ARB, texture->pbo); |
| 2941 | 2941 | glEnable(texture->texTarget); |
| 2942 | 2942 | } |
| r243303 | r243304 | |
| 2951 | 2951 | if ( texture->type == TEXTURE_TYPE_SHADER ) |
| 2952 | 2952 | { |
| 2953 | 2953 | texture_shader_update(window, texture, shaderIdx); |
| 2954 | | if ( sdl->glsl_program_num>1 ) |
| 2954 | if ( sdl->m_glsl_program_num>1 ) |
| 2955 | 2955 | { |
| 2956 | 2956 | texture_mpass_flip(sdl, texture, shaderIdx); |
| 2957 | 2957 | } |
| r243303 | r243304 | |
| 2975 | 2975 | texture_coord_update(window, texture, prim, shaderIdx); |
| 2976 | 2976 | |
| 2977 | 2977 | glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
| 2978 | | if(sdl->usevbo) |
| 2978 | if(sdl->m_usevbo) |
| 2979 | 2979 | { |
| 2980 | 2980 | pfn_glBindBuffer( GL_ARRAY_BUFFER_ARB, texture->texCoordBufferName ); |
| 2981 | 2981 | // Load The Data |
| r243303 | r243304 | |
| 2995 | 2995 | { |
| 2996 | 2996 | if ( texture->type == TEXTURE_TYPE_SHADER ) |
| 2997 | 2997 | { |
| 2998 | | assert ( sdl->useglsl ); |
| 2998 | assert ( sdl->m_useglsl ); |
| 2999 | 2999 | pfn_glUseProgramObjectARB(0); // back to fixed function pipeline |
| 3000 | 3000 | } else if ( texture->type == TEXTURE_TYPE_DYNAMIC ) |
| 3001 | 3001 | { |
| r243303 | r243304 | |
| 3008 | 3008 | |
| 3009 | 3009 | static void texture_all_disable(sdl_info *sdl) |
| 3010 | 3010 | { |
| 3011 | | if ( sdl->useglsl ) |
| 3011 | if ( sdl->m_useglsl ) |
| 3012 | 3012 | { |
| 3013 | 3013 | pfn_glUseProgramObjectARB(0); // back to fixed function pipeline |
| 3014 | 3014 | |
| 3015 | 3015 | pfn_glActiveTexture(GL_TEXTURE3); |
| 3016 | 3016 | glBindTexture(GL_TEXTURE_2D, 0); |
| 3017 | | if ( sdl->usefbo ) pfn_glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0); |
| 3017 | if ( sdl->m_usefbo ) pfn_glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0); |
| 3018 | 3018 | pfn_glActiveTexture(GL_TEXTURE2); |
| 3019 | 3019 | glBindTexture(GL_TEXTURE_2D, 0); |
| 3020 | | if ( sdl->usefbo ) pfn_glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0); |
| 3020 | if ( sdl->m_usefbo ) pfn_glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0); |
| 3021 | 3021 | pfn_glActiveTexture(GL_TEXTURE1); |
| 3022 | 3022 | glBindTexture(GL_TEXTURE_2D, 0); |
| 3023 | | if ( sdl->usefbo ) pfn_glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0); |
| 3023 | if ( sdl->m_usefbo ) pfn_glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0); |
| 3024 | 3024 | pfn_glActiveTexture(GL_TEXTURE0); |
| 3025 | 3025 | glBindTexture(GL_TEXTURE_2D, 0); |
| 3026 | | if ( sdl->usefbo ) pfn_glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0); |
| 3026 | if ( sdl->m_usefbo ) pfn_glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0); |
| 3027 | 3027 | } |
| 3028 | 3028 | glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0); |
| 3029 | 3029 | |
| 3030 | | if(sdl->usetexturerect) |
| 3030 | if(sdl->m_usetexturerect) |
| 3031 | 3031 | { |
| 3032 | 3032 | glDisable(GL_TEXTURE_RECTANGLE_ARB); |
| 3033 | 3033 | } |
| 3034 | 3034 | glDisable(GL_TEXTURE_2D); |
| 3035 | 3035 | |
| 3036 | 3036 | glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
| 3037 | | if(sdl->usevbo) |
| 3037 | if(sdl->m_usevbo) |
| 3038 | 3038 | { |
| 3039 | 3039 | pfn_glBindBuffer( GL_ARRAY_BUFFER_ARB, 0); // unbind .. |
| 3040 | 3040 | } |
| 3041 | | if ( sdl->usepbo ) |
| 3041 | if ( sdl->m_usepbo ) |
| 3042 | 3042 | { |
| 3043 | 3043 | pfn_glBindBuffer( GL_PIXEL_UNPACK_BUFFER_ARB, 0); |
| 3044 | 3044 | } |
| r243303 | r243304 | |
| 3054 | 3054 | if (sdl == NULL) |
| 3055 | 3055 | return; |
| 3056 | 3056 | |
| 3057 | | if ( !sdl->initialized ) |
| 3057 | if ( !sdl->m_initialized ) |
| 3058 | 3058 | return; |
| 3059 | 3059 | |
| 3060 | 3060 | #if (SDLMAME_SDL2) |
| 3061 | | SDL_GL_MakeCurrent(window->m_sdl_window, sdl->gl_context_id); |
| 3061 | SDL_GL_MakeCurrent(window->m_sdl_window, sdl->m_gl_context_id); |
| 3062 | 3062 | #endif |
| 3063 | 3063 | |
| 3064 | 3064 | if(window->m_primlist) |
| r243303 | r243304 | |
| 3076 | 3076 | i=0; |
| 3077 | 3077 | while (i<HASH_SIZE+OVERFLOW_SIZE) |
| 3078 | 3078 | { |
| 3079 | | texture = sdl->texhash[i]; |
| 3080 | | sdl->texhash[i] = NULL; |
| 3079 | texture = sdl->m_texhash[i]; |
| 3080 | sdl->m_texhash[i] = NULL; |
| 3081 | 3081 | if (texture != NULL) |
| 3082 | 3082 | { |
| 3083 | | if(sdl->usevbo) |
| 3083 | if(sdl->m_usevbo) |
| 3084 | 3084 | { |
| 3085 | 3085 | pfn_glDeleteBuffers( 1, &(texture->texCoordBufferName) ); |
| 3086 | 3086 | texture->texCoordBufferName=0; |
| 3087 | 3087 | } |
| 3088 | 3088 | |
| 3089 | | if(sdl->usepbo && texture->pbo) |
| 3089 | if(sdl->m_usepbo && texture->pbo) |
| 3090 | 3090 | { |
| 3091 | 3091 | pfn_glDeleteBuffers( 1, (GLuint *)&(texture->pbo) ); |
| 3092 | 3092 | texture->pbo=0; |
| 3093 | 3093 | } |
| 3094 | 3094 | |
| 3095 | | if( sdl->glsl_program_num > 1 ) |
| 3095 | if( sdl->m_glsl_program_num > 1 ) |
| 3096 | 3096 | { |
| 3097 | | assert(sdl->usefbo); |
| 3097 | assert(sdl->m_usefbo); |
| 3098 | 3098 | pfn_glDeleteFramebuffers(2, (GLuint *)&texture->mpass_fbo_mamebm[0]); |
| 3099 | 3099 | glDeleteTextures(2, (GLuint *)&texture->mpass_texture_mamebm[0]); |
| 3100 | 3100 | } |
| 3101 | 3101 | |
| 3102 | | if ( sdl->glsl_program_mb2sc < sdl->glsl_program_num - 1 ) |
| 3102 | if ( sdl->m_glsl_program_mb2sc < sdl->m_glsl_program_num - 1 ) |
| 3103 | 3103 | { |
| 3104 | | assert(sdl->usefbo); |
| 3104 | assert(sdl->m_usefbo); |
| 3105 | 3105 | pfn_glDeleteFramebuffers(2, (GLuint *)&texture->mpass_fbo_scrn[0]); |
| 3106 | 3106 | glDeleteTextures(2, (GLuint *)&texture->mpass_texture_scrn[0]); |
| 3107 | 3107 | } |
| r243303 | r243304 | |
| 3117 | 3117 | } |
| 3118 | 3118 | i++; |
| 3119 | 3119 | } |
| 3120 | | if ( sdl->useglsl ) |
| 3120 | if ( sdl->m_useglsl ) |
| 3121 | 3121 | { |
| 3122 | | glsl_shader_free(sdl->glsl); |
| 3123 | | sdl->glsl = NULL; |
| 3122 | glsl_shader_free(sdl->m_glsl); |
| 3123 | sdl->m_glsl = NULL; |
| 3124 | 3124 | } |
| 3125 | 3125 | |
| 3126 | | sdl->initialized = 0; |
| 3126 | sdl->m_initialized = 0; |
| 3127 | 3127 | |
| 3128 | 3128 | if (lock) |
| 3129 | 3129 | window->m_primlist->release_lock(); |
| r243303 | r243304 | |
| 3138 | 3138 | sdl_info *sdl = (sdl_info *) window->m_dxdata; |
| 3139 | 3139 | |
| 3140 | 3140 | //FIXME: Handled in drawogl_window_draw as well |
| 3141 | | sdl->blittimer = 3; |
| 3141 | sdl->m_blittimer = 3; |
| 3142 | 3142 | } |
trunk/src/osd/sdl/drawsdl.c
| r243303 | r243304 | |
| 48 | 48 | /* sdl_info is the information about SDL for the current screen */ |
| 49 | 49 | struct sdl_info |
| 50 | 50 | { |
| 51 | | INT32 blittimer; |
| 52 | | UINT32 extra_flags; |
| 51 | INT32 m_blittimer; |
| 52 | UINT32 m_extra_flags; |
| 53 | 53 | |
| 54 | 54 | #if (SDLMAME_SDL2) |
| 55 | | SDL_Renderer *sdl_renderer; |
| 56 | | SDL_Texture *texture_id; |
| 55 | SDL_Renderer *m_sdl_renderer; |
| 56 | SDL_Texture *m_texture_id; |
| 57 | 57 | #else |
| 58 | 58 | // SDL surface |
| 59 | | SDL_Surface *sdlsurf; |
| 60 | | SDL_Overlay *yuvsurf; |
| 59 | SDL_Surface *m_sdlsurf; |
| 60 | SDL_Overlay *m_yuvsurf; |
| 61 | 61 | #endif |
| 62 | 62 | |
| 63 | 63 | // YUV overlay |
| 64 | | UINT32 *yuv_lookup; |
| 65 | | UINT16 *yuv_bitmap; |
| 64 | UINT32 *m_yuv_lookup; |
| 65 | UINT16 *m_yuv_bitmap; |
| 66 | 66 | |
| 67 | 67 | // if we leave scaling to SDL and the underlying driver, this |
| 68 | 68 | // is the render_target_width/height to use |
| 69 | 69 | |
| 70 | | int hw_scale_width; |
| 71 | | int hw_scale_height; |
| 72 | | int last_hofs; |
| 73 | | int last_vofs; |
| 74 | | int old_blitwidth; |
| 75 | | int old_blitheight; |
| 70 | int m_hw_scale_width; |
| 71 | int m_hw_scale_height; |
| 72 | int m_last_hofs; |
| 73 | int m_last_vofs; |
| 74 | int m_old_blitwidth; |
| 75 | int m_old_blitheight; |
| 76 | 76 | }; |
| 77 | 77 | |
| 78 | 78 | struct sdl_scale_mode |
| r243303 | r243304 | |
| 83 | 83 | int mult_w; /* Width multiplier */ |
| 84 | 84 | int mult_h; /* Height multiplier */ |
| 85 | 85 | #if (!SDLMAME_SDL2) |
| 86 | | int extra_flags; /* Texture/surface flags */ |
| 86 | int m_extra_flags; /* Texture/surface flags */ |
| 87 | 87 | #else |
| 88 | 88 | const char *sdl_scale_mode; /* what to use as a hint ? */ |
| 89 | 89 | #endif |
| r243303 | r243304 | |
| 253 | 253 | // Determine preferred pixelformat and set up yuv if necessary |
| 254 | 254 | SDL_GetCurrentDisplayMode(window->monitor()->handle(), &mode); |
| 255 | 255 | |
| 256 | | if (sdl->yuv_bitmap) |
| 256 | if (sdl->m_yuv_bitmap) |
| 257 | 257 | { |
| 258 | | global_free_array(sdl->yuv_bitmap); |
| 259 | | sdl->yuv_bitmap = NULL; |
| 258 | global_free_array(sdl->m_yuv_bitmap); |
| 259 | sdl->m_yuv_bitmap = NULL; |
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | if (sdl_sm->is_scale) |
| 263 | 263 | { |
| 264 | | window->m_target->compute_minimum_size(sdl->hw_scale_width, sdl->hw_scale_height); |
| 264 | window->m_target->compute_minimum_size(sdl->m_hw_scale_width, sdl->m_hw_scale_height); |
| 265 | 265 | if (video_config.prescale) |
| 266 | 266 | { |
| 267 | | sdl->hw_scale_width *= video_config.prescale; |
| 268 | | sdl->hw_scale_height *= video_config.prescale; |
| 267 | sdl->m_hw_scale_width *= video_config.prescale; |
| 268 | sdl->m_hw_scale_height *= video_config.prescale; |
| 269 | 269 | |
| 270 | 270 | /* This must be a multiple of 2 */ |
| 271 | | sdl->hw_scale_width = (sdl->hw_scale_width + 1) & ~1; |
| 271 | sdl->m_hw_scale_width = (sdl->m_hw_scale_width + 1) & ~1; |
| 272 | 272 | } |
| 273 | 273 | } |
| 274 | 274 | |
| 275 | 275 | if (sdl_sm->is_yuv) |
| 276 | | sdl->yuv_bitmap = global_alloc_array(UINT16, sdl->hw_scale_width * sdl->hw_scale_height); |
| 276 | sdl->m_yuv_bitmap = global_alloc_array(UINT16, sdl->m_hw_scale_width * sdl->m_hw_scale_height); |
| 277 | 277 | |
| 278 | 278 | fmt = (sdl_sm->pixel_format ? sdl_sm->pixel_format : mode.format); |
| 279 | 279 | |
| 280 | 280 | if (sdl_sm->is_scale) |
| 281 | 281 | { |
| 282 | | int w = sdl->hw_scale_width * sdl_sm->mult_w; |
| 283 | | int h = sdl->hw_scale_height * sdl_sm->mult_h; |
| 282 | int w = sdl->m_hw_scale_width * sdl_sm->mult_w; |
| 283 | int h = sdl->m_hw_scale_height * sdl_sm->mult_h; |
| 284 | 284 | |
| 285 | | sdl->texture_id = SDL_CreateTexture(sdl->sdl_renderer, fmt, SDL_TEXTUREACCESS_STREAMING, w, h); |
| 285 | sdl->m_texture_id = SDL_CreateTexture(sdl->m_sdl_renderer, fmt, SDL_TEXTUREACCESS_STREAMING, w, h); |
| 286 | 286 | |
| 287 | 287 | } |
| 288 | 288 | else |
| 289 | 289 | { |
| 290 | | sdl->texture_id = SDL_CreateTexture(sdl->sdl_renderer,fmt, SDL_TEXTUREACCESS_STREAMING, |
| 290 | sdl->m_texture_id = SDL_CreateTexture(sdl->m_sdl_renderer,fmt, SDL_TEXTUREACCESS_STREAMING, |
| 291 | 291 | tempwidth, tempheight); |
| 292 | 292 | } |
| 293 | 293 | } |
| r243303 | r243304 | |
| 318 | 318 | sdl->yuvsurf = NULL; |
| 319 | 319 | } |
| 320 | 320 | |
| 321 | | if (sdl->yuv_bitmap != NULL) |
| 321 | if (sdl->m_yuv_bitmap != NULL) |
| 322 | 322 | { |
| 323 | | global_free_array(sdl->yuv_bitmap); |
| 323 | global_free_array(sdl->m_yuv_bitmap); |
| 324 | 324 | } |
| 325 | 325 | |
| 326 | 326 | osd_printf_verbose("SDL: Creating %d x %d YUV-Overlay ...\n", minimum_width, minimum_height); |
| 327 | 327 | |
| 328 | | sdl->yuv_bitmap = global_alloc_array(UINT16, minimum_width*minimum_height); |
| 328 | sdl->m_yuv_bitmap = global_alloc_array(UINT16, minimum_width*minimum_height); |
| 329 | 329 | |
| 330 | 330 | sdl->yuvsurf = SDL_CreateYUVOverlay(minimum_width * sdl_sm->mult_w, minimum_height * sdl_sm->mult_h, |
| 331 | 331 | sdl_sm->pixel_format, sdl->sdlsurf); |
| r243303 | r243304 | |
| 335 | 335 | //return 1; |
| 336 | 336 | } |
| 337 | 337 | |
| 338 | | sdl->hw_scale_width = minimum_width; |
| 339 | | sdl->hw_scale_height = minimum_height; |
| 338 | sdl->m_hw_scale_width = minimum_width; |
| 339 | sdl->m_hw_scale_height = minimum_height; |
| 340 | 340 | |
| 341 | 341 | if (!shown_video_info) |
| 342 | 342 | { |
| r243303 | r243304 | |
| 402 | 402 | |
| 403 | 403 | SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, sm->sdl_scale_mode); |
| 404 | 404 | |
| 405 | | sdl->extra_flags = (window->fullscreen() ? |
| 405 | sdl->m_extra_flags = (window->fullscreen() ? |
| 406 | 406 | SDL_WINDOW_BORDERLESS | SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_MOUSE_FOCUS |
| 407 | 407 | | SDL_WINDOW_INPUT_GRABBED : SDL_WINDOW_RESIZABLE); |
| 408 | 408 | |
| 409 | 409 | window->m_sdl_window = SDL_CreateWindow(window->m_title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, |
| 410 | | width, height, sdl->extra_flags); |
| 410 | width, height, sdl->m_extra_flags); |
| 411 | 411 | |
| 412 | 412 | if (window->fullscreen() && video_config.switchres) |
| 413 | 413 | { |
| r243303 | r243304 | |
| 435 | 435 | // create a texture |
| 436 | 436 | |
| 437 | 437 | if (video_config.waitvsync) |
| 438 | | sdl->sdl_renderer = SDL_CreateRenderer(window->m_sdl_window, -1, /*SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTDISCARD |*/ SDL_RENDERER_PRESENTVSYNC); |
| 438 | sdl->m_sdl_renderer = SDL_CreateRenderer(window->m_sdl_window, -1, /*SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTDISCARD |*/ SDL_RENDERER_PRESENTVSYNC); |
| 439 | 439 | else |
| 440 | | sdl->sdl_renderer = SDL_CreateRenderer(window->m_sdl_window, -1, /*SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTDISCARD*/ 0); |
| 440 | sdl->m_sdl_renderer = SDL_CreateRenderer(window->m_sdl_window, -1, /*SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTDISCARD*/ 0); |
| 441 | 441 | |
| 442 | 442 | //SDL_SelectRenderer(window->sdl_window); |
| 443 | 443 | |
| 444 | 444 | { |
| 445 | 445 | struct SDL_RendererInfo render_info; |
| 446 | 446 | |
| 447 | | SDL_GetRendererInfo(sdl->sdl_renderer, &render_info); |
| 447 | SDL_GetRendererInfo(sdl->m_sdl_renderer, &render_info); |
| 448 | 448 | drawsdl_show_info(window, &render_info); |
| 449 | 449 | |
| 450 | 450 | // Check scale mode |
| r243303 | r243304 | |
| 467 | 467 | |
| 468 | 468 | setup_texture(window, width, height); |
| 469 | 469 | #else |
| 470 | | sdl->extra_flags = (window->fullscreen() ? SDL_FULLSCREEN : SDL_RESIZABLE); |
| 470 | sdl->m_extra_flags = (window->fullscreen() ? SDL_FULLSCREEN : SDL_RESIZABLE); |
| 471 | 471 | |
| 472 | | sdl->extra_flags |= sm->extra_flags; |
| 472 | sdl->m_extra_flags |= sm->m_extra_flags; |
| 473 | 473 | |
| 474 | 474 | sdl->sdlsurf = SDL_SetVideoMode(m_width, m_height, |
| 475 | | 0, SDL_SWSURFACE | SDL_ANYFORMAT | sdl->extra_flags); |
| 475 | 0, SDL_SWSURFACE | SDL_ANYFORMAT | sdl->m_extra_flags); |
| 476 | 476 | |
| 477 | 477 | if (!sdl->sdlsurf) |
| 478 | 478 | return 1; |
| r243303 | r243304 | |
| 486 | 486 | // set the window title |
| 487 | 487 | SDL_WM_SetCaption(window->m_title, "SDLMAME"); |
| 488 | 488 | #endif |
| 489 | | sdl->yuv_lookup = NULL; |
| 490 | | sdl->blittimer = 0; |
| 489 | sdl->m_yuv_lookup = NULL; |
| 490 | sdl->m_blittimer = 0; |
| 491 | 491 | |
| 492 | 492 | drawsdl_yuv_init(sdl); |
| 493 | 493 | return 0; |
| r243303 | r243304 | |
| 518 | 518 | //printf("SetVideoMode %d %d\n", wp->resize_new_width, wp->resize_new_height); |
| 519 | 519 | |
| 520 | 520 | sdl->sdlsurf = SDL_SetVideoMode(m_width, m_height, 0, |
| 521 | | SDL_SWSURFACE | SDL_ANYFORMAT | sdl->extra_flags); |
| 521 | SDL_SWSURFACE | SDL_ANYFORMAT | sdl->m_extra_flags); |
| 522 | 522 | window->m_width = sdl->sdlsurf->w; |
| 523 | 523 | window->m_height = sdl->sdlsurf->h; |
| 524 | 524 | |
| r243303 | r243304 | |
| 545 | 545 | |
| 546 | 546 | #if (SDLMAME_SDL2) |
| 547 | 547 | //SDL_SelectRenderer(window->sdl_window); |
| 548 | | SDL_DestroyTexture(sdl->texture_id); |
| 548 | SDL_DestroyTexture(sdl->m_texture_id); |
| 549 | 549 | //SDL_DestroyRenderer(window->sdl_window); |
| 550 | 550 | SDL_DestroyWindow(window->m_sdl_window); |
| 551 | 551 | #else |
| r243303 | r243304 | |
| 563 | 563 | #endif |
| 564 | 564 | // free the memory in the window |
| 565 | 565 | |
| 566 | | if (sdl->yuv_lookup != NULL) |
| 566 | if (sdl->m_yuv_lookup != NULL) |
| 567 | 567 | { |
| 568 | | global_free_array(sdl->yuv_lookup); |
| 569 | | sdl->yuv_lookup = NULL; |
| 568 | global_free_array(sdl->m_yuv_lookup); |
| 569 | sdl->m_yuv_lookup = NULL; |
| 570 | 570 | } |
| 571 | | if (sdl->yuv_bitmap != NULL) |
| 571 | if (sdl->m_yuv_bitmap != NULL) |
| 572 | 572 | { |
| 573 | | global_free_array(sdl->yuv_bitmap); |
| 574 | | sdl->yuv_bitmap = NULL; |
| 573 | global_free_array(sdl->m_yuv_bitmap); |
| 574 | sdl->m_yuv_bitmap = NULL; |
| 575 | 575 | } |
| 576 | 576 | osd_free(sdl); |
| 577 | 577 | window->m_dxdata = NULL; |
| r243303 | r243304 | |
| 585 | 585 | { |
| 586 | 586 | sdl_info *sdl = (sdl_info *) window->m_dxdata; |
| 587 | 587 | |
| 588 | | sdl->blittimer = 3; |
| 588 | sdl->m_blittimer = 3; |
| 589 | 589 | } |
| 590 | 590 | |
| 591 | 591 | //============================================================ |
| r243303 | r243304 | |
| 597 | 597 | sdl_info *sdl = (sdl_info *) window->m_dxdata; |
| 598 | 598 | const sdl_scale_mode *sm = &scale_modes[video_config.scale_mode]; |
| 599 | 599 | |
| 600 | | *xt = x - sdl->last_hofs; |
| 601 | | *yt = y - sdl->last_vofs; |
| 600 | *xt = x - sdl->m_last_hofs; |
| 601 | *yt = y - sdl->m_last_vofs; |
| 602 | 602 | if (*xt<0 || *xt >= window->m_blitwidth) |
| 603 | 603 | return 0; |
| 604 | 604 | if (*yt<0 || *xt >= window->m_blitheight) |
| r243303 | r243304 | |
| 608 | 608 | return 1; |
| 609 | 609 | } |
| 610 | 610 | /* Rescale */ |
| 611 | | *xt = (*xt * sdl->hw_scale_width) / window->m_blitwidth; |
| 612 | | *yt = (*yt * sdl->hw_scale_height) / window->m_blitheight; |
| 611 | *xt = (*xt * sdl->m_hw_scale_width) / window->m_blitwidth; |
| 612 | *yt = (*yt * sdl->m_hw_scale_height) / window->m_blitheight; |
| 613 | 613 | return 1; |
| 614 | 614 | } |
| 615 | 615 | |
| r243303 | r243304 | |
| 625 | 625 | if (!sm->is_scale) |
| 626 | 626 | window->m_target->set_bounds(window->m_blitwidth, window->m_blitheight, window->monitor()->aspect()); |
| 627 | 627 | else |
| 628 | | window->m_target->set_bounds(sdl->hw_scale_width, sdl->hw_scale_height); |
| 628 | window->m_target->set_bounds(sdl->m_hw_scale_width, sdl->m_hw_scale_height); |
| 629 | 629 | } |
| 630 | 630 | |
| 631 | 631 | //============================================================ |
| r243303 | r243304 | |
| 664 | 664 | bmask = sdl->sdlsurf->format->Bmask; |
| 665 | 665 | // amask = sdl->sdlsurf->format->Amask; |
| 666 | 666 | |
| 667 | | if (window->m_blitwidth != sdl->old_blitwidth || window->m_blitheight != sdl->old_blitheight) |
| 667 | if (window->m_blitwidth != sdl->m_old_blitwidth || window->m_blitheight != sdl->m_old_blitheight) |
| 668 | 668 | { |
| 669 | 669 | if (sm->is_yuv) |
| 670 | 670 | yuv_overlay_init(window); |
| 671 | | sdl->old_blitwidth = window->m_blitwidth; |
| 672 | | sdl->old_blitheight = window->m_blitheight; |
| 673 | | sdl->blittimer = 3; |
| 671 | sdl->m_old_blitwidth = window->m_blitwidth; |
| 672 | sdl->m_old_blitheight = window->m_blitheight; |
| 673 | sdl->m_blittimer = 3; |
| 674 | 674 | } |
| 675 | 675 | |
| 676 | 676 | if (SDL_MUSTLOCK(sdl->sdlsurf)) SDL_LockSurface(sdl->sdlsurf); |
| 677 | 677 | // Clear if necessary |
| 678 | 678 | |
| 679 | | if (sdl->blittimer > 0) |
| 679 | if (sdl->m_blittimer > 0) |
| 680 | 680 | { |
| 681 | 681 | memset(sdl->sdlsurf->pixels, 0, window->m_height * sdl->sdlsurf->pitch); |
| 682 | | sdl->blittimer--; |
| 682 | sdl->m_blittimer--; |
| 683 | 683 | } |
| 684 | 684 | |
| 685 | 685 | |
| 686 | 686 | if (sm->is_yuv) |
| 687 | 687 | { |
| 688 | 688 | SDL_LockYUVOverlay(sdl->yuvsurf); |
| 689 | | surfptr = sdl->yuvsurf->pixels[0]; // (UINT8 *) sdl->yuv_bitmap; |
| 690 | | pitch = sdl->yuvsurf->pitches[0]; // (UINT8 *) sdl->yuv_bitmap; |
| 689 | surfptr = sdl->yuvsurf->pixels[0]; // (UINT8 *) sdl->m_yuv_bitmap; |
| 690 | pitch = sdl->yuvsurf->pitches[0]; // (UINT8 *) sdl->m_yuv_bitmap; |
| 691 | 691 | } |
| 692 | 692 | else |
| 693 | 693 | surfptr = (UINT8 *)sdl->sdlsurf->pixels; |
| 694 | 694 | #else |
| 695 | 695 | //SDL_SelectRenderer(window->sdl_window); |
| 696 | 696 | |
| 697 | | if (window->m_blitwidth != sdl->old_blitwidth || window->m_blitheight != sdl->old_blitheight) |
| 697 | if (window->m_blitwidth != sdl->m_old_blitwidth || window->m_blitheight != sdl->m_old_blitheight) |
| 698 | 698 | { |
| 699 | | SDL_RenderSetViewport(sdl->sdl_renderer, NULL); |
| 699 | SDL_RenderSetViewport(sdl->m_sdl_renderer, NULL); |
| 700 | 700 | |
| 701 | | SDL_DestroyTexture(sdl->texture_id); |
| 701 | SDL_DestroyTexture(sdl->m_texture_id); |
| 702 | 702 | setup_texture(window, window->m_blitwidth, window->m_blitheight); |
| 703 | | sdl->old_blitwidth = window->m_blitwidth; |
| 704 | | sdl->old_blitheight = window->m_blitheight; |
| 705 | | sdl->blittimer = 3; |
| 703 | sdl->m_old_blitwidth = window->m_blitwidth; |
| 704 | sdl->m_old_blitheight = window->m_blitheight; |
| 705 | sdl->m_blittimer = 3; |
| 706 | 706 | } |
| 707 | 707 | |
| 708 | 708 | { |
| 709 | 709 | Uint32 format; |
| 710 | 710 | int access, w, h; |
| 711 | 711 | |
| 712 | | SDL_QueryTexture(sdl->texture_id, &format, &access, &w, &h); |
| 712 | SDL_QueryTexture(sdl->m_texture_id, &format, &access, &w, &h); |
| 713 | 713 | SDL_PixelFormatEnumToMasks(format, &bpp, &rmask, &gmask, &bmask, &amask); |
| 714 | 714 | bpp = bpp / 8; /* convert to bytes per pixels */ |
| 715 | 715 | } |
| 716 | 716 | |
| 717 | 717 | // Clear if necessary |
| 718 | | if (sdl->blittimer > 0) |
| 718 | if (sdl->m_blittimer > 0) |
| 719 | 719 | { |
| 720 | 720 | /* SDL Underlays need alpha = 0 ! */ |
| 721 | | SDL_SetRenderDrawColor(sdl->sdl_renderer,0,0,0,0); |
| 722 | | SDL_RenderFillRect(sdl->sdl_renderer,NULL); |
| 721 | SDL_SetRenderDrawColor(sdl->m_sdl_renderer,0,0,0,0); |
| 722 | SDL_RenderFillRect(sdl->m_sdl_renderer,NULL); |
| 723 | 723 | //SDL_RenderFill(0,0,0,0 /*255*/,NULL); |
| 724 | | sdl->blittimer--; |
| 724 | sdl->m_blittimer--; |
| 725 | 725 | } |
| 726 | 726 | |
| 727 | | SDL_LockTexture(sdl->texture_id, NULL, (void **) &surfptr, &pitch); |
| 727 | SDL_LockTexture(sdl->m_texture_id, NULL, (void **) &surfptr, &pitch); |
| 728 | 728 | |
| 729 | 729 | #endif |
| 730 | 730 | // get ready to center the image |
| r243303 | r243304 | |
| 765 | 765 | hofs = (cw - window->m_blitwidth) / 2; |
| 766 | 766 | } |
| 767 | 767 | |
| 768 | | sdl->last_hofs = hofs; |
| 769 | | sdl->last_vofs = vofs; |
| 768 | sdl->m_last_hofs = hofs; |
| 769 | sdl->m_last_vofs = vofs; |
| 770 | 770 | |
| 771 | 771 | window->m_primlist->acquire_lock(); |
| 772 | 772 | |
| r243303 | r243304 | |
| 785 | 785 | } |
| 786 | 786 | else |
| 787 | 787 | { |
| 788 | | mamewidth = sdl->hw_scale_width; |
| 789 | | mameheight = sdl->hw_scale_height; |
| 788 | mamewidth = sdl->m_hw_scale_width; |
| 789 | mameheight = sdl->m_hw_scale_height; |
| 790 | 790 | } |
| 791 | 791 | switch (rmask) |
| 792 | 792 | { |
| r243303 | r243304 | |
| 817 | 817 | } |
| 818 | 818 | else |
| 819 | 819 | { |
| 820 | | assert (sdl->yuv_bitmap != NULL); |
| 820 | assert (sdl->m_yuv_bitmap != NULL); |
| 821 | 821 | assert (surfptr != NULL); |
| 822 | | software_renderer<UINT16, 3,3,3, 10,5,0>::draw_primitives(*window->m_primlist, sdl->yuv_bitmap, sdl->hw_scale_width, sdl->hw_scale_height, sdl->hw_scale_width); |
| 823 | | sm->yuv_blit((UINT16 *)sdl->yuv_bitmap, sdl, surfptr, pitch); |
| 822 | software_renderer<UINT16, 3,3,3, 10,5,0>::draw_primitives(*window->m_primlist, sdl->m_yuv_bitmap, sdl->m_hw_scale_width, sdl->m_hw_scale_height, sdl->m_hw_scale_width); |
| 823 | sm->yuv_blit((UINT16 *)sdl->m_yuv_bitmap, sdl, surfptr, pitch); |
| 824 | 824 | } |
| 825 | 825 | |
| 826 | 826 | window->m_primlist->release_lock(); |
| r243303 | r243304 | |
| 844 | 844 | SDL_DisplayYUVOverlay(sdl->yuvsurf, &r); |
| 845 | 845 | } |
| 846 | 846 | #else |
| 847 | | SDL_UnlockTexture(sdl->texture_id); |
| 847 | SDL_UnlockTexture(sdl->m_texture_id); |
| 848 | 848 | { |
| 849 | 849 | SDL_Rect r; |
| 850 | 850 | |
| r243303 | r243304 | |
| 854 | 854 | r.h=blitheight; |
| 855 | 855 | //printf("blitwidth %d %d - %d %d\n", blitwidth, blitheight, window->width, window->height); |
| 856 | 856 | //SDL_UpdateTexture(sdl->sdltex, NULL, sdl->sdlsurf->pixels, pitch); |
| 857 | | SDL_RenderCopy(sdl->sdl_renderer,sdl->texture_id, NULL, &r); |
| 858 | | SDL_RenderPresent(sdl->sdl_renderer); |
| 857 | SDL_RenderCopy(sdl->m_sdl_renderer,sdl->m_texture_id, NULL, &r); |
| 858 | SDL_RenderPresent(sdl->m_sdl_renderer); |
| 859 | 859 | } |
| 860 | 860 | #endif |
| 861 | 861 | return 0; |
| r243303 | r243304 | |
| 910 | 910 | |
| 911 | 911 | /* Storing this data in YUYV order simplifies using the data for |
| 912 | 912 | YUY2, both with and without smoothing... */ |
| 913 | | sdl->yuv_lookup[pen]=(y<<Y1SHIFT)|(u<<USHIFT)|(y<<Y2SHIFT)|(v<<VSHIFT); |
| 913 | sdl->m_yuv_lookup[pen]=(y<<Y1SHIFT)|(u<<USHIFT)|(y<<Y2SHIFT)|(v<<VSHIFT); |
| 914 | 914 | } |
| 915 | 915 | |
| 916 | 916 | static void drawsdl_yuv_init(sdl_info *sdl) |
| 917 | 917 | { |
| 918 | 918 | unsigned char r,g,b; |
| 919 | | if (sdl->yuv_lookup == NULL) |
| 920 | | sdl->yuv_lookup = global_alloc_array(UINT32, 65536); |
| 919 | if (sdl->m_yuv_lookup == NULL) |
| 920 | sdl->m_yuv_lookup = global_alloc_array(UINT32, 65536); |
| 921 | 921 | for (r = 0; r < 32; r++) |
| 922 | 922 | for (g = 0; g < 32; g++) |
| 923 | 923 | for (b = 0; b < 32; b++) |
| r243303 | r243304 | |
| 938 | 938 | UINT8 *dest_v; |
| 939 | 939 | UINT16 *src; |
| 940 | 940 | UINT16 *src2; |
| 941 | | UINT32 *lookup = sdl->yuv_lookup; |
| 941 | UINT32 *lookup = sdl->m_yuv_lookup; |
| 942 | 942 | UINT8 *pixels[3]; |
| 943 | 943 | int u1,v1,y1,u2,v2,y2,u3,v3,y3,u4,v4,y4; /* 12 */ |
| 944 | 944 | |
| 945 | 945 | pixels[0] = ptr; |
| 946 | | pixels[1] = ptr + pitch * sdl->hw_scale_height; |
| 947 | | pixels[2] = pixels[1] + pitch * sdl->hw_scale_height / 4; |
| 946 | pixels[1] = ptr + pitch * sdl->m_hw_scale_height; |
| 947 | pixels[2] = pixels[1] + pitch * sdl->m_hw_scale_height / 4; |
| 948 | 948 | |
| 949 | | for(y=0;y<sdl->hw_scale_height;y+=2) |
| 949 | for(y=0;y<sdl->m_hw_scale_height;y+=2) |
| 950 | 950 | { |
| 951 | | src=bitmap + (y * sdl->hw_scale_width) ; |
| 952 | | src2=src + sdl->hw_scale_width; |
| 951 | src=bitmap + (y * sdl->m_hw_scale_width) ; |
| 952 | src2=src + sdl->m_hw_scale_width; |
| 953 | 953 | |
| 954 | 954 | dest_y = pixels[0] + y * pitch; |
| 955 | 955 | dest_v = pixels[1] + (y>>1) * pitch / 2; |
| 956 | 956 | dest_u = pixels[2] + (y>>1) * pitch / 2; |
| 957 | 957 | |
| 958 | | for(x=0;x<sdl->hw_scale_width;x+=2) |
| 958 | for(x=0;x<sdl->m_hw_scale_width;x+=2) |
| 959 | 959 | { |
| 960 | 960 | v1 = lookup[src[x]]; |
| 961 | 961 | y1 = (v1>>Y1SHIFT) & 0xff; |
| r243303 | r243304 | |
| 1001 | 1001 | UINT8 *pixels[3]; |
| 1002 | 1002 | |
| 1003 | 1003 | pixels[0] = ptr; |
| 1004 | | pixels[1] = ptr + pitch * sdl->hw_scale_height * 2; |
| 1005 | | pixels[2] = pixels[1] + pitch * sdl->hw_scale_height / 2; |
| 1004 | pixels[1] = ptr + pitch * sdl->m_hw_scale_height * 2; |
| 1005 | pixels[2] = pixels[1] + pitch * sdl->m_hw_scale_height / 2; |
| 1006 | 1006 | |
| 1007 | | for(y=0;y<sdl->hw_scale_height;y++) |
| 1007 | for(y=0;y<sdl->m_hw_scale_height;y++) |
| 1008 | 1008 | { |
| 1009 | | src = bitmap + (y * sdl->hw_scale_width) ; |
| 1009 | src = bitmap + (y * sdl->m_hw_scale_width) ; |
| 1010 | 1010 | |
| 1011 | 1011 | dest_y = (UINT16 *)(pixels[0] + 2 * y * pitch); |
| 1012 | 1012 | dest_v = pixels[1] + y * pitch / 2; |
| 1013 | 1013 | dest_u = pixels[2] + y * pitch / 2; |
| 1014 | | for(x=0;x<sdl->hw_scale_width;x++) |
| 1014 | for(x=0;x<sdl->m_hw_scale_width;x++) |
| 1015 | 1015 | { |
| 1016 | | v1 = sdl->yuv_lookup[src[x]]; |
| 1016 | v1 = sdl->m_yuv_lookup[src[x]]; |
| 1017 | 1017 | y1 = (v1 >> Y1SHIFT) & 0xff; |
| 1018 | 1018 | u1 = (v1 >> USHIFT) & 0xff; |
| 1019 | 1019 | v1 = (v1 >> VSHIFT) & 0xff; |
| r243303 | r243304 | |
| 1034 | 1034 | UINT16 *src; |
| 1035 | 1035 | UINT16 *end; |
| 1036 | 1036 | UINT32 p1,p2,uv; |
| 1037 | | UINT32 *lookup = sdl->yuv_lookup; |
| 1037 | UINT32 *lookup = sdl->m_yuv_lookup; |
| 1038 | 1038 | int yuv_pitch = pitch/4; |
| 1039 | 1039 | |
| 1040 | | for(y=0;y<sdl->hw_scale_height;y++) |
| 1040 | for(y=0;y<sdl->m_hw_scale_height;y++) |
| 1041 | 1041 | { |
| 1042 | | src=bitmap + (y * sdl->hw_scale_width) ; |
| 1043 | | end=src+sdl->hw_scale_width; |
| 1042 | src=bitmap + (y * sdl->m_hw_scale_width) ; |
| 1043 | end=src+sdl->m_hw_scale_width; |
| 1044 | 1044 | |
| 1045 | 1045 | dest = (UINT32 *) ptr; |
| 1046 | 1046 | dest += y * yuv_pitch; |
| r243303 | r243304 | |
| 1062 | 1062 | UINT32 *dest; |
| 1063 | 1063 | UINT16 *src; |
| 1064 | 1064 | UINT16 *end; |
| 1065 | | UINT32 *lookup = sdl->yuv_lookup; |
| 1065 | UINT32 *lookup = sdl->m_yuv_lookup; |
| 1066 | 1066 | int yuv_pitch = pitch / 4; |
| 1067 | 1067 | |
| 1068 | | for(y=0;y<sdl->hw_scale_height;y++) |
| 1068 | for(y=0;y<sdl->m_hw_scale_height;y++) |
| 1069 | 1069 | { |
| 1070 | | src=bitmap + (y * sdl->hw_scale_width) ; |
| 1071 | | end=src+sdl->hw_scale_width; |
| 1070 | src=bitmap + (y * sdl->m_hw_scale_width) ; |
| 1071 | end=src+sdl->m_hw_scale_width; |
| 1072 | 1072 | |
| 1073 | 1073 | dest = (UINT32 *) ptr; |
| 1074 | 1074 | dest += (y * yuv_pitch); |