diff options
Diffstat (limited to 'gpu/demos/app_framework')
-rw-r--r-- | gpu/demos/app_framework/application.cc | 10 | ||||
-rw-r--r-- | gpu/demos/app_framework/application.h | 12 |
2 files changed, 20 insertions, 2 deletions
diff --git a/gpu/demos/app_framework/application.cc b/gpu/demos/app_framework/application.cc index 0ae2cb9..b82e691a 100644 --- a/gpu/demos/app_framework/application.cc +++ b/gpu/demos/app_framework/application.cc @@ -74,7 +74,15 @@ void Application::MainLoop() { } void Application::OnPaint() { - Draw(); + float elapsed_sec = 0.0f; + const base::Time current_time = base::Time::Now(); + if (!last_draw_time_.is_null()) { + base::TimeDelta time_delta = current_time - last_draw_time_; + elapsed_sec = static_cast<float>(time_delta.InSecondsF()); + } + last_draw_time_ = current_time; + + Draw(elapsed_sec); gles2::GetGLContext()->SwapBuffers(); } diff --git a/gpu/demos/app_framework/application.h b/gpu/demos/app_framework/application.h index f7d1a50..d9d48e9 100644 --- a/gpu/demos/app_framework/application.h +++ b/gpu/demos/app_framework/application.h @@ -9,6 +9,7 @@ #include "base/at_exit.h" #include "base/message_loop.h" +#include "base/time.h" #include "gpu/demos/app_framework/platform.h" @@ -36,7 +37,13 @@ class Application { bool InitRenderContext(); - virtual void Draw() = 0; + // The framework calls this function for the derived classes to do custom + // rendering. There is no default implementation. It must be defined by the + // derived classes. The elapsed_sec param represents the time elapsed + // (in seconds) after Draw was called the last time. It can be used to + // make the application frame-rate independent. It is 0.0f for the + // first draw call. + virtual void Draw(float elapsed_sec) = 0; private: // Creates a native on-screen window. @@ -46,6 +53,9 @@ class Application { int height_; NativeWindowHandle window_handle_; + // Time at which draw was called last. + base::Time last_draw_time_; + // The following two variables are just needed to satisfy // the assumption that we are running inside a browser. base::AtExitManager at_exit_manager_; |