~ubuntu-branches/ubuntu/lucid/sdlmame/lucid

« back to all changes in this revision

Viewing changes to src/osd/sdl/draw13.c

  • Committer: Bazaar Package Importer
  • Author(s): Cesare Falco
  • Date: 2009-11-03 17:10:15 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20091103171015-6hop4ory5lxnumpn
Tags: 0.135-0ubuntu1
* New upstream release - Closes (LP: #403212)
* debian/watch: unstable releases are no longer detected
* mame.ini: added the cheat subdirectories to cheatpath so zipped
  cheatfiles will be searched too
* renamed crsshair subdirectory to crosshair to reflect upstream change
* mame.ini: renamed references to crosshair subdirectory (see above)

Show diffs side-by-side

added added

removed removed

Lines of Context:
426
426
}       
427
427
#endif
428
428
 
429
 
int RendererSupportsFormat(Uint32 format, Uint32 access)
 
429
int RendererSupportsFormat(Uint32 format, Uint32 access, const char *sformat)
430
430
{
431
431
        int i;
432
432
        SDL_TextureID texid;
447
447
                SDL_DestroyTexture(texid);
448
448
                return 1;
449
449
        }
 
450
        mame_printf_verbose("Pixelformat <%s> not supported\n", sformat);
450
451
        fmt_support[i].status = 0;
451
452
        return 0;
452
453
}       
551
552
        window->dxdata = sdl;
552
553
 
553
554
        sdl->extra_flags = (window->fullscreen ? 
554
 
                        SDL_WINDOW_BORDERLESS | SDL_WINDOW_INPUT_FOCUS : SDL_WINDOW_RESIZABLE);
 
555
                        SDL_WINDOW_BORDERLESS | SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_FULLSCREEN: SDL_WINDOW_RESIZABLE);
555
556
 
556
557
        // create the SDL window
557
558
        SDL_SelectVideoDisplay(window->monitor->handle);
593
594
                        width, height, sdl->extra_flags);
594
595
 
595
596
        SDL_ShowWindow(window->window_id);
596
 
        SDL_SetWindowFullscreen(window->window_id, window->fullscreen);
 
597
        //SDL_SetWindowFullscreen(window->window_id, window->fullscreen);
597
598
        SDL_RaiseWindow(window->window_id);
598
599
        SDL_GetWindowSize(window->window_id, &window->width, &window->height);
599
600
        
820
821
                if ((texture->is_rotated == bi->rotate) 
821
822
                                && (texture->sdl_blendmode == bi->bm_mask))
822
823
                {
823
 
                        if (RendererSupportsFormat(bi->dst_fmt, texture->sdl_access)) 
 
824
                        if (RendererSupportsFormat(bi->dst_fmt, texture->sdl_access, bi->dstname)) 
824
825
                        {
825
826
                                if (bi->perf == 0)
826
827
                                        return bi;
839
840
        {
840
841
                if ((texture->is_rotated == bi->rotate) 
841
842
                        && (texture->sdl_blendmode == bi->bm_mask))
842
 
                        if (RendererSupportsFormat(bi->dst_fmt, texture->sdl_access)) 
 
843
                        if (RendererSupportsFormat(bi->dst_fmt, texture->sdl_access, bi->dstname)) 
843
844
                                return bi;
844
845
        }
845
846
        //FIXME: crash implement a -do nothing handler */
903
904
        
904
905
        //texture->sdl_access = SDL_TEXTUREACCESS_STATIC;
905
906
        texture->sdl_access = SDL_TEXTUREACCESS_STREAMING;
 
907
 
 
908
        // Watch out for 0x0 textures ...
 
909
        if (!texture->setup.rotwidth || !texture->setup.rotheight)
 
910
                mame_printf_warning("Trying to create texture with zero dim\n");
906
911
        
907
912
        // compute the size
908
913
        texture->copyinfo = texture_compute_size_type(texsource, texture, flags);
909
914
 
910
915
        texture->texture_id = SDL_CreateTexture(texture->copyinfo->dst_fmt, texture->sdl_access, 
911
916
                        texture->setup.rotwidth, texture->setup.rotheight);
912
 
        
913
 
    if ( (texture->copyinfo->func != NULL) && (texture->sdl_access == SDL_TEXTUREACCESS_STATIC))
914
 
    {
 
917
                
 
918
        if (!texture->texture_id)
 
919
                mame_printf_error("Error creating texture: %d x %d, pixelformat %s error: %s\n", texture->setup.rotwidth, texture->setup.rotheight,
 
920
                                texture->copyinfo->dstname, SDL_GetError());
 
921
                
 
922
        if ( (texture->copyinfo->func != NULL) && (texture->sdl_access == SDL_TEXTUREACCESS_STATIC))
 
923
        {
915
924
                texture->pixels = malloc(texture->setup.rotwidth * texture->setup.rotheight * texture->copyinfo->dst_bpp);
916
 
        texture->pixels_own=TRUE;
917
 
    }
 
925
         texture->pixels_own=TRUE;
 
926
 }
918
927
        /* add us to the texture list */
919
928
        texture->next = sdl->texlist;
920
929
        sdl->texlist = texture;
972
981
//  compute rotation setup
973
982
//============================================================
974
983
 
975
 
static void compute_setup(const render_quad_texuv *texcoords, int texwidth, int texheight, quad_setup_data *setup, int flags)
 
984
static void compute_setup(sdl_info *sdl, const render_primitive *prim, quad_setup_data *setup, int flags)
976
985
{
 
986
        const render_quad_texuv *texcoords = &prim->texcoords;
 
987
        int texwidth = prim->texture.width;
 
988
        int texheight = prim->texture.height; 
977
989
        float fdudx, fdvdx, fdudy, fdvdy;
978
 
        float x0, y0, x1, y1;
979
990
        float width, height;
980
991
        float fscale;
981
 
        float prec;
982
 
        
983
992
        /* determine U/V deltas */
984
993
        if ((PRIMFLAG_GET_SCREENTEX(flags)))
985
994
                fscale = (float) video_config.prescale;
986
995
        else
987
996
                fscale = 1.0f;
988
997
 
989
 
        x0 = MIN4(texcoords->tl.u, texcoords->tr.u, texcoords->br.u, texcoords->bl.u);
990
 
        x1 = MAX4(texcoords->tl.u, texcoords->tr.u, texcoords->br.u, texcoords->bl.u);
991
 
        y0 = MIN4(texcoords->tl.v, texcoords->tr.v, texcoords->br.v, texcoords->bl.v);
992
 
        y1 = MAX4(texcoords->tl.v, texcoords->tr.v, texcoords->br.v, texcoords->bl.v);
993
 
 
994
 
        
995
 
        fdudx = (texcoords->tr.u - texcoords->tl.u) / (x1 - x0) / fscale;
996
 
        fdvdx = (texcoords->tr.v - texcoords->tl.v) / (x1 - x0) / fscale;
997
 
        fdudy = (texcoords->bl.u - texcoords->tl.u) / (y1 - y0) / fscale;
998
 
        fdvdy = (texcoords->bl.v - texcoords->tl.v) / (y1 - y0) / fscale;
999
 
 
1000
 
        /* for some reasons the core introduces distortions in the order
1001
 
         * of 0.001 when scaling to fullscreen. 
1002
 
         * Get rid of them */
1003
 
        prec = 100.0f * fscale;
1004
 
        fdudx = round_nearest(fdudx * prec) / prec;
1005
 
        fdudy = round_nearest(fdudy * prec) / prec;
1006
 
        fdvdx = round_nearest(fdvdx * prec) / prec;
1007
 
        fdvdy = round_nearest(fdvdy * prec) / prec;
1008
 
        
1009
 
        width = round_nearest(abs(fdudx * texwidth + fdvdx * texheight) * fscale * fscale);
1010
 
        height = round_nearest(abs(fdudy * texwidth + fdvdy * texheight) * fscale * fscale);
1011
 
 
1012
 
        /* clamp to integers */
1013
 
        setup->rotwidth = width;
1014
 
        setup->rotheight = height;
1015
 
 
 
998
        fdudx = (texcoords->tr.u - texcoords->tl.u) / fscale; // a a11
 
999
        fdvdx = (texcoords->tr.v - texcoords->tl.v) / fscale; // c a21
 
1000
        fdudy = (texcoords->bl.u - texcoords->tl.u) / fscale; // b a12
 
1001
        fdvdy = (texcoords->bl.v - texcoords->tl.v) / fscale; // d a22
 
1002
        
1016
1003
        /* compute start and delta U,V coordinates now */
 
1004
        
1017
1005
        setup->dudx = round_nearest(65536.0f * fdudx);
1018
1006
        setup->dvdx = round_nearest(65536.0f * fdvdx);
1019
1007
        setup->dudy = round_nearest(65536.0f * fdudy);
1020
1008
        setup->dvdy = round_nearest(65536.0f * fdvdy);
1021
 
        setup->startu = round_nearest(65536.0f * texwidth * texcoords->tl.u);
1022
 
        setup->startv = round_nearest(65536.0f * texheight * texcoords->tl.v);
1023
 
 
1024
 
        //printf("%d %d %d %d \n", setup->dudx, setup->dvdx, setup->dudy, setup->dvdy);
1025
 
        /* advance U/V to the middle of the first texel 
1026
 
         * the division by 2.1 is a workaround to prevent
1027
 
         * crashes in certain cases */
1028
 
        setup->startu += (float) (setup->dudx + setup->dudy) / 2.1f;
1029
 
        setup->startv += (float) (setup->dvdx + setup->dvdy) / 2.1f;
 
1009
        setup->startu = round_nearest(65536.0f * (float) texwidth * texcoords->tl.u);
 
1010
        setup->startv = round_nearest(65536.0f * (float) texheight * texcoords->tl.v);
 
1011
 
 
1012
        /* clamp to integers */
 
1013
 
 
1014
        width = fabs((fdudx * (float) (texwidth) + fdvdx * (float) (texheight)) * fscale * fscale);
 
1015
        height = fabs((fdudy * (float)(texwidth) + fdvdy * (float) (texheight)) * fscale * fscale);
 
1016
 
 
1017
        setup->rotwidth = width;
 
1018
        setup->rotheight = height;
 
1019
 
 
1020
        setup->startu += (setup->dudx + setup->dudy) / 2;
 
1021
        setup->startv += (setup->dvdx + setup->dvdy) / 2;
 
1022
        
1030
1023
}
1031
1024
 
1032
1025
//============================================================
1093
1086
        quad_setup_data setup;
1094
1087
        texture_info *texture;
1095
1088
        
1096
 
        compute_setup(&prim->texcoords, prim->texture.width, prim->texture.height, &setup, prim->flags);
 
1089
        compute_setup(sdl, prim, &setup, prim->flags);
1097
1090
 
1098
1091
        texture = texture_find(sdl, prim, &setup);
1099
1092