direct3d11: Fixed incorrect texture coordinates (thanks, Martin!).
authorRyan C. Gordon <icculus@icculus.org>
Tue, 03 Dec 2019 03:07:34 -0500
changeset 13307805a3b5cdcc8
parent 13306 c51961094960
child 13308 fb600198ec12
direct3d11: Fixed incorrect texture coordinates (thanks, Martin!).

Fixes Bugzilla #4860.
src/render/direct3d11/SDL_render_d3d11.c
     1.1 --- a/src/render/direct3d11/SDL_render_d3d11.c	Tue Dec 03 02:49:01 2019 -0500
     1.2 +++ b/src/render/direct3d11/SDL_render_d3d11.c	Tue Dec 03 03:07:34 2019 -0500
     1.3 @@ -1728,82 +1728,88 @@
     1.4      float minx, miny, maxx, maxy;
     1.5      float minu, maxu, minv, maxv;
     1.6  
     1.7 -    if (flip & SDL_FLIP_HORIZONTAL) {
     1.8 -        minu = (float) srcrect->x / texture->w;
     1.9 -        maxu = (float) (srcrect->x + srcrect->w) / texture->w;
    1.10 -    } else {
    1.11 -        minu = (float) (srcrect->x + srcrect->w) / texture->w;
    1.12 -        maxu = (float) srcrect->x / texture->w;
    1.13 +    if (!verts) {
    1.14 +        return -1;
    1.15      }
    1.16  
    1.17 -    if (flip & SDL_FLIP_VERTICAL) {
    1.18 -        minv = (float) srcrect->y / texture->h;
    1.19 -        maxv = (float) (srcrect->y + srcrect->h) / texture->h;
    1.20 -    } else {
    1.21 -        minv = (float) (srcrect->y + srcrect->h) / texture->h;
    1.22 -        maxv = (float) srcrect->y / texture->h;
    1.23 -    }
    1.24 +    cmd->data.draw.count = 1;
    1.25  
    1.26      minx = -center->x;
    1.27      maxx = dstrect->w - center->x;
    1.28      miny = -center->y;
    1.29      maxy = dstrect->h - center->y;
    1.30  
    1.31 -    cmd->data.draw.count = 1;
    1.32 +    if (flip & SDL_FLIP_HORIZONTAL) {
    1.33 +        minu = (float) (srcrect->x + srcrect->w) / texture->w;
    1.34 +        maxu = (float) srcrect->x / texture->w;
    1.35 +    } else {
    1.36 +        minu = (float) srcrect->x / texture->w;
    1.37 +        maxu = (float) (srcrect->x + srcrect->w) / texture->w;
    1.38 +    }
    1.39 +
    1.40 +    if (flip & SDL_FLIP_VERTICAL) {
    1.41 +        minv = (float) (srcrect->y + srcrect->h) / texture->h;
    1.42 +        maxv = (float) srcrect->y / texture->h;
    1.43 +    } else {
    1.44 +        minv = (float) srcrect->y / texture->h;
    1.45 +        maxv = (float) (srcrect->y + srcrect->h) / texture->h;
    1.46 +    }
    1.47 +
    1.48 +
    1.49  
    1.50      verts->pos.x = minx;
    1.51      verts->pos.y = miny;
    1.52      verts->pos.z = 0.0f;
    1.53 -    verts->tex.x = minu;
    1.54 -    verts->tex.y = minv;
    1.55      verts->color.x = r;
    1.56      verts->color.y = g;
    1.57      verts->color.z = b;
    1.58      verts->color.w = a;
    1.59 +    verts->tex.x = minu;
    1.60 +    verts->tex.y = minv;
    1.61      verts++;
    1.62  
    1.63      verts->pos.x = minx;
    1.64      verts->pos.y = maxy;
    1.65      verts->pos.z = 0.0f;
    1.66 -    verts->tex.x = minu;
    1.67 -    verts->tex.y = maxv;
    1.68      verts->color.x = r;
    1.69      verts->color.y = g;
    1.70      verts->color.z = b;
    1.71      verts->color.w = a;
    1.72 +    verts->tex.x = minu;
    1.73 +    verts->tex.y = maxv;
    1.74      verts++;
    1.75  
    1.76      verts->pos.x = maxx;
    1.77      verts->pos.y = miny;
    1.78      verts->pos.z = 0.0f;
    1.79 -    verts->tex.x = maxu;
    1.80 -    verts->tex.y = minv;
    1.81      verts->color.x = r;
    1.82      verts->color.y = g;
    1.83      verts->color.z = b;
    1.84      verts->color.w = a;
    1.85 +    verts->tex.x = maxu;
    1.86 +    verts->tex.y = minv;
    1.87      verts++;
    1.88  
    1.89      verts->pos.x = maxx;
    1.90      verts->pos.y = maxy;
    1.91      verts->pos.z = 0.0f;
    1.92 -    verts->tex.x = maxu;
    1.93 -    verts->tex.y = maxv;
    1.94      verts->color.x = r;
    1.95      verts->color.y = g;
    1.96      verts->color.z = b;
    1.97      verts->color.w = a;
    1.98 +    verts->tex.x = maxu;
    1.99 +    verts->tex.y = maxv;
   1.100      verts++;
   1.101  
   1.102      verts->pos.x = dstrect->x + center->x;  /* X translation */
   1.103      verts->pos.y = dstrect->y + center->y;  /* Y translation */
   1.104      verts->pos.z = (float)(M_PI * (float) angle / 180.0f);  /* rotation */
   1.105 -    verts->tex.x = 0.0f;
   1.106 -    verts->tex.y = 0.0f;
   1.107      verts->color.x = 0;
   1.108      verts->color.y = 0;
   1.109      verts->color.z = 0;
   1.110      verts->color.w = 0;
   1.111 +    verts->tex.x = 0.0f;
   1.112 +    verts->tex.y = 0.0f;
   1.113      verts++;
   1.114  
   1.115      return 0;