Skip to content

Instantly share code, notes, and snippets.

@KRNKRS
Last active November 8, 2018 11:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KRNKRS/da5d62c72ec58cdcc47f4ebdd7538ac0 to your computer and use it in GitHub Desktop.
Save KRNKRS/da5d62c72ec58cdcc47f4ebdd7538ac0 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