fixed merge mistake

pull/3471/head
kallaballa 2 years ago
parent 8f7732933a
commit f564e0ba9c
  1. 142
      modules/v4d/src/detail/framebuffercontext.cpp
  2. 5
      modules/v4d/src/detail/framebuffercontext.hpp
  3. 1
      modules/v4d/src/detail/nanoguicontext.cpp
  4. 1
      modules/v4d/src/detail/nanoguicontext.hpp
  5. 2
      modules/v4d/src/detail/nanovgcontext.cpp
  6. 32
      modules/v4d/src/v4d.cpp

@ -21,19 +21,14 @@
namespace cv {
namespace v4d {
namespace detail {
static bool contains_absolute(nanogui::Widget* w, const nanogui::Vector2i& p) {
nanogui::Vector2i d = p - w->absolute_position();
return d.x() >= 0 && d.y() >= 0 && d.x() < w->size().x() && d.y() < w->size().y();
}
int frameBufferContextCnt = 0;
FrameBufferContext::FrameBufferContext(V4D& v4d, const string& title, const FrameBufferContext& other) : FrameBufferContext(v4d, other.frameBufferSize_, true, title, other.major_, other.minor_, other.compat_, other.samples_, other.debug_, other.glfwWindow_, &other) {
FrameBufferContext::FrameBufferContext(const string& title, const FrameBufferContext& other) : FrameBufferContext(other.frameBufferSize_, true, title, other.major_, other.minor_, other.compat_, other.samples_, other.debug_, other.glfwWindow_, &other) {
}
FrameBufferContext::FrameBufferContext(V4D& v4d, const cv::Size& framebufferSize, bool offscreen,
FrameBufferContext::FrameBufferContext(const cv::Size& framebufferSize, bool offscreen,
const string& title, int major, int minor, bool compat, int samples, bool debug, GLFWwindow* sharedWindow, const FrameBufferContext* parent) :
v4d_(&v4d), offscreen_(offscreen), title_(title), major_(major), minor_(
offscreen_(offscreen), title_(title), major_(major), minor_(
minor), compat_(compat), samples_(samples), debug_(debug), viewport_(0, 0, framebufferSize.width, framebufferSize.height), frameBufferSize_(framebufferSize), isShared_(false), sharedWindow_(sharedWindow), parent_(parent), framebuffer_(framebufferSize, CV_8UC4) {
run_sync_on_main<1>([this](){ init(); });
index_ = ++frameBufferContextCnt;
@ -251,7 +246,9 @@ void FrameBufferContext::init() {
assert(false);
}
this->makeCurrent();
#ifndef __EMSCRIPTEN__
glfwSwapInterval(0);
#endif
#if !defined(OPENCV_V4D_USE_ES3) && !defined(__EMSCRIPTEN__)
if (!gladLoadGLLoader((GLADloadproc) glfwGetProcAddress))
throw std::runtime_error("Could not initialize GLAD!");
@ -276,106 +273,6 @@ void FrameBufferContext::init() {
#endif
setup(frameBufferSize_);
glfwSetWindowUserPointer(getGLFWWindow(), v4d_);
glfwSetCursorPosCallback(getGLFWWindow(), [](GLFWwindow* glfwWin, double x, double y) {
V4D* v4d = reinterpret_cast<V4D*>(glfwGetWindowUserPointer(glfwWin));
if(v4d->hasNguiCtx()) {
auto pt = v4d->fbCtx().toWindowCoord(cv::Point2f(x, y));
v4d->nguiCtx().screen().cursor_pos_callback_event(pt.x, pt.y);
}
#ifndef __EMSCRIPTEN__
auto cursor = v4d->getMousePosition();
auto diff = cursor - cv::Vec2f(x, y);
if (v4d->isMouseDrag()) {
v4d->pan(diff[0], -diff[1]);
}
#endif
v4d->setMousePosition(x, y);
}
);
glfwSetMouseButtonCallback(getGLFWWindow(),
[](GLFWwindow* glfwWin, int button, int action, int modifiers) {
V4D* v4d = reinterpret_cast<V4D*>(glfwGetWindowUserPointer(glfwWin));
if(v4d->hasNguiCtx())
v4d->nguiCtx().screen().mouse_button_callback_event(button, action, modifiers);
if (button == GLFW_MOUSE_BUTTON_RIGHT) {
v4d->setMouseDrag(action == GLFW_PRESS);
}
}
);
glfwSetKeyCallback(getGLFWWindow(),
[](GLFWwindow* glfwWin, int key, int scancode, int action, int mods) {
V4D* v4d = reinterpret_cast<V4D*>(glfwGetWindowUserPointer(glfwWin));
if(v4d->hasNguiCtx())
v4d->nguiCtx().screen().key_callback_event(key, scancode, action, mods);
}
);
glfwSetCharCallback(getGLFWWindow(), [](GLFWwindow* glfwWin, unsigned int codepoint) {
V4D* v4d = reinterpret_cast<V4D*>(glfwGetWindowUserPointer(glfwWin));
if(v4d->hasNguiCtx())
v4d->nguiCtx().screen().char_callback_event(codepoint);
}
);
glfwSetDropCallback(getGLFWWindow(),
[](GLFWwindow* glfwWin, int count, const char** filenames) {
V4D* v4d = reinterpret_cast<V4D*>(glfwGetWindowUserPointer(glfwWin));
if(v4d->hasNguiCtx())
v4d->nguiCtx().screen().drop_callback_event(count, filenames);
}
);
glfwSetScrollCallback(getGLFWWindow(),
[](GLFWwindow* glfwWin, double x, double y) {
V4D* v4d = reinterpret_cast<V4D*>(glfwGetWindowUserPointer(glfwWin));
std::vector<nanogui::Widget*> widgets;
if(v4d->hasNguiCtx()) {
for (auto* w : v4d->nguiCtx().screen().children()) {
auto pt = v4d->fbCtx().toWindowCoord(v4d->getMousePosition());
auto mousePos = nanogui::Vector2i(pt[0] / v4d->pixelRatioX(), pt[1] / v4d->pixelRatioY());
if(contains_absolute(w, mousePos)) {
v4d->nguiCtx().screen().scroll_callback_event(x, y);
return;
}
}
}
#ifndef __EMSCRIPTEN__
v4d->zoom(y < 0 ? 1.1 : 0.9);
#endif
}
);
glfwSetWindowSizeCallback(getGLFWWindow(),
[](GLFWwindow* glfwWin, int width, int height) {
V4D* v4d = reinterpret_cast<V4D*>(glfwGetWindowUserPointer(glfwWin));
if(v4d->hasNguiCtx())
v4d->nguiCtx().screen().resize_callback_event(width, height);
cv::Rect& vp = v4d->viewport();
cv::Size fbsz = v4d->framebufferSize();
vp.x = 0;
vp.y = 0;
vp.width = fbsz.width;
vp.height = fbsz.height;
});
// glfwSetFramebufferSizeCallback(getGLFWWindow(),
// [](GLFWwindow* glfwWin, int width, int height) {
// V4D* v4d = reinterpret_cast<V4D*>(glfwGetWindowUserPointer(glfwWin));
// cv::Rect& vp = v4d->viewport();
// vp.x = 0;
// vp.y = 0;
// vp.width = width;
// vp.height = height;
//#ifndef __EMSCRIPTEN__
// if(v4d->isResizable()) {
// v4d->nvgCtx().fbCtx().teardown();
// v4d->glCtx().fbCtx().teardown();
// v4d->fbCtx().teardown();
// v4d->fbCtx().setup(cv::Size(width, height));
// v4d->glCtx().fbCtx().setup(cv::Size(width, height));
// v4d->nvgCtx().fbCtx().setup(cv::Size(width, height));
// }
//#endif
// });
}
int FrameBufferContext::getIndex() {
@ -659,21 +556,14 @@ void FrameBufferContext::begin(GLenum framebufferTarget) {
this->makeCurrent();
GL_CHECK(glFinish());
GL_CHECK(glBindFramebuffer(framebufferTarget, frameBufferID_));
if(frameBufferID_ > 0) {
GL_CHECK(glBindTexture(GL_TEXTURE_2D, textureID_));
GL_CHECK(glBindRenderbuffer(GL_RENDERBUFFER, renderBufferID_));
GL_CHECK(
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, size().width, size().height));
GL_CHECK(
glFramebufferRenderbuffer(framebufferTarget, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, renderBufferID_));
GL_CHECK(
glFramebufferTexture2D(framebufferTarget, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textureID_, 0));
} else {
// GL_CHECK(
// glFramebufferRenderbuffer(framebufferTarget, GL_DEPTH_STENCIL, GL_RENDERBUFFER, renderBufferID_));
// GL_CHECK(
// glFramebufferTexture2D(framebufferTarget, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textureID_, 0));
}
GL_CHECK(glBindTexture(GL_TEXTURE_2D, textureID_));
GL_CHECK(glBindRenderbuffer(GL_RENDERBUFFER, renderBufferID_));
GL_CHECK(
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, size().width, size().height));
GL_CHECK(
glFramebufferRenderbuffer(framebufferTarget, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, renderBufferID_));
GL_CHECK(
glFramebufferTexture2D(framebufferTarget, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textureID_, 0));
assert(glCheckFramebufferStatus(framebufferTarget) == GL_FRAMEBUFFER_COMPLETE);
}
@ -846,9 +736,7 @@ bool FrameBufferContext::isShared() {
return isShared_;
}
V4D& FrameBufferContext::getWindow() {
return *v4d_;
}
}
}
}

@ -154,10 +154,10 @@ public:
* Create a FrameBufferContext with given size.
* @param frameBufferSize The frame buffer size.
*/
FrameBufferContext(V4D& v4d, const cv::Size& frameBufferSize, bool offscreen,
FrameBufferContext(const cv::Size& frameBufferSize, bool offscreen,
const string& title, int major, int minor, bool compat, int samples, bool debug, GLFWwindow* sharedWindow, const FrameBufferContext* parent);
FrameBufferContext(V4D& v4d, const string& title, const FrameBufferContext& other);
FrameBufferContext(const string& title, const FrameBufferContext& other);
/*!
* Default destructor.
@ -199,7 +199,6 @@ public:
bool isClosed();
bool isShared();
protected:
V4D& getWindow();
int getIndex();
void setup(const cv::Size& sz);
void teardown();

@ -5,7 +5,6 @@
#include "opencv2/v4d/v4d.hpp"
#include "nanoguicontext.hpp"
#include "nanovgcontext.hpp"
namespace cv {
namespace v4d {

@ -39,6 +39,7 @@ public:
void build(std::function<void(cv::v4d::FormHelper&)> fn);
nanogui::Screen& screen();
cv::v4d::FormHelper& form();
FrameBufferContext& fbCtx();
};
}
}

@ -11,7 +11,7 @@ namespace v4d {
namespace detail {
NanoVGContext::NanoVGContext(FrameBufferContext& fbContext) :
mainFbContext_(fbContext), nvgFbContext_(mainFbContext_.getWindow(), "NanoVG", fbContext), context_(
mainFbContext_(fbContext), nvgFbContext_("NanoVG", fbContext), context_(
nullptr) {
UMat tmp(fbCtx().size(), CV_8UC4);

@ -16,6 +16,10 @@
namespace cv {
namespace v4d {
namespace detail {
static bool contains_absolute(nanogui::Widget* w, const nanogui::Vector2i& p) {
nanogui::Vector2i d = p - w->absolute_position();
return d.x() >= 0 && d.y() >= 0 && d.x() < w->size().x() && d.y() < w->size().y();
}
void glfw_error_callback(int error, const char* description) {
fprintf(stderr, "GLFW Error: (%d) %s\n", error, description);
@ -49,13 +53,9 @@ V4D::V4D(const cv::Size& size, const cv::Size& fbsize, const string& title, bool
#ifdef __EMSCRIPTEN__
printf(""); //makes sure we have FS as a dependency
#endif
mainFbContext_ = new detail::FrameBufferContext(*this, fbsize.empty() ? size : fbsize, offscreen, title_, major_,
mainFbContext_ = new detail::FrameBufferContext(fbsize.empty() ? size : fbsize, offscreen, title_, major_,
minor_, compat_, samples_, debug_, nullptr, nullptr);
nvgContext_ = new detail::NanoVGContext(*mainFbContext_);
nguiContext_ = new detail::NanoguiContext(*mainFbContext_);
clvaContext_ = new detail::CLVAContext(*mainFbContext_);
glContext_ = new detail::GLContext(*mainFbContext_);
run_sync_on_main<21>([this](){
this->makeCurrent();
glfwSetWindowUserPointer(getGLFWWindow(), this);
@ -175,6 +175,10 @@ V4D::V4D(const cv::Size& size, const cv::Size& fbsize, const string& title, bool
// }
// #endif
});
nvgContext_ = new detail::NanoVGContext(*mainFbContext_);
nguiContext_ = new detail::NanoguiContext(*mainFbContext_);
clvaContext_ = new detail::CLVAContext(*mainFbContext_);
glContext_ = new detail::GLContext(*mainFbContext_);
});
}
@ -636,15 +640,15 @@ void V4D::swapContextBuffers() {
#endif
});
// run_sync_on_main<12>([this]() {
// FrameBufferContext::GLScope glScope(nguiCtx().fbCtx(), GL_READ_FRAMEBUFFER);
// nguiCtx().fbCtx().blitFrameBufferToScreen(viewport(), nguiCtx().fbCtx().getWindowSize(), isFrameBufferScaling());
//#ifndef __EMSCRIPTEN__
// glfwSwapBuffers(nguiCtx().fbCtx().getGLFWWindow());
//#else
// emscripten_webgl_commit_frame();
//#endif
// });
run_sync_on_main<12>([this]() {
FrameBufferContext::GLScope glScope(nguiCtx().fbCtx(), GL_READ_FRAMEBUFFER);
nguiCtx().fbCtx().blitFrameBufferToScreen(viewport(), nguiCtx().fbCtx().getWindowSize(), isFrameBufferScaling());
#ifndef __EMSCRIPTEN__
glfwSwapBuffers(nguiCtx().fbCtx().getGLFWWindow());
#else
emscripten_webgl_commit_frame();
#endif
});
}
bool V4D::display() {

Loading…
Cancel
Save