From 5ba06f1d77a786db214d541dc78eaf09e4955bc0 Mon Sep 17 00:00:00 2001 From: "alokp@chromium.org" Date: Wed, 13 Jan 2010 19:55:52 +0000 Subject: Changed the signature of Application::Draw to accept elapsed time. It will be used to update key frames or making the application frame-rate independent. However I think there is some bug somewhere. It takes an eternity for the cube in simple-vertex-shader demo to start rotating. Even when the cube starts rotatiing the performance is quite choppy. Review URL: http://codereview.chromium.org/551011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@36156 0039d316-1c4b-4281-b951-d872f2087c98 --- gpu/demos/app_framework/application.cc | 10 +++++++++- gpu/demos/app_framework/application.h | 12 +++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) (limited to 'gpu/demos/app_framework') 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(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_; -- cgit v1.1