marcel
marcel

Reputation: 696

best way to stop ondraw() opengl for a time

I use opengl to draw values from an array. The values are from the 3 Android sensors. I want to turn of the renderer during I collect the values. It seems that drawing and gathering at the same time have differenet results, so I want to turn off rendering while I gathering sensorvalues. At the moment I use a boolean in the ondraw() to stop drawing. But is there a better way to do this? There happen freaky things when I stop drawing , like the stuff I draw jittering a little bit some times, but it can't be because there are no drawing( ondraw(){ if(boolean){.........}}

Thank you so much for your help :-)

Upvotes: 2

Views: 2170

Answers (2)

Darrell
Darrell

Reputation: 2045

You can ask GLSurfaceView to only draw when asked via setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY), then call requestRender() when you're ready to draw.

Upvotes: 5

Mark Storer
Mark Storer

Reputation: 15868

I have a suggestion: Create a thread to collect the sensor data, and make it available as an object. This thread would gather all the data, and synchronize on the public value object. Blocking time would be minimized.

collectLocalData = getData();
synchronized(pubData) {
  pubData.set(collectLocalData);
}

Your render thread can then Do the same when copying the public values for local consumption.

synchronized(pubData) {
  renderLocalData.set( pubData );
}

renderData( renderLocalData );

If polling the sensors takes longer than rendering time, the same data will be rendered more than once. The animation might get a little twitchy, but no more so than what the data represents.

PS: your jitters may be a result of the data itself rather than your code.

Upvotes: 1

Related Questions