Files
UnrealEngineUWP/Engine/Source/Runtime/RenderCore/Private/RenderCaptureInterface.cpp
Marc Audy bf80889353 UE5/Release-Engine-Staging to UE5/Main
This represents UE4/Main up to CL# 14958402

[CL 15028197 by Marc Audy in ue5-main branch]
2021-01-08 19:56:07 -04:00

107 lines
2.3 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "RenderCaptureInterface.h"
#include "RenderingThread.h"
namespace RenderCaptureInterface
{
static FOnFrameCaptureDelegate GFrameCaptureDelegates;
static FOnBeginCaptureDelegate GBeginDelegates;
static FOnEndCaptureDelegate GEndDelegates;
void RegisterCallbacks(FOnFrameCaptureDelegate InFrameCaptureDelegate)
{
check(!GFrameCaptureDelegates.IsBound());
GFrameCaptureDelegates = InFrameCaptureDelegate;
}
void RegisterCallbacks(FOnBeginCaptureDelegate InBeginDelegate, FOnEndCaptureDelegate InEndDelegate)
{
check(!GBeginDelegates.IsBound());
GBeginDelegates = InBeginDelegate;
check(!GEndDelegates.IsBound());
GEndDelegates = InEndDelegate;
}
void UnregisterCallbacks()
{
GFrameCaptureDelegates.Unbind();
GBeginDelegates.Unbind();
GEndDelegates.Unbind();
}
void FrameCapture()
{
if (GFrameCaptureDelegates.IsBound())
{
GFrameCaptureDelegates.Execute();
}
}
void BeginCapture(FRHICommandListImmediate* RHICommandList, TCHAR const* Name)
{
if (GBeginDelegates.IsBound())
{
GBeginDelegates.Execute(RHICommandList, Name);
}
}
void EndCapture(FRHICommandListImmediate* RHICommandList)
{
if (GEndDelegates.IsBound())
{
GEndDelegates.Execute(RHICommandList);
}
}
FScopedCapture::FScopedCapture(bool bEnable, TCHAR const* Name)
: bCapture(bEnable)
, RHICmdList(nullptr)
{
check(!GUseThreadedRendering || !IsInRenderingThread());
if (bCapture)
{
ENQUEUE_RENDER_COMMAND(CaptureCommand)([Name](FRHICommandListImmediate& RHICommandListLocal)
{
BeginCapture(&RHICommandListLocal, Name);
});
}
}
FScopedCapture::FScopedCapture(bool bEnable, FRHICommandListImmediate* RHICommandList, TCHAR const* Name)
: bCapture(bEnable)
, RHICmdList(RHICommandList)
{
check(!GUseThreadedRendering || IsInRenderingThread());
if (bCapture)
{
BeginCapture(RHICmdList, Name);
}
}
FScopedCapture::~FScopedCapture()
{
if (bCapture)
{
if (RHICmdList != nullptr)
{
check(!GUseThreadedRendering || IsInRenderingThread());
EndCapture(RHICmdList);
}
else
{
check(!GUseThreadedRendering || !IsInRenderingThread());
ENQUEUE_RENDER_COMMAND(CaptureCommand)([](FRHICommandListImmediate& RHICommandListLocal)
{
EndCapture(&RHICommandListLocal);
});
}
}
}
}