diff --git a/modules/v4d/include/opencv2/v4d/detail/framebuffercontext.hpp b/modules/v4d/include/opencv2/v4d/detail/framebuffercontext.hpp index 2e3afe45e..ede333480 100644 --- a/modules/v4d/include/opencv2/v4d/detail/framebuffercontext.hpp +++ b/modules/v4d/include/opencv2/v4d/detail/framebuffercontext.hpp @@ -209,15 +209,15 @@ public: bool isClosed(); bool isShared(); void fence(); - bool wait(uint64_t timeout = 0); + bool wait(const uint64_t& timeout = 0); /*! * Blit the framebuffer to the screen * @param viewport ROI to blit * @param windowSize The size of the window to blit to * @param stretch if true stretch the framebuffer to window size */ - void blitFrameBufferToFrameBuffer(const cv::Rect& viewport, const cv::Size& windowSize, - bool stretch = false, GLuint drawFramebufferID = 0, bool flipY = false); + void blitFrameBufferToFrameBuffer(const cv::Rect& srcViewport, const cv::Size& targetFbSize, + GLuint targetFramebufferID = 0, bool stretch = true, bool flipY = false); protected: cv::Ptr getV4D(); int getIndex(); diff --git a/modules/v4d/src/detail/framebuffercontext.cpp b/modules/v4d/src/detail/framebuffercontext.cpp index c21b1912e..a898001fd 100644 --- a/modules/v4d/src/detail/framebuffercontext.cpp +++ b/modules/v4d/src/detail/framebuffercontext.cpp @@ -144,7 +144,7 @@ void FrameBufferContext::doWebGLCopy(FrameBufferContext& other) { other.blitFrameBufferToFrameBuffer( cv::Rect(0,0, other.size().width, other.size().height), this->getWindowSize(), - false); + 0, false); emscripten_webgl_commit_frame(); } this->makeCurrent(); @@ -379,7 +379,7 @@ void FrameBufferContext::init() { V4D* v4d = reinterpret_cast(glfwGetWindowUserPointer(glfwWin)); if(v4d->getGLFWWindow() == glfwWin) { v4d->setFocused(i == 1); - cerr << "FOCUSED: " << v4d->title() << endl; +// cerr << "FOCUSED: " << v4d->title() << endl; } }); } @@ -645,11 +645,11 @@ CLExecContext_t& FrameBufferContext::getCLExecContext() { } #endif -void FrameBufferContext::blitFrameBufferToFrameBuffer(const cv::Rect& viewport, - const cv::Size& windowSize, bool stretch, GLuint drawFramebufferID, bool flipY) { +void FrameBufferContext::blitFrameBufferToFrameBuffer(const cv::Rect& srcViewport, + const cv::Size& targetFbSize, GLuint targetFramebufferID, bool stretch, bool flipY) { this->makeCurrent(); - double hf = double(windowSize.height) / framebufferSize_.height; - double wf = double(windowSize.width) / framebufferSize_.width; + double hf = double(targetFbSize.height) / framebufferSize_.height; + double wf = double(targetFbSize.width) / framebufferSize_.width; double f; if (hf > wf) f = wf; @@ -659,15 +659,15 @@ void FrameBufferContext::blitFrameBufferToFrameBuffer(const cv::Rect& viewport, double fbws = framebufferSize_.width * f; double fbhs = framebufferSize_.height * f; - double marginw = (windowSize.width - framebufferSize_.width) / 2.0; - double marginh = (windowSize.height - framebufferSize_.height) / 2.0; - double marginws = (windowSize.width - fbws) / 2.0; - double marginhs = (windowSize.height - fbhs) / 2.0; + double marginw = (targetFbSize.width - framebufferSize_.width) / 2.0; + double marginh = (targetFbSize.height - framebufferSize_.height) / 2.0; + double marginws = (targetFbSize.width - fbws) / 2.0; + double marginhs = (targetFbSize.height - fbhs) / 2.0; - GLint srcX0 = viewport.x; - GLint srcY0 = viewport.y; - GLint srcX1 = viewport.x + viewport.width; - GLint srcY1 = viewport.y + viewport.height; + GLint srcX0 = srcViewport.x; + GLint srcY0 = srcViewport.y; + GLint srcX1 = srcViewport.x + srcViewport.width; + GLint srcY1 = srcViewport.y + srcViewport.height; GLint dstX0 = stretch ? marginws : marginw; GLint dstY0 = stretch ? marginhs : marginh; GLint dstX1 = stretch ? marginws + fbws : marginw + framebufferSize_.width; @@ -678,7 +678,7 @@ void FrameBufferContext::blitFrameBufferToFrameBuffer(const cv::Rect& viewport, dstY1 = tmp; } - GL_CHECK(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, drawFramebufferID)); + GL_CHECK(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, targetFramebufferID)); GL_CHECK(glBlitFramebuffer( srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, GL_COLOR_BUFFER_BIT, GL_NEAREST)); @@ -875,7 +875,7 @@ void FrameBufferContext::fence() { CV_Assert(current_sync_object_ != 0); } -bool FrameBufferContext::wait(uint64_t timeout) { +bool FrameBufferContext::wait(const uint64_t& timeout) { if(first_sync_) { current_sync_object_ = 0; first_sync_ = false; diff --git a/modules/v4d/src/util.cpp b/modules/v4d/src/util.cpp index 7b1c9710a..4a5585edf 100644 --- a/modules/v4d/src/util.cpp +++ b/modules/v4d/src/util.cpp @@ -469,7 +469,7 @@ public: ); GL_CHECK(glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0)); cv::Size fbSz = window_->framebufferSize(); - window_->fbCtx().blitFrameBufferToFrameBuffer(cv::Rect(0, 0, width_, height_), cv::Size(width_, height_), false, window_->fbCtx().getFramebufferID(), true); + window_->fbCtx().blitFrameBufferToFrameBuffer(cv::Rect(0, 0, width_, height_), cv::Size(width_, height_), window_->fbCtx().getFramebufferID(), true, true); return true; } diff --git a/modules/v4d/src/v4d.cpp b/modules/v4d/src/v4d.cpp index 742a5726a..b9346cc8c 100644 --- a/modules/v4d/src/v4d.cpp +++ b/modules/v4d/src/v4d.cpp @@ -505,7 +505,7 @@ void V4D::swapContextBuffers() { run_sync_on_main<10>([this]() { for(size_t i = 0; i < numGlCtx(); ++i) { FrameBufferContext::GLScope glScope(glCtx(i).fbCtx(), GL_READ_FRAMEBUFFER); - glCtx(i).fbCtx().blitFrameBufferToFrameBuffer(viewport(), glCtx(i).fbCtx().getWindowSize(), isStretching()); + glCtx(i).fbCtx().blitFrameBufferToFrameBuffer(viewport(), glCtx(i).fbCtx().getWindowSize(), 0, isStretching()); #ifndef __EMSCRIPTEN__ glfwSwapBuffers(glCtx(i).fbCtx().getGLFWWindow()); #else @@ -516,7 +516,7 @@ void V4D::swapContextBuffers() { run_sync_on_main<11>([this]() { FrameBufferContext::GLScope glScope(nvgCtx().fbCtx(), GL_READ_FRAMEBUFFER); - nvgCtx().fbCtx().blitFrameBufferToFrameBuffer(viewport(), nvgCtx().fbCtx().getWindowSize(), isStretching()); + nvgCtx().fbCtx().blitFrameBufferToFrameBuffer(viewport(), nvgCtx().fbCtx().getWindowSize(), 0, isStretching()); #ifndef __EMSCRIPTEN__ glfwSwapBuffers(nvgCtx().fbCtx().getGLFWWindow()); #else @@ -535,7 +535,7 @@ bool V4D::display() { run_sync_on_main<6>([&, this]() { { FrameBufferContext::GLScope glScope(fbCtx(), GL_READ_FRAMEBUFFER); - fbCtx().blitFrameBufferToFrameBuffer(viewport(), fbCtx().getWindowSize(), isStretching()); + fbCtx().blitFrameBufferToFrameBuffer(viewport(), fbCtx().getWindowSize(), 0, isStretching()); } imguiCtx().render(getShowFPS()); #ifndef __EMSCRIPTEN__