diff --git a/renderdoc/driver/d3d9/d3d9_device.cpp b/renderdoc/driver/d3d9/d3d9_device.cpp
index c58b5af43..a660a0d1c 100644
--- a/renderdoc/driver/d3d9/d3d9_device.cpp
+++ b/renderdoc/driver/d3d9/d3d9_device.cpp
@@ -27,7 +27,7 @@
#include "serialise/serialiser.h"
#include "d3d9_debug.h"
-WrappedD3DDevice9::WrappedD3DDevice9(IDirect3DDevice9 *device)
+WrappedD3DDevice9::WrappedD3DDevice9(IDirect3DDevice9 *device, HWND wnd)
: m_RefCounter(device, false),
m_SoftRefCounter(NULL, false),
m_device(device),
@@ -40,6 +40,16 @@ WrappedD3DDevice9::WrappedD3DDevice9(IDirect3DDevice9 *device)
m_SoftRefCounter.Release();
m_InternalRefcount = 0;
m_Alive = true;
+
+ if(!RenderDoc::Inst().IsReplayApp())
+ {
+ RenderDoc::Inst().AddDeviceFrameCapturer((IDirect3DDevice9 *)this, this);
+
+ m_Wnd = wnd;
+
+ if(wnd != NULL)
+ RenderDoc::Inst().AddFrameCapturer((IDirect3DDevice9 *)this, wnd, this);
+ }
}
void WrappedD3DDevice9::CheckForDeath()
@@ -61,6 +71,11 @@ void WrappedD3DDevice9::CheckForDeath()
WrappedD3DDevice9::~WrappedD3DDevice9()
{
+ RenderDoc::Inst().RemoveDeviceFrameCapturer((IDirect3DDevice9 *)this);
+
+ if(m_Wnd != NULL)
+ RenderDoc::Inst().RemoveFrameCapturer((IDirect3DDevice9 *)this, m_Wnd);
+
SAFE_DELETE(m_DebugManager);
SAFE_RELEASE(m_device);
@@ -92,6 +107,17 @@ void WrappedD3DDevice9::LazyInit()
m_DebugManager = new D3D9DebugManager(this);
}
+void WrappedD3DDevice9::StartFrameCapture(void *dev, void *wnd)
+{
+ RDCERR("Capture not supported on D3D9");
+}
+
+bool WrappedD3DDevice9::EndFrameCapture(void *dev, void *wnd)
+{
+ RDCERR("Capture not supported on D3D9");
+ return false;
+}
+
HRESULT __stdcall WrappedD3DDevice9::TestCooperativeLevel()
{
return m_device->TestCooperativeLevel();
@@ -167,6 +193,20 @@ HRESULT __stdcall WrappedD3DDevice9::Reset(D3DPRESENT_PARAMETERS *pPresentationP
HRESULT __stdcall WrappedD3DDevice9::Present(CONST RECT *pSourceRect, CONST RECT *pDestRect,
HWND hDestWindowOverride, CONST RGNDATA *pDirtyRegion)
{
+ // if(m_State == WRITING_IDLE)
+ RenderDoc::Inst().Tick();
+
+ IDirect3DSwapChain9 *swapChain;
+ m_device->GetSwapChain(0, &swapChain);
+ D3DPRESENT_PARAMETERS presentParams;
+ swapChain->GetPresentParameters(&presentParams);
+
+ HWND wnd = presentParams.hDeviceWindow;
+ if(hDestWindowOverride != NULL)
+ wnd = hDestWindowOverride;
+
+ bool activeWindow = RenderDoc::Inst().IsActiveWindow((IDirect3DDevice9 *)this, wnd);
+
m_FrameCounter++;
// if (m_State == WRITING_IDLE)
@@ -189,11 +229,6 @@ HRESULT __stdcall WrappedD3DDevice9::Present(CONST RECT *pSourceRect, CONST RECT
D3DSURFACE_DESC bbDesc;
backBuffer->GetDesc(&bbDesc);
- IDirect3DSwapChain9 *swapChain;
- m_device->GetSwapChain(0, &swapChain);
- D3DPRESENT_PARAMETERS presentParams;
- swapChain->GetPresentParameters(&presentParams);
-
//
D3DVIEWPORT9 viewport = {0, 0, bbDesc.Width, bbDesc.Height, 0.f, 1.f};
res |= m_device->SetViewport(&viewport);
@@ -201,8 +236,10 @@ HRESULT __stdcall WrappedD3DDevice9::Present(CONST RECT *pSourceRect, CONST RECT
GetDebugManager()->SetOutputDimensions(bbDesc.Width, bbDesc.Height);
GetDebugManager()->SetOutputWindow(presentParams.hDeviceWindow);
- string overlayText = RenderDoc::Inst().GetOverlayText(RDC_D3D9, m_FrameCounter,
- RenderDoc::eOverlay_CaptureDisabled);
+ int flags = activeWindow ? RenderDoc::eOverlay_ActiveWindow : 0;
+ flags |= RenderDoc::eOverlay_CaptureDisabled;
+
+ string overlayText = RenderDoc::Inst().GetOverlayText(RDC_D3D9, m_FrameCounter, flags);
overlayText += "Captures not supported with D3D9\n";
@@ -214,6 +251,11 @@ HRESULT __stdcall WrappedD3DDevice9::Present(CONST RECT *pSourceRect, CONST RECT
}
}
+ if(activeWindow)
+ {
+ RenderDoc::Inst().SetCurrentDriver(RDC_D3D9);
+ }
+
return m_device->Present(pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
}
@@ -936,7 +978,14 @@ HRESULT __stdcall WrappedD3D9::CreateDevice(UINT Adapter, D3DDEVTYPE DeviceType,
{
RDCLOG("App creating d3d9 device");
- WrappedD3DDevice9 *wrappedDevice = new WrappedD3DDevice9(device);
+ HWND wnd = pPresentationParameters->hDeviceWindow;
+ if(wnd == NULL)
+ wnd = hFocusWindow;
+
+ if(!wnd)
+ RDCWARN("Couldn't find valid non-NULL window at CreateDevice time");
+
+ WrappedD3DDevice9 *wrappedDevice = new WrappedD3DDevice9(device, wnd);
wrappedDevice->LazyInit(); // TODO this can be moved later probably
*ppReturnedDeviceInterface = wrappedDevice;
}
diff --git a/renderdoc/driver/d3d9/d3d9_device.h b/renderdoc/driver/d3d9/d3d9_device.h
index 5c6f8f2fa..e0f841a3e 100644
--- a/renderdoc/driver/d3d9/d3d9_device.h
+++ b/renderdoc/driver/d3d9/d3d9_device.h
@@ -28,14 +28,17 @@
class D3D9DebugManager;
-class WrappedD3DDevice9 : public IDirect3DDevice9
+class WrappedD3DDevice9 : public IDirect3DDevice9, public IFrameCapturer
{
public:
- WrappedD3DDevice9(IDirect3DDevice9 *device);
+ WrappedD3DDevice9(IDirect3DDevice9 *device, HWND wnd);
~WrappedD3DDevice9();
void LazyInit();
+ void StartFrameCapture(void *dev, void *wnd);
+ bool EndFrameCapture(void *dev, void *wnd);
+
void InternalRef() { InterlockedIncrement(&m_InternalRefcount); }
void InternalRelease() { InterlockedDecrement(&m_InternalRefcount); }
void SoftRef() { m_SoftRefCounter.AddRef(); }
@@ -247,6 +250,8 @@ private:
IDirect3DDevice9 *m_device;
D3D9DebugManager *m_DebugManager;
+ HWND m_Wnd;
+
unsigned int m_InternalRefcount;
RefCounter9 m_RefCounter;
RefCounter9 m_SoftRefCounter;
diff --git a/renderdoc/driver/d3d9/d3d9_replay.cpp b/renderdoc/driver/d3d9/d3d9_replay.cpp
new file mode 100644
index 000000000..89e705ebc
--- /dev/null
+++ b/renderdoc/driver/d3d9/d3d9_replay.cpp
@@ -0,0 +1,33 @@
+/******************************************************************************
+* The MIT License (MIT)
+*
+* Copyright (c) 2016 Baldur Karlsson
+*
+* Permission is hereby granted, free of charge, to any person obtaining a copy
+* of this software and associated documentation files (the "Software"), to deal
+* in the Software without restriction, including without limitation the rights
+* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+* copies of the Software, and to permit persons to whom the Software is
+* furnished to do so, subject to the following conditions:
+*
+* The above copyright notice and this permission notice shall be included in
+* all copies or substantial portions of the Software.
+*
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+* THE SOFTWARE.
+******************************************************************************/
+
+#include "d3d9_common.h"
+
+ReplayCreateStatus D3D9_CreateReplayDevice(const char *logfile, IReplayDriver **driver)
+{
+ RDCERR("D3D9 captures are not currently supported");
+ return eReplayCreate_APIUnsupported;
+}
+
+static DriverRegistration D3D9DriverRegistration(RDC_D3D9, "D3D9", &D3D9_CreateReplayDevice);
diff --git a/renderdoc/driver/d3d9/renderdoc_d3d9.vcxproj b/renderdoc/driver/d3d9/renderdoc_d3d9.vcxproj
index e4e59fa4c..a74dfe6cf 100644
--- a/renderdoc/driver/d3d9/renderdoc_d3d9.vcxproj
+++ b/renderdoc/driver/d3d9/renderdoc_d3d9.vcxproj
@@ -188,6 +188,7 @@
+
diff --git a/renderdoc/driver/d3d9/renderdoc_d3d9.vcxproj.filters b/renderdoc/driver/d3d9/renderdoc_d3d9.vcxproj.filters
index 5c72514b2..33473de91 100644
--- a/renderdoc/driver/d3d9/renderdoc_d3d9.vcxproj.filters
+++ b/renderdoc/driver/d3d9/renderdoc_d3d9.vcxproj.filters
@@ -13,6 +13,9 @@
{503975e6-f4c0-4efc-8ff1-77e4082c5998}
+
+ {03d937fd-e33a-4b97-aa7e-5f2990163c9b}
+
@@ -27,6 +30,9 @@
Common
+
+ Replay
+