-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathd3d8to9_device.cpp
More file actions
108 lines (81 loc) · 3.66 KB
/
d3d8to9_device.cpp
File metadata and controls
108 lines (81 loc) · 3.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include "../imguihandler.hpp"
#include <imgui.h>
Direct3DDevice8::Direct3DDevice8(Direct3D8* d3d, IDirect3DDevice9* ProxyInterface, DWORD BehaviorFlags, D3DFORMAT ZBufferFormat, BOOL EnableZBufferDiscarding) :
D3D(d3d), ProxyInterface(ProxyInterface), ZBufferDiscarding(EnableZBufferDiscarding)
{
ProxyAddressLookupTable = new AddressLookupTable(this);
PaletteFlag = SupportsPalettes();
ZBufferBitCount = GetDepthStencilBitCount(ZBufferFormat);
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);
// The DEPTHBIAS value of -0.0f works differently than 0.0f
// Some games require defaulting to -0.0f to work correctly
float DepthBias = -0.0f;
ProxyInterface->SetRenderState(D3DRS_DEPTHBIAS, *(DWORD*)&DepthBias);
D3DDEVICE_CREATION_PARAMETERS params;
ProxyInterface->GetCreationParameters(¶ms);
ImGuiHandler::init(ProxyInterface, params.hFocusWindow);
}
Direct3DDevice8::~Direct3DDevice8()
{
ImGuiHandler::shutdown();
delete ProxyAddressLookupTable;
}
HRESULT STDMETHODCALLTYPE Direct3DDevice8::CreateAdditionalSwapChain(D3DPRESENT_PARAMETERS8* pPresentationParameters, IDirect3DSwapChain8** ppSwapChain)
{
#ifndef D3D8TO9NOLOG
LOG << "Redirecting '" << "IDirect3DDevice8::CreateAdditionalSwapChain" << "(" << this << ", " << pPresentationParameters << ", " << ppSwapChain << ")' ..." << std::endl;
#endif
if (pPresentationParameters == nullptr || ppSwapChain == nullptr)
return D3DERR_INVALIDCALL;
*ppSwapChain = nullptr;
D3DPRESENT_PARAMETERS PresentParams;
ConvertPresentParameters(*pPresentationParameters, PresentParams);
IDirect3DSwapChain9* SwapChainInterface = nullptr;
const HRESULT hr = ProxyInterface->CreateAdditionalSwapChain(&PresentParams, &SwapChainInterface);
if (FAILED(hr))
return hr;
*ppSwapChain = ProxyAddressLookupTable->FindAddress<Direct3DSwapChain8>(SwapChainInterface);
return D3D_OK;
}
HRESULT STDMETHODCALLTYPE Direct3DDevice8::Reset(D3DPRESENT_PARAMETERS8* pPresentationParameters)
{
#ifndef D3D8TO9NOLOG
LOG << "Redirecting '" << "IDirect3DDevice8::Reset" << "(" << this << ", " << pPresentationParameters << ")' ..." << std::endl;
#endif
if (pPresentationParameters == nullptr)
return D3DERR_INVALIDCALL;
ImGuiHandler::onReset();
ZBiasRenderState = 0;
const HRESULT deviceState = ProxyInterface->TestCooperativeLevel();
if (deviceState == D3DERR_DEVICENOTRESET) {
while (!StateBlockTokens.empty())
{
DWORD Token = *StateBlockTokens.begin();
DeleteStateBlock(Token);
}
}
D3DPRESENT_PARAMETERS PresentParams;
ConvertPresentParameters(*pPresentationParameters, PresentParams);
const HRESULT hr = ProxyInterface->Reset(&PresentParams);
if (SUCCEEDED(hr))
{
// 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);
// The DEPTHBIAS value of -0.0f works differently than 0.0f
// Some games require defaulting to -0.0f to work correctly
float DepthBias = -0.0f;
ProxyInterface->SetRenderState(D3DRS_DEPTHBIAS, *(DWORD*)&DepthBias);
ImGuiHandler::onResetComplete();
}
return hr;
}
HRESULT STDMETHODCALLTYPE Direct3DDevice8::Present(const RECT* pSourceRect, const RECT* pDestRect, HWND hDestWindowOverride, const RGNDATA* pDirtyRegion)
{
UNREFERENCED_PARAMETER(pDirtyRegion);
ImGuiHandler::render();
return ProxyInterface->Present(pSourceRect, pDestRect, hDestWindowOverride, nullptr);
}