implemented stretching mode

pull/3471/head
kallaballa 2 years ago
parent d668f6a9e6
commit ea85e3d4d3
  1. 5
      src/common/detail/clglcontext.cpp
  2. 2
      src/common/detail/clglcontext.hpp
  3. 12
      src/common/viz2d.cpp
  4. 3
      src/common/viz2d.hpp
  5. 6
      src/optflow/optflow-demo.cpp

@ -60,11 +60,12 @@ CLExecContext_t& CLGLContext::getCLExecContext() {
return context_;
}
void CLGLContext::blitFrameBufferToScreen(const cv::Rect& viewport, const cv::Size& windowSize) {
void CLGLContext::blitFrameBufferToScreen(const cv::Rect& viewport, const cv::Size& windowSize, bool stretch) {
GL_CHECK(glBindFramebuffer(GL_READ_FRAMEBUFFER, frameBufferID));
GL_CHECK(glReadBuffer(GL_COLOR_ATTACHMENT0));
GL_CHECK(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0));
GL_CHECK(glBlitFramebuffer(viewport.x, viewport.y, viewport.x + viewport.width, viewport.y + viewport.height, 0, windowSize.height - frameBufferSize_.height, frameBufferSize_.width, windowSize.height, GL_COLOR_BUFFER_BIT, GL_NEAREST));
GL_CHECK(glBlitFramebuffer(viewport.x, viewport.y, viewport.x + viewport.width, viewport.y + viewport.height,
0, stretch ? 0 : windowSize.height - frameBufferSize_.height, stretch ? windowSize.width : frameBufferSize_.width, windowSize.height, GL_COLOR_BUFFER_BIT, GL_NEAREST));
}
void CLGLContext::begin() {

@ -35,7 +35,7 @@ class CLGLContext {
cv::Size frameBufferSize_;
cv::ogl::Texture2D& getTexture2D();
CLExecContext_t& getCLExecContext();
void blitFrameBufferToScreen(const cv::Rect& viewport, const cv::Size& windowSize);
void blitFrameBufferToScreen(const cv::Rect& viewport, const cv::Size& windowSize, bool stretch = false);
public:
class FrameBufferScope {
CLGLContext& ctx_;

@ -134,7 +134,7 @@ bool Viz2DWindow::mouse_drag_event(const nanogui::Vector2i &p, const nanogui::Ve
}
Viz2D::Viz2D(const cv::Size &size, const cv::Size& frameBufferSize, bool offscreen, const string &title, int major, int minor, int samples, bool debug) :
initialSize_(size), frameBufferSize_(frameBufferSize), viewport_(0, 0, frameBufferSize.width, frameBufferSize.height), scale_(1), cursor_(0,0), offscreen_(offscreen), title_(title), major_(major), minor_(minor), samples_(samples), debug_(debug) {
initialSize_(size), frameBufferSize_(frameBufferSize), viewport_(0, 0, frameBufferSize.width, frameBufferSize.height), scale_(1), cursor_(0,0), offscreen_(offscreen), stretch_(false), title_(title), major_(major), minor_(minor), samples_(samples), debug_(debug) {
assert(frameBufferSize_.width >= initialSize_.width && frameBufferSize_.height >= initialSize_.height);
initialize();
}
@ -572,6 +572,14 @@ void Viz2D::setOffscreen(bool o) {
setVisible(!o);
}
void Viz2D::setStretching(bool s) {
stretch_ = s;
}
bool Viz2D::isStretching() {
return stretch_;
}
nanogui::Window* Viz2D::makeWindow(int x, int y, const string &title) {
return form()->add_window(nanogui::Vector2i(x, y), title);
}
@ -632,7 +640,7 @@ bool Viz2D::display() {
if (!offscreen_) {
glfwPollEvents();
screen().draw_contents();
clglContext_->blitFrameBufferToScreen(getViewport(), getWindowSize());
clglContext_->blitFrameBufferToScreen(getViewport(), getWindowSize(), isStretching());
screen().draw_widgets();
glfwSwapBuffers(glfwWindow_);
result = !glfwWindowShouldClose(glfwWindow_);

@ -62,6 +62,7 @@ class Viz2D: public nanogui::Screen {
float scale_;
cv::Vec2f cursor_;
bool offscreen_;
bool stretch_;
string title_;
int major_;
int minor_;
@ -123,6 +124,8 @@ public:
void setVisible(bool v);
bool isOffscreen();
void setOffscreen(bool o);
void setStretching(bool s);
bool isStretching();
bool isClosed();
void close();
bool display();

@ -65,6 +65,8 @@ float alpha = 0.05f;
nanogui::Color effect_color(1.0f, 0.75f, 0.4f, 1.0f);
//display on-screen FPS
bool show_fps = true;
//Stretch frame buffer to window size
bool stretch = false;
//Use OpenCL or not
bool use_acceleration = true;
//Use a global bloom effect
@ -303,6 +305,10 @@ void setup_gui(cv::Ptr<kb::viz2d::Viz2D> v2d) {
v2d->makeGroup("Display");
v2d->makeFormVariable("Show FPS", show_fps, "Enable or disable the On-screen FPS display");
v2d->makeFormVariable("Stetch", stretch, "Stretch the frame buffer to the window size")->set_callback([=](const bool& s) {
v2d->setStretching(s);
});
v2d->form()->add_button("Fullscreen", [=]() {
v2d->setFullscreen(!v2d->isFullscreen());
});

Loading…
Cancel
Save