I've a Problem with my Rendering Loop. During moving object's I see a Little stutter that Looks like eglSwapBuffers
swap's same buffer twice. My FPS is constantly between 59 - 60 FPS. The movement takes deltaTime
into account at calculate new Position.
What could that be ??? Could double buffering solve this Problem ???
Here is a small Video ( hopefully you'll see what I mean ). http://youtu.be/bQYiqHUzPuI
Here is my Rendering Loop
BOOL CEngine::OnStep()
{
BOOL bResult = TRUE;
UINT32 u32CurrFrameStartTime = GetTime();
FLOAT32 f32DeltaTime;
f32DeltaTime = ( u32CurrFrameStartTime - m_u32LastFrameStartTime ) / 1000000000.0f;
m_u32LastFrameStartTime = u32CurrFrameStartTime;
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
GLERROR();
if ( m_pScreenBase == NULL )
{
if ( eglSwapBuffers( m_pDisplay, m_pSurface ) == EGL_FALSE )
{
LogError( "eglSwapBuffers function failed." );
}
if ( ( m_pScreenBase = new CStartScreen() ) == NULL )
LogError( "Can't allocate memory for CStartScreen." );
m_pScreenBase->Initialize();
}
m_pScreenBase->Update( f32DeltaTime );
m_pScreenBase->Render();
if ( eglSwapBuffers( m_pDisplay, m_pSurface ) == EGL_FALSE )
{
LogError( "eglSwapBuffers function failed." );
}
m_i32FramesPerSecond += 1;
if ( GetTime() - m_u32FPSResetTimer >= 1000000000 )
{
LogFPS( "%d", m_i32FramesPerSecond );
m_i32FramesPerSecond = 0;
m_u32FPSResetTimer = GetTime();
}
// return false when app should be exit
return bResult;
}
Here is the update function
void CStartScreen::Update( FLOAT32 f32DeltaTime )
{
for ( INT32 i = 0; i < MAX_SQUARES; i++ )
{
m_pSquare[ i ]->IncPosX( ( 400.0f * f32DeltaTime ) );
if ( m_pSquare[ i ]->GetPosX() >= 800.0f )
{
m_pSquare[ i ]->IncPosX( -( 800.0f + m_pSquare[ i ]->GetWidth() ) );
}
}
}
If it's needed, I can post my EGL
and OpenGL
Setup too.
UPDATE 1 :
UINT32 is defined as
typedef unsigned int UINT32;
inline UINT32 GetTime()
{
timespec sTime;
UINT32 u32Return = 0;
clock_gettime( CLOCK_MONOTONIC, &sTime );
u32Return = ( sTime.tv_sec * 1000000000LL ) + sTime.tv_nsec;
return u32Return;
}
And here is the delta time for 1 second
f32DeltaTime : 0.012029
f32DeltaTime : 0.016487
f32DeltaTime : 0.016548
f32DeltaTime : 0.023608
f32DeltaTime : 0.017631
f32DeltaTime : 0.023363
f32DeltaTime : 0.012963
f32DeltaTime : 0.026373
f32DeltaTime : 0.016470
f32DeltaTime : 0.012811
f32DeltaTime : 0.016439
f32DeltaTime : 0.016852
f32DeltaTime : 0.025931
f32DeltaTime : 0.012679
f32DeltaTime : 0.013243
f32DeltaTime : 0.014694
f32DeltaTime : 0.016561
f32DeltaTime : 0.016589
f32DeltaTime : 0.020299
f32DeltaTime : 0.014101
f32DeltaTime : 0.016626
f32DeltaTime : 0.016892
f32DeltaTime : 0.016347
f32DeltaTime : 0.018130
f32DeltaTime : 0.019623
f32DeltaTime : 0.012288
f32DeltaTime : 0.016677
f32DeltaTime : 0.016895
f32DeltaTime : 0.016405
f32DeltaTime : 0.018474
f32DeltaTime : 0.017564
f32DeltaTime : 0.014213
f32DeltaTime : 0.016659
f32DeltaTime : 0.016830
f32DeltaTime : 0.016486
f32DeltaTime : 0.018657
f32DeltaTime : 0.026178
**f32DeltaTime : 0.006349**
f32DeltaTime : 0.014091
f32DeltaTime : 0.016504
f32DeltaTime : 0.016617
f32DeltaTime : 0.024325
f32DeltaTime : 0.013866
f32DeltaTime : 0.015417
f32DeltaTime : 0.014500
f32DeltaTime : 0.016950
f32DeltaTime : 0.016418
f32DeltaTime : 0.018194
f32DeltaTime : 0.016803
f32DeltaTime : 0.017097
f32DeltaTime : 0.013594
f32DeltaTime : 0.016732
f32DeltaTime : 0.016599
f32DeltaTime : 0.017600
f32DeltaTime : 0.021286
f32DeltaTime : 0.012039
f32DeltaTime : 0.016735
f32DeltaTime : 0.017146
f32DeltaTime : 0.020083
Not sure but i think the line " f32DeltaTime : 0.006349 " could be the problem... But why f32DeltaTime is so small in some Frames ??? Does eglSwapBuffers does nothing at this Frame ??? But why ??? Question over question :)