Re: [osg-users] compositeview and offscreen rendering

79 views
Skip to first unread message

Peiman Shakeri

unread,
Jan 26, 2016, 7:35:16 AM1/26/16
to osg-...@lists.openscenegraph.org
Hi,

I am newbie in osg
based on example's I can do off-screen rendering and auto-screen-capture then make a movie from my scene graph with single view and camera

when I use composeitview ,these are my views and cameras:

topview->topcamera
leftview->leftcamera
rightview->rightcamera
captureview->capturecamera

I can capturing and then make a movie too but no one should can see my captureview ,its just for capturing!


how can I off-screen rendering on my capture camera in captureview ?


Thank you!

Cheers,
peimansh

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=66032#66032





_______________________________________________
osg-users mailing list
osg-...@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Robert Osfield

unread,
Jan 26, 2016, 8:53:48 AM1/26/16
to OpenSceneGraph Users
Hi Peimansh,

The two options for off screen rendering are a PixelBuffer context or
FrameBufferObject, if you have an existing on screen window in your
application then using a FrameBufferObject becomes preferable. The
way to do it would be to set up your viewer's off screen Camera with
FBO settings and a custom final draw callback to do the read to main
memory. The read will be more efficient if you use a pair of
PixelBufferObjects - the osgscreencapture example illustrates this in
action.

As you are already using CompositeViewer the most natural thing to do
would be to have a dedicated View with it's master Camera as the
offscreen camera, this way you can control the Camera's view matrix in
straight forward manner in the same way to the rest of the Camera's.
Also during debugging having the option of making this Camera an
onscreen one would give you means to visually QA things as you go
along.

Robert.

Peiman Shakeri

unread,
Jan 27, 2016, 12:31:33 AM1/27/16
to osg-...@lists.openscenegraph.org

robertosfield wrote:
> Hi Peimansh,
>
> The two options for off screen rendering are a PixelBuffer context or
> FrameBufferObject, if you have an existing on screen window in your
> application then using a FrameBufferObject becomes preferable. The
> way to do it would be to set up your viewer's off screen Camera with
> FBO settings and a custom final draw callback to do the read to main
> memory. The read will be more efficient if you use a pair of
> PixelBufferObjects - the osgscreencapture example illustrates this in
> action.
>
> As you are already using CompositeViewer the most natural thing to do
> would be to have a dedicated View with it's master Camera as the
> offscreen camera, this way you can control the Camera's view matrix in
> straight forward manner in the same way to the rest of the Camera's.
> Also during debugging having the option of making this Camera an
> onscreen one would give you means to visually QA things as you go
> along.
>
> Robert.
>
>
>


hi
thx Robert
my problem is gone
but I use autocapture example and now I have frame rate problem
is there different between these two example?

cheers
peiman

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=66142#66142

Robert Osfield

unread,
Jan 27, 2016, 4:06:34 AM1/27/16
to OpenSceneGraph Users
On 27 January 2016 at 05:36, Peiman Shakeri <peiman...@gmail.com> wrote:
> my problem is gone
> but I use autocapture example and now I have frame rate problem
> is there different between these two example?

There is no way for me to know what is causing your frame rate problem
given the information I have on what you are doing.

Robert

Peiman Shakeri

unread,
Jan 27, 2016, 9:23:05 AM1/27/16
to osg-...@lists.openscenegraph.org
Hi,
this is a part of my source
I cut unnecessary part cause of clarification

Thank you!

Cheers,
Peiman

source:


Code:

void VisSystem::CreateArea( )
{
city=new CityArea();
city->Create(false,7);
root->addChild(weather->group);
root->addChild(weather->skyLightSource);
city->setLight(weather->skyLight);
SystemData::getInstance()->area=city;
root->addChild(city->areaGroup->getChild(0));
rootRear=new osg::Group;
rootRear->addChild(weather->skyLightSource);
rootRear->addChild(weather->group);
rootRear->addChild(city->areaGroup->getChild(1));


viewer.Create();
viewer.CreateLeftSide();
viewer.CreateRightSide();

viewer.AddfrontScene(root);
viewer.AddfrontScene(city->TrafficGroup);
viewer.AddRearScene(rootRear);
viewer.AddRearScene(city->TrafficGroup);


viewer.CreateTopview();
viewer.AddTopScene(root);
viewer.AddTopScene(city->TrafficGroup);
viewer.AddTopScene(city->TrafficGroup2);


}

