STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
vsgcapture.h
Go to the documentation of this file.
1 #pragma once
2 #pragma comment(lib,"VsGraphicsHelper.lib")
3 
4 #include <Windows.h>
5 #include <stdio.h>
6 #include <sal.h>
7 #include <functional>
8 
9 #if defined(__ID3D11DeviceContext2_INTERFACE_DEFINED__)
10 #error Programmatic graphics capture does not support Direct3D 11.2 APIs.
11 #endif
12 
13 #ifndef VSG_DEFAULT_RUN_FILENAME
14 #define VSG_DEFAULT_RUN_FILENAME L"default.vsglog"
15 #endif
16 
17 extern "C" void __stdcall VsgDbgInit(_In_z_ wchar_t const * szVSGLog);
18 extern "C" void __stdcall VsgDbgInitDelayed(std::function<void (int len, wchar_t * pszBuffer)>);
19 extern "C" void __stdcall VsgDbgUnInit();
20 extern "C" void __stdcall VsgDbgToggleHUD();
21 extern "C" void __stdcall VsgDbgCaptureCurrentFrame();
22 extern "C" void __stdcall VsgDbgBeginCapture();
23 extern "C" void __stdcall VsgDbgEndCapture();
24 extern "C" void __stdcall VsgDbgCopy(_In_z_ wchar_t const * szNewVSGLog);
25 extern "C" void __stdcall VsgDbgAddHUDMessage(_In_z_ wchar_t const * szMessage);
26 
27 
28 class VsgDbg
29 {
30 public:
31  VsgDbg(bool bDefaultInit)
32  {
33  if(bDefaultInit)
34  {
35 #ifndef DONT_SAVE_VSGLOG_TO_TEMP
36 
37 #if WINAPI_FAMILY == 2
38  Init([=] (int len, wchar_t * pszBuffer) {
39 
40  const wchar_t * tempPath = Platform::String::Concat(Platform::String::Concat(Windows::Storage::ApplicationData::Current->TemporaryFolder->Path, L"\\"), VSG_DEFAULT_RUN_FILENAME)->Data();
41  wcscpy_s(pszBuffer, len, tempPath);
42  });
43 #else
44  Init([=] (int len, wchar_t * pszBuffer) {
45 
46  wchar_t tempDir[MAX_PATH];
47  wchar_t filePath[MAX_PATH];
48 
49  if(GetTempPath(MAX_PATH, tempDir) == 0)
50  {
51  return;
52  }
53 
54  swprintf_s(filePath, MAX_PATH, L"%s%s", tempDir, VSG_DEFAULT_RUN_FILENAME);
55 
56  wcscpy_s(pszBuffer, len, filePath);
57  });
58 #endif
59 
60 #else
61  Init([=] (int len, wchar_t * pszBuffer) {
62  wcscpy_s(pszBuffer, len, VSG_DEFAULT_RUN_FILENAME);
63  });
64 #endif
65  }
66  }
67 
69  {
70  UnInit();
71  }
72 
73  void Init(std::function<void (int len, wchar_t * pszBuffer)> vsgLogGetter)
74  {
75  VsgDbgInitDelayed(vsgLogGetter);
76  }
77 
78 
79  void UnInit()
80  {
81  VsgDbgUnInit();
82  }
83 
84  void ToggleHUD()
85  {
87  }
88 
89  void BeginCapture ()
90  {
92  }
93 
94  void EndCapture ()
95  {
97  }
98 
100  {
102  }
103 
104  void Copy(_In_z_ wchar_t const * szNewVSGLog)
105  {
106  VsgDbgCopy(szNewVSGLog);
107  }
108 
109  void AddMessage(_In_z_ wchar_t const * szMessage)
110  {
111  VsgDbgAddHUDMessage(szMessage);
112  }
113 };
114 
115 #ifndef VSG_NODEFAULT_INSTANCE
116  _declspec(selectany) VsgDbg *g_pVsgDbg;
117 
118  inline void UnInitVsPix()
119  {
120  if(g_pVsgDbg != NULL)
121  {
122  delete g_pVsgDbg;
123  }
124  }
125 
126  inline void InitVsPix()
127  {
128  g_pVsgDbg = new VsgDbg(true); atexit(&UnInitVsPix);
129  }
130 
131 
132  #pragma section(".CRT$XCT",long,read)
133  __declspec(allocate(".CRT$XCT")) _declspec(selectany) _declspec(dllexport) void (*pInitFunc)() = InitVsPix;
134 
135 #endif
void __stdcall VsgDbgInitDelayed(std::function< void(int len, wchar_t *pszBuffer)>)
void ToggleHUD()
Definition: vsgcapture.h:84
void Init(std::function< void(int len, wchar_t *pszBuffer)> vsgLogGetter)
Definition: vsgcapture.h:73
_CRTIMP_ALTERNATIVE int __cdecl swprintf_s(_Out_writes_z_(_SizeInWords) wchar_t *_Dst, _In_ size_t _SizeInWords, _In_z_ _Printf_format_string_ const wchar_t *_Format,...)
void UnInitVsPix()
Definition: vsgcapture.h:118
void __stdcall VsgDbgEndCapture()
void CaptureCurrentFrame()
Definition: vsgcapture.h:99
void UnInit()
Definition: vsgcapture.h:79
_declspec(selectany) VsgDbg *g_pVsgDbg
int __cdecl atexit(void(__cdecl *)(void))
#define NULL
Definition: crtdbg.h:30
~VsgDbg()
Definition: vsgcapture.h:68
void __stdcall VsgDbgAddHUDMessage(_In_z_ wchar_t const *szMessage)
#define _In_z_
Definition: sal.h:319
_Check_return_wat_ _CRTIMP_ALTERNATIVE errno_t __cdecl wcscpy_s(_Out_writes_z_(_SizeInWords) wchar_t *_Dst, _In_ rsize_t _SizeInWords, _In_z_ const wchar_t *_Src)
void __stdcall VsgDbgUnInit()
__declspec(allocate(".CRT$XCT")) _declspec(selectany) _declspec(dllexport) void(*pInitFunc)()
void __stdcall VsgDbgCaptureCurrentFrame()
void BeginCapture()
Definition: vsgcapture.h:89
void InitVsPix()
Definition: vsgcapture.h:126
void EndCapture()
Definition: vsgcapture.h:94
Definition: vsgcapture.h:28
void __stdcall VsgDbgBeginCapture()
#define VSG_DEFAULT_RUN_FILENAME
Definition: vsgcapture.h:14
void __stdcall VsgDbgCopy(_In_z_ wchar_t const *szNewVSGLog)
void AddMessage(_In_z_ wchar_t const *szMessage)
Definition: vsgcapture.h:109
void Copy(_In_z_ wchar_t const *szNewVSGLog)
Definition: vsgcapture.h:104
VsgDbg(bool bDefaultInit)
Definition: vsgcapture.h:31
void __stdcall VsgDbgToggleHUD()
void __stdcall VsgDbgInit(_In_z_ wchar_t const *szVSGLog)