Skip to content

Commit

Permalink
Setup software vertex processing toggle for mixed mode devices (#188)
Browse files Browse the repository at this point in the history
  • Loading branch information
WinterSnowfall authored Oct 27, 2024
1 parent b39e6d8 commit 3e293ca
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
3 changes: 2 additions & 1 deletion source/d3d8to9.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Direct3DDevice8 : public IDirect3DDevice8
Direct3DDevice8 &operator=(const Direct3DDevice8 &) = delete;

public:
Direct3DDevice8(Direct3D8 *d3d, IDirect3DDevice9 *ProxyInterface, BOOL EnableZBufferDiscarding = FALSE);
Direct3DDevice8(Direct3D8 *d3d, IDirect3DDevice9 *ProxyInterface, DWORD BehaviorFlags, BOOL EnableZBufferDiscarding = FALSE);
~Direct3DDevice8();

IDirect3DDevice9 *GetProxyInterface() const { return ProxyInterface; }
Expand Down Expand Up @@ -171,6 +171,7 @@ class Direct3DDevice8 : public IDirect3DDevice8
IDirect3DSurface9 *pCurrentRenderTarget = nullptr;
bool PaletteFlag = false;
bool IsRecordingState = false;
bool IsMixedVPModeDevice = false;

static constexpr size_t MAX_CLIP_PLANES = 6;
float StoredClipPlanes[MAX_CLIP_PLANES][4] = {};
Expand Down
2 changes: 1 addition & 1 deletion source/d3d8to9_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ HRESULT STDMETHODCALLTYPE Direct3D8::CreateDevice(UINT Adapter, D3DDEVTYPE Devic
if (FAILED(hr))
return hr;

*ppReturnedDeviceInterface = new Direct3DDevice8(this, DeviceInterface, (PresentParams.Flags & D3DPRESENTFLAG_DISCARD_DEPTHSTENCIL) != 0);
*ppReturnedDeviceInterface = new Direct3DDevice8(this, DeviceInterface, BehaviorFlags, (PresentParams.Flags & D3DPRESENTFLAG_DISCARD_DEPTHSTENCIL) != 0);

// Set default vertex declaration
DeviceInterface->SetFVF(D3DFVF_XYZ);
Expand Down
10 changes: 8 additions & 2 deletions source/d3d8to9_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ struct VertexShaderInfo
IDirect3DVertexDeclaration9 *Declaration = nullptr;
};

Direct3DDevice8::Direct3DDevice8(Direct3D8 *d3d, IDirect3DDevice9 *ProxyInterface, BOOL EnableZBufferDiscarding) :
Direct3DDevice8::Direct3DDevice8(Direct3D8 *d3d, IDirect3DDevice9 *ProxyInterface, DWORD BehaviorFlags, BOOL EnableZBufferDiscarding) :
D3D(d3d), ProxyInterface(ProxyInterface), ZBufferDiscarding(EnableZBufferDiscarding)
{
ProxyAddressLookupTable = new AddressLookupTable(this);
PaletteFlag = SupportsPalettes();

IsMixedVPModeDevice = BehaviorFlags & D3DCREATE_MIXED_VERTEXPROCESSING;
// The default value of D3DRS_POINTSIZE_MIN is 0.0f in D3D8,
// whereas in D3D9 it is 1.0f, so adjust it as needed
ProxyInterface->SetRenderState(D3DRS_POINTSIZE_MIN, (DWORD) 0.0f);
Expand Down Expand Up @@ -772,7 +773,12 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::SetRenderState(D3DRENDERSTATETYPE Sta
case D3DRS_ZVISIBLE:
case D3DRS_PATCHSEGMENTS:
case D3DRS_LINEPATTERN:
return D3D_OK;
case D3DRS_SOFTWAREVERTEXPROCESSING:
// SWVP can be modified by this render state only on devices
// created with the D3DCREATE_MIXED_VERTEXPROCESSING flag
if (IsMixedVPModeDevice)
return ProxyInterface->SetSoftwareVertexProcessing(static_cast<BOOL>(Value));
return D3D_OK;
case D3DRS_EDGEANTIALIAS:
return ProxyInterface->SetRenderState(D3DRS_ANTIALIASEDLINEENABLE, Value);
Expand Down Expand Up @@ -810,7 +816,7 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::GetRenderState(D3DRENDERSTATETYPE Sta
*pValue = static_cast<DWORD>(*reinterpret_cast<const FLOAT*>(pValue) * -200000.0f);
return hr;
case D3DRS_SOFTWAREVERTEXPROCESSING:
*pValue = ProxyInterface->GetSoftwareVertexProcessing();
*pValue = static_cast<DWORD>(ProxyInterface->GetSoftwareVertexProcessing());
return D3D_OK;
case D3DRS_PATCHSEGMENTS:
*pValue = 1;
Expand Down

0 comments on commit 3e293ca

Please sign in to comment.