OLD | NEW |
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Base class for OpenGL ES 2.0 book examples. | 5 // Base class for OpenGL ES 2.0 book examples. |
6 | 6 |
7 #ifndef GPU_DEMOS_GLES2_BOOK_EXAMPLE_H_ | 7 #ifndef GPU_DEMOS_GLES2_BOOK_EXAMPLE_H_ |
8 #define GPU_DEMOS_GLES2_BOOK_EXAMPLE_H_ | 8 #define GPU_DEMOS_GLES2_BOOK_EXAMPLE_H_ |
9 | 9 |
10 #include <cassert> | 10 #include <cassert> |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 context_.userData = &user_data_; | 44 context_.userData = &user_data_; |
45 } | 45 } |
46 virtual ~Example() { | 46 virtual ~Example() { |
47 shut_down_func_(&context_); | 47 shut_down_func_(&context_); |
48 } | 48 } |
49 | 49 |
50 virtual bool InitGL() { | 50 virtual bool InitGL() { |
51 // Note that update_func is optional. | 51 // Note that update_func is optional. |
52 assert(init_func_ && draw_func_ && shut_down_func_); | 52 assert(init_func_ && draw_func_ && shut_down_func_); |
53 | 53 |
54 context_.width = width(); | |
55 context_.height = height(); | |
56 if (!init_func_(&context_)) return false; | 54 if (!init_func_(&context_)) return false; |
57 return true; | 55 return true; |
58 } | 56 } |
59 | 57 |
60 protected: | 58 protected: |
61 void RegisterCallbacks(InitFunc* init_func, | 59 void RegisterCallbacks(InitFunc* init_func, |
62 UpdateFunc* update_func, | 60 UpdateFunc* update_func, |
63 DrawFunc* draw_func, | 61 DrawFunc* draw_func, |
64 ShutDownFunc* shut_down_func) { | 62 ShutDownFunc* shut_down_func) { |
65 init_func_ = init_func; | 63 init_func_ = init_func; |
66 update_func_ = update_func; | 64 update_func_ = update_func; |
67 draw_func_ = draw_func; | 65 draw_func_ = draw_func; |
68 shut_down_func_ = shut_down_func; | 66 shut_down_func_ = shut_down_func; |
69 } | 67 } |
70 | 68 |
71 virtual void Render(float elapsed_sec) { | 69 virtual void Render(float elapsed_sec) { |
| 70 context_.width = width(); |
| 71 context_.height = height(); |
| 72 |
72 if (update_func_) update_func_(&context_, elapsed_sec); | 73 if (update_func_) update_func_(&context_, elapsed_sec); |
73 draw_func_(&context_); | 74 draw_func_(&context_); |
74 } | 75 } |
75 | 76 |
76 private: | 77 private: |
77 ESContext context_; | 78 ESContext context_; |
78 UserData user_data_; | 79 UserData user_data_; |
79 | 80 |
80 // Callback functions. | 81 // Callback functions. |
81 InitFunc* init_func_; | 82 InitFunc* init_func_; |
82 UpdateFunc* update_func_; | 83 UpdateFunc* update_func_; |
83 DrawFunc* draw_func_; | 84 DrawFunc* draw_func_; |
84 ShutDownFunc* shut_down_func_; | 85 ShutDownFunc* shut_down_func_; |
85 }; | 86 }; |
86 | 87 |
87 } // namespace gles2_book | 88 } // namespace gles2_book |
88 } // namespace demos | 89 } // namespace demos |
89 } // namespace gpu | 90 } // namespace gpu |
90 #endif // GPU_DEMOS_GLES2_BOOK_EXAMPLE_H_ | 91 #endif // GPU_DEMOS_GLES2_BOOK_EXAMPLE_H_ |
OLD | NEW |