diff --git a/source/d3d8to9.hpp b/source/d3d8to9.hpp index 5ef4d86..bcc087d 100644 --- a/source/d3d8to9.hpp +++ b/source/d3d8to9.hpp @@ -173,12 +173,18 @@ class Direct3DDevice8 : public IUnknown AddressLookupTable *ProxyAddressLookupTable; private: + void ApplyClipPlanes(); + Direct3D8 *const D3D; IDirect3DDevice9 *const ProxyInterface; INT CurrentBaseVertexIndex = 0; const BOOL ZBufferDiscarding = FALSE; DWORD CurrentVertexShaderHandle = 0, CurrentPixelShaderHandle = 0; bool PaletteFlag = false; + + static constexpr size_t MAX_CLIP_PLANES = 6; + float StoredClipPlanes[MAX_CLIP_PLANES][4] = {}; + DWORD ClipPlaneRenderState = 0; }; class Direct3DSwapChain8 : public IUnknown, public AddressLookupTableObject diff --git a/source/d3d8to9_base.cpp b/source/d3d8to9_base.cpp index 288dbb0..d8978f3 100644 --- a/source/d3d8to9_base.cpp +++ b/source/d3d8to9_base.cpp @@ -43,10 +43,6 @@ Direct3D8::Direct3D8(IDirect3D9 *ProxyInterface) : } Direct3D8::~Direct3D8() { - for (UINT x = 0; x < CurrentAdapterCount; x++) - { - CurrentAdapterModes[x].clear(); - } } HRESULT STDMETHODCALLTYPE Direct3D8::QueryInterface(REFIID riid, void **ppvObj) diff --git a/source/d3d8to9_device.cpp b/source/d3d8to9_device.cpp index 4117a33..837fe7e 100644 --- a/source/d3d8to9_device.cpp +++ b/source/d3d8to9_device.cpp @@ -737,15 +737,22 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::GetLightEnable(DWORD Index, BOOL *pEn } HRESULT STDMETHODCALLTYPE Direct3DDevice8::SetClipPlane(DWORD Index, const float *pPlane) { - return ProxyInterface->SetClipPlane(Index, pPlane); + if (pPlane == nullptr || Index >= MAX_CLIP_PLANES) return D3DERR_INVALIDCALL; + + memcpy(StoredClipPlanes[Index], pPlane, sizeof(StoredClipPlanes[0])); + return D3D_OK; } HRESULT STDMETHODCALLTYPE Direct3DDevice8::GetClipPlane(DWORD Index, float *pPlane) { - return ProxyInterface->GetClipPlane(Index, pPlane); + if (pPlane == nullptr || Index >= MAX_CLIP_PLANES) return D3DERR_INVALIDCALL; + + memcpy(pPlane, StoredClipPlanes[Index], sizeof(StoredClipPlanes[0])); + return D3D_OK; } HRESULT STDMETHODCALLTYPE Direct3DDevice8::SetRenderState(D3DRENDERSTATETYPE State, DWORD Value) { FLOAT Biased; + HRESULT hr; switch (static_cast(State)) { @@ -756,6 +763,13 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::SetRenderState(D3DRENDERSTATETYPE Sta return D3DERR_INVALIDCALL; case D3DRS_SOFTWAREVERTEXPROCESSING: return D3D_OK; + case D3DRS_CLIPPLANEENABLE: + hr = ProxyInterface->SetRenderState(State, Value); + if (SUCCEEDED(hr)) + { + ClipPlaneRenderState = Value; + } + return hr; case D3DRS_ZBIAS: Biased = static_cast(Value) * -0.000005f; Value = *reinterpret_cast(&Biased); @@ -1034,18 +1048,22 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::GetCurrentTexturePalette(UINT *pPalet } HRESULT STDMETHODCALLTYPE Direct3DDevice8::DrawPrimitive(D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount) { + ApplyClipPlanes(); return ProxyInterface->DrawPrimitive(PrimitiveType, StartVertex, PrimitiveCount); } HRESULT STDMETHODCALLTYPE Direct3DDevice8::DrawIndexedPrimitive(D3DPRIMITIVETYPE PrimitiveType, UINT MinIndex, UINT NumVertices, UINT StartIndex, UINT PrimitiveCount) { + ApplyClipPlanes(); return ProxyInterface->DrawIndexedPrimitive(PrimitiveType, CurrentBaseVertexIndex, MinIndex, NumVertices, StartIndex, PrimitiveCount); } HRESULT STDMETHODCALLTYPE Direct3DDevice8::DrawPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType, UINT PrimitiveCount, const void *pVertexStreamZeroData, UINT VertexStreamZeroStride) { + ApplyClipPlanes(); return ProxyInterface->DrawPrimitiveUP(PrimitiveType, PrimitiveCount, pVertexStreamZeroData, VertexStreamZeroStride); } HRESULT STDMETHODCALLTYPE Direct3DDevice8::DrawIndexedPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType, UINT MinVertexIndex, UINT NumVertexIndices, UINT PrimitiveCount, const void *pIndexData, D3DFORMAT IndexDataFormat, const void *pVertexStreamZeroData, UINT VertexStreamZeroStride) { + ApplyClipPlanes(); return ProxyInterface->DrawIndexedPrimitiveUP(PrimitiveType, MinVertexIndex, NumVertexIndices, PrimitiveCount, pIndexData, IndexDataFormat, pVertexStreamZeroData, VertexStreamZeroStride); } HRESULT STDMETHODCALLTYPE Direct3DDevice8::ProcessVertices(UINT SrcStartIndex, UINT DestIndex, UINT VertexCount, Direct3DVertexBuffer8 *pDestBuffer, DWORD Flags) @@ -2207,3 +2225,16 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::DeletePatch(UINT Handle) { return ProxyInterface->DeletePatch(Handle); } + +void Direct3DDevice8::ApplyClipPlanes() +{ + DWORD index = 0; + for (const auto clipPlane : StoredClipPlanes) + { + if ((ClipPlaneRenderState & (1 << index)) != 0) + { + ProxyInterface->SetClipPlane(index, clipPlane); + } + index++; + } +} \ No newline at end of file diff --git a/source/lookup_table.cpp b/source/lookup_table.cpp index e10b55d..4bbffeb 100644 --- a/source/lookup_table.cpp +++ b/source/lookup_table.cpp @@ -13,15 +13,11 @@ AddressLookupTable::AddressLookupTable(Direct3DDevice8 *Device) : } AddressLookupTable::~AddressLookupTable() { - for (UINT i = 0; i < 8; i++) + for (const auto& cache : AddressCache) { - while (AddressCache[i].size()) + for (const auto& entry : cache) { - auto it = AddressCache[i].begin(); - - it->second->DeleteMe(); - - it = AddressCache[i].erase(it); + entry.second->DeleteMe(); } } }