Beispiel #1
0
	void Update(float DeltaSeconds)
	{
		bool bShouldUpdate = true;
		const float CaptureFrequency = 1.0f/(float)GEngine->MatineeScreenshotOptions.MatineeCaptureFPS;
		if (CaptureFrequency > 0.f)
		{
			CurrentAccumSeconds += DeltaSeconds;

			if (CurrentAccumSeconds > CaptureFrequency)
			{
				while (CurrentAccumSeconds > CaptureFrequency)
				{
					CurrentAccumSeconds -= CaptureFrequency;
				}
			}
			else
			{
				bShouldUpdate = false;
			}
		}

		if (GIsRequestingExit || !bShouldUpdate || CaptureSlateRenderer)
		{
			return;
		}

		if (bMatineeFinished)
		{
			if (GEngine->MatineeScreenshotOptions.MatineeCaptureType == 0)
			{
				if (CaptureViewport)
				{
					CaptureViewport->GetClient()->CloseRequested(CaptureViewport);
				}
			}
			else
			{
				FViewport* ViewportUsed = GEngine->GameViewport != NULL ? GEngine->GameViewport->Viewport : NULL;
				if (ViewportUsed)
				{
					ViewportUsed->GetClient()->CloseRequested(ViewportUsed);
				}
			}
			StopCapture();
		}
		else if (bCapturing)
		{
			// Wait for the directshow thread to finish encoding the last data
			GCaptureSyncEvent->Wait();

			CaptureViewport->ReadPixels(ViewportColorBuffer, FReadSurfaceDataFlags());

			// Allow the directshow thread to encode more data if the event is still available
			if ( GCaptureSyncEvent )
			{
				GCaptureSyncEvent->Trigger();

				UE_LOG(LogMovieCapture, Log, TEXT("-----------------START------------------"));
				UE_LOG(LogMovieCapture, Log, TEXT(" INCREASE FrameNumber from %d "), FrameNumber);
				FrameNumber++;
			}
		}
		else if (bReadyForCapture)
		{
			CaptureViewport->ReadPixels(ViewportColorBuffer, FReadSurfaceDataFlags());

			// Allow the directshow thread to process the pixels we just read
			GCaptureSyncEvent->Trigger();
			Control->Run();
			bReadyForCapture = false;
			bCapturing = true;
			UE_LOG(LogMovieCapture, Log, TEXT("-----------------START------------------"));
			UE_LOG(LogMovieCapture, Log, TEXT(" INCREASE FrameNumber from %d "), FrameNumber);
			FrameNumber++;
		}
	}
void USceneCapturer::CaptureComponent( int32 CurrentHorizontalStep, int32 CurrentVerticalStep, FString Folder, USceneCaptureComponent2D* CaptureComponent, TArray<FColor>& Atlas )
{
	TArray<FColor> SurfaceData;

	{
		SCOPE_CYCLE_COUNTER( STAT_SPReadStrip );
		FTextureRenderTargetResource* RenderTarget = CaptureComponent->TextureTarget->GameThread_GetRenderTargetResource();

		//TODO: ikrimae: Might need to validate that this divides evenly. Might not matter
		int32 CenterX = CaptureWidth / 2;
		int32 CenterY = CaptureHeight / 2;

		SurfaceData.AddUninitialized( StripWidth * StripHeight );

		// Read pixels
		FIntRect Area( CenterX - ( StripWidth / 2 ), CenterY - ( StripHeight / 2 ), CenterX + ( StripWidth / 2 ), CenterY + ( StripHeight / 2) );
        auto readSurfaceDataFlags = FReadSurfaceDataFlags();
        readSurfaceDataFlags.SetLinearToGamma(false);
		RenderTarget->ReadPixelsPtr( SurfaceData.GetData(), readSurfaceDataFlags, Area );
	}

	// Copy off strip to atlas texture
	CopyToUnprojAtlas( CurrentHorizontalStep, CurrentVerticalStep, Atlas, SurfaceData );

	if( FStereoPanoramaManager::GenerateDebugImages->GetInt() != 0 )
	{
		SCOPE_CYCLE_COUNTER( STAT_SPSavePNG );

		// Generate name
		FString TickString = FString::Printf( TEXT( "_%05d_%04d_%04d" ), CurrentFrameCount, CurrentHorizontalStep, CurrentVerticalStep );
		FString CaptureName = OutputDir / Timestamp / Folder / TickString + TEXT( ".png" );
		UE_LOG( LogStereoPanorama, Log, TEXT( "Writing snapshot: %s" ), *CaptureName );

		// Write out PNG
        if (FStereoPanoramaManager::GenerateDebugImages->GetInt() == 2)
        {
            //Read Whole Capture Buffer
		    IImageWrapperPtr ImageWrapper = ImageWrapperModule.CreateImageWrapper( EImageFormat::PNG );

            TArray<FColor> SurfaceDataWhole;
            SurfaceDataWhole.AddUninitialized(CaptureWidth * CaptureHeight);
            // Read pixels
            FTextureRenderTargetResource* RenderTarget = CaptureComponent->TextureTarget->GameThread_GetRenderTargetResource();
            RenderTarget->ReadPixelsPtr(SurfaceDataWhole.GetData(), FReadSurfaceDataFlags());

            // Force alpha value
            if (bForceAlpha)
            {
                for (FColor& Color : SurfaceDataWhole)
                {
                    Color.A = 255;
                }
            }

            ImageWrapper->SetRaw(SurfaceDataWhole.GetData(), SurfaceDataWhole.GetAllocatedSize(), CaptureWidth, CaptureHeight, ERGBFormat::BGRA, 8);
            const TArray<uint8>& PNGData = ImageWrapper->GetCompressed(100);

            FFileHelper::SaveArrayToFile(PNGData, *CaptureName);
            ImageWrapper.Reset();
        }
        else
        {
            if (bForceAlpha)
            {
                for (FColor& Color : SurfaceData)
                {
                    Color.A = 255;
                }
            }

            IImageWrapperPtr ImageWrapper = ImageWrapperModule.CreateImageWrapper(EImageFormat::PNG);
            ImageWrapper->SetRaw(SurfaceData.GetData(), SurfaceData.GetAllocatedSize(), StripWidth, StripHeight, ERGBFormat::BGRA, 8);
		    const TArray<uint8>& PNGData = ImageWrapper->GetCompressed(100);

		    FFileHelper::SaveArrayToFile( PNGData, *CaptureName );
		    ImageWrapper.Reset();
	    }
    }
}