direct3d: Make sure streaming textures update before being used for drawing.
authorRyan C. Gordon <icculus@icculus.org>
Mon, 03 Dec 2018 01:58:23 -0500
changeset 124463da9ecf40a13
parent 12445 2cdb34815a86
child 12447 0844007ea1c2
direct3d: Make sure streaming textures update before being used for drawing.

Fixes Bugzilla #4402.
src/render/direct3d/SDL_render_d3d.c
     1.1 --- a/src/render/direct3d/SDL_render_d3d.c	Sun Dec 02 21:57:33 2018 -0500
     1.2 +++ b/src/render/direct3d/SDL_render_d3d.c	Mon Dec 03 01:58:23 2018 -0500
     1.3 @@ -995,11 +995,10 @@
     1.4  }
     1.5  
     1.6  static int
     1.7 -BindTextureRep(IDirect3DDevice9 *device, D3D_TextureRep *texture, DWORD sampler)
     1.8 +UpdateDirtyTexture(IDirect3DDevice9 *device, D3D_TextureRep *texture)
     1.9  {
    1.10 -    HRESULT result;
    1.11 -
    1.12      if (texture->dirty && texture->staging) {
    1.13 +        HRESULT result;
    1.14          if (!texture->texture) {
    1.15              result = IDirect3DDevice9_CreateTexture(device, texture->w, texture->h, 1, texture->usage,
    1.16                  PixelFormatToD3DFMT(texture->format), D3DPOOL_DEFAULT, &texture->texture, NULL);
    1.17 @@ -1014,6 +1013,14 @@
    1.18          }
    1.19          texture->dirty = SDL_FALSE;
    1.20      }
    1.21 +    return 0;
    1.22 +}
    1.23 +
    1.24 +static int
    1.25 +BindTextureRep(IDirect3DDevice9 *device, D3D_TextureRep *texture, DWORD sampler)
    1.26 +{
    1.27 +    HRESULT result;
    1.28 +    UpdateDirtyTexture(device, texture);
    1.29      result = IDirect3DDevice9_SetTexture(device, sampler, (IDirect3DBaseTexture9 *)texture->texture);
    1.30      if (FAILED(result)) {
    1.31          return D3D_SetError("SetTexture()", result);
    1.32 @@ -1091,6 +1098,13 @@
    1.33      SDL_Texture *texture = cmd->data.draw.texture;
    1.34      const SDL_BlendMode blend = cmd->data.draw.blend;
    1.35  
    1.36 +    if (texture) {
    1.37 +        D3D_TextureData *texturedata = (D3D_TextureData *)texture->driverdata;
    1.38 +        if (texturedata) {
    1.39 +            UpdateDirtyTexture(data->device, &texturedata->texture);
    1.40 +        }
    1.41 +    }
    1.42 +
    1.43      if (texture != data->drawstate.texture) {
    1.44          D3D_TextureData *oldtexturedata = data->drawstate.texture ? (D3D_TextureData *) data->drawstate.texture->driverdata : NULL;
    1.45          D3D_TextureData *newtexturedata = texture ? (D3D_TextureData *) texture->driverdata : NULL;