Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(103)

Side by Side Diff: gpu/demos/gles2_book/example.h

Issue 543110: Created a base class for examples taken from gles2 book. It encapsulates the ... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | gpu/demos/hello_triangle/main.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 // Base class for OpenGL ES 2.0 book examples.
6
7 #ifndef GPU_DEMOS_GLES2_BOOK_EXAMPLE_H_
8 #define GPU_DEMOS_GLES2_BOOK_EXAMPLE_H_
9
10 #include "gpu/demos/app_framework/application.h"
11 #include "third_party/gles2_book/Common/Include/esUtil.h"
12
13 namespace gpu {
14 namespace demos {
15 namespace gles2_book {
16
17 typedef int InitFunc(ESContext* context);
18 typedef void UpdateFunc(ESContext* context, float elapsed_sec);
19 typedef void DrawFunc(ESContext* context);
20 typedef void ShutDownFunc(ESContext* context);
21
22 // The examples taken from OpenGL 2.0 ES book follow a well-defined pattern.
23 // They all use one ESContext that holds a reference to a custom UserData.
24 // Each example provides four functions:
25 // 1. InitFunc to initialize OpenGL state and custom UserData
26 // 2. UpdateFunc is called before drawing each frame to update animation etc.
27 // 3. DrawFunc is called to do the actual frame rendering
28 // 4. ShutDownFunc is called when program terminates
29 // This class encapsulates this pattern to make it easier to write classes
30 // for each example.
31 template <typename UserData,
32 InitFunc init_func,
33 UpdateFunc update_func,
34 DrawFunc draw_func,
35 ShutDownFunc shut_down_func>
36 class Example : public gpu_demos::Application {
37 public:
38 Example() {
39 esInitContext(&context_);
40 memset(&user_data_, 0, sizeof(UserData));
41 context_.userData = &user_data_;
42 }
43 virtual ~Example() {
44 shut_down_func(&context_);
45 }
46
47 bool Init() {
48 if (!InitRenderContext()) return false;
49
50 context_.width = width();
51 context_.height = height();
52 if (!init_func(&context_)) return false;
53 return true;
54 }
55
56 protected:
57 virtual void Draw(float elapsed_sec) {
58 update_func(&context_, elapsed_sec);
59 draw_func(&context_);
60 }
61
62 private:
63 ESContext context_;
64 UserData user_data_;
65 DISALLOW_COPY_AND_ASSIGN(Example);
66 };
67
68 // Many examples do need to update anything and hence do not provide an
69 // update function. This no-op function can be used for such examples.
70 inline void NoOpUpdateFunc(ESContext* context, float elapsed_sec) {}
71
72 } // namespace gles2_book
73 } // namespace demos
74 } // namespace gpu
75 #endif // GPU_DEMOS_GLES2_BOOK_EXAMPLE_H_
OLDNEW
« no previous file with comments | « no previous file | gpu/demos/hello_triangle/main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698