diff --git a/patches/d3dx9-sprite-state/0001-d3dx9-Improve-handling-of-Sprite-render-states.patch b/patches/d3dx9-sprite-state/0001-d3dx9-Improve-handling-of-Sprite-render-states.patch new file mode 100644 index 00000000..477f0db3 --- /dev/null +++ b/patches/d3dx9-sprite-state/0001-d3dx9-Improve-handling-of-Sprite-render-states.patch @@ -0,0 +1,127 @@ +From cf47173eec41f4427248796a781e3aa4463a79db Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Rafa=C5=82=20Mu=C5=BCy=C5=82o?= +Date: Wed, 7 Jun 2023 08:17:59 +1000 +Subject: [PATCH] d3dx9: Improve handling of Sprite render states + +--- + dlls/d3dx9_36/sprite.c | 76 +++++++++++++++++++++++------------------- + 1 file changed, 41 insertions(+), 35 deletions(-) + +diff --git a/dlls/d3dx9_36/sprite.c b/dlls/d3dx9_36/sprite.c +index 1a072e52cda..0ce2ab977f3 100644 +--- a/dlls/d3dx9_36/sprite.c ++++ b/dlls/d3dx9_36/sprite.c +@@ -193,7 +193,7 @@ static HRESULT WINAPI d3dx9_sprite_SetWorldViewLH(ID3DXSprite *iface, + } + + /* Helper function */ +-static void set_states(struct d3dx9_sprite *object) ++static void set_states(struct d3dx9_sprite *object, DWORD flags) + { + D3DXMATRIX mat; + D3DVIEWPORT9 vp; +@@ -204,32 +204,35 @@ static void set_states(struct d3dx9_sprite *object) + IDirect3DDevice9_SetNPatchMode(object->device, 0.0f); + + /* Render states */ +- IDirect3DDevice9_SetRenderState(object->device, D3DRS_ALPHABLENDENABLE, TRUE); +- IDirect3DDevice9_SetRenderState(object->device, D3DRS_ALPHAFUNC, D3DCMP_GREATER); +- IDirect3DDevice9_SetRenderState(object->device, D3DRS_ALPHAREF, 0x00); +- IDirect3DDevice9_SetRenderState(object->device, D3DRS_ALPHATESTENABLE, object->alphacmp_caps); +- IDirect3DDevice9_SetRenderState(object->device, D3DRS_BLENDOP, D3DBLENDOP_ADD); +- IDirect3DDevice9_SetRenderState(object->device, D3DRS_CLIPPING, TRUE); +- IDirect3DDevice9_SetRenderState(object->device, D3DRS_CLIPPLANEENABLE, 0); +- IDirect3DDevice9_SetRenderState(object->device, D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_ALPHA | D3DCOLORWRITEENABLE_BLUE | +- D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_RED); +- IDirect3DDevice9_SetRenderState(object->device, D3DRS_CULLMODE, D3DCULL_NONE); +- IDirect3DDevice9_SetRenderState(object->device, D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); +- IDirect3DDevice9_SetRenderState(object->device, D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_COLOR1); +- IDirect3DDevice9_SetRenderState(object->device, D3DRS_ENABLEADAPTIVETESSELLATION, FALSE); +- IDirect3DDevice9_SetRenderState(object->device, D3DRS_FILLMODE, D3DFILL_SOLID); +- IDirect3DDevice9_SetRenderState(object->device, D3DRS_FOGENABLE, FALSE); +- IDirect3DDevice9_SetRenderState(object->device, D3DRS_INDEXEDVERTEXBLENDENABLE, FALSE); +- IDirect3DDevice9_SetRenderState(object->device, D3DRS_LIGHTING, FALSE); +- IDirect3DDevice9_SetRenderState(object->device, D3DRS_RANGEFOGENABLE, FALSE); +- IDirect3DDevice9_SetRenderState(object->device, D3DRS_SEPARATEALPHABLENDENABLE, FALSE); +- IDirect3DDevice9_SetRenderState(object->device, D3DRS_SHADEMODE, D3DSHADE_GOURAUD); +- IDirect3DDevice9_SetRenderState(object->device, D3DRS_SPECULARENABLE, FALSE); +- IDirect3DDevice9_SetRenderState(object->device, D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); +- IDirect3DDevice9_SetRenderState(object->device, D3DRS_SRGBWRITEENABLE, FALSE); +- IDirect3DDevice9_SetRenderState(object->device, D3DRS_STENCILENABLE, FALSE); +- IDirect3DDevice9_SetRenderState(object->device, D3DRS_VERTEXBLEND, FALSE); +- IDirect3DDevice9_SetRenderState(object->device, D3DRS_WRAP0, 0); ++ if (!(flags & D3DXSPRITE_DONOTMODIFY_RENDERSTATE)) ++ { ++ IDirect3DDevice9_SetRenderState(object->device, D3DRS_ALPHABLENDENABLE, TRUE); ++ IDirect3DDevice9_SetRenderState(object->device, D3DRS_ALPHAFUNC, D3DCMP_GREATER); ++ IDirect3DDevice9_SetRenderState(object->device, D3DRS_ALPHAREF, 0x00); ++ IDirect3DDevice9_SetRenderState(object->device, D3DRS_ALPHATESTENABLE, object->alphacmp_caps); ++ IDirect3DDevice9_SetRenderState(object->device, D3DRS_BLENDOP, D3DBLENDOP_ADD); ++ IDirect3DDevice9_SetRenderState(object->device, D3DRS_CLIPPING, TRUE); ++ IDirect3DDevice9_SetRenderState(object->device, D3DRS_CLIPPLANEENABLE, 0); ++ IDirect3DDevice9_SetRenderState(object->device, D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_ALPHA | D3DCOLORWRITEENABLE_BLUE | ++ D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_RED); ++ IDirect3DDevice9_SetRenderState(object->device, D3DRS_CULLMODE, D3DCULL_NONE); ++ IDirect3DDevice9_SetRenderState(object->device, D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); ++ IDirect3DDevice9_SetRenderState(object->device, D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_COLOR1); ++ IDirect3DDevice9_SetRenderState(object->device, D3DRS_ENABLEADAPTIVETESSELLATION, FALSE); ++ IDirect3DDevice9_SetRenderState(object->device, D3DRS_FILLMODE, D3DFILL_SOLID); ++ IDirect3DDevice9_SetRenderState(object->device, D3DRS_FOGENABLE, FALSE); ++ IDirect3DDevice9_SetRenderState(object->device, D3DRS_INDEXEDVERTEXBLENDENABLE, FALSE); ++ IDirect3DDevice9_SetRenderState(object->device, D3DRS_LIGHTING, FALSE); ++ IDirect3DDevice9_SetRenderState(object->device, D3DRS_RANGEFOGENABLE, FALSE); ++ IDirect3DDevice9_SetRenderState(object->device, D3DRS_SEPARATEALPHABLENDENABLE, FALSE); ++ IDirect3DDevice9_SetRenderState(object->device, D3DRS_SHADEMODE, D3DSHADE_GOURAUD); ++ IDirect3DDevice9_SetRenderState(object->device, D3DRS_SPECULARENABLE, FALSE); ++ IDirect3DDevice9_SetRenderState(object->device, D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); ++ IDirect3DDevice9_SetRenderState(object->device, D3DRS_SRGBWRITEENABLE, FALSE); ++ IDirect3DDevice9_SetRenderState(object->device, D3DRS_STENCILENABLE, FALSE); ++ IDirect3DDevice9_SetRenderState(object->device, D3DRS_VERTEXBLEND, FALSE); ++ IDirect3DDevice9_SetRenderState(object->device, D3DRS_WRAP0, 0); ++ } + + /* Texture stage states */ + IDirect3DDevice9_SetTextureStageState(object->device, 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); +@@ -266,12 +269,15 @@ static void set_states(struct d3dx9_sprite *object) + IDirect3DDevice9_SetSamplerState(object->device, 0, D3DSAMP_SRGBTEXTURE, 0); + + /* Matrices */ +- D3DXMatrixIdentity(&mat); +- IDirect3DDevice9_SetTransform(object->device, D3DTS_WORLD, &mat); +- IDirect3DDevice9_SetTransform(object->device, D3DTS_VIEW, &object->view); +- IDirect3DDevice9_GetViewport(object->device, &vp); +- D3DXMatrixOrthoOffCenterLH(&mat, vp.X+0.5f, (float)vp.Width+vp.X+0.5f, (float)vp.Height+vp.Y+0.5f, vp.Y+0.5f, vp.MinZ, vp.MaxZ); +- IDirect3DDevice9_SetTransform(object->device, D3DTS_PROJECTION, &mat); ++ if (!(flags & D3DXSPRITE_OBJECTSPACE)) ++ { ++ D3DXMatrixIdentity(&mat); ++ IDirect3DDevice9_SetTransform(object->device, D3DTS_WORLD, &mat); ++ IDirect3DDevice9_SetTransform(object->device, D3DTS_VIEW, &object->view); ++ IDirect3DDevice9_GetViewport(object->device, &vp); ++ D3DXMatrixOrthoOffCenterLH(&mat, vp.X+0.5f, (float)vp.Width+vp.X+0.5f, (float)vp.Height+vp.Y+0.5f, vp.Y+0.5f, vp.MinZ, vp.MaxZ); ++ IDirect3DDevice9_SetTransform(object->device, D3DTS_PROJECTION, &mat); ++ } + } + + static HRESULT WINAPI d3dx9_sprite_Begin(ID3DXSprite *iface, DWORD flags) +@@ -317,7 +323,7 @@ D3DXSPRITE_SORT_TEXTURE: sort by texture (so that it doesn't change too often) + hr=IDirect3DDevice9_BeginStateBlock(This->device); + if(hr!=D3D_OK) return hr; + +- set_states(This); ++ set_states(This, flags); + + IDirect3DDevice9_SetVertexDeclaration(This->device, This->vdecl); + IDirect3DDevice9_SetStreamSource(This->device, 0, NULL, 0, sizeof(struct sprite_vertex)); +@@ -330,7 +336,7 @@ D3DXSPRITE_SORT_TEXTURE: sort by texture (so that it doesn't change too often) + } + + /* Apply device state */ +- set_states(This); ++ set_states(This, flags); + + This->flags=flags; + This->ready=TRUE; +-- +2.40.1 + diff --git a/patches/d3dx9-sprite-state/definition b/patches/d3dx9-sprite-state/definition new file mode 100644 index 00000000..3f1510da --- /dev/null +++ b/patches/d3dx9-sprite-state/definition @@ -0,0 +1 @@ +Fixes: [54034] d3dx9: Improve sprite rendering state handling.