big time refactoring mainly for portability reasons

pull/3471/head
kallaballa 2 years ago
parent a403a0bbe0
commit 55592b3dcb
  1. 1
      modules/v4d/include/opencv2/v4d/detail/threadpool.hpp
  2. 12
      modules/v4d/include/opencv2/v4d/v4d.hpp
  3. 26
      modules/v4d/samples/custom_source_and_sink.cpp
  4. 23
      modules/v4d/samples/display_image.cpp
  5. 21
      modules/v4d/samples/display_image_fb.cpp
  6. 3
      modules/v4d/samples/example_v4d_custom_source_and_sink.html
  7. 3
      modules/v4d/samples/example_v4d_display_image.html
  8. 3
      modules/v4d/samples/example_v4d_display_image_fb.html
  9. 3
      modules/v4d/samples/example_v4d_font_rendering.html
  10. 3
      modules/v4d/samples/example_v4d_font_with_gui.html
  11. 2
      modules/v4d/samples/example_v4d_render_opengl.html
  12. 3
      modules/v4d/samples/example_v4d_vector_graphics.html
  13. 2
      modules/v4d/samples/example_v4d_vector_graphics_and_fb.html
  14. 3
      modules/v4d/samples/example_v4d_video_editing.html
  15. 36
      modules/v4d/samples/font_rendering.cpp
  16. 21
      modules/v4d/samples/font_with_gui.cpp
  17. 25
      modules/v4d/samples/render_opengl.cpp
  18. 21
      modules/v4d/samples/vector_graphics.cpp
  19. 20
      modules/v4d/samples/vector_graphics_and_fb.cpp
  20. 7
      modules/v4d/samples/video-demo.cpp
  21. 31
      modules/v4d/samples/video_editing.cpp
  22. 48
      modules/v4d/src/detail/framebuffercontext.cpp
  23. 2
      modules/v4d/src/detail/framebuffercontext.hpp
  24. 1
      modules/v4d/src/detail/nanoguicontext.cpp
  25. 2
      modules/v4d/src/util.cpp
  26. 53
      modules/v4d/src/v4d.cpp
  27. 2
      modules/v4d/tutorials/04-vector_graphics_and_fb.markdown
  28. 2
      modules/v4d/tutorials/05-render_opengl.markdown

@ -29,7 +29,6 @@ public:
}
for (auto i = 0llu; i < threads; i++) {
std::cerr << "work" << std::endl;
workers.emplace_back([this] { worker_main(); });
}
}