void VisSystem::Run(void)
{
CreateArea();


std::string fileName;
osgDB::DatabasePager* pager = viewer.Topview->getDatabasePager();
pager->setDoPreCompile(true);
osg::ref_ptr<CustomRenderer> customRenderer = new CustomRenderer(viewer.Topview->getCamera());
viewer.Topview->getCamera()->setRenderer(customRenderer.get());
customRenderer->setCullOnly(false);
GLenum buffer = viewer.Topview->getCamera()->getGraphicsContext()->getTraits()->doubleBuffer ? GL_BACK : GL_FRONT;

viewer.TopRTT->RTTCam->setDrawBuffer(buffer);
viewer.TopRTT->RTTCam->setReadBuffer(buffer);

const osg::FrameStamp* fs2 = viewer.Topview->getFrameStamp();

osg::ref_ptr<osg::Image> posterImage = 0;
posterImage = new osg::Image;

bool outputPoster = true, outputTiles = false;
int tileWidth = 640, tileHeight = 480;
int posterWidth = 640, posterHeight = 480;
int numCameras = 1;
std::string posterName = "poster.bmp", extName = "bmp";
char filename[50];
int i=1;


IplImage *iplimg = cvCreateImage(CvSize(640,480),IPL_DEPTH_8U,3);

CvSize size;
int isColor = 1;
int fps = 25; // or 30

size.width = 640;
size.height = 480;

CvVideoWriter *writer = cvCreateVideoWriter(
"D:\\PEIMAN\\video\\test.avi",
CV_FOURCC('P','I','M','1'),//CV_FOURCC('I','Y','U','V'), // VIDEO CODEC
fps,
size);

while(writer == NULL)
{
writer = cvCreateVideoWriter(
"D:\\PEIMAN\\video\\test.avi",
CV_FOURCC('P','I','M','1'),//CV_FOURCC('I','Y','U','V'), // VIDEO CODEC
fps,
size);

}

viewer.viewer.realize();
viewer.viewer.stopThreading();
viewer.Topview->getCamera()->getGraphicsContext()->releaseContext();
viewer.viewer.startThreading();

while(!viewer.viewer.done())
{
//updating stuff

viewer.viewer.frame();


std::ostringstream os;
std::string snum;
os<<fs2->getFrameNumber();
snum=os.str();
fileName="D:\\PEIMAN\\image\\poster"+snum+".bmp";
char* Fname=new char[fileName.size()+1];
std::copy(fileName.begin(),fileName.end(),Fname);
Fname[fileName.size()]='\0';
std::cout<<Fname<<std::endl;
viewer.viewer.renderingTraversals();
viewer.Topview->getCamera()->setFinalDrawCallback( new WindowCaptureCallback(buffer, fileName,posterImage.get()));

if ( (fs2->getFrameNumber()%2)==0 )
{

iplimg->imageData=(char*)posterImage->data();
cvCvtColor(iplimg,iplimg,CV_BGR2RGB);
cvFlip(iplimg, iplimg, 0);
cvWriteFrame(writer,iplimg);

}




}

cvReleaseVideoWriter(&writer);
cvReleaseImage(&iplimg);

}





------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=66152#66152

Robert Osfield

unread,
Jan 27, 2016, 9:43:31 AM1/27/16
to OpenSceneGraph Users
Hi Peinman,

Looking at your code the performance problems have little to do with
OpenGL and the OSG and everything to with creating a new callback on
every frame and writing to disk from the main thread, File IO is very
expensive so absolutely not something you want to do in main rendering
thread. The start/stop of threading and releaseContext() is rather
odd too, I can't think what you are trying to achieve here.

What you should do is create a single callback that you can toggle
on/off when needed and have it generate an image write operation that
it dispatches to a back ground thread that does the writing to disk.
Ideally you'd recycle the images once you've finished.

If this all sounds a bit involved, well what you are trying to do is
reasonable advanced stuff, you are rather diving into the deep end
without armbands having not learnt to swim yet...

Robert.

Peiman Shakeri

unread,
Jan 30, 2016, 2:05:14 AM1/30/16
to osg-...@lists.openscenegraph.org

robertosfield wrote:
> Hi Peinman,
>
> Looking at your code the performance problems have little to do with
> OpenGL and the OSG and everything to with creating a new callback on
> every frame and writing to disk from the main thread, File IO is very
> expensive so absolutely not something you want to do in main rendering
> thread. The start/stop of threading and releaseContext() is rather
> odd too, I can't think what you are trying to achieve here.
>
> What you should do is create a single callback that you can toggle
> on/off when needed and have it generate an image write operation that
> it dispatches to a back ground thread that does the writing to disk.
> Ideally you'd recycle the images once you've finished.
>
> If this all sounds a bit involved, well what you are trying to do is
> reasonable advanced stuff, you are rather diving into the deep end
> without armbands having not learnt to swim yet...
>
> Robert.
>
>
>


hi Robert
thx for replying

1.without any writing to disk, frame rate is still down.my WindowCaptureCallback write nothing into disk.
2.The start/stop of threading and releaseContext() is necessary for multi threading model because of off-screen rendering on topview.
3.please more explain about that single callback and the way on/off it.

cheers peiman

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=66169#66169

Robert Osfield

unread,
Feb 1, 2016, 5:10:24 AM2/1/16
to OpenSceneGraph Users
Hi Peiman,

On 30 January 2016 at 07:09, Peiman Shakeri <peiman...@gmail.com> wrote:
> 1.without any writing to disk, frame rate is still down.my WindowCaptureCallback write nothing into disk.

Then benchmark it, find out what the bottleneck is.

> 2.The start/stop of threading and releaseContext() is necessary for multi threading model because of off-screen rendering on topview.

Again, as I said before this is a red flag, this shouldn't be
required, that fact you have it in there suggests something else amiss
with the set up of your viewer.

> 3.please more explain about that single callback and the way on/off it.

Brace yourself for a radical bit of programming. It's called an if statement.

MyClass:Mymethod()
{
if (active)
{
// do stuff

Peiman Shakeri

unread,
Feb 2, 2016, 9:37:24 AM2/2/16
to osg-...@lists.openscenegraph.org
Hi,

on/off method does not make any change!
I have a question...
I use osg autocapture example,so is that example unpractical?
how can i write a better example for autocapturing?
and about that red flag,...
I found "The start/stop of threading and releaseContext() " in this forum as a solution for multi-thread model in off-rendering.


Thank you!

Cheers,
Peiman

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=66177#66177
Reply all
Reply to author
Forward
0 new messages