title: Android OpenGL stuttering - vsync?
body: <p>I've a Problem with my Rendering Loop. During moving object's I see a Little stutter that Looks like <code>eglSwapBuffers</code> swap's same buffer twice. My FPS is constantly between 59 - 60 FPS. The movement takes <code>deltaTime</code> into account at calculate new Position.</p>
  
  <p>What could that be ??? Could double buffering solve this Problem ???</p>
  
  <p>Here is a small Video ( hopefully you'll see what I mean ).
  <a href="http://youtu.be/bQYiqHUzPuI" rel="nofollow">http://youtu.be/bQYiqHUzPuI</a></p>
  
  <p>Here is my Rendering Loop</p>
  
  <pre><code>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-&gt;Initialize();
      }
  
      m_pScreenBase-&gt;Update( f32DeltaTime );
      m_pScreenBase-&gt;Render();
  
      if ( eglSwapBuffers( m_pDisplay, m_pSurface ) == EGL_FALSE )
      {
          LogError( "eglSwapBuffers function failed." );
      }
  
      m_i32FramesPerSecond += 1;
  
      if ( GetTime() - m_u32FPSResetTimer &gt;= 1000000000 )
      {
          LogFPS( "%d", m_i32FramesPerSecond );
          m_i32FramesPerSecond = 0;
          m_u32FPSResetTimer = GetTime();
      }
  
      // return false when app should be exit
      return bResult;
  }
  </code></pre>
  
  <p>Here is the update function</p>
  
  <pre><code>void CStartScreen::Update( FLOAT32  f32DeltaTime )
  {
      for ( INT32 i = 0; i &lt; MAX_SQUARES; i++ )
      {
          m_pSquare[ i ]-&gt;IncPosX( ( 400.0f * f32DeltaTime ) );
  
          if ( m_pSquare[ i ]-&gt;GetPosX() &gt;= 800.0f )
          {
              m_pSquare[ i ]-&gt;IncPosX( -( 800.0f + m_pSquare[ i ]-&gt;GetWidth() ) );
          }
      }
  }
  </code></pre>
  
  <p>If it's needed, I can post my <code>EGL</code> and <code>OpenGL</code> Setup too.</p>
  
  <p><strong>UPDATE 1 :</strong></p>
  
  <p>UINT32 is defined as</p>
  
  <p>typedef unsigned int            UINT32;</p>
  
  <pre><code>inline UINT32 GetTime()
  {
      timespec    sTime;
      UINT32      u32Return = 0;
  
      clock_gettime( CLOCK_MONOTONIC, &amp;sTime );
      u32Return = ( sTime.tv_sec * 1000000000LL ) + sTime.tv_nsec;
  
      return u32Return;
  }
  </code></pre>
  
  <p>And here is the delta time for 1 second</p>
  
  <pre><code>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
  </code></pre>
  
  <p>Not sure but i think the line " <strong>f32DeltaTime : 0.006349</strong> " 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 :)</p>