Skip to content

Instantly share code, notes, and snippets.

@KRNKRS
Created October 22, 2018 09:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KRNKRS/8252ff7ea0bf656932f78bc150a0eb86 to your computer and use it in GitHub Desktop.
Save KRNKRS/8252ff7ea0bf656932f78bc150a0eb86 to your computer and use it in GitHub Desktop.
bool AFrameGrabberActor::StartFrameGrab()
{
TSharedPtr<FSceneViewport> SceneViewport;
// Get SceneViewport
// ( quoted from FRemoteSessionHost::OnCreateChannels() )
#if WITH_EDITOR
if (GIsEditor)
{
for (const FWorldContext& Context : GEngine->GetWorldContexts())
{
if (Context.WorldType == EWorldType::PIE)
{
FSlatePlayInEditorInfo* SlatePlayInEditorSession = GEditor->SlatePlayInEditorMap.Find(Context.ContextHandle);
if (SlatePlayInEditorSession)
{
if (SlatePlayInEditorSession->DestinationSlateViewport.IsValid())
{
TSharedPtr<ILevelViewport> DestinationLevelViewport = SlatePlayInEditorSession->DestinationSlateViewport.Pin();
SceneViewport = DestinationLevelViewport->GetSharedActiveViewport();
}
else if (SlatePlayInEditorSession->SlatePlayInEditorWindowViewport.IsValid())
{
SceneViewport = SlatePlayInEditorSession->SlatePlayInEditorWindowViewport;
}
}
}
}
}
else
#endif
{
UGameEngine* GameEngine = Cast<UGameEngine>(GEngine);
SceneViewport = GameEngine->SceneViewport;
}
if (!SceneViewport.IsValid())
{
return false;
}
// Setup Texture
if (!CaptureFrameTexture)
{
CaptureFrameTexture = UTexture2D::CreateTransient(SceneViewport.Get()->GetSize().X, SceneViewport.Get()->GetSize().Y, PF_B8G8R8A8);
CaptureFrameTexture->UpdateResource();
MaterialInstanceDynamic->SetTextureParameterValue(FName("Texture"), CaptureFrameTexture);
}
// Capture Start
ReleaseFrameGrabber();
FrameGrabber = MakeShareable(new FFrameGrabber(SceneViewport.ToSharedRef(), SceneViewport->GetSize()));
FrameGrabber->StartCapturingFrames();
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment