summaryrefslogtreecommitdiffstats
path: root/gpu/demos/framework/demo.h
blob: 801609b886c578dfffcc36b592fb557dde656261 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Base class for gles2 demos.

#ifndef GPU_DEMOS_FRAMEWORK_DEMO_H_
#define GPU_DEMOS_FRAMEWORK_DEMO_H_

#include "base/time.h"

namespace gpu {
namespace demos {

// Base class for GLES2 demos. The same demo class is supposed to be run as
// standalone apps (exe), pepper plugin (dll), and nacl module (nexe). This is
// accomplished by creating framework for each platfom and hosting the demo
// class object.
class Demo {
 public:
  Demo();
  virtual ~Demo();

  // Returns the title of demo. This title is used to name the window or
  // html page where demo is running.
  virtual const wchar_t* Title() const = 0;

  // Initializes the size of the window on which this demo object will render.
  void InitWindowSize(int width, int height);

  // This function is called by the framework to initialize the OpenGL state
  // required by this demo. When this function is called, it is assumed that
  // a rendering context has already been created and made current.
  virtual bool InitGL() = 0;

  // This function is called by the framework to perform OpenGL rendering.
  // When this function is called, it is assumed that the rendering context
  // has been made current.
  void Draw();

 protected:
  // Returns the width of window.
  int width() const { return width_; }
  // Returns the height of window.
  int height() const { return height_; }

  // 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 Render was called the last time. It can be used to
  // make the application frame-rate independent. It is 0.0f for the
  // first render call.
  virtual void Render(float elapsed_sec) = 0;

 private:
  int width_;  // Window width.
  int height_;  // Window height.

  // Time at which draw was called last.
  base::Time last_draw_time_;

  DISALLOW_COPY_AND_ASSIGN(Demo);
};

}  // namespace demos
}  // namespace gpu
#endif  // GPU_DEMOS_FRAMEWORK_DEMO_H_