From 3604786e6b5e8c4fad5776c1fa5ad1720b686d37 Mon Sep 17 00:00:00 2001 From: Pavel Rojtberg Date: Fri, 22 Nov 2019 12:14:10 +0100 Subject: [PATCH] ovis: add support for off-screen windows --- modules/ovis/include/opencv2/ovis.hpp | 8 +++++++- modules/ovis/src/ovis.cpp | 18 +++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/modules/ovis/include/opencv2/ovis.hpp b/modules/ovis/include/opencv2/ovis.hpp index 8d42c6f6e..c1300b4fc 100644 --- a/modules/ovis/include/opencv2/ovis.hpp +++ b/modules/ovis/include/opencv2/ovis.hpp @@ -25,7 +25,9 @@ enum SceneSettings /// draw coordinate system crosses for debugging SCENE_SHOW_CS_CROSS = 4, /// Apply anti-aliasing. The first window determines the setting for all windows. - SCENE_AA = 8 + SCENE_AA = 8, + /// Render off-screen without a window. Allows separate AA setting. Requires manual update via @ref WindowScene::update + SCENE_OFFSCREEN = 16 }; enum MaterialProperty @@ -276,6 +278,10 @@ public: CV_WRAP virtual void setCameraIntrinsics(InputArray K, const Size& imsize, float zNear = -1, float zFar = -1) = 0; + /** + * render this window, but do not swap buffers. Automatically called by @ref ovis::waitKey + */ + CV_WRAP virtual void update() = 0; }; /** diff --git a/modules/ovis/src/ovis.cpp b/modules/ovis/src/ovis.cpp index 85f5d5f67..664832028 100644 --- a/modules/ovis/src/ovis.cpp +++ b/modules/ovis/src/ovis.cpp @@ -289,7 +289,7 @@ class WindowSceneImpl : public WindowScene Root* root; SceneManager* sceneMgr; SceneNode* camNode; - RenderWindow* rWin; + RenderTarget* rWin; Ptr camman; Ptr bgplane; std::unordered_map*> frameCtrlrs; @@ -344,11 +344,22 @@ public: if (!app->sceneMgr) { + CV_Assert((flags & SCENE_OFFSCREEN) == 0 && "off-screen rendering for main window not supported"); + app->sceneMgr = sceneMgr; rWin = app->getRenderWindow(); if (camman) app->addInputListener(camman.get()); } + else if (flags & SCENE_OFFSCREEN) + { + // render into an offscreen texture + TexturePtr tex = TextureManager::getSingleton().createManual( + title, RESOURCEGROUP_NAME, TEX_TYPE_2D, sz.width, sz.height, 0, PF_BYTE_RGB, + TU_RENDERTARGET, NULL, false, flags & SCENE_AA ? 4 : 0); + rWin = tex->getBuffer()->getRenderTarget(); + rWin->setAutoUpdated(false); // only update when requested + } else { OgreBites::NativeWindowPair nwin = app->createWindow(title, sz.width, sz.height); @@ -820,6 +831,11 @@ public: ndc = (2 * f * n) / ndc; } + void update() + { + rWin->update(false); + } + void fixCameraYawAxis(bool useFixed, InputArray _up) CV_OVERRIDE { #if OGRE_VERSION >= ((1 << 16) | (11 << 8) | 5)