Skip to content

Commit

Permalink
Merge pull request #74 from CookiePLMonster/master
Browse files Browse the repository at this point in the history
  • Loading branch information
crosire authored Apr 14, 2018
2 parents 882a425 + cc7bc67 commit 08bd54c
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 13 deletions.
6 changes: 6 additions & 0 deletions source/d3d8to9.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions source/d3d8to9_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
35 changes: 33 additions & 2 deletions source/d3d8to9_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<DWORD>(State))
{
Expand All @@ -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<FLOAT>(Value) * -0.000005f;
Value = *reinterpret_cast<const DWORD *>(&Biased);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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++;
}
}
10 changes: 3 additions & 7 deletions source/lookup_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}

0 comments on commit 08bd54c

Please sign in to comment.