Imported Upstream version 2.81
[platform/upstream/libbullet.git] / Demos / NativeClient / tumbler_module.cc
1 // Copyright (c) 2011 The Native Client 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 #include "tumbler.h"
6 #include "ppapi/cpp/instance.h"
7 #include "ppapi/cpp/module.h"
8 #include "ppapi/gles2/gl2ext_ppapi.h"
9
10 /// The Module class.  The browser calls the CreateInstance() method to create
11 /// an instance of your NaCl module on the web page.  The browser creates a new
12 /// instance for each <embed> tag with type="application/x-nacl".
13 class TumberModule : public pp::Module {
14  public:
15   TumberModule() : pp::Module() {}
16   virtual ~TumberModule() {
17     glTerminatePPAPI();
18   }
19
20   /// Called by the browser when the module is first loaded and ready to run.
21   /// This is called once per module, not once per instance of the module on
22   /// the page.
23   virtual bool Init() {
24     return glInitializePPAPI(get_browser_interface()) == GL_TRUE;
25   }
26
27   /// Create and return a Tumbler instance object.
28   /// @param[in] instance The browser-side instance.
29   /// @return the plugin-side instance.
30   virtual pp::Instance* CreateInstance(PP_Instance instance) {
31     return new tumbler::Tumbler(instance);
32   }
33 };
34
35 namespace pp {
36 /// Factory function called by the browser when the module is first loaded.
37 /// The browser keeps a singleton of this module.  It calls the
38 /// CreateInstance() method on the object you return to make instances.  There
39 /// is one instance per <embed> tag on the page.  This is the main binding
40 /// point for your NaCl module with the browser.
41 Module* CreateModule() {
42   return new TumberModule();
43 }
44 }  // namespace pp
45