From 2430559d8ca0d8cc200d2e2bbfdc2433e9296d5a Mon Sep 17 00:00:00 2001 From: doterop Date: Mon, 27 Jul 2020 11:48:27 +0200 Subject: [PATCH] Added check of atalas size texture before created --- .../Source/Carla/Game/CarlaGameModeBase.cpp | 34 ++++++++++++++----- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameModeBase.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameModeBase.cpp index 805f04245..818f14bae 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameModeBase.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameModeBase.cpp @@ -16,6 +16,7 @@ #include #include "Async/ParallelFor.h" +#include "DynamicRHI.h" #include "DrawDebugHelpers.h" #include "Kismet/KismetSystemLibrary.h" @@ -205,7 +206,8 @@ void ACarlaGameModeBase::Tick(float DeltaSeconds) Recorder->Tick(DeltaSeconds); } - if(!IsAtlasTextureValid) { + if(!IsAtlasTextureValid) + { CreateAtlasTextures(); } } @@ -254,7 +256,9 @@ void ACarlaGameModeBase::ParseOpenDrive(const FString &MapName) Map = carla::opendrive::OpenDriveParser::Load(opendrive_xml); if (!Map.has_value()) { UE_LOG(LogCarla, Error, TEXT("Invalid Map")); - } else { + } + else + { Episode->MapGeoReference = Map->GetGeoReference(); } } @@ -378,17 +382,22 @@ void ACarlaGameModeBase::DebugShowSignals(bool enable) void ACarlaGameModeBase::CreateAtlasTextures() { - UE_LOG(LogCarla, Warning, TEXT("ACarlaGameModeBase::CreateAtlasTextures %d %dx%d"), SceneCaptureSensors.Num(), AtlasTextureWidth, AtlasTextureHeight); - - FRHIResourceCreateInfo CreateInfo; - for(int i = 0; i < kMaxNumTextures; i++) + if(AtlasTextureWidth > 0 && AtlasTextureHeight > 0) { - CamerasAtlasTexture[i] = RHICreateTexture2D(AtlasTextureWidth, AtlasTextureHeight, PF_B8G8R8A8, 1, 1, TexCreate_CPUReadback, CreateInfo); - AtlasPixels[i].Init(FColor(), AtlasTextureWidth * AtlasTextureHeight); + UE_LOG(LogCarla, Warning, TEXT("ACarlaGameModeBase::CreateAtlasTextures %d %dx%d"), SceneCaptureSensors.Num(), AtlasTextureWidth, AtlasTextureHeight); + + FRHIResourceCreateInfo CreateInfo; + for(int i = 0; i < kMaxNumTextures; i++) + { + CamerasAtlasTexture[i] = RHICreateTexture2D(AtlasTextureWidth, AtlasTextureHeight, PF_B8G8R8A8, 1, 1, TexCreate_CPUReadback, CreateInfo); + AtlasPixels[i].Init(FColor(), AtlasTextureWidth * AtlasTextureHeight); + } + IsAtlasTextureValid = true; } - IsAtlasTextureValid = true; } +extern FDynamicRHI* GDynamicRHI; + void ACarlaGameModeBase::CaptureAtlas() { ACarlaGameModeBase* This = this; @@ -422,12 +431,19 @@ void ACarlaGameModeBase::CaptureAtlas() } #endif + // GDynamicRHI->RHIReadSurfaceData(AtlasTexture, Rect, CurrentAtlasPixels, FReadSurfaceDataFlags(RCM_UNorm, CubeFace_MAX)); + + // FRHICommandBeginRenderPass RHICommandBeginRenderPass; + // FRHICommandBeginParallelRenderPass RHICommandBeginParallelRenderPass; + + RHICmdList.ReadSurfaceData( AtlasTexture, Rect, CurrentAtlasPixels, FReadSurfaceDataFlags(RCM_UNorm, CubeFace_MAX)); + // PreviousTexture = CurrentTexture; // CurrentTexture = (CurrentTexture + 1) & ~MaxNumTextures; }