Commit 233d80f3 authored by Alexander Alekhin's avatar Alexander Alekhin

Merge pull request #1804 from paroj:ovis_texup

parents ff9d3132 0bb0989f
...@@ -24,10 +24,8 @@ enum SceneSettings ...@@ -24,10 +24,8 @@ enum SceneSettings
SCENE_INTERACTIVE = 2, SCENE_INTERACTIVE = 2,
/// draw coordinate system crosses for debugging /// draw coordinate system crosses for debugging
SCENE_SHOW_CS_CROSS = 4, SCENE_SHOW_CS_CROSS = 4,
/// @ref WindowScene::getScreenshot returns images as CV_32FC4 instead of CV_8UC3
SCENE_RENDER_FLOAT = 8,
/// Apply anti-aliasing. The first window determines the setting for all windows. /// Apply anti-aliasing. The first window determines the setting for all windows.
SCENE_AA = 16 SCENE_AA = 8
}; };
enum MaterialProperty enum MaterialProperty
...@@ -161,6 +159,16 @@ public: ...@@ -161,6 +159,16 @@ public:
*/ */
CV_WRAP virtual void getScreenshot(OutputArray frame) = 0; CV_WRAP virtual void getScreenshot(OutputArray frame) = 0;
/**
* read back the texture of an active compositor
* @param compname name of the compositor
* @param texname name of the texture inside the compositor
* @param mrtIndex if texture is a MRT, specifies the attachment
* @param out the texture contents
*/
CV_WRAP virtual void getCompositorTexture(const String& compname, const String& texname,
OutputArray out, int mrtIndex = 0) = 0;
/** /**
* get the depth for the current frame. * get the depth for the current frame.
* *
......
...@@ -264,7 +264,6 @@ class WindowSceneImpl : public WindowScene ...@@ -264,7 +264,6 @@ class WindowSceneImpl : public WindowScene
Ptr<OgreBites::CameraMan> camman; Ptr<OgreBites::CameraMan> camman;
Ptr<Rectangle2D> bgplane; Ptr<Rectangle2D> bgplane;
Ogre::RenderTarget* frameSrc;
Ogre::RenderTarget* depthRTT; Ogre::RenderTarget* depthRTT;
public: public:
WindowSceneImpl(Ptr<Application> app, const String& _title, const Size& sz, int flags) WindowSceneImpl(Ptr<Application> app, const String& _title, const Size& sz, int flags)
...@@ -324,18 +323,6 @@ public: ...@@ -324,18 +323,6 @@ public:
} }
rWin->addViewport(cam); rWin->addViewport(cam);
frameSrc = rWin;
if (flags & SCENE_RENDER_FLOAT)
{
// also render into an offscreen texture
// currently this draws everything twice, but we spare the float->byte conversion for display
TexturePtr tex = TextureManager::getSingleton().createManual(
title + "_rt", RESOURCEGROUP_NAME, TEX_TYPE_2D, sz.width, sz.height, 0, PF_FLOAT32_RGBA,
TU_RENDERTARGET);
frameSrc = tex->getBuffer()->getRenderTarget();
frameSrc->addViewport(cam);
}
} }
void setBackground(InputArray image) CV_OVERRIDE void setBackground(InputArray image) CV_OVERRIDE
...@@ -361,9 +348,9 @@ public: ...@@ -361,9 +348,9 @@ public:
{ {
CompositorManager& cm = CompositorManager::getSingleton(); CompositorManager& cm = CompositorManager::getSingleton();
// this should be applied to all owned render targets // this should be applied to all owned render targets
Ogre::RenderTarget* targets[] = {frameSrc, rWin, depthRTT}; Ogre::RenderTarget* targets[] = {rWin, depthRTT};
for(int j = (frameSrc == rWin); j < 3; j++) // skip frameSrc if it is the same as rWin for(int j = 0; j < 2; j++)
{ {
Ogre::RenderTarget* tgt = targets[j]; Ogre::RenderTarget* tgt = targets[j];
if(!tgt) continue; if(!tgt) continue;
...@@ -382,6 +369,57 @@ public: ...@@ -382,6 +369,57 @@ public:
} }
} }
void getCompositorTexture(const String& compname, const String& texname, OutputArray out,
int mrtIndex) CV_OVERRIDE
{
CompositorManager& cm = CompositorManager::getSingleton();
CompositorChain* chain = cm.getCompositorChain(rWin->getViewport(0));
CV_Assert(chain && "no active compositors");
CompositorInstance* inst = chain->getCompositor(compname);
if(!inst)
CV_Error_(Error::StsBadArg, ("no active compositor named: %s", compname.c_str()));
TexturePtr tex = inst->getTextureInstance(texname, mrtIndex);
if(!tex)
CV_Error_(Error::StsBadArg, ("no texture named: %s", texname.c_str()));
PixelFormat src_type = tex->getFormat();
int dst_type;
switch(src_type)
{
case PF_BYTE_RGB:
dst_type = CV_8UC3;
break;
case PF_BYTE_RGBA:
dst_type = CV_8UC4;
break;
case PF_FLOAT32_RGB:
dst_type = CV_32FC3;
break;
case PF_FLOAT32_RGBA:
dst_type = CV_32FC4;
break;
case PF_DEPTH16:
dst_type = CV_16U;
break;
default:
CV_Error(Error::StsNotImplemented, "unsupported texture format");
}
out.create(tex->getHeight(), tex->getWidth(), dst_type);
Mat mat = out.getMat();
PixelBox pb(tex->getWidth(), tex->getHeight(), 1, src_type, mat.ptr());
tex->getBuffer()->blitToMemory(pb, pb);
if(CV_MAT_CN(dst_type) < 3)
return;
// convert to OpenCV channel order
cvtColor(mat, mat, CV_MAT_CN(dst_type) == 3 ? COLOR_RGB2BGR : COLOR_RGBA2BGRA);
}
void setBackground(const Scalar& color) CV_OVERRIDE void setBackground(const Scalar& color) CV_OVERRIDE
{ {
// hide background plane // hide background plane
...@@ -390,8 +428,6 @@ public: ...@@ -390,8 +428,6 @@ public:
// BGRA as uchar // BGRA as uchar
ColourValue _color = ColourValue(color[2], color[1], color[0], color[3]) / 255; ColourValue _color = ColourValue(color[2], color[1], color[0], color[3]) / 255;
rWin->getViewport(0)->setBackgroundColour(_color); rWin->getViewport(0)->setBackgroundColour(_color);
if(frameSrc != rWin)
frameSrc->getViewport(0)->setBackgroundColour(_color);
} }
void createEntity(const String& name, const String& meshname, InputArray tvec, InputArray rot) CV_OVERRIDE void createEntity(const String& name, const String& meshname, InputArray tvec, InputArray rot) CV_OVERRIDE
...@@ -543,17 +579,14 @@ public: ...@@ -543,17 +579,14 @@ public:
void getScreenshot(OutputArray frame) CV_OVERRIDE void getScreenshot(OutputArray frame) CV_OVERRIDE
{ {
PixelFormat src_type = frameSrc->suggestPixelFormat(); frame.create(rWin->getHeight(), rWin->getWidth(), CV_8UC3);
int dst_type = src_type == PF_BYTE_RGB ? CV_8UC3 : CV_32FC4;
frame.create(frameSrc->getHeight(), frameSrc->getWidth(), dst_type);
Mat out = frame.getMat(); Mat out = frame.getMat();
PixelBox pb(frameSrc->getWidth(), frameSrc->getHeight(), 1, src_type, out.ptr()); PixelBox pb(rWin->getWidth(), rWin->getHeight(), 1, PF_BYTE_RGB, out.ptr());
frameSrc->copyContentsToMemory(pb, pb); rWin->copyContentsToMemory(pb, pb);
// convert to OpenCV channel order // convert to OpenCV channel order
cvtColor(out, out, dst_type == CV_8UC3 ? COLOR_RGB2BGR : COLOR_RGBA2BGRA); cvtColor(out, out, COLOR_RGB2BGR);
} }
void getDepth(OutputArray depth) CV_OVERRIDE void getDepth(OutputArray depth) CV_OVERRIDE
...@@ -564,8 +597,8 @@ public: ...@@ -564,8 +597,8 @@ public:
// render into an offscreen texture // render into an offscreen texture
// currently this draws everything twice as OGRE lacks depth texture attachments // currently this draws everything twice as OGRE lacks depth texture attachments
TexturePtr tex = TextureManager::getSingleton().createManual( TexturePtr tex = TextureManager::getSingleton().createManual(
title + "_Depth", RESOURCEGROUP_NAME, TEX_TYPE_2D, frameSrc->getWidth(), title + "_Depth", RESOURCEGROUP_NAME, TEX_TYPE_2D, rWin->getWidth(),
frameSrc->getHeight(), 0, PF_DEPTH, TU_RENDERTARGET); rWin->getHeight(), 0, PF_DEPTH, TU_RENDERTARGET);
depthRTT = tex->getBuffer()->getRenderTarget(); depthRTT = tex->getBuffer()->getRenderTarget();
depthRTT->addViewport(cam); depthRTT->addViewport(cam);
depthRTT->setAutoUpdated(false); // only update when requested depthRTT->setAutoUpdated(false); // only update when requested
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment