gl optimizations in nanoguicontext

pull/3471/head
kallaballa 2 years ago
parent ffcd91b189
commit a7b6b0e9ff
  1. 16
      modules/v4d/src/detail/nanoguicontext.cpp

@ -15,11 +15,8 @@ NanoguiContext::NanoguiContext(FrameBufferContext& fbContext) :
mainFbContext_(fbContext), nguiFbContext_(fbContext.getV4D(), "NanoGUI", fbContext), context_( mainFbContext_(fbContext), nguiFbContext_(fbContext.getV4D(), "NanoGUI", fbContext), context_(
nullptr), copyBuffer_(mainFbContext_.size(), CV_8UC4) { nullptr), copyBuffer_(mainFbContext_.size(), CV_8UC4) {
run_sync_on_main<25>([&, this]() { run_sync_on_main<25>([&, this]() {
// { fbCtx().makeCurrent();
// //Workaround for first frame glitch GL_CHECK(glFinish());
// FrameBufferContext::GLScope glScope(fbCtx(), GL_FRAMEBUFFER);
// FrameBufferContext::FrameBufferScope fbScope(fbCtx(), copyBuffer_);
// }
{ {
#ifndef __EMSCRIPTEN__ #ifndef __EMSCRIPTEN__
mainFbContext_.makeCurrent(); mainFbContext_.makeCurrent();
@ -29,7 +26,7 @@ NanoguiContext::NanoguiContext(FrameBufferContext& fbContext) :
#endif #endif
screen_ = new nanogui::Screen(true, true, false); screen_ = new nanogui::Screen(true, true, false);
screen_->initialize(fbCtx().getGLFWWindow(), false); screen_->initialize(fbCtx().getGLFWWindow(), false);
Size winSize = fbContext.getV4D().getWindowSize(); Size winSize = fbContext.getV4D().size();
screen_->set_size({int(winSize.width / fbContext.getV4D().pixelRatioX()), int(winSize.height / fbContext.getV4D().pixelRatioY())}); screen_->set_size({int(winSize.width / fbContext.getV4D().pixelRatioX()), int(winSize.height / fbContext.getV4D().pixelRatioY())});
context_ = screen_->nvg_context(); context_ = screen_->nvg_context();
form_ = new cv::v4d::FormHelper(screen_); form_ = new cv::v4d::FormHelper(screen_);
@ -46,8 +43,9 @@ void NanoguiContext::render(bool printFPS, bool showFPS, bool showTracking) {
tick_.stop(); tick_.stop();
if (tick_.getTimeMilli() > 100) { if (tick_.getTimeMilli() > 100) {
fps_ = tick_.getFPS();
if(printFPS) { if(printFPS) {
cerr << "FPS : " << (fps_ = tick_.getFPS()) << endl; cerr << "FPS : " << (fps_) << endl;
#ifndef __EMSCRIPTEN__ #ifndef __EMSCRIPTEN__
cerr << '\r'; cerr << '\r';
#else #else
@ -136,9 +134,6 @@ void NanoguiContext::render(bool printFPS, bool showFPS, bool showTracking) {
nvgRestore(context_); nvgRestore(context_);
} }
screen().draw_widgets(); screen().draw_widgets();
#ifndef __EMSCRIPTEN__
GL_CHECK(glFinish());
#endif
} }
if(!fbCtx().isShared()) { if(!fbCtx().isShared()) {
@ -149,6 +144,7 @@ void NanoguiContext::render(bool printFPS, bool showFPS, bool showTracking) {
mainFbContext_.copyFrom(copyBuffer_); mainFbContext_.copyFrom(copyBuffer_);
#endif #endif
} }
GL_CHECK(glFinish());
}); });
tick_.start(); tick_.start();
} }

Loading…
Cancel
Save