From cca9d24cde52d7c9311293c4ba7ce9f6f871bfdd Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Mon, 3 Dec 2018 09:26:05 -0500 Subject: [PATCH] direct3d: be more aggressive about resetting invalidated cached state. Fixes Bugzilla #4402. --- src/render/direct3d/SDL_render_d3d.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/render/direct3d/SDL_render_d3d.c b/src/render/direct3d/SDL_render_d3d.c index 20e4cc029..76f149939 100644 --- a/src/render/direct3d/SDL_render_d3d.c +++ b/src/render/direct3d/SDL_render_d3d.c @@ -690,7 +690,7 @@ D3D_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, static void D3D_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture) { - /*D3D_RenderData *data = (D3D_RenderData *)renderer->driverdata;*/ + D3D_RenderData *data = (D3D_RenderData *)renderer->driverdata; D3D_TextureData *texturedata = (D3D_TextureData *)texture->driverdata; if (!texturedata) { @@ -706,6 +706,9 @@ D3D_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture) } else { IDirect3DTexture9_UnlockRect(texturedata->texture.staging, 0); texturedata->texture.dirty = SDL_TRUE; + if (data->drawstate.texture == texture) { + data->drawstate.texture = NULL; + } } } @@ -1098,13 +1101,6 @@ 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; @@ -1558,6 +1554,7 @@ static int D3D_Reset(SDL_Renderer * renderer) { D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata; + const Float4X4 d3dmatrix = MatrixIdentity(); HRESULT result; SDL_Texture *texture; int i; @@ -1610,6 +1607,13 @@ D3D_Reset(SDL_Renderer * renderer) D3D_InitRenderState(data); D3D_SetRenderTargetInternal(renderer, renderer->target); data->drawstate.viewport_dirty = SDL_TRUE; + data->drawstate.cliprect_dirty = SDL_TRUE; + data->drawstate.cliprect_enabled_dirty = SDL_TRUE; + data->drawstate.texture = NULL; + data->drawstate.shader = NULL; + data->drawstate.blend = SDL_BLENDMODE_INVALID; + data->drawstate.is_copy_ex = SDL_FALSE; + IDirect3DDevice9_SetTransform(data->device, D3DTS_VIEW, (D3DMATRIX*)&d3dmatrix); /* Let the application know that render targets were reset */ {