Created
October 22, 2018 09:35
-
-
Save KRNKRS/8252ff7ea0bf656932f78bc150a0eb86 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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