Skip to content

Commit c9514b8

Browse files
committed
Merge pull request #2358 from paroj:ovisup
2 parents 6a95558 + 647e79c commit c9514b8

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

modules/ovis/include/opencv2/ovis.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ enum SceneSettings
2525
/// draw coordinate system crosses for debugging
2626
SCENE_SHOW_CS_CROSS = 4,
2727
/// Apply anti-aliasing. The first window determines the setting for all windows.
28-
SCENE_AA = 8
28+
SCENE_AA = 8,
29+
/// Render off-screen without a window. Allows separate AA setting. Requires manual update via @ref WindowScene::update
30+
SCENE_OFFSCREEN = 16
2931
};
3032

3133
enum MaterialProperty
@@ -276,6 +278,10 @@ class CV_EXPORTS_W WindowScene {
276278
CV_WRAP virtual void setCameraIntrinsics(InputArray K, const Size& imsize,
277279
float zNear = -1,
278280
float zFar = -1) = 0;
281+
/**
282+
* render this window, but do not swap buffers. Automatically called by @ref ovis::waitKey
283+
*/
284+
CV_WRAP virtual void update() = 0;
279285
};
280286

281287
/**

modules/ovis/src/ovis.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ class WindowSceneImpl : public WindowScene
289289
Root* root;
290290
SceneManager* sceneMgr;
291291
SceneNode* camNode;
292-
RenderWindow* rWin;
292+
RenderTarget* rWin;
293293
Ptr<OgreBites::CameraMan> camman;
294294
Ptr<Rectangle2D> bgplane;
295295
std::unordered_map<AnimationState*, Controller<Real>*> frameCtrlrs;
@@ -344,11 +344,22 @@ class WindowSceneImpl : public WindowScene
344344

345345
if (!app->sceneMgr)
346346
{
347+
CV_Assert((flags & SCENE_OFFSCREEN) == 0 && "off-screen rendering for main window not supported");
348+
347349
app->sceneMgr = sceneMgr;
348350
rWin = app->getRenderWindow();
349351
if (camman)
350352
app->addInputListener(camman.get());
351353
}
354+
else if (flags & SCENE_OFFSCREEN)
355+
{
356+
// render into an offscreen texture
357+
TexturePtr tex = TextureManager::getSingleton().createManual(
358+
title, RESOURCEGROUP_NAME, TEX_TYPE_2D, sz.width, sz.height, 0, PF_BYTE_RGB,
359+
TU_RENDERTARGET, NULL, false, flags & SCENE_AA ? 4 : 0);
360+
rWin = tex->getBuffer()->getRenderTarget();
361+
rWin->setAutoUpdated(false); // only update when requested
362+
}
352363
else
353364
{
354365
OgreBites::NativeWindowPair nwin = app->createWindow(title, sz.width, sz.height);
@@ -820,6 +831,11 @@ class WindowSceneImpl : public WindowScene
820831
ndc = (2 * f * n) / ndc;
821832
}
822833

834+
void update()
835+
{
836+
rWin->update(false);
837+
}
838+
823839
void fixCameraYawAxis(bool useFixed, InputArray _up) CV_OVERRIDE
824840
{
825841
#if OGRE_VERSION >= ((1 << 16) | (11 << 8) | 5)
@@ -923,6 +939,7 @@ class WindowSceneImpl : public WindowScene
923939

924940
CV_EXPORTS_W void addResourceLocation(const String& path)
925941
{
942+
CV_Assert(!_app && "must be called before the first createWindow");
926943
_extraResourceLocations.insert(Ogre::StringUtil::normalizeFilePath(path, false));
927944
}
928945

0 commit comments

Comments
 (0)