| 386 | } |
| 387 | |
| 388 | void GLFWOSPRayWindow::display() |
| 389 | { |
| 390 | static float totalRenderTime = 0.f; |
| 391 | static auto displayStart = std::chrono::steady_clock::now(); |
| 392 | |
| 393 | static bool firstFrame = true; |
| 394 | if (firstFrame || currentFrame.isReady()) { |
| 395 | // display frame rate in window title |
| 396 | const auto displayEnd = std::chrono::steady_clock::now(); |
| 397 | const auto displayMilliseconds = |
| 398 | std::chrono::duration_cast<std::chrono::milliseconds>( |
| 399 | displayEnd - displayStart); |
| 400 | const auto renderTime = currentFrame.duration(); |
| 401 | totalRenderTime += renderTime; |
| 402 | |
| 403 | // update fps every 10 frames or every second |
| 404 | framesCounter++; |
| 405 | if (framesCounter > 9 || totalRenderTime > 1.f |
| 406 | || displayMilliseconds > std::chrono::seconds(1)) { |
| 407 | displayFPS = 1000.f * float(framesCounter) / displayMilliseconds.count(); |
| 408 | latestFPS = float(framesCounter) / totalRenderTime; |
| 409 | |
| 410 | displayStart = displayEnd; |
| 411 | totalRenderTime = 0.f; |
| 412 | framesCounter = 0; |
| 413 | |
| 414 | updateTitleBar(); |
| 415 | } |
| 416 | |
| 417 | waitOnOSPRayFrame(); |
| 418 | |
| 419 | auto fbChannel = OSP_FB_COLOR; |
| 420 | if (showDepth) |
| 421 | fbChannel = OSP_FB_DEPTH; |
| 422 | if (showAlbedo) |
| 423 | fbChannel = OSP_FB_ALBEDO; |
| 424 | if (showNormal) |
| 425 | fbChannel = OSP_FB_NORMAL; |
| 426 | if (showPrimID) |
| 427 | fbChannel = OSP_FB_ID_PRIMITIVE; |
| 428 | if (showGeomID) |
| 429 | fbChannel = OSP_FB_ID_OBJECT; |
| 430 | if (showInstID) |
| 431 | fbChannel = OSP_FB_ID_INSTANCE; |
| 432 | auto *fb = framebuffer.map(fbChannel); |
| 433 | |
| 434 | // Copy and normalize depth layer if showDepth is on |
| 435 | float *depthFb = static_cast<float *>(fb); |
| 436 | std::vector<float> depthCopy; |
| 437 | if (showDepth) { |
| 438 | depthCopy.assign(depthFb, depthFb + (windowSize.x * windowSize.y)); |
| 439 | depthFb = depthCopy.data(); |
| 440 | |
| 441 | float minDepth = rkcommon::math::inf; |
| 442 | float maxDepth = rkcommon::math::neg_inf; |
| 443 | |
| 444 | for (int i = 0; i < windowSize.x * windowSize.y; i++) { |
| 445 | if (std::isinf(depthFb[i])) |