/
Manifest
/
Real_Texture
Обзор
Документация
Войти
/
Manifest
/
Real_Texture
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
Plugins/pixelreader/Source/PixelReader/Private/ReadPixelsLib.cpp
117 строк
3 KB
m.samodurov
init commit for The Invaders
17 фев 2026, 04:57
17 фев 2026, 04:57
4a668d4
Код
Авторство
О чём код?
// Fill out your copyright notice in the Description page of Project Settings. #include "ReadPixelsLib.h" #include "Async/Async.h" // void ReadPixelsLib::ThreadSafe_ReadPixels_Fast ( FRenderTarget* RT, TFunction<void(TSharedPtr<TArray<FColor>>)> Callback, FReadSurfaceDataFlags InFlags, FIntRect InRect ) { if (!RT) { UE_LOG(LogTemp, Error, TEXT("RenderTarget is null")); if (Callback) { AsyncTask(ENamedThreads::GameThread, [Callback]() { Callback(nullptr); }); } return; } if (InRect == FIntRect(0, 0, 0, 0)) { InRect = FIntRect(0, 0, RT->GetSizeXY().X, RT->GetSizeXY().Y); } // Create shared data that will be passed between threads TSharedPtr<TArray<FColor>> SharedImageData = MakeShared<TArray<FColor>>(); ENQUEUE_RENDER_COMMAND(ReadSurfaceCommandFast) ( [RT, InRect, InFlags, SharedImageData, Callback](FRHICommandListImmediate& RHICmdList) { //check(IsInRenderingThread()); FTextureRHIRef RenderTargetTexture = RT->GetRenderTargetTexture(); if (!RenderTargetTexture.IsValid()) { UE_LOG(LogTemp, Error, TEXT("RenderTargetTexture is invalid")); if (Callback) { AsyncTask(ENamedThreads::GameThread, [Callback]() { Callback(nullptr); }); } return; } // Read surface data directly to shared pointer RHICmdList.ReadSurfaceData( RenderTargetTexture, InRect, *SharedImageData, InFlags ); // Execute callback with shared data if (Callback) { AsyncTask(ENamedThreads::GameThread, [SharedImageData, Callback]() { Callback(SharedImageData); }); } } ); } void ReadPixelsLib::Command_ReadPixels_Fast ( FRenderTarget* RT, TArray<FColor>& outCapturedData, FReadSurfaceDataFlags InFlags, FIntRect InRect ) { if (!RT) { UE_LOG(LogTemp, Error, TEXT("RenderTarget is null")); return; } if (InRect == FIntRect(0, 0, 0, 0)) { InRect = FIntRect(0, 0, RT->GetSizeXY().X, RT->GetSizeXY().Y); } // Create shared data that will be passed between threads //TSharedPtr<TArray<FColor>> SharedImageData = MakeShared<TArray<FColor>>(); ENQUEUE_RENDER_COMMAND(ReadSurfaceCommandFast) ( [RT, InRect, InFlags, &outCapturedData](FRHICommandListImmediate& RHICmdList) { //check(IsInRenderingThread()); FTextureRHIRef RenderTargetTexture = RT->GetRenderTargetTexture(); if (!RenderTargetTexture.IsValid()) { UE_LOG(LogTemp, Error, TEXT("RenderTargetTexture is invalid")); return; } // Read surface data directly to shared pointer RHICmdList.ReadSurfaceData( RenderTargetTexture, InRect, outCapturedData,//*SharedImageData, InFlags ); } ); }