forked from baldurk/renderdoc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentry_points.cpp
More file actions
309 lines (247 loc) · 7.45 KB
/
entry_points.cpp
File metadata and controls
309 lines (247 loc) · 7.45 KB
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
/******************************************************************************
* The MIT License (MIT)
*
* Copyright (c) 2014 Crytek
*
* 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 "common/common.h"
#include "maths/camera.h"
#include "maths/formatpacking.h"
#include "serialise/serialiser.h"
#include "core/core.h"
#include "replay/replay_renderer.h"
#include "replay/renderdoc.h"
extern "C" RENDERDOC_API float RENDERDOC_CC Maths_HalfToFloat(uint16_t half)
{
return ConvertFromHalf(half);
}
extern "C" RENDERDOC_API uint16_t RENDERDOC_CC Maths_FloatToHalf(float f)
{
return ConvertToHalf(f);
}
extern "C" RENDERDOC_API void RENDERDOC_CC Maths_CameraArcball(float dist, const FloatVector &rot, FloatVector *pos, FloatVector *fwd, FloatVector *right)
{
Camera c;
c.Arcball(dist, Vec3f(rot.x, rot.y, rot.z));
Vec3f p = c.GetPosition();
Vec3f f = c.GetForward();
Vec3f r = c.GetRight();
pos->x = p.x;
pos->y = p.y;
pos->z = p.z;
fwd->x = f.x;
fwd->y = f.y;
fwd->z = f.z;
right->x = r.x;
right->y = r.y;
right->z = r.z;
}
extern "C" RENDERDOC_API void RENDERDOC_CC Maths_CameraFPSLook(const FloatVector &lookpos, const FloatVector &rot, FloatVector *pos, FloatVector *fwd, FloatVector *right)
{
Camera c;
c.fpsLook(Vec3f(lookpos.x, lookpos.y, lookpos.z), Vec3f(rot.x, rot.y, rot.z));
Vec3f p = c.GetPosition();
Vec3f f = c.GetForward();
Vec3f r = c.GetRight();
pos->x = p.x;
pos->y = p.y;
pos->z = p.z;
fwd->x = f.x;
fwd->y = f.y;
fwd->z = f.z;
right->x = r.x;
right->y = r.y;
right->z = r.z;
}
extern "C" RENDERDOC_API
void RENDERDOC_CC RENDERDOC_LogText(const wchar_t *text)
{
RDCLOG("%ls", text);
}
extern "C" RENDERDOC_API
const wchar_t* RENDERDOC_CC RENDERDOC_GetLogFilename()
{
return RDCGETLOGFILE();
}
extern "C" RENDERDOC_API
void RENDERDOC_CC RENDERDOC_TriggerExceptionHandler(void *exceptionPtrs, bool crashed)
{
if(RenderDoc::Inst().GetCrashHandler() == NULL)
return;
if(exceptionPtrs)
{
RenderDoc::Inst().GetCrashHandler()->WriteMinidump(exceptionPtrs);
}
else
{
if(!crashed)
{
RDCLOG("Writing crash log");
}
RenderDoc::Inst().GetCrashHandler()->WriteMinidump();
if(!crashed)
{
RenderDoc::Inst().RecreateCrashHandler();
}
}
}
extern "C" RENDERDOC_API
bool RENDERDOC_CC RENDERDOC_SupportLocalReplay(const wchar_t *logfile, rdctype::wstr *driver)
{
if(logfile == NULL)
return false;
RDCDriver driverType = RDC_Unknown;
wstring driverName = L"";
RenderDoc::Inst().FillInitParams(logfile, driverType, driverName, NULL);
if(driver) *driver = driverName;
return RenderDoc::Inst().HasReplayDriver(driverType);
}
extern "C" RENDERDOC_API
ReplayCreateStatus RENDERDOC_CC RENDERDOC_CreateReplayRenderer(const wchar_t *logfile, float *progress, ReplayRenderer **rend)
{
if(rend == NULL) return eReplayCreate_InternalError;
RenderDoc::Inst().SetProgressPtr(progress);
ReplayRenderer *render = new ReplayRenderer();
if(!render)
{
RenderDoc::Inst().SetProgressPtr(NULL);
return eReplayCreate_InternalError;
}
ReplayCreateStatus ret = render->CreateDevice(logfile);
if(ret != eReplayCreate_Success)
{
delete render;
RenderDoc::Inst().SetProgressPtr(NULL);
return ret;
}
*rend = render;
RenderDoc::Inst().SetProgressPtr(NULL);
return eReplayCreate_Success;
}
extern "C" RENDERDOC_API
void RENDERDOC_CC RENDERDOC_SetLogFile(const wchar_t *logfile)
{
RDCLOG("Using logfile %ls", logfile);
RenderDoc::Inst().SetLogFile(logfile);
}
extern "C" RENDERDOC_API
void RENDERDOC_CC RENDERDOC_SetCaptureOptions(const CaptureOptions *opts)
{
RDCLOG("Setting capture options");
RenderDoc::Inst().SetCaptureOptions(opts);
}
extern "C" RENDERDOC_API
uint32_t RENDERDOC_CC RENDERDOC_ExecuteAndInject(const wchar_t *app, const wchar_t *workingDir, const wchar_t *cmdLine,
const wchar_t *logfile, const CaptureOptions *opts, bool waitForExit)
{
return Process::CreateAndInjectIntoProcess(app, workingDir, cmdLine, logfile, opts, waitForExit);
}
extern "C" RENDERDOC_API
uint32_t RENDERDOC_CC RENDERDOC_InjectIntoProcess(uint32_t pid, const wchar_t *logfile, const CaptureOptions *opts, bool waitForExit)
{
return Process::InjectIntoProcess(pid, logfile, opts, waitForExit);
}
extern "C" RENDERDOC_API
void RENDERDOC_CC RENDERDOC_TriggerCapture()
{
RenderDoc::Inst().TriggerCapture();
}
extern "C" RENDERDOC_API
void RENDERDOC_CC RENDERDOC_QueueCapture(uint32_t frameNumber)
{
RenderDoc::Inst().QueueCapture(frameNumber);
}
extern "C" RENDERDOC_API
bool RENDERDOC_CC RENDERDOC_GetThumbnail(const wchar_t *filename, byte *buf, uint32_t &len)
{
Serialiser ser(filename, Serialiser::READING, false);
if(ser.HasError())
return false;
ser.Rewind();
int chunkType = ser.PushContext(NULL, 1, false);
if(chunkType != THUMBNAIL_DATA)
return false;
bool HasThumbnail = false;
ser.Serialise(NULL, HasThumbnail);
if(!HasThumbnail)
return false;
byte *jpgbuf = NULL;
size_t thumblen = 0;
uint32_t thumbwidth = 0, thumbheight = 0;
{
ser.Serialise("ThumbWidth", thumbwidth);
ser.Serialise("ThumbHeight", thumbheight);
ser.SerialiseBuffer("ThumbnailPixels", jpgbuf, thumblen);
}
if(jpgbuf == NULL)
return false;
if(buf == NULL)
{
len = (uint32_t)thumblen;
return true;
}
if(thumblen > len)
{
delete[] jpgbuf;
return false;
}
memcpy(buf, jpgbuf, thumblen);
delete[] jpgbuf;
return true;
}
extern "C" RENDERDOC_API
void RENDERDOC_CC RENDERDOC_FreeArrayMem(const void *mem)
{
rdctype::array<char>::deallocate(mem);
}
extern "C" RENDERDOC_API
void RENDERDOC_CC RENDERDOC_InitRemoteAccess(uint32_t *ident)
{
if(ident) *ident = RenderDoc::Inst().GetRemoteAccessIdent();
}
extern "C" RENDERDOC_API
uint32_t RENDERDOC_CC RENDERDOC_EnumerateRemoteConnections(const wchar_t *host, uint32_t *idents)
{
if(idents == NULL)
return RenderDoc_LastCaptureNetworkPort-RenderDoc_FirstCaptureNetworkPort+1;
wstring s = L"localhost";
if(host != NULL && host[0] != L'\0')
s = host;
uint32_t numIdents = 0;
for(uint16_t ident = RenderDoc_FirstCaptureNetworkPort; ident <= RenderDoc_LastCaptureNetworkPort; ident++)
{
Network::Socket *sock = Network::CreateClientSocket(s.c_str(), ident, 250);
if(sock)
{
*idents = (uint32_t)ident;
idents++;
numIdents++;
SAFE_DELETE(sock);
}
}
return numIdents;
}
extern "C" RENDERDOC_API
void RENDERDOC_CC RENDERDOC_SpawnReplayHost(volatile bool *killReplay)
{
bool dummy = false;
if(killReplay == NULL) killReplay = &dummy;
RenderDoc::Inst().BecomeReplayHost(*killReplay);
}