MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / OnPostRender

Method OnPostRender

Source/Engine/Engine/Base/GameBase.cpp:204–260  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

202}
203
204void 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

Callers

nothing calls this directly

Calls 15

GetResidentMipLevelsMethod · 0.80
GetMipLevelsMethod · 0.80
GetTextureMethod · 0.80
GetWidthMethod · 0.80
GetOutputViewMethod · 0.80
CeilFunction · 0.50
BeginFunction · 0.50
ColorFunction · 0.50
EndFunction · 0.50
IsLoadedMethod · 0.45
GetMethod · 0.45
GetViewportMethod · 0.45

Tested by

no test coverage detected