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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | gpu/demos/hello_triangle/main.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gpu/demos/gles2_book/example.h
===================================================================
--- gpu/demos/gles2_book/example.h (revision 0)
+++ gpu/demos/gles2_book/example.h (revision 0)
@@ -0,0 +1,75 @@
+// Copyright (c) 2006-2009 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 OpenGL ES 2.0 book examples.
+
+#ifndef GPU_DEMOS_GLES2_BOOK_EXAMPLE_H_
+#define GPU_DEMOS_GLES2_BOOK_EXAMPLE_H_
+
+#include "gpu/demos/app_framework/application.h"
+#include "third_party/gles2_book/Common/Include/esUtil.h"
+
+namespace gpu {
+namespace demos {
+namespace gles2_book {
+
+typedef int InitFunc(ESContext* context);
+typedef void UpdateFunc(ESContext* context, float elapsed_sec);
+typedef void DrawFunc(ESContext* context);
+typedef void ShutDownFunc(ESContext* context);
+
+// The examples taken from OpenGL 2.0 ES book follow a well-defined pattern.
+// They all use one ESContext that holds a reference to a custom UserData.
+// Each example provides four functions:
+// 1. InitFunc to initialize OpenGL state and custom UserData
+// 2. UpdateFunc is called before drawing each frame to update animation etc.
+// 3. DrawFunc is called to do the actual frame rendering
+// 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 {
+ public:
+ Example() {
+ esInitContext(&context_);
+ memset(&user_data_, 0, sizeof(UserData));
+ context_.userData = &user_data_;
+ }
+ virtual ~Example() {
+ shut_down_func(&context_);
+ }
+
+ bool Init() {
+ if (!InitRenderContext()) return false;
+
+ context_.width = width();
+ context_.height = height();
+ if (!init_func(&context_)) return false;
+ return true;
+ }
+
+ protected:
+ virtual void Draw(float elapsed_sec) {
+ update_func(&context_, elapsed_sec);
+ draw_func(&context_);
+ }
+
+ private:
+ ESContext context_;
+ UserData user_data_;
+ 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
+#endif // GPU_DEMOS_GLES2_BOOK_EXAMPLE_H_
Property changes on: gpu\demos\gles2_book\example.h
___________________________________________________________________
Added: svn:eol-style
+ LF
« 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