direct3d: Make sure streaming textures update before being used for drawing.

Fixes Bugzilla #4402.
diff --git a/src/render/direct3d/SDL_render_d3d.c b/src/render/direct3d/SDL_render_d3d.c
index b934f4d..20e4cc0 100644
--- a/src/render/direct3d/SDL_render_d3d.c
+++ b/src/render/direct3d/SDL_render_d3d.c
@@ -995,11 +995,10 @@
 }
 
 static int
-BindTextureRep(IDirect3DDevice9 *device, D3D_TextureRep *texture, DWORD sampler)
+UpdateDirtyTexture(IDirect3DDevice9 *device, D3D_TextureRep *texture)
 {
-    HRESULT result;
-
     if (texture->dirty && texture->staging) {
+        HRESULT result;
         if (!texture->texture) {
             result = IDirect3DDevice9_CreateTexture(device, texture->w, texture->h, 1, texture->usage,
                 PixelFormatToD3DFMT(texture->format), D3DPOOL_DEFAULT, &texture->texture, NULL);
@@ -1014,6 +1013,14 @@
         }
         texture->dirty = SDL_FALSE;
     }
+    return 0;
+}
+
+static int
+BindTextureRep(IDirect3DDevice9 *device, D3D_TextureRep *texture, DWORD sampler)
+{
+    HRESULT result;
+    UpdateDirtyTexture(device, texture);
     result = IDirect3DDevice9_SetTexture(device, sampler, (IDirect3DBaseTexture9 *)texture->texture);
     if (FAILED(result)) {
         return D3D_SetError("SetTexture()", result);
@@ -1091,6 +1098,13 @@
     SDL_Texture *texture = cmd->data.draw.texture;
     const SDL_BlendMode blend = cmd->data.draw.blend;
 
+    if (texture) {
+        D3D_TextureData *texturedata = (D3D_TextureData *)texture->driverdata;
+        if (texturedata) {
+            UpdateDirtyTexture(data->device, &texturedata->texture);
+        }
+    }
+
     if (texture != data->drawstate.texture) {
         D3D_TextureData *oldtexturedata = data->drawstate.texture ? (D3D_TextureData *) data->drawstate.texture->driverdata : NULL;
         D3D_TextureData *newtexturedata = texture ? (D3D_TextureData *) texture->driverdata : NULL;