@ -115,7 +115,7 @@ class NVG;
class CV_EXPORTS V4D {
friend class detail::NanoVGContext;
friend class detail::FrameBufferContext;
const cv::Size initialSize_;
cv::Size initialSize_;
bool offscreen_;
const string& title_;
int major_;
@ -305,17 +305,13 @@ public:
* @return The current viewport.
*/
CV_EXPORTS cv::Rect& viewport();
CV_EXPORTS float getXPixelRatio();
CV_EXPORTS float getYPixelRatio();
/*!
* Set the window size.
* @param sz The new window size.
*/
CV_EXPORTS void resizeWindow(const cv::Size& sz);
CV_EXPORTS void setWindowSize(const cv::Size& sz);
/*!
* Get the window size
* @return The current window size.
*/
CV_EXPORTS cv::Size getWindowSize();
/*!
* Get the initial size.
* @return The initial size.
@ -404,7 +400,7 @@ public:
bool display_impl();
private:
V4D(const cv::Size& initialSize, bool offscreen,
const string& title, int major = 4, int minor = 6, bool compat = true, int samples = 0, bool debug = true);
const string& title, int major = 4, int minor = 6, bool compat = true, int samples = 0, bool debug = false);
void setDefaultKeyboardEventCallback();
void setKeyboardEventCallback(
std::function<bool(int key, int scancode, int action, int modifiers)> fn);

@ -3,13 +3,13 @@
# include <opencv2/imgcodecs.hpp>
#endif
int main() {
using namespace cv;
using namespace cv::v4d;
using namespace cv;
using namespace cv::v4d;
static Ptr<V4D> window = V4D::make(Size(1280, 720), "Custom Source/Sink");
int main() {
string hr = "Hello Rainbow!";
Ptr<V4D> v4d = V4D::make(Size(1280, 720), "Custom Source/Sink");
v4d->setVisible(true);
//Make a Source that generates rainbow frames.
Source src([](cv::UMat& frame){
static long cnt = 0;
@ -36,16 +36,16 @@ int main() {
});
//Attach source and sink
v4d->setSource(src);
v4d->setSink(sink);
window->setSource(src);
window->setSink(sink);
v4d->run([=]() {
window->run([=]() {
//Capture video from the Source
if(!v4d->capture())
if(!window->capture())
return false; //end of input video
//Render "Hello Rainbow!" over the frame
v4d->nvg([=](const Size& sz) {
window->nvg([=](const Size& sz) {
using namespace cv::v4d::nvg;
fontSize(40.0f);
@ -54,9 +54,9 @@ int main() {
textAlign(NVG_ALIGN_CENTER | NVG_ALIGN_TOP);
text(sz.width / 2.0, sz.height / 2.0, hr.c_str(), hr.c_str() + hr.size());
});
updateFps(v4d,true);
v4d->write(); //Write video to the Sink
return v4d->display(); //Display the framebuffer in the native window
updateFps(window,true);
window->write(); //Write video to the Sink
return window->display(); //Display the framebuffer in the native window
});
}

@ -1,30 +1,27 @@
#include <opencv2/v4d/v4d.hpp>
#include <opencv2/imgcodecs.hpp>
#ifdef __EMSCRIPTEN__
# include <fstream>
#endif
using namespace cv;
using namespace cv::v4d;
int main() {
using namespace cv;
using namespace cv::v4d;
//Creates a V4D window for on screen rendering
static Ptr<V4D> window = V4D::make(Size(1280, 720), "Show image");
//Creates a V4D object for on screen rendering
Ptr<V4D> v4d = V4D::make(Size(1280, 720), "Show image");
v4d->setVisible(true);
int main() {
//An image
#ifdef __EMSCRIPTEN__
Mat image = read_image("doc/lena.png");
#else
Mat image = imread(samples::findFile("lena.jpg"));
#endif
//Feeds the image to the video pipeline
window->feed(image);
//Display the framebuffer in the native window in an endless loop.
//V4D::run() though it takes a functor is not a context. It is simply an abstraction
//of a run loop for portability reasons and executes the functor until the application
//terminates or the functor returns false.
v4d->run([=](){
//Feeds the image to the video pipeline
v4d->feed(image);
return v4d->display();
window->run([=](){
updateFps(window, true);
return window->display();
});
}

@ -1,13 +1,13 @@
#include <opencv2/v4d/v4d.hpp>
#include <opencv2/imgcodecs.hpp>
int main() {
using namespace cv;
using namespace cv::v4d;
using namespace cv;
using namespace cv::v4d;
//Creates a V4D object for on screen rendering
static Ptr<V4D> window = V4D::make(Size(1280, 720), "Show image");
//Creates a V4D object for on screen rendering
Ptr<V4D> v4d = V4D::make(Size(1280, 720), "Show image");
v4d->setVisible(true);
int main() {
//Read an image as UMat
#ifdef __EMSCRIPTEN__
UMat image = read_image("doc/lena.png").getUMat(ACCESS_READ);
@ -16,13 +16,14 @@ int main() {
#endif
UMat resized;
//Resize and color convert the image to framebuffer size
v4d->fb([&](const UMat& framebuffer) {
resize(image, resized, v4d->getFrameBufferSize());
window->fb([&](const UMat& framebuffer) {
resize(image, resized, window->getFrameBufferSize());
cvtColor(resized, framebuffer, COLOR_RGB2BGRA);
});
//Display the framebuffer in the native window in an endless loop
v4d->run([=](){
return v4d->display();
window->run([=](){
updateFps(window, true);
return window->display();
});
}

@ -134,10 +134,11 @@
var Module = {
onRuntimeInitialized: function() {
fixCanvasSize();
},
preRun: [],
postRun: function() {
fixCanvasSize();
},
print: (function() {
var element = document.getElementById('output');

@ -134,10 +134,11 @@
var Module = {
onRuntimeInitialized: function() {
fixCanvasSize();
},
preRun: [],
postRun: function() {
fixCanvasSize();
},
print: (function() {
var element = document.getElementById('output');

@ -134,10 +134,11 @@
var Module = {
onRuntimeInitialized: function() {
fixCanvasSize();
},
preRun: [],
postRun: function() {
fixCanvasSize();
},
print: (function() {
var element = document.getElementById('output');

@ -134,10 +134,11 @@
var Module = {
onRuntimeInitialized: function() {
fixCanvasSize();
},
preRun: [],
postRun: function() {
fixCanvasSize();
},
print: (function() {
var element = document.getElementById('output');

@ -135,10 +135,11 @@
var Module = {
onRuntimeInitialized: function() {
fixCanvasSize();
},
preRun: [],
postRun: function() {
fixCanvasSize();
},
print: (function() {
var element = document.getElementById('output');

@ -134,10 +134,10 @@
var Module = {
onRuntimeInitialized: function() {
fixCanvasSize();
},
preRun: [],
postRun: function() {
fixCanvasSize();
},
print: (function() {
var element = document.getElementById('output');

@ -134,10 +134,11 @@
var Module = {
onRuntimeInitialized: function() {
fixCanvasSize();
},
preRun: [],
postRun: function() {
fixCanvasSize();
},
print: (function() {
var element = document.getElementById('output');

@ -134,10 +134,10 @@
var Module = {
onRuntimeInitialized: function() {
fixCanvasSize();
},
preRun: [],
postRun: function() {
fixCanvasSize();
},
print: (function() {
var element = document.getElementById('output');

@ -134,10 +134,11 @@
var Module = {
onRuntimeInitialized: function() {
fixCanvasSize();
},
preRun: [],
postRun: function() {
fixCanvasSize();
},
print: (function() {
var element = document.getElementById('output');

@ -1,30 +1,28 @@
#include <opencv2/v4d/v4d.hpp>
int main() {
using namespace cv;
using namespace cv::v4d;
using namespace cv;
using namespace cv::v4d;
Ptr<V4D> v4d = V4D::make(Size(1280, 720), "Font Rendering");
v4d->setVisible(true);
static Ptr<V4D> window = V4D::make(Size(1280, 720), "Font Rendering");
int main() {
//The text to render
string hw = "Hello World";
//Clear with black
v4d->clear();
//Render the text at the center of the screen
v4d->nvg([&](const Size& sz) {
using namespace cv::v4d::nvg;
fontSize(40.0f);
fontFace("sans-bold");
fillColor(Scalar(255, 0, 0, 255));
textAlign(NVG_ALIGN_CENTER | NVG_ALIGN_TOP);
text(sz.width / 2.0, sz.height / 2.0, hw.c_str(), hw.c_str() + hw.size());
});
//Display the framebuffer in the native window in an endless loop
v4d->run([=](){
updateFps(v4d,true);
return v4d->display();
window->run([=](){
window->clear();
//Render the text at the center of the screen
window->nvg([&](const Size& sz) {
using namespace cv::v4d::nvg;
fontSize(40.0f);
fontFace("sans-bold");
fillColor(Scalar(255, 0, 0, 255));
textAlign(NVG_ALIGN_CENTER | NVG_ALIGN_TOP);
text(sz.width / 2.0, sz.height / 2.0, hw.c_str(), hw.c_str() + hw.size());
});
updateFps(window,true);
return window->display();
});
}

@ -1,12 +1,11 @@
#include <opencv2/v4d/v4d.hpp>
int main() {
using namespace cv;
using namespace cv::v4d;
using namespace cv;
using namespace cv::v4d;
Ptr<V4D> v4d = V4D::make(Size(1280, 720), "Font Rendering with GUI");
v4d->setVisible(true);
static Ptr<V4D> window = V4D::make(Size(1280, 720), "Font Rendering with GUI");
int main() {
//The text color. NanoGUI uses rgba with floating point
nanogui::Color textColor = {0.0f, 0.0f, 1.0f, 1.0f};
//The font size
@ -14,7 +13,7 @@ int main() {
//The text
string hw = "hello world";
//Setup the GUI
v4d->nanogui([&](FormHelper& form) {
window->nanogui([&](FormHelper& form) {
//Create a light-weight dialog
form.makeDialog(5, 30, "Settings");
//Create a group
@ -25,10 +24,10 @@ int main() {
form.makeColorPicker("Text Color", textColor, "The text color");
});
v4d->run([&]() {
v4d->clear();
window->run([&]() {
window->clear();
//Render the text at the center of the screen
v4d->nvg([&](const Size& sz) {
window->nvg([&](const Size& sz) {
using namespace cv::v4d::nvg;
fontSize(size);
fontFace("sans-bold");
@ -36,9 +35,9 @@ int main() {
textAlign(NVG_ALIGN_CENTER | NVG_ALIGN_TOP);
text(sz.width / 2.0, sz.height / 2.0, hw.c_str(), hw.c_str() + hw.size());
});
updateFps(v4d,true);
updateFps(window,true);
//Display the framebuffer in the native window
return v4d->display();
return window->display();
});
}

@ -1,23 +1,24 @@
#include <opencv2/v4d/v4d.hpp>
int main() {
using namespace cv;
using namespace cv::v4d;
using namespace cv;
using namespace cv::v4d;
Ptr<V4D> v4d = V4D::make(Size(1280, 720), "GL Blue Screen", true);
v4d->printSystemInfo();
v4d->setVisible(true);
static Ptr<V4D> window = V4D::make(Size(1280, 720), "GL Blue Screen");
v4d->run([=]() {
v4d->gl([]() {
//Clears the screen blue
glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
int main() {
window->gl([](){
//Sets blue as clear color
glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
});
window->run([=]() {
window->gl([]() {
//Clears the screen
glClear(GL_COLOR_BUFFER_BIT);
});
updateFps(v4d,true);
updateFps(window,true);
//If onscreen rendering is enabled it displays the framebuffer in the native window.
//Returns false if the window was closed.
return v4d->display();
return window->display();
});
}

@ -1,16 +1,16 @@
#include <opencv2/v4d/v4d.hpp>
int main() {
using namespace cv;
using namespace cv::v4d;
using namespace cv;
using namespace cv::v4d;
Ptr<V4D> v4d = V4D::make(Size(1280, 720), "Vector Graphics");
v4d->setVisible(true);
//Creates a NanoVG context and draws a cross-hair on the framebuffer
static Ptr<V4D> window = V4D::make(Size(1280, 720), "Vector Graphics");
int main() {
//Display the framebuffer in the native window in an endless loop
v4d->run([=](){
v4d->nvg([](const Size& sz) {
window->run([=](){
window->clear();
//Creates a NanoVG context and draws a cross-hair on the framebuffer
window->nvg([](const Size& sz) {
//Calls from this namespace may only be used inside a nvg context
using namespace cv::v4d::nvg;
@ -24,8 +24,9 @@ int main() {
lineTo(sz.width, sz.height/2.0);
stroke();
});
updateFps(v4d,true);
return v4d->display();
updateFps(window,true);
return window->display();
});
}

@ -1,16 +1,16 @@
#include <opencv2/v4d/v4d.hpp>
int main() {
using namespace cv;
using namespace cv::v4d;
using namespace cv;
using namespace cv::v4d;
Ptr<V4D> v4d = V4D::make(Size(1280, 720), "Vector Graphics and Framebuffer");
v4d->setVisible(true);
static Ptr<V4D> window = V4D::make(Size(1280, 720), "Vector Graphics and Framebuffer");
int main() {
//Display the framebuffer in the native window in an endless loop
v4d->run([=](){
window->run([=](){
window->clear();
//Creates a NanoVG context and draws a cross-hair on the framebuffer
v4d->nvg([](const Size& sz) {
window->nvg([](const Size& sz) {
//Calls from this namespace may only be used inside a nvg context
using namespace cv::v4d::nvg;
@ -25,12 +25,12 @@ int main() {
stroke();
});
v4d->fb([](UMat& framebuffer) {
window->fb([](UMat& framebuffer) {
//Heavily blurs the crosshair using a cheap boxFilter
boxFilter(framebuffer, framebuffer, -1, Size(15, 15), Point(-1,-1), true, BORDER_REPLICATE);
});
updateFps(v4d,true);
return v4d->display();
updateFps(window,true);
return window->display();
});
}

@ -206,13 +206,10 @@ static bool iteration() {
updateFps(v4d, true);
//If onscreen rendering is enabled it displays the framebuffer in the native window. Returns false if the window was closed.
if (!v4d->display())
return false;
v4d->write();
return true;
//If onscreen rendering is enabled it displays the framebuffer in the native window. Returns false if the window was closed.
return v4d->display();
}
#ifndef __EMSCRIPTEN__

@ -1,40 +1,41 @@
#include <opencv2/v4d/v4d.hpp>
using namespace cv;
using namespace cv::v4d;
static Ptr<V4D> window = V4D::make(cv::Size(1280, 720), "Video Editing");
int main(int argc, char** argv) {
try {
//In case of emscripten
CV_UNUSED(argc);
CV_UNUSED(argv);
using namespace cv;
using namespace cv::v4d;
string hv = "Hello Video!";
Ptr<V4D> v4d = V4D::make(Size(1280, 720), "Video Editing");
v4d->setVisible(true);
#ifndef __EMSCRIPTEN__
//Make the video source
Source src = makeCaptureSource(argv[1]);
//Make the video sink
Sink sink = makeWriterSink(argv[2], VideoWriter::fourcc('V', 'P', '9', '0'), src.fps(), v4d->getFrameBufferSize());
Sink sink = makeWriterSink(argv[2], VideoWriter::fourcc('V', 'P', '9', '0'), src.fps(), window->getFrameBufferSize());
//Attach source and sink
v4d->setSource(src);
v4d->setSink(sink);
window->setSource(src);
window->setSink(sink);
#else
//Make a webcam Source
Source src = makeCaptureSource(1280,720);
//Attach web source
v4d->setSource(src);
window->setSource(src);
#endif
v4d->run([=]() {
window->run([=]() {
//Capture video from the Source
if(!v4d->capture())
if(!window->capture())
return false; //end of input video
v4d->nvg([=](const Size& sz) {
window->nvg([=](const Size& sz) {
using namespace cv::v4d::nvg;
fontSize(40.0f);
@ -43,11 +44,11 @@ int main(int argc, char** argv) {
textAlign(NVG_ALIGN_CENTER | NVG_ALIGN_TOP);
text(sz.width / 2.0, sz.height / 2.0, hv.c_str(), hv.c_str() + hv.size());
});
updateFps(v4d,true);
updateFps(window,true);
v4d->write(); //Write video to the Sink
window->write(); //Write video to the Sink
return v4d->display(); //Display the framebuffer in the native window
return window->display(); //Display the framebuffer in the native window
});
} catch(std::exception& ex) {
cerr << ex.what() << endl;

@ -49,11 +49,8 @@ void FrameBufferContext::init() {
#endif
if (glfwInit() != GLFW_TRUE)
assert(false);
#ifndef __EMSCRIPTEN__
glfwSetErrorCallback(cv::v4d::glfw_error_callback);
cerr << "after" << endl;
glfwDefaultWindowHints();
#endif
if (debug_)
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GLFW_TRUE);
@ -87,17 +84,16 @@ void FrameBufferContext::init() {
glfwWindowHint(GLFW_STENCIL_BITS, 8);
glfwWindowHint(GLFW_DEPTH_BITS, 24);
glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
glfwWindowHint(GLFW_DOUBLEBUFFER, GL_FALSE);
// glfwWindowHint(GLFW_DOUBLEBUFFER, GL_FALSE);
glfwWindow_ = glfwCreateWindow(frameBufferSize_.width, frameBufferSize_.height, std::to_string(++window_cnt).c_str(), nullptr,
sharedWindow_);
if (glfwWindow_ == NULL) {
assert(false);
}
cerr << "win" << endl;
this->makeCurrent();
cerr << "current" << endl;
glfwSwapInterval(0);
#ifndef OPENCV_V4D_USE_ES3
if (!gladLoadGLLoader((GLADloadproc) glfwGetProcAddress))
throw std::runtime_error("Could not initialize GLAD!");
@ -114,16 +110,19 @@ void FrameBufferContext::init() {
cerr << "CL-GL sharing failed with unknown error." << endl;
clglSharing_ = false;
}
context_ = CLExecContext_t::getCurrent();
#else
clglSharing_ = false;
#endif
#ifndef __EMSCRIPTEN__
context_ = CLExecContext_t::getCurrent();
#endif
setup(frameBufferSize_);
glfwSetWindowUserPointer(getGLFWWindow(), v4d_);
glfwSetCursorPosCallback(getGLFWWindow(), [](GLFWwindow* glfwWin, double x, double y) {
V4D* v4d = reinterpret_cast<V4D*>(glfwGetWindowUserPointer(glfwWin));
v4d->nguiCtx().screen().cursor_pos_callback_event(x, y);
v4d->nguiCtx().screen().cursor_pos_callback_event(x * v4d->getXPixelRatio(), y * v4d->getXPixelRatio());
auto cursor = v4d->getMousePosition();
auto diff = cursor - cv::Vec2f(x, y);
if (v4d->isMouseDrag()) {
@ -163,7 +162,7 @@ void FrameBufferContext::init() {
V4D* v4d = reinterpret_cast<V4D*>(glfwGetWindowUserPointer(glfwWin));
std::vector<nanogui::Widget*> widgets;
for (auto* w : v4d->nguiCtx().screen().children()) {
auto mousePos = nanogui::Vector2i(v4d->getMousePosition()[0] / v4d->fbCtx().getXPixelRatio(), v4d->getMousePosition()[1] / v4d->fbCtx().getYPixelRatio());
auto mousePos = nanogui::Vector2i(v4d->getMousePosition()[0] / v4d->getXPixelRatio(), v4d->getMousePosition()[1] / v4d->getYPixelRatio());
if(contains_absolute(w, mousePos)) {
v4d->nguiCtx().screen().scroll_callback_event(x, y);
return;
@ -174,15 +173,19 @@ void FrameBufferContext::init() {
}
);
// glfwSetWindowSizeCallback(getGLFWWindow(),
// [](GLFWwindow* glfwWin, int width, int height) {
// V4D* v4d = reinterpret_cast<V4D*>(glfwGetWindowUserPointer(glfwWin));
// v4d->nguiCtx().screen().resize_callback_event(width, height);
// });
glfwSetFramebufferSizeCallback(getGLFWWindow(),
[](GLFWwindow* glfwWin, int width, int height) {
V4D* v4d = reinterpret_cast<V4D*>(glfwGetWindowUserPointer(glfwWin));
v4d->setWindowSize(cv::Size(width, height));
cv::Rect& vp = v4d->viewport();
vp.x = 0;
vp.y = 0;
vp.width = width;
vp.height = height;
// 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();
@ -200,7 +203,6 @@ void FrameBufferContext::setup(const cv::Size& sz) {
this->makeCurrent();
if(!isShared_) {
GL_CHECK(glGenFramebuffers(1, &frameBufferID_));
cerr << "GENFB1: " << frameBufferID_ << "/" << getGLFWWindow() << endl;
GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, frameBufferID_));
GL_CHECK(glGenRenderbuffers(1, &renderBufferID_));
@ -227,7 +229,6 @@ void FrameBufferContext::setup(const cv::Size& sz) {
} else {
assert(parent_ != nullptr);
GL_CHECK(glGenFramebuffers(1, &frameBufferID_));
cerr << "GENFB2: " << frameBufferID_ << "/" << getGLFWWindow() << endl;
GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, frameBufferID_));
GL_CHECK(glBindTexture(GL_TEXTURE_2D, textureID_));
@ -533,21 +534,12 @@ void FrameBufferContext::makeCurrent() {
bool FrameBufferContext::isResizable() {
makeCurrent();
return glfwGetWindowAttrib(getGLFWWindow(), GLFW_RESIZABLE) == GLFW_TRUE;
}
void FrameBufferContext::setResizable(bool r) {
makeCurrent();
glfwWindowHint(GLFW_RESIZABLE, r ? GLFW_TRUE : GLFW_FALSE);
}
cv::Size FrameBufferContext::getWindowSize() {
return windowSize_;
}
void FrameBufferContext::setWindowSize(const cv::Size& sz) {
windowSize_ = sz;
glfwSetWindowAttrib(getGLFWWindow(), GLFW_RESIZABLE, r ? GLFW_TRUE : GLFW_FALSE);
}
void FrameBufferContext::resizeWindow(const cv::Size& sz) {

@ -178,8 +178,6 @@ public:
* To make it possible for other V4D objects to become current all other
* V4D instances have to become non-current.
*/
CV_EXPORTS void setWindowSize(const cv::Size& sz);
CV_EXPORTS cv::Size getWindowSize();
CV_EXPORTS void resizeWindow(const cv::Size& sz);
CV_EXPORTS bool isFullscreen();
CV_EXPORTS void setFullscreen(bool f);

@ -19,7 +19,6 @@ void NanoguiContext::init() {
screen_ = new nanogui::Screen();
screen_->initialize(nguiFbContext_.getGLFWWindow(), false);
form_ = new cv::v4d::FormHelper(screen_);
fbCtx().resizeWindow(fbCtx().getSize());
}
void NanoguiContext::render() {

@ -32,7 +32,7 @@ namespace v4d {
namespace detail {
void run_sync_on_main(std::function<void()> fn) {
#ifdef __EMSCRIPTEN__
emscripten_sync_run_in_main_runtime_thread(EM_FUNC_SIG_V, cv::v4d::detail::get_fn_ptr<0>(fn));
emscripten_sync_run_in_main_runtime_thread(EM_FUNC_SIG_V, cv::v4d::detail::get_fn_ptr<__COUNTER__>(fn));
#else
fn();
#endif

@ -71,11 +71,6 @@ V4D::V4D(const cv::Size& size, bool offscreen, const string& title, int major, i
nguiContext_ = new detail::NanoguiContext(*this, *mainFbContext_);
clvaContext_ = new detail::CLVAContext(*this, *mainFbContext_);
glContext_ = new detail::GLContext(*this, *mainFbContext_);
// fbCtx().resizeWindow(initialSize_);
// clvaCtx().fbCtx().resizeWindow(initialSize_);
// glCtx().fbCtx().resizeWindow(initialSize_);
// nvgCtx().fbCtx().resizeWindow(initialSize_);
// nguiCtx().fbCtx().resizeWindow(initialSize_);
}
V4D::~V4D() {
@ -199,7 +194,7 @@ void V4D::feed(cv::InputArray& in) {
}, frame);
fb([frame](cv::UMat& frameBuffer){
cvtColor(frame,frameBuffer, cv::COLOR_BGR2BGRA);
cvtColor(frame,frameBuffer, cv::COLOR_RGB2BGRA);
});
}
@ -405,6 +400,34 @@ cv::Rect& V4D::viewport() {
return viewport_;
}
float V4D::getXPixelRatio() {
fbCtx().makeCurrent();
#ifdef __EMSCRIPTEN__
float r = emscripten_get_device_pixel_ratio();
return r;
#else
float xscale, yscale;
glfwGetWindowContentScale(getGLFWWindow(), &xscale, &yscale);
return xscale;
#endif
}
float V4D::getYPixelRatio() {
fbCtx().makeCurrent();
#ifdef __EMSCRIPTEN__
float r = emscripten_get_device_pixel_ratio();
return r;
#else
float xscale, yscale;
glfwGetWindowContentScale(getGLFWWindow(), &xscale, &yscale);
return yscale;
#endif
}
cv::Size V4D::getNativeFrameBufferSize() {
fbCtx().makeCurrent();
int w, h;
@ -416,24 +439,12 @@ cv::Size V4D::getFrameBufferSize() {
return fbCtx().getSize();
}
cv::Size V4D::getWindowSize() {
return fbCtx().getWindowSize();
}
cv::Size V4D::getInitialSize() {
return initialSize_;
}
void V4D::setWindowSize(const cv::Size& sz) {
if(mainFbContext_ != nullptr)
fbCtx().setWindowSize(sz);
if(nguiContext_ != nullptr)
nguiCtx().screen().resize_callback_event(sz.width, sz.height);
}
void V4D::resizeWindow(const cv::Size& sz) {
fbCtx().resizeWindow(sz);
fbCtx().setWindowSize(sz);
}
bool V4D::isFullscreen() {
@ -538,12 +549,12 @@ bool V4D::display() {
nguiCtx().render();
run_sync_on_main([this](){
run_sync_on_main([&, this](){
FrameBufferContext::GLScope glScope(fbCtx());
fbCtx().blitFrameBufferToScreen(viewport(), getWindowSize(), isStretching());
fbCtx().blitFrameBufferToScreen(viewport(), getFrameBufferSize(), isStretching());
glfwSwapBuffers(fbCtx().getGLFWWindow());
glfwPollEvents();
return !glfwWindowShouldClose(getGLFWWindow());
result = !glfwWindowShouldClose(getGLFWWindow());
});
}

@ -1,4 +1,4 @@
# Render vector graphics {#v4d_vector_graphics_and_fb}
# Render vector graphics and manipulate the framebuffer {#v4d_vector_graphics_and_fb}
@prev_tutorial{v4d_vector_graphics}
@next_tutorial{v4d_render_opengl}

@ -1,6 +1,6 @@
# OpenGL Rendering {#v4d_render_opengl}
@prev_tutorial{v4d_vector_graphics}
@prev_tutorial{v4d_vector_graphics_and_fb}
@next_tutorial{v4d_font_rendering}
| | |

Loading…
Cancel
Save