| Index: gpu/demos/gles2_book/example.h
|
| ===================================================================
|
| --- gpu/demos/gles2_book/example.h (revision 36982)
|
| +++ gpu/demos/gles2_book/example.h (working copy)
|
| @@ -7,7 +7,7 @@
|
| #ifndef GPU_DEMOS_GLES2_BOOK_EXAMPLE_H_
|
| #define GPU_DEMOS_GLES2_BOOK_EXAMPLE_H_
|
|
|
| -#include "gpu/demos/app_framework/application.h"
|
| +#include "gpu/demos/framework/demo.h"
|
| #include "third_party/gles2_book/Common/Include/esUtil.h"
|
|
|
| namespace gpu {
|
| @@ -28,47 +28,61 @@
|
| // 4. ShutDownFunc is called when program terminates
|
| // This class encapsulates this pattern to make it easier to write classes
|
| // for each example.
|
| -template <typename UserData,
|
| - InitFunc init_func,
|
| - UpdateFunc update_func,
|
| - DrawFunc draw_func,
|
| - ShutDownFunc shut_down_func>
|
| -class Example : public gpu_demos::Application {
|
| +template <typename UserData>
|
| +class Example : public gpu::demos::Demo {
|
| public:
|
| - Example() {
|
| + Example()
|
| + : init_func_(NULL),
|
| + update_func_(NULL),
|
| + draw_func_(NULL),
|
| + shut_down_func_(NULL) {
|
| esInitContext(&context_);
|
| memset(&user_data_, 0, sizeof(UserData));
|
| context_.userData = &user_data_;
|
| }
|
| virtual ~Example() {
|
| - shut_down_func(&context_);
|
| + shut_down_func_(&context_);
|
| }
|
|
|
| - bool Init() {
|
| - if (!InitRenderContext()) return false;
|
| + virtual bool InitGL() {
|
| + // Note that update_func is optional.
|
| + CHECK(init_func_ && draw_func_ && shut_down_func_);
|
|
|
| context_.width = width();
|
| context_.height = height();
|
| - if (!init_func(&context_)) return false;
|
| + if (!init_func_(&context_)) return false;
|
| return true;
|
| }
|
|
|
| protected:
|
| - virtual void Draw(float elapsed_sec) {
|
| - update_func(&context_, elapsed_sec);
|
| - draw_func(&context_);
|
| + void RegisterCallbacks(InitFunc* init_func,
|
| + UpdateFunc* update_func,
|
| + DrawFunc* draw_func,
|
| + ShutDownFunc* shut_down_func) {
|
| + init_func_ = init_func;
|
| + update_func_ = update_func;
|
| + draw_func_ = draw_func;
|
| + shut_down_func_ = shut_down_func;
|
| }
|
|
|
| + virtual void Render(float elapsed_sec) {
|
| + if (update_func_) update_func_(&context_, elapsed_sec);
|
| + draw_func_(&context_);
|
| + }
|
| +
|
| private:
|
| ESContext context_;
|
| UserData user_data_;
|
| +
|
| + // Callback functions.
|
| + InitFunc* init_func_;
|
| + UpdateFunc* update_func_;
|
| + DrawFunc* draw_func_;
|
| + ShutDownFunc* shut_down_func_;
|
| +
|
| DISALLOW_COPY_AND_ASSIGN(Example);
|
| };
|
|
|
| -// Many examples do need to update anything and hence do not provide an
|
| -// update function. This no-op function can be used for such examples.
|
| -inline void NoOpUpdateFunc(ESContext* context, float elapsed_sec) {}
|
| -
|
| } // namespace gles2_book
|
| } // namespace demos
|
| } // namespace gpu
|
|
|