Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Threading: doing processing in background of C++ Cinder app to keep the UI responsive

I was happy to get my first C++ app working after a few hours of hacking this afternoon. The app trades the X-dimension for the time-dimension in a video.

  • Example: http://www.flickr.com/photos/forresto/5489312991/
  • Source: https://gist.github.com/849779

Any suggestions for how to optimize the source would be welcome, but I'm interested in how to do the image processing that I'm doing in update() in a way that doesn't make the app so unresponsive.

(Crossposted in libcinder forum: http://forum.libcinder.org/#Topic/23286000000669039 )

like image 782
forresto Avatar asked Nov 14 '22 02:11

forresto


1 Answers

The answer seems be threading. It works like this with Cinder:

void MyApp::setup()
{
  thread(&MyApp::processFrame, this);
}
void MyApp::processFrame()
{
  // TODO define mFrameTemp here
  // Copy to the texture which we'll actually render
  mFrame = mFrameTemp;
}
void MyApp::draw()
{
  if (mFrame)
    gl::draw(mFrame, mFrame.getBounds());
}
like image 178
forresto Avatar answered Dec 18 '22 01:12

forresto