| 53 | } |
| 54 | |
| 55 | void UMjCameraFeedEntry::RefreshBrush() |
| 56 | { |
| 57 | if (!BoundCamera || !FeedImage) |
| 58 | return; |
| 59 | |
| 60 | UTextureRenderTarget2D* RT = BoundCamera->RenderTarget; |
| 61 | if (!RT) |
| 62 | return; |
| 63 | |
| 64 | const float W = 320.f; |
| 65 | const float H = (BoundCamera->resolution[0] > 0) |
| 66 | ? W * static_cast<float>(BoundCamera->resolution[1]) / static_cast<float>(BoundCamera->resolution[0]) |
| 67 | : W * 0.75f; |
| 68 | |
| 69 | // Depth RT is R32f — slate can't display it directly. Build (or reuse) |
| 70 | // a BGRA UTexture2D preview and bind THAT as the brush. For all other |
| 71 | // modes the RT is BGRA8 and we can bind it directly. |
| 72 | UObject* BrushResource = nullptr; |
| 73 | if (BoundCamera->CaptureMode == EMjCameraMode::Depth) |
| 74 | { |
| 75 | if (!DepthPreviewTexture |
| 76 | || DepthPreviewTexture->GetSizeX() != BoundCamera->resolution[0] |
| 77 | || DepthPreviewTexture->GetSizeY() != BoundCamera->resolution[1]) |
| 78 | { |
| 79 | DepthPreviewTexture = UTexture2D::CreateTransient( |
| 80 | BoundCamera->resolution[0], BoundCamera->resolution[1], PF_B8G8R8A8, |
| 81 | TEXT("URLabDepthPreview")); |
| 82 | DepthPreviewTexture->CompressionSettings = TC_VectorDisplacementmap; |
| 83 | DepthPreviewTexture->SRGB = false; |
| 84 | DepthPreviewTexture->UpdateResource(); |
| 85 | } |
| 86 | BrushResource = DepthPreviewTexture; |
| 87 | } |
| 88 | else |
| 89 | { |
| 90 | DepthPreviewTexture = nullptr; |
| 91 | BrushResource = RT; |
| 92 | } |
| 93 | |
| 94 | FeedImage->SetBrushResourceObject(BrushResource); |
| 95 | |
| 96 | FSlateBrush Brush = FeedImage->GetBrush(); |
| 97 | Brush.DrawAs = ESlateBrushDrawType::Image; |
| 98 | Brush.ImageType = ESlateBrushImageType::FullColor; |
| 99 | Brush.Tiling = ESlateBrushTileType::NoTile; |
| 100 | Brush.ImageSize = FVector2D(W, H); |
| 101 | FeedImage->SetBrush(Brush); |
| 102 | |
| 103 | UE_LOG(LogURLab, Log, |
| 104 | TEXT("[MjCameraFeedEntry] Brush set: '%s' mode=%s RT=%dx%d display=%.0fx%.0f"), |
| 105 | *BoundCamera->MjName, *UEnum::GetValueAsString(BoundCamera->CaptureMode), |
| 106 | RT->SizeX, RT->SizeY, W, H); |
| 107 | } |
| 108 | |
| 109 | void UMjCameraFeedEntry::UpdateDepthPreview() |
| 110 | { |
nothing calls this directly
no outgoing calls
no test coverage detected