mirror of
https://github.com/bkaradzic/bgfx.git
synced 2026-02-17 20:52:36 +01:00
Metal: Added ability to make capture programmatically.
This commit is contained in:
@@ -2410,7 +2410,7 @@ namespace bgfx
|
||||
|
||||
id pool;
|
||||
};
|
||||
#endif // BX_PLATFORM_OSX
|
||||
#endif // BX_PLATFORM_OSX || BX_PLATFORM_IOS || BX_PLATFORM_VISIONOS
|
||||
|
||||
RenderFrame::Enum Context::renderFrame(int32_t _msecs)
|
||||
{
|
||||
@@ -2418,7 +2418,7 @@ namespace bgfx
|
||||
|
||||
#if BX_PLATFORM_OSX || BX_PLATFORM_IOS || BX_PLATFORM_VISIONOS
|
||||
NSAutoreleasePoolScope pool;
|
||||
#endif // BX_PLATFORM_OSX
|
||||
#endif // BX_PLATFORM_OSX || BX_PLATFORM_IOS || BX_PLATFORM_VISIONOS
|
||||
|
||||
if (!m_flipAfterRender)
|
||||
{
|
||||
|
||||
@@ -1093,6 +1093,20 @@ namespace bgfx { namespace mtl
|
||||
|
||||
typedef MTLRenderPipelineReflection* RenderPipelineReflection;
|
||||
|
||||
typedef MTLCaptureManager* CaptureManager;
|
||||
|
||||
MTLCaptureManager* getSharedCaptureManager()
|
||||
{
|
||||
return [MTLCaptureManager sharedCaptureManager];
|
||||
}
|
||||
|
||||
typedef MTLCaptureDescriptor* CaptureDescriptor;
|
||||
|
||||
inline MTLCaptureDescriptor* newCaptureDescriptor()
|
||||
{
|
||||
return [MTLCaptureDescriptor new];
|
||||
}
|
||||
|
||||
//helper functions
|
||||
inline void release(NSObject* _obj)
|
||||
{
|
||||
|
||||
@@ -4124,6 +4124,22 @@ BX_PRAGMA_DIAGNOSTIC_POP();
|
||||
m_commandBuffer = m_cmd.alloc();
|
||||
}
|
||||
|
||||
if (_render->m_capture)
|
||||
{
|
||||
CaptureManager captureMgr = getSharedCaptureManager();
|
||||
CaptureDescriptor captureDesc = newCaptureDescriptor();
|
||||
captureDesc.captureObject = m_device;
|
||||
captureDesc.destination = MTLCaptureDestinationDeveloperTools;
|
||||
|
||||
NSError* err = NULL;
|
||||
[captureMgr startCaptureWithDescriptor: captureDesc error: &err];
|
||||
|
||||
if (NULL != err)
|
||||
{
|
||||
BX_TRACE("Failed to start capture. Error %d: %s", err.code, err.localizedDescription.UTF8String);
|
||||
}
|
||||
}
|
||||
|
||||
BGFX_MTL_PROFILER_BEGIN_LITERAL("rendererSubmit", kColorFrame);
|
||||
|
||||
int64_t timeBegin = bx::getHPCounter();
|
||||
@@ -5336,6 +5352,15 @@ BX_PRAGMA_DIAGNOSTIC_POP();
|
||||
|
||||
m_renderCommandEncoderFrameBufferHandle = BGFX_INVALID_HANDLE;
|
||||
|
||||
if (_render->m_capture)
|
||||
{
|
||||
CaptureManager captureMgr = getSharedCaptureManager();
|
||||
if ([captureMgr isCapturing])
|
||||
{
|
||||
[captureMgr stopCapture];
|
||||
}
|
||||
}
|
||||
|
||||
if (m_screenshotTarget)
|
||||
{
|
||||
RenderPassDescriptor renderPassDescriptor = newRenderPassDescriptor();
|
||||
|
||||
Reference in New Issue
Block a user