Skip to content

Commit b34ad36

Browse files
author
Alexandre Pestana
committed
First Commit
1 parent c25129e commit b34ad36

File tree

4 files changed

+415
-0
lines changed

4 files changed

+415
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This is a small code skeleton heavily based on the work of Temaran (https://github.com/Temaran/UE4RenderDocPlugin) that will integrate RenderDoc (https://github.com/baldurk/renderdoc) in your engine.
2+
You just need to call the RenderDocManager constructor before the D3D initialization and you should be able to capture a frame using the StartFrameCapture() and EndFrameCapture() or by pressing the "CaptureKey" defined in the constructor.
3+

RenderDocManager.cpp

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/******************************************************************************
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2014 Fredrik Lindh
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
******************************************************************************/
24+
25+
#include "stdafx.h"
26+
#include "RenderDocManager.h"
27+
#include <string>
28+
29+
RenderDocManager::RenderDocManager(HWND p_Handle, LPCWSTR pRenderDocPath, LPCWSTR pCapturePath)
30+
{
31+
m_Handle = p_Handle;
32+
m_CaptureStarted = false;
33+
34+
m_RenderDocDLL = LoadLibrary(pRenderDocPath);
35+
36+
//Init function pointers
37+
m_RenderDocGetAPIVersion = (pRENDERDOC_GetAPIVersion)GetRenderDocFunctionPointer(m_RenderDocDLL, "RENDERDOC_GetAPIVersion");
38+
m_RenderDocSetLogFile = (pRENDERDOC_SetLogFile)GetRenderDocFunctionPointer(m_RenderDocDLL, "RENDERDOC_SetLogFile");
39+
40+
m_RenderDocSetCaptureOptions = (pRENDERDOC_SetCaptureOptions)GetRenderDocFunctionPointer(m_RenderDocDLL, "RENDERDOC_SetCaptureOptions");
41+
m_RenderDocGetCapture = (pRENDERDOC_GetCapture)GetRenderDocFunctionPointer(m_RenderDocDLL, "RENDERDOC_GetCapture");
42+
m_RenderDocSetActiveWindow = (pRENDERDOC_SetActiveWindow)GetRenderDocFunctionPointer(m_RenderDocDLL, "RENDERDOC_SetActiveWindow");
43+
m_RenderDocTriggerCapture = (pRENDERDOC_TriggerCapture)GetRenderDocFunctionPointer(m_RenderDocDLL, "RENDERDOC_TriggerCapture");
44+
m_RenderDocStartFrameCapture = (pRENDERDOC_StartFrameCapture)GetRenderDocFunctionPointer(m_RenderDocDLL, "RENDERDOC_StartFrameCapture");
45+
m_RenderDocEndFrameCapture = (pRENDERDOC_EndFrameCapture)GetRenderDocFunctionPointer(m_RenderDocDLL, "RENDERDOC_EndFrameCapture");
46+
47+
m_RenderDocGetOverlayBits = (pRENDERDOC_GetOverlayBits)GetRenderDocFunctionPointer(m_RenderDocDLL, "RENDERDOC_GetOverlayBits");
48+
m_RenderDocMaskOverlayBits = (pRENDERDOC_MaskOverlayBits)GetRenderDocFunctionPointer(m_RenderDocDLL, "RENDERDOC_MaskOverlayBits");
49+
50+
m_RenderDocSetFocusToggleKeys = (pRENDERDOC_SetFocusToggleKeys)GetRenderDocFunctionPointer(m_RenderDocDLL, "RENDERDOC_SetFocusToggleKeys");
51+
m_RenderDocSetCaptureKeys = (pRENDERDOC_SetCaptureKeys)GetRenderDocFunctionPointer(m_RenderDocDLL, "RENDERDOC_SetCaptureKeys");
52+
53+
m_RenderDocInitRemoteAccess = (pRENDERDOC_InitRemoteAccess)GetRenderDocFunctionPointer(m_RenderDocDLL, "RENDERDOC_InitRemoteAccess");
54+
55+
m_RenderDocSetLogFile(pCapturePath);
56+
57+
KeyButton captureKey = eKey_F12;
58+
59+
m_RenderDocSetFocusToggleKeys(NULL, 0);
60+
m_RenderDocSetCaptureKeys(NULL, 0);
61+
62+
//KeyButton captureKey = eKey_F12;
63+
//m_RenderDocSetCaptureKeys(&captureKey, 1);
64+
65+
CaptureOptions options;
66+
options.CaptureCallstacks = true;
67+
options.CaptureAllCmdLists = true;
68+
options.SaveAllInitials = true;
69+
70+
m_RenderDocSetCaptureOptions(&options);
71+
72+
// Init remote access.
73+
m_SocketPort = 0;
74+
m_RenderDocInitRemoteAccess(&m_SocketPort);
75+
76+
m_RenderDocMaskOverlayBits(eOverlay_None, eOverlay_None);
77+
}
78+
79+
void RenderDocManager::StartFrameCapture()
80+
{
81+
m_RenderDocStartFrameCapture(m_Handle);
82+
m_CaptureStarted = true;
83+
}
84+
85+
void RenderDocManager::EndFrameCapture()
86+
{
87+
if(!m_CaptureStarted)
88+
return;
89+
90+
m_RenderDocEndFrameCapture(m_Handle);
91+
m_CaptureStarted = false;
92+
}
93+
94+
RenderDocManager::~RenderDocManager(void)
95+
{
96+
FreeLibrary(m_RenderDocDLL);
97+
}
98+
99+
void* RenderDocManager::GetRenderDocFunctionPointer(HINSTANCE ModuleHandle, LPCSTR FunctionName)
100+
{
101+
void* OutTarget = NULL;
102+
OutTarget = (void*)GetProcAddress(ModuleHandle, FunctionName);
103+
104+
return OutTarget;
105+
}

RenderDocManager.h

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/******************************************************************************
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2014 Fredrik Lindh
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
******************************************************************************/
24+
25+
#pragma once
26+
#include "renderdoc_app.h"
27+
28+
class RenderDocManager
29+
{
30+
public:
31+
RenderDocManager(HWND p_Handle, LPCWSTR pRenderDocPath, LPCWSTR pCapturePath);
32+
~RenderDocManager(void);
33+
void StartFrameCapture();
34+
void EndFrameCapture();
35+
36+
private:
37+
HINSTANCE m_RenderDocDLL;
38+
UINT32 m_SocketPort;
39+
HWND m_Handle;
40+
bool m_CaptureStarted;
41+
42+
//General
43+
pRENDERDOC_GetAPIVersion m_RenderDocGetAPIVersion;
44+
pRENDERDOC_SetLogFile m_RenderDocSetLogFile;
45+
46+
//Capture
47+
pRENDERDOC_SetCaptureOptions m_RenderDocSetCaptureOptions;
48+
pRENDERDOC_GetCapture m_RenderDocGetCapture;
49+
pRENDERDOC_SetActiveWindow m_RenderDocSetActiveWindow;
50+
pRENDERDOC_TriggerCapture m_RenderDocTriggerCapture;
51+
pRENDERDOC_StartFrameCapture m_RenderDocStartFrameCapture;
52+
pRENDERDOC_EndFrameCapture m_RenderDocEndFrameCapture;
53+
54+
//Overlay
55+
pRENDERDOC_GetOverlayBits m_RenderDocGetOverlayBits;
56+
pRENDERDOC_MaskOverlayBits m_RenderDocMaskOverlayBits;
57+
58+
//Hotkeys
59+
pRENDERDOC_SetFocusToggleKeys m_RenderDocSetFocusToggleKeys;
60+
pRENDERDOC_SetCaptureKeys m_RenderDocSetCaptureKeys;
61+
62+
//Remote access
63+
pRENDERDOC_InitRemoteAccess m_RenderDocInitRemoteAccess;
64+
65+
void* GetRenderDocFunctionPointer(HINSTANCE ModuleHandle, LPCSTR FunctionName);
66+
};
67+

0 commit comments

Comments
 (0)