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://gi开发者_Go百科st.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 )
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());
}
精彩评论