forked from prototype99/dsfix
-
Notifications
You must be signed in to change notification settings - Fork 1
/
RenderstateManager.h
157 lines (157 loc) · 7.4 KB
/
RenderstateManager.h
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#pragma once
#include <map>
#include <set>
#include <vector>
#include "d3d9.h"
#include "SMAA.h"
#include "FXAA.h"
#include "SSAO.h"
#include "GAUSS.h"
#include "HUD.h"
class RSManager {
static RSManager instance;
bool inited;
D3DVIEWPORT9 viewport;
IDirect3DDevice9 *d3ddev;
double lastPresentTime;
bool lowFPSmode;
bool doAA;
SMAA* smaa;
FXAA* fxaa;
bool doSsao;
SSAO* ssao;
bool doDofGauss;
GAUSS* gauss;
bool doHud;
HUD* hud;
IDirect3DTexture9* rgbaBuffer1Tex;
IDirect3DSurface9* rgbaBuffer1Surf;
IDirect3DSurface9* depthStencilSurf;
IDirect3DSurface9* zSurf;
bool hideHud;
bool onHudRT, pausedHudRT;
bool paused;
std::set<int> dumpedTextures;
unsigned texIndex, mainRenderTexIndex, mainRenderSurfIndex;
typedef std::map<IDirect3DTexture9*, int> TexIntMap;
TexIntMap texIndices, mainRenderTexIndices;
typedef std::map<IDirect3DSurface9*, int> SurfIntMap;
SurfIntMap mainRenderSurfIndices;
bool captureNextFrame, capturing, hudStarted, takeScreenshot;
unsigned dumpCaptureIndex;
void dumpSurface(const char* name, IDirect3DSurface9* surface);
#define TEXTURE(_name, _hash) \
private: \
static const UINT32 texture##_name##Hash = _hash; \
IDirect3DTexture9* texture##_name; \
bool isTexture##_name(IDirect3DBaseTexture9* pTexture) { return texture##_name && ((IDirect3DTexture9*)pTexture) == texture##_name; };
#include "Textures.def"
#undef TEXTURE
bool isTextureText(IDirect3DBaseTexture9* pTexture);
const char* getTextureName(IDirect3DBaseTexture9* pTexture);
unsigned numKnownTextures, foundKnownTextures;
unsigned skippedPresents;
/*RenderDoneDetectionProgress
basically, when the game switches rendertargets after setting texture 0 to 3 in order, but no others,
we assume we just finished rendering the hud-less image. This variable keeps track of the number of "correct" texture settings.*/
unsigned rddp;
/*NumRenderTargetSwitches
we use the number of switches between rendertargets to figure out where we are in the pipeline. Yeah, it's flaky*/
unsigned nrts;
//Count the number of times the 2 upper DoF rendertargets were set in doft[1] & doft[2]
unsigned doft[3];
unsigned isDof(unsigned width, unsigned height);
/*HudDoneDetectionProgress
sequence: 5xHudHealthbar, 2-3xCategoryIconsSoulCount, followed by any other texture signals end of normal Hud drawing
TODO: handle cursed*/
unsigned hddp;
//main rendertarget for this frame
IDirect3DSurface9* mainRT;
unsigned mainRTuses;
void registerKnowTexture(LPCVOID pSrcData, UINT SrcDataSize, LPDIRECT3DTEXTURE9 pTexture);
IDirect3DTexture9* getSurfTexture(IDirect3DSurface9* pSurface);
//Render state store/restore
void storeRenderState();
void restoreRenderState();
IDirect3DVertexDeclaration9* prevVDecl;
IDirect3DSurface9* prevDepthStencilSurf;
IDirect3DSurface9* prevRenderTarget;
IDirect3DTexture9* prevRenderTex;
IDirect3DStateBlock9* prevStateBlock;
struct MemData
{
char* buffer;
long size;
};
std::map<UINT32, MemData> cachedTexFiles;
bool disassembleShader(CONST DWORD *pFunction, LPD3DXBUFFER *ppBuffer);
void dumpShader(UINT32 hash, const char *directory, LPD3DXBUFFER pBuffer);
bool getOverrideShader(UINT32 hash, const char *directory, LPD3DXBUFFER *ppBuffer);
bool haveOcclusionScale;
float occlusionScale;
void measureOcclusionScale();
private:
~RSManager();
public:
static RSManager& get() {
return instance;
}
RSManager() : smaa(NULL), fxaa(NULL), ssao(NULL), gauss(NULL), rgbaBuffer1Surf(NULL), rgbaBuffer1Tex(NULL),
inited(false), doAA(true), doSsao(true), doDofGauss(true), doHud(true), captureNextFrame(false), capturing(false), hudStarted(false), takeScreenshot(false), hideHud(false),
mainRenderTexIndex(0), mainRenderSurfIndex(0), dumpCaptureIndex(0), numKnownTextures(0), foundKnownTextures(0), skippedPresents(0), haveOcclusionScale(false), occlusionScale(1) {
#define TEXTURE(_name, _hash) ++numKnownTextures;
#include "Textures.def"
#undef TEXTURE
}
void setD3DDevice(IDirect3DDevice9 *pD3Ddev) { d3ddev = pD3Ddev; }
void initResources();
void releaseResources();
void prefetchTextures();
void setViewport(const D3DVIEWPORT9& vp) {
viewport = vp;
}
bool isViewport(const RECT& r) {
return (r.left == viewport.X) && (r.top == viewport.Y) && (r.bottom == viewport.Height) && (r.right == viewport.Width);
}
D3DPRESENT_PARAMETERS adjustPresentationParameters(const D3DPRESENT_PARAMETERS *pPresentationParameters);
void enableSingleFrameCapture();
void enableTakeScreenshot();
bool takingScreenshot() { return takeScreenshot; }
void toggleAA() { doAA = !doAA; }
void toggleVssao() { doSsao = !doSsao; }
void toggleHideHud() { hideHud = !hideHud; }
void toggleChangeHud() { doHud = !doHud; }
void toggleDofGauss() { doDofGauss = !doDofGauss; }
void reloadVssao();
void reloadHbao();
void reloadScao();
void reloadGauss();
void reloadAA();
bool allowStateChanges() { return !onHudRT; }
INT16 hudVertices[32];
void reloadHudVertices();
void registerMainRenderTexture(IDirect3DTexture9* pTexture);
void registerMainRenderSurface(IDirect3DSurface9* pSurface);
unsigned getTextureIndex(IDirect3DTexture9* ppTexture);
void registerD3DXCreateTextureFromFileInMemory(LPCVOID pSrcData, UINT SrcDataSize, LPDIRECT3DTEXTURE9 pTexture);
void registerD3DXCompileShader(LPCSTR pSrcData, UINT srcDataLen, const D3DXMACRO *pDefines, LPD3DXINCLUDE pInclude, LPCSTR pFunctionName, LPCSTR pProfile, DWORD Flags, LPD3DXBUFFER * ppShader, LPD3DXBUFFER * ppErrorMsgs, LPD3DXCONSTANTTABLE * ppConstantTable);
HRESULT redirectSetRenderTarget(DWORD RenderTargetIndex, IDirect3DSurface9* pRenderTarget);
void finishHudRendering();
void pauseHudRendering();
void resumeHudRendering();
HRESULT redirectStretchRect(IDirect3DSurface9* pSourceSurface, CONST RECT* pSourceRect, IDirect3DSurface9* pDestSurface, CONST RECT* pDestRect, D3DTEXTUREFILTERTYPE Filter);
HRESULT redirectSetTexture(DWORD Stage, IDirect3DBaseTexture9 * pTexture);
HRESULT redirectSetDepthStencilSurface(IDirect3DSurface9* pNewZStencil);
HRESULT redirectPresent(CONST RECT * pSourceRect, CONST RECT * pDestRect, HWND hDestWindowOverride, CONST RGNDATA * pDirtyRegion);
void frameTimeManagement();
void togglePaused() { paused = !paused; }
bool isPaused() { return paused; }
HRESULT redirectDrawIndexedPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType, UINT MinIndex, UINT NumVertices, UINT PrimitiveCount, CONST void* pIndexData, D3DFORMAT IndexDataFormat, CONST void* pVertexStreamZeroData, UINT VertexStreamZeroStride);
HRESULT redirectDrawPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType, UINT PrimitiveCount, CONST void* pVertexStreamZeroData, UINT VertexStreamZeroStride);
HRESULT redirectD3DXCreateTextureFromFileInMemoryEx(LPDIRECT3DDEVICE9 pDevice, LPCVOID pSrcData, UINT SrcDataSize, UINT Width, UINT Height, UINT MipLevels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, DWORD Filter, DWORD MipFilter, D3DCOLOR ColorKey, D3DXIMAGE_INFO* pSrcInfo, PALETTEENTRY* pPalette, LPDIRECT3DTEXTURE9* ppTexture);
HRESULT redirectSetTextureStageState(DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value);
HRESULT redirectSetRenderState(D3DRENDERSTATETYPE State, DWORD Value);
HRESULT redirectCreatePixelShader(CONST DWORD *pfunction, IDirect3DPixelShader9 **ppShader);
HRESULT redirectCreateVertexShader(CONST DWORD *pfunction, IDirect3DVertexShader9 **ppShader);
float getOcclusionScale() const { return occlusionScale; }
};