draw() on demand?

Is it possible to exit the normal draw/update loop, and just call draw as needed and have it render at that moment? Ideally this call would come from a another thread which is reading serial data.

what i do when i need something like this is to use a condition, a condition is something that stops the execution of a thread till it’s signaled from a different thread:

  
  
// testApp.h  
  
Poco::Condition condition;  
ofMutex mutex;  
  
  
// testapp.cpp  
  
void testApp::setup(){  
    mutex.lock();  
}  
  
void testApp::update(){  
    condition.wait(mutex);  
    ...  
}  
  
void testApp::draw(){  
    ...  
}  
  
void threadedFunction(){  
    mutex.lock();  
    condition.signal();  
    mutex.unlock();  
}  
  

that will make the GL thread stop on the condition wait till it’s signaled from the serial thread then do 1 update/draw cycle and sleep again on the wait.

the mutex has to be locked before you call condition.wait then it’s unlocked while waiting and locked again when exiting the condition so if you use the mutex for something else be aware that the condition locks it for you in the waiting thread