@@ -264,7 +264,6 @@ class WindowSceneImpl : public WindowScene
264
264
Ptr<OgreBites::CameraMan> camman;
265
265
Ptr<Rectangle2D> bgplane;
266
266
267
- Ogre::RenderTarget* frameSrc;
268
267
Ogre::RenderTarget* depthRTT;
269
268
public:
270
269
WindowSceneImpl (Ptr<Application> app, const String& _title, const Size& sz, int flags)
@@ -324,18 +323,6 @@ class WindowSceneImpl : public WindowScene
324
323
}
325
324
326
325
rWin->addViewport (cam);
327
- frameSrc = rWin;
328
-
329
- if (flags & SCENE_RENDER_FLOAT)
330
- {
331
- // also render into an offscreen texture
332
- // currently this draws everything twice, but we spare the float->byte conversion for display
333
- TexturePtr tex = TextureManager::getSingleton ().createManual (
334
- title + " _rt" , RESOURCEGROUP_NAME, TEX_TYPE_2D, sz.width , sz.height , 0 , PF_FLOAT32_RGBA,
335
- TU_RENDERTARGET);
336
- frameSrc = tex->getBuffer ()->getRenderTarget ();
337
- frameSrc->addViewport (cam);
338
- }
339
326
}
340
327
341
328
void setBackground (InputArray image) CV_OVERRIDE
@@ -361,9 +348,9 @@ class WindowSceneImpl : public WindowScene
361
348
{
362
349
CompositorManager& cm = CompositorManager::getSingleton ();
363
350
// this should be applied to all owned render targets
364
- Ogre::RenderTarget* targets[] = {frameSrc, rWin, depthRTT};
351
+ Ogre::RenderTarget* targets[] = {rWin, depthRTT};
365
352
366
- for (int j = (frameSrc == rWin) ; j < 3 ; j++) // skip frameSrc if it is the same as rWin
353
+ for (int j = 0 ; j < 2 ; j++)
367
354
{
368
355
Ogre::RenderTarget* tgt = targets[j];
369
356
if (!tgt) continue ;
@@ -382,6 +369,57 @@ class WindowSceneImpl : public WindowScene
382
369
}
383
370
}
384
371
372
+ void getCompositorTexture (const String& compname, const String& texname, OutputArray out,
373
+ int mrtIndex) CV_OVERRIDE
374
+ {
375
+ CompositorManager& cm = CompositorManager::getSingleton ();
376
+ CompositorChain* chain = cm.getCompositorChain (rWin->getViewport (0 ));
377
+ CV_Assert (chain && " no active compositors" );
378
+
379
+ CompositorInstance* inst = chain->getCompositor (compname);
380
+ if (!inst)
381
+ CV_Error_ (Error::StsBadArg, (" no active compositor named: %s" , compname.c_str ()));
382
+
383
+ TexturePtr tex = inst->getTextureInstance (texname, mrtIndex);
384
+ if (!tex)
385
+ CV_Error_ (Error::StsBadArg, (" no texture named: %s" , texname.c_str ()));
386
+
387
+ PixelFormat src_type = tex->getFormat ();
388
+ int dst_type;
389
+ switch (src_type)
390
+ {
391
+ case PF_BYTE_RGB:
392
+ dst_type = CV_8UC3;
393
+ break ;
394
+ case PF_BYTE_RGBA:
395
+ dst_type = CV_8UC4;
396
+ break ;
397
+ case PF_FLOAT32_RGB:
398
+ dst_type = CV_32FC3;
399
+ break ;
400
+ case PF_FLOAT32_RGBA:
401
+ dst_type = CV_32FC4;
402
+ break ;
403
+ case PF_DEPTH16:
404
+ dst_type = CV_16U;
405
+ break ;
406
+ default :
407
+ CV_Error (Error::StsNotImplemented, " unsupported texture format" );
408
+ }
409
+
410
+ out.create (tex->getHeight (), tex->getWidth (), dst_type);
411
+
412
+ Mat mat = out.getMat ();
413
+ PixelBox pb (tex->getWidth (), tex->getHeight (), 1 , src_type, mat.ptr ());
414
+ tex->getBuffer ()->blitToMemory (pb, pb);
415
+
416
+ if (CV_MAT_CN (dst_type) < 3 )
417
+ return ;
418
+
419
+ // convert to OpenCV channel order
420
+ cvtColor (mat, mat, CV_MAT_CN (dst_type) == 3 ? COLOR_RGB2BGR : COLOR_RGBA2BGRA);
421
+ }
422
+
385
423
void setBackground (const Scalar& color) CV_OVERRIDE
386
424
{
387
425
// hide background plane
@@ -390,8 +428,6 @@ class WindowSceneImpl : public WindowScene
390
428
// BGRA as uchar
391
429
ColourValue _color = ColourValue (color[2 ], color[1 ], color[0 ], color[3 ]) / 255 ;
392
430
rWin->getViewport (0 )->setBackgroundColour (_color);
393
- if (frameSrc != rWin)
394
- frameSrc->getViewport (0 )->setBackgroundColour (_color);
395
431
}
396
432
397
433
void createEntity (const String& name, const String& meshname, InputArray tvec, InputArray rot) CV_OVERRIDE
@@ -543,17 +579,14 @@ class WindowSceneImpl : public WindowScene
543
579
544
580
void getScreenshot (OutputArray frame) CV_OVERRIDE
545
581
{
546
- PixelFormat src_type = frameSrc->suggestPixelFormat ();
547
- int dst_type = src_type == PF_BYTE_RGB ? CV_8UC3 : CV_32FC4;
548
-
549
- frame.create (frameSrc->getHeight (), frameSrc->getWidth (), dst_type);
582
+ frame.create (rWin->getHeight (), rWin->getWidth (), CV_8UC3);
550
583
551
584
Mat out = frame.getMat ();
552
- PixelBox pb (frameSrc ->getWidth (), frameSrc ->getHeight (), 1 , src_type , out.ptr ());
553
- frameSrc ->copyContentsToMemory (pb, pb);
585
+ PixelBox pb (rWin ->getWidth (), rWin ->getHeight (), 1 , PF_BYTE_RGB , out.ptr ());
586
+ rWin ->copyContentsToMemory (pb, pb);
554
587
555
588
// convert to OpenCV channel order
556
- cvtColor (out, out, dst_type == CV_8UC3 ? COLOR_RGB2BGR : COLOR_RGBA2BGRA );
589
+ cvtColor (out, out, COLOR_RGB2BGR);
557
590
}
558
591
559
592
void getDepth (OutputArray depth) CV_OVERRIDE
@@ -564,8 +597,8 @@ class WindowSceneImpl : public WindowScene
564
597
// render into an offscreen texture
565
598
// currently this draws everything twice as OGRE lacks depth texture attachments
566
599
TexturePtr tex = TextureManager::getSingleton ().createManual (
567
- title + " _Depth" , RESOURCEGROUP_NAME, TEX_TYPE_2D, frameSrc ->getWidth (),
568
- frameSrc ->getHeight (), 0 , PF_DEPTH, TU_RENDERTARGET);
600
+ title + " _Depth" , RESOURCEGROUP_NAME, TEX_TYPE_2D, rWin ->getWidth (),
601
+ rWin ->getHeight (), 0 , PF_DEPTH, TU_RENDERTARGET);
569
602
depthRTT = tex->getBuffer ()->getRenderTarget ();
570
603
depthRTT->addViewport (cam);
571
604
depthRTT->setAutoUpdated (false ); // only update when requested
0 commit comments