direct3d: Make sure streaming textures update before being used for drawing. Fixes Bugzilla #4402.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
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 @@ D3D_QueueCopyEx(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture * t
}
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 @@ BindTextureRep(IDirect3DDevice9 *device, D3D_TextureRep *texture, DWORD sampler)
}
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 @@ SetDrawState(D3D_RenderData *data, const SDL_RenderCommand *cmd)
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;