[osg-users] compositeview and offscreen rendering
Robert Osfield
robert.osfield at gmail.com
Wed Jan 27 06:43:26 PST 2016
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.
On 27 January 2016 at 14:27, Peiman Shakeri <peimansh2014 at gmail.com> wrote:
> 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
>
>
>
>
>
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
More information about the osg-users
mailing list