summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoralokp@chromium.org <alokp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-13 19:55:52 +0000
committeralokp@chromium.org <alokp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-13 19:55:52 +0000
commit5ba06f1d77a786db214d541dc78eaf09e4955bc0 (patch)
treea3223a40a78af47ac1eef020ffd50fca60061eff
parente9ac491f099bd100cb78f53122b9b9805c54fbf3 (diff)
downloadchromium_src-5ba06f1d77a786db214d541dc78eaf09e4955bc0.zip
chromium_src-5ba06f1d77a786db214d541dc78eaf09e4955bc0.tar.gz
chromium_src-5ba06f1d77a786db214d541dc78eaf09e4955bc0.tar.bz2
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
-rw-r--r--gpu/demos/app_framework/application.cc10
-rw-r--r--gpu/demos/app_framework/application.h12
-rw-r--r--gpu/demos/hello_triangle/main.cc4
-rw-r--r--gpu/demos/simple_vertex_shader/main.cc7
4 files changed, 26 insertions, 7 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_;
diff --git a/gpu/demos/hello_triangle/main.cc b/gpu/demos/hello_triangle/main.cc
index 573b1c9..3f75bc9 100644
--- a/gpu/demos/hello_triangle/main.cc
+++ b/gpu/demos/hello_triangle/main.cc
@@ -19,7 +19,7 @@ class HelloTriangle : public Application {
bool Init();
protected:
- virtual void Draw();
+ virtual void Draw(float);
private:
ESContext context_;
@@ -49,7 +49,7 @@ bool HelloTriangle::Init() {
return true;
}
-void HelloTriangle::Draw() {
+void HelloTriangle::Draw(float) {
htDraw(&context_);
}
} // namespace gpu_demos
diff --git a/gpu/demos/simple_vertex_shader/main.cc b/gpu/demos/simple_vertex_shader/main.cc
index d042942..350c5d7 100644
--- a/gpu/demos/simple_vertex_shader/main.cc
+++ b/gpu/demos/simple_vertex_shader/main.cc
@@ -19,7 +19,7 @@ class SimpleVertexShader : public Application {
bool Init();
protected:
- virtual void Draw();
+ virtual void Draw(float elapsed_sec);
private:
ESContext context_;
@@ -45,12 +45,13 @@ bool SimpleVertexShader::Init() {
context_.width = width();
context_.height = height();
if (!svsInit(&context_)) return false;
- svsUpdate(&context_, 0.0f);
return true;
}
-void SimpleVertexShader::Draw() {
+void SimpleVertexShader::Draw(float elapsed_sec) {
+ svsUpdate(&context_, elapsed_sec);
+
svsDraw(&context_);
}
} // namespace gpu_demos