forked from sarkankur/Plugin_D3D
-
Notifications
You must be signed in to change notification settings - Fork 1
/
D3DPlugin_Sample_DX9_impl.h
76 lines (61 loc) · 1.71 KB
/
D3DPlugin_Sample_DX9_impl.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
// This sample will make your rendering window green, but you are free
// to do something more meaningfull ;)
#include <IPluginManager.h>
#include <IPluginD3D.h>
#include <d3d9.h>
class CMyD3D
: private D3DPlugin::ID3DEventListener
{
protected:
bool bDX9;
union device // Declare union type
{
void* ptr;
IDirect3DDevice9* dx9;
} m_pDevice;
PluginManager::IPluginBase* m_pD3DPlugin;
D3DPlugin::IPluginD3D* m_pD3DSystem;
IDirect3DStateBlock9* m_pStateBlock;
void OnPrePresent() {
if(bDX9)
{
// Save current D3D State [Optional: if you don't modify it]
m_pStateBlock->Capture();
// Apply custom rendering
// Make window green (TODO: Remove this and add your own stuff)
//m_pDevice.dx9->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(200,255,0), 1.0f, 0);
// Restore D3D State for next frame
m_pStateBlock->Apply();
}
};
void OnPostPresent() {};
void OnPreReset() {
SAFE_RELEASE(m_pStateBlock);
};
void OnPostReset() {};
void OnPostBeginScene() {};
public:
CMyD3D() {
m_pDevice.ptr = NULL;
m_pStateBlock = NULL;
m_pD3DPlugin = gPluginManager->GetPluginByName("D3D");
m_pD3DSystem = static_cast<D3DPlugin::IPluginD3D*>(m_pD3DPlugin ? m_pD3DPlugin->GetConcreteInterface() : NULL);
if(m_pD3DSystem)
{
// Initialize the device
m_pDevice.ptr = m_pD3DSystem->GetDevice();
bDX9 = true;
if(bDX9 && m_pDevice.ptr)
{ // Create D3D State [Optional: if you don't modify it]
m_pDevice.dx9->CreateStateBlock(D3DSBT_ALL, &m_pStateBlock);
}
// the listeners will be called renderer thread.
m_pD3DSystem->RegisterListener(this);
}
}
~CMyD3D() {
if(m_pD3DSystem)
m_pD3DSystem->UnregisterListener(this);
SAFE_RELEASE(m_pStateBlock);
}
};