| 202 | } |
| 203 | |
| 204 | void GameBaseImpl::OnPostRender(GPUContext* context, RenderContext& renderContext) |
| 205 | { |
| 206 | // Handle missing splash screen texture case |
| 207 | if (SplashScreen == nullptr) |
| 208 | { |
| 209 | OnSplashScreenEnd(); |
| 210 | return; |
| 211 | } |
| 212 | |
| 213 | // Wait for texture loaded before showing splash screen |
| 214 | if (!SplashScreen->IsLoaded() || SplashScreen.Get()->GetResidentMipLevels() != SplashScreen.Get()->GetMipLevels()) |
| 215 | { |
| 216 | return; |
| 217 | } |
| 218 | const auto splashScreen = SplashScreen.Get()->GetTexture(); |
| 219 | |
| 220 | // Configuration |
| 221 | const float fadeTime = 0.5f; |
| 222 | const float showTime = 1.0f; |
| 223 | const float totalTime = fadeTime + showTime + fadeTime; |
| 224 | |
| 225 | // Update animation |
| 226 | const auto deltaTime = static_cast<float>(Time::Draw.UnscaledDeltaTime.GetTotalSeconds()); |
| 227 | SplashScreenTime += deltaTime; |
| 228 | if (SplashScreenTime >= totalTime) |
| 229 | { |
| 230 | OnSplashScreenEnd(); |
| 231 | return; |
| 232 | } |
| 233 | |
| 234 | PROFILE_GPU_CPU_NAMED("Splash Screen"); |
| 235 | |
| 236 | // Calculate visibility |
| 237 | float fade = 1.0f; |
| 238 | if (SplashScreenTime < fadeTime) |
| 239 | fade = SplashScreenTime / fadeTime; |
| 240 | else if (SplashScreenTime > fadeTime + showTime) |
| 241 | fade = 1.0f - (SplashScreenTime - fadeTime - showTime) / fadeTime; |
| 242 | |
| 243 | // Calculate image area (fill screen, keep aspect ratio, and snap to pixels) |
| 244 | const auto viewport = renderContext.Task->GetViewport(); |
| 245 | const Rectangle screenRect(viewport.X, viewport.Y, viewport.Width, viewport.Height); |
| 246 | Rectangle imageArea = screenRect; |
| 247 | imageArea.Scale(0.6f); |
| 248 | const float aspectRatio = static_cast<float>(splashScreen->Width()) / static_cast<float>(splashScreen->Height()); |
| 249 | const float height = imageArea.GetWidth() / aspectRatio; |
| 250 | imageArea.Location.Y += (imageArea.GetHeight() - height) * 0.5f; |
| 251 | imageArea.Size.Y = height; |
| 252 | imageArea.Location = Float2::Ceil(imageArea.Location); |
| 253 | imageArea.Size = Float2::Ceil(imageArea.Size); |
| 254 | |
| 255 | // Draw |
| 256 | Render2D::Begin(GPUDevice::Instance->GetMainContext(), renderContext.Task->GetOutputView(), nullptr, viewport); |
| 257 | Render2D::FillRectangle(screenRect, Color::Black); |
| 258 | Render2D::DrawTexture(splashScreen, imageArea, Color(1.0f, 1.0f, 1.0f, fade)); |
| 259 | Render2D::End(); |
| 260 | } |
| 261 |
nothing calls this directly
no test coverage detected