pull/3471/head
kallaballa 2 years ago
parent 9bb26f9511
commit d09471aa92
  1. 71
      modules/v4d/src/v4d.cpp

@ -27,13 +27,13 @@ cv::Ptr<V4D> V4D::make(const cv::Size& size, const cv::Size& fbsize, const strin
} }
V4D::V4D(const cv::Size& size, const cv::Size& fbsize, const string& title, bool offscreen, bool debug, int samples) : V4D::V4D(const cv::Size& size, const cv::Size& fbsize, const string& title, bool offscreen, bool debug, int samples) :
initialSize_(size), title_(title), samples_(samples), debug_(debug), viewport_(0, 0, size.width, size.height), scaling_(true), pool_(2) { initialSize_(size), debug_(debug), viewport_(0, 0, size.width, size.height), stretching_(true), pool_(2) {
#ifdef __EMSCRIPTEN__ #ifdef __EMSCRIPTEN__
printf(""); //makes sure we have FS as a dependency printf(""); //makes sure we have FS as a dependency
#endif #endif
self_ = cv::Ptr<V4D>(this); self_ = cv::Ptr<V4D>(this);
mainFbContext_ = new detail::FrameBufferContext(*this, fbsize.empty() ? size : fbsize, offscreen, title_, 3, mainFbContext_ = new detail::FrameBufferContext(*this, fbsize.empty() ? size : fbsize, offscreen, title, 3,
2, samples_, debug_, nullptr, nullptr); 2, samples, debug, nullptr, nullptr);
#ifndef __EMSCRIPTEN__ #ifndef __EMSCRIPTEN__
CLExecScope_t scope(mainFbContext_->getCLExecContext()); CLExecScope_t scope(mainFbContext_->getCLExecContext());
#endif #endif
@ -61,6 +61,11 @@ cv::ogl::Texture2D& V4D::texture() {
return mainFbContext_->getTexture2D(); return mainFbContext_->getTexture2D();
} }
std::string V4D::title() {
return fbCtx().title_;
}
cv::Point2f V4D::getMousePosition() { cv::Point2f V4D::getMousePosition() {
return mousePos_; return mousePos_;
} }
@ -409,34 +414,35 @@ cv::Size V4D::size() {
return fbCtx().getWindowSize(); return fbCtx().getWindowSize();
} }
void V4D::setWindowSize(const cv::Size& sz) { void V4D::setSize(const cv::Size& sz) {
fbCtx().setWindowSize(sz); fbCtx().setWindowSize(sz);
} }
bool V4D::getShowFPS() {
return showFPS_;
}
bool V4D::getPrintFPS() {
return printFPS_;
}
bool V4D::getShowTracking() {
return showTracking_;
}
void V4D::setShowFPS(bool s) { void V4D::setShowFPS(bool s) {
showFPS_ = s; showFPS_ = s;
} }
bool V4D::getShowFPS() {
return showFPS_;
}
void V4D::setPrintFPS(bool p) { void V4D::setPrintFPS(bool p) {
printFPS_ = p; printFPS_ = p;
} }
bool V4D::getPrintFPS() {
return printFPS_;
}
void V4D::setShowTracking(bool st) { void V4D::setShowTracking(bool st) {
showTracking_ = st; showTracking_ = st;
} }
bool V4D::getShowTracking() {
return showTracking_;
}
bool V4D::isFullscreen() { bool V4D::isFullscreen() {
return fbCtx().isFullscreen(); return fbCtx().isFullscreen();
} }
@ -461,19 +467,27 @@ void V4D::setVisible(bool v) {
fbCtx().setVisible(v); fbCtx().setVisible(v);
} }
void V4D::setScaling(bool s) { void V4D::setStretching(bool s) {
scaling_ = s; stretching_ = s;
}
bool V4D::isStretching() {
return stretching_;
} }
bool V4D::isScaling() { void V4D::setFocused(bool f) {
return scaling_; focused_ = f;
}
bool V4D::isFocused() {
return focused_;
} }
void V4D::swapContextBuffers() { void V4D::swapContextBuffers() {
run_sync_on_main<10>([this]() { run_sync_on_main<10>([this]() {
for(size_t i = 0; i < numGlCtx(); ++i) { for(size_t i = 0; i < numGlCtx(); ++i) {
FrameBufferContext::GLScope glScope(glCtx(i).fbCtx(), GL_READ_FRAMEBUFFER); FrameBufferContext::GLScope glScope(glCtx(i).fbCtx(), GL_READ_FRAMEBUFFER);
glCtx(i).fbCtx().blitFrameBufferToScreen(viewport(), glCtx(i).fbCtx().getWindowSize(), isScaling()); glCtx(i).fbCtx().blitFrameBufferToScreen(viewport(), glCtx(i).fbCtx().getWindowSize(), isStretching());
#ifndef __EMSCRIPTEN__ #ifndef __EMSCRIPTEN__
glfwSwapBuffers(glCtx(i).fbCtx().getGLFWWindow()); glfwSwapBuffers(glCtx(i).fbCtx().getGLFWWindow());
#else #else
@ -484,7 +498,7 @@ void V4D::swapContextBuffers() {
run_sync_on_main<11>([this]() { run_sync_on_main<11>([this]() {
FrameBufferContext::GLScope glScope(nvgCtx().fbCtx(), GL_READ_FRAMEBUFFER); FrameBufferContext::GLScope glScope(nvgCtx().fbCtx(), GL_READ_FRAMEBUFFER);
nvgCtx().fbCtx().blitFrameBufferToScreen(viewport(), nvgCtx().fbCtx().getWindowSize(), isScaling()); nvgCtx().fbCtx().blitFrameBufferToScreen(viewport(), nvgCtx().fbCtx().getWindowSize(), isStretching());
#ifndef __EMSCRIPTEN__ #ifndef __EMSCRIPTEN__
glfwSwapBuffers(nvgCtx().fbCtx().getGLFWWindow()); glfwSwapBuffers(nvgCtx().fbCtx().getGLFWWindow());
#else #else
@ -503,9 +517,9 @@ bool V4D::display() {
run_sync_on_main<6>([&, this]() { run_sync_on_main<6>([&, this]() {
{ {
FrameBufferContext::GLScope glScope(fbCtx(), GL_READ_FRAMEBUFFER); FrameBufferContext::GLScope glScope(fbCtx(), GL_READ_FRAMEBUFFER);
fbCtx().blitFrameBufferToScreen(viewport(), fbCtx().getWindowSize(), isScaling()); fbCtx().blitFrameBufferToScreen(viewport(), fbCtx().getWindowSize(), isStretching());
} }
imguiCtx().render(); imguiCtx().render(getShowFPS());
#ifndef __EMSCRIPTEN__ #ifndef __EMSCRIPTEN__
if(debug_) if(debug_)
swapContextBuffers(); swapContextBuffers();
@ -518,11 +532,21 @@ bool V4D::display() {
#endif #endif
glfwPollEvents(); glfwPollEvents();
result = !glfwWindowShouldClose(getGLFWWindow()); result = !glfwWindowShouldClose(getGLFWWindow());
{ {
FrameBufferContext::GLScope glScope(fbCtx(), GL_DRAW_FRAMEBUFFER); FrameBufferContext::GLScope glScope(fbCtx(), GL_DRAW_FRAMEBUFFER);
GL_CHECK(glViewport(0, 0, fbCtx().size().width, fbCtx().size().height));
GL_CHECK(glClearColor(0,0,0,255)); GL_CHECK(glClearColor(0,0,0,255));
GL_CHECK(glClear(GL_COLOR_BUFFER_BIT)); GL_CHECK(glClear(GL_COLOR_BUFFER_BIT));
} }
#ifndef __EMSCRIPTEN__
{
GL_CHECK(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0));
GL_CHECK(glViewport(0, 0, size().width, size().height));
GL_CHECK(glClearColor(0,0,0,255));
GL_CHECK(glClear(GL_COLOR_BUFFER_BIT));
}
#endif
}); });
} }
if (frameCnt_ == (std::numeric_limits<uint64_t>().max() - 1)) if (frameCnt_ == (std::numeric_limits<uint64_t>().max() - 1))
@ -559,6 +583,7 @@ void V4D::printSystemInfo() {
void V4D::makeCurrent() { void V4D::makeCurrent() {
fbCtx().makeCurrent(); fbCtx().makeCurrent();
imguiCtx().makeCurrent();
} }
cv::Ptr<V4D> V4D::self() { cv::Ptr<V4D> V4D::self() {

Loading…
Cancel
Save