OpenGL ES presentRenderBuffer duration depends on frameInterval value - iphone

I'm using CADisplayLink to fire the "update" event for a very simple OpenGL ES animation on iOS. The animation has around 10 textured quads. I tried to run this at 60 FPS and I saw some glitches. When changing this to 30 FPS the animation runs smoother. After profiling this I saw that the most of the time is spent in presentRenderBuffer.
These are the results:
m_displayLink.frameInterval = 2;
[379406923.204] Update time 0.000358
[379406923.206] Render time 0.001402
[379406923.207] Present time 0.001136
[379406923.238] Update time 0.000370
[379406923.239] Render time 0.001393
[379406923.241] Present time 0.001148
[379406923.271] Update time 0.000368
[379406923.273] Render time 0.001377
[379406923.274] Present time 0.001226
[379406923.305] Update time 0.000380
[379406923.307] Render time 0.001390
[379406923.308] Present time 0.001183
[379406923.338] Update time 0.000375
[379406923.339] Render time 0.001376
[379406923.341] Present time 0.001178
[379406923.372] Update time 0.000981
[379406923.375] Render time 0.001418
[379406923.379] Present time 0.004452
From the results from m_displayLink.frameInterval = 2 profiling I can see that the total frame time is more than enough to achieve 60 FPS, but when changing m_displayLink.frameInterval value to 1 the results are unexpected:
m_displayLink.frameInterval = 1;
[379407317.151] Update time 0.000204
[379407317.152] Render time 0.000827
[379407317.172] Present time 0.019173
[379407317.172] Update time 0.000231
[379407317.173] Render time 0.000856
[379407317.201] Present time 0.027540
[379407317.202] Update time 0.000204
[379407317.202] Render time 0.000834
[379407317.218] Present time 0.015187
[379407317.218] Update time 0.000192
[379407317.219] Render time 0.000803
[379407317.251] Present time 0.031392
[379407317.252] Update time 0.000215
[379407317.253] Render time 0.000858
[379407317.267] Present time 0.014433
[379407317.268] Update time 0.000196
[379407317.269] Render time 0.001248
[379407317.301] Present time 0.031312
As you can see the present time it several times bigger when using
m_displayLink.frameInterval = 1;
Please note that last command from Render() is glFinish()
Do you have any idea why there is this unexpected behaviour? Is it possible to achieve 60 FPS(from the first profiling I have around 500FPS!)?

I solved the problem (pure luck!) by moving OpenGL initialization from view initWithFrame. I know this sounds very awkward, but this reduced my GPU usage from 96% to 6%. Now the simple application runs very smooth at 60 FPS with 2% CPU and 6% GPU usage(as it should be!).

Related

How to get the current time during the simulation

I would like to display the current time during my simulation so that I can simulate with full screen and also have the time. I tried the function getMinute(Date date) and a variable date. I didn't get an error but I also didn't get the time. Is it also possible to have a clock which displays the time?
You can do this:
String.format("%02d:%02d",getHourOfDay(), getMinute())
This will give you a string with the current time during the simulation
You can also use the clock object in the pictures palette to display time
you can use date() to know the date and time

Alternative for Timers

I am having a simple game with a player, a moving background and moving walls, kinda like flappy bird. My player is able to collect a powerUp. It is transforming after and put into a special level.
I want this level to run for like 10 seconds and then call a backtransformation.
Currently I am using a timer which just calls the backtransformation after 10 seconds. I am having trouble now when the player pauses the game, the timer is still running.
--> what I found on stackoverflow is that you can't resume a timer, you can just invalidate and restart it. This would miss my target, otherwise the player pauses the game every 9 seconds and can stay in the super Level forever.
Do you guys have any idea how I can solve my problem or like an alternative to use Timers in my code?
I appreciate any help
Edit: Here is how I simply used the timer
// transform and go into super level added here
self.transform()
timer = Timer.scheduledTimer(withTimeInterval:10, repeats: false) {
timer in
self.backtransform()
}
When you start the timer record the current time as a Double using
let start = Date().timeIntervalSinceReferenceDate
var remaining = 10.0
When the user pauses the timer, calculate the amount of time that has passed with:
let elapsed = Date().timeIntervalSinceReferenceDate - start
And the amount of remaining time for your timer:
remaining -= elapsed
If the user resumes the timer, set it to remaining, not 10 seconds.

Long delay in chromedevtools timeline

The timeline display a long delay of more than 20 min before the real recording ( just somes seconds ) . I tried to restart and clear the record and I have the same effect on next record..
Heberger image http://img4.hostingpics.net/thumbs/mini_322349dvbug.png
am I doing something wrong ? Someones have an idea ?

Real time video processing from camera

I have a problem with real time video processing.
I want to access consequent frames (previous, current & next).
...
trigger(RawVideo)
cur_frame=getdata(RawVideo,1,'uint8');
imshow(cur_frame);
...
I can't access previous or next frame from this code though.
Please help me.
If you're processing in "real time" you won't have access to the next frame. As for the previous frame, you'll have to create a buffer to store it in so when you process the current frame you may reference it. You could also make two buffers (the last two previous frames) and call the first previous frame "current", the current frame "next", and the second previous frame "previous". Maybe that helps?

not accurate setTimeout and it works only on mousedown

I have problem with setTimeout.
In all major browsers it works fine but not in IE...
I'm creating a facebook app- puzzle. When player press Start button, the timer starts count his time of playing one game.
At the beginning I used setInterval to increase timer but with cooperate of facebook scripts it delayed about 2 seconds at the end of game. Then I found on stackoverflow trick to increase accuracy of timer: setInterval timing slowly drifts away from staying accurate
And again- without facebook it worked fine, no delays were shown. With facebook it still has delays.
Now to condensate info that might interest You:
When user clicks Start then I create new Date as startTime.
When user ends game script creates finalTime new Date, then substract finalTime - startTime.
In code there is setTimeout:
(...)
f : function() {
var sec_time = Math.floor((puzzle.nextAt - puzzle.startTime)/1000);
$('.timer').html(sec_time);
if (!puzzle.startTime) {
puzzle.startTime = new Date().getTime();
puzzle.nextAt = puzzle.startTime;
$('.timer').html('0');
}
puzzle.nextAt += 100;
puzzle.to = setTimeout(puzzle.f, puzzle.nextAt - new Date().getTime());
}
(...)
when user place on correct place last puzzle piece then I call clearTimeout(puzzle.to);
I have now 2 issues:
not accurate time, in IE it can be even 7 second difference!
in IE during game it works only when user have mousedown... :/
To drag puzzles I use jQuery drag & drop plugin.
At least very helpful info will be how to achieve accurate timer.
You should put your scripts in jQuery's ready function and not at the bottom of the page, as the Facebook SDK is loaded asynchronously and may impact timed executions if they're initiated at the bottom of the page.
As for timing, you're gonna see inaccuracy of between 15ms and 45ms in IE7 depending on other JS executions on the page. Your 100ms timeout will drift badly because of this. Better to record a start time and build a timer with a higher polling frequency than needed and do a comparison between start time and 'now' in each cycle to determine what to do next.