| 375 | } |
| 376 | |
| 377 | void Engine::OnDraw() |
| 378 | { |
| 379 | #if COMPILE_WITH_PROFILER |
| 380 | // Auto-enable GPU events when Tracy got connected |
| 381 | if (!ProfilerGPU::EventsEnabled && TracyIsConnected) |
| 382 | ProfilerGPU::EventsEnabled = true; |
| 383 | #endif |
| 384 | PROFILE_CPU_NAMED("Draw"); |
| 385 | |
| 386 | // Begin frame rendering |
| 387 | FrameCount++; |
| 388 | const double time = Platform::GetTimeSeconds(); |
| 389 | auto device = GPUDevice::Instance; |
| 390 | device->Locker.Lock(); |
| 391 | #if COMPILE_WITH_PROFILER |
| 392 | ProfilerGPU::BeginFrame(); |
| 393 | #endif |
| 394 | |
| 395 | device->Draw(); |
| 396 | |
| 397 | // End frame rendering |
| 398 | FrameMark; |
| 399 | #if COMPILE_WITH_PROFILER |
| 400 | ProfilerGPU::EndFrame(); |
| 401 | #endif |
| 402 | device->Locker.Unlock(); |
| 403 | |
| 404 | // Calculate FPS |
| 405 | EngineImpl::FpsAccumulatedFrames++; |
| 406 | if (time - EngineImpl::FpsAccumulated >= 1.0) |
| 407 | { |
| 408 | EngineImpl::Fps = EngineImpl::FpsAccumulatedFrames; |
| 409 | EngineImpl::FpsAccumulatedFrames = 0; |
| 410 | EngineImpl::FpsAccumulated = time; |
| 411 | } |
| 412 | |
| 413 | #if !LOG_ENABLE_AUTO_FLUSH |
| 414 | // Flush log file every fourth frame |
| 415 | if (FrameCount % 4 == 0) |
| 416 | { |
| 417 | LOG_FLUSH(); |
| 418 | } |
| 419 | #endif |
| 420 | } |
| 421 | |
| 422 | bool Engine::IsHeadless() |
| 423 | { |