904
905
//texture->sdl_access = SDL_TEXTUREACCESS_STATIC;
905
906
texture->sdl_access = SDL_TEXTUREACCESS_STREAMING;
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");
907
912
// compute the size
908
913
texture->copyinfo = texture_compute_size_type(texsource, texture, flags);
910
915
texture->texture_id = SDL_CreateTexture(texture->copyinfo->dst_fmt, texture->sdl_access,
911
916
texture->setup.rotwidth, texture->setup.rotheight);
913
if ( (texture->copyinfo->func != NULL) && (texture->sdl_access == SDL_TEXTUREACCESS_STATIC))
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());
922
if ( (texture->copyinfo->func != NULL) && (texture->sdl_access == SDL_TEXTUREACCESS_STATIC))
915
924
texture->pixels = malloc(texture->setup.rotwidth * texture->setup.rotheight * texture->copyinfo->dst_bpp);
916
texture->pixels_own=TRUE;
925
texture->pixels_own=TRUE;
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
//============================================================
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)
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;
983
992
/* determine U/V deltas */
984
993
if ((PRIMFLAG_GET_SCREENTEX(flags)))
985
994
fscale = (float) video_config.prescale;
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);
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;
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;
1009
width = round_nearest(abs(fdudx * texwidth + fdvdx * texheight) * fscale * fscale);
1010
height = round_nearest(abs(fdudy * texwidth + fdvdy * texheight) * fscale * fscale);
1012
/* clamp to integers */
1013
setup->rotwidth = width;
1014
setup->rotheight = height;
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
1016
1003
/* compute start and delta U,V coordinates now */
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);
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);
1012
/* clamp to integers */
1014
width = fabs((fdudx * (float) (texwidth) + fdvdx * (float) (texheight)) * fscale * fscale);
1015
height = fabs((fdudy * (float)(texwidth) + fdvdy * (float) (texheight)) * fscale * fscale);
1017
setup->rotwidth = width;
1018
setup->rotheight = height;
1020
setup->startu += (setup->dudx + setup->dudy) / 2;
1021
setup->startv += (setup->dvdx + setup->dvdy) / 2;
1032
1025
//============================================================