source: trunk/src/platform/nacl/opengl_context.h @ 1440

Last change on this file since 1440 was 1440, checked in by sam, 9 years ago

nacl: NaCl binaries no longer need a modified main() to work, the NaCl
instance object takes care of everything for us.

  • Property svn:keywords set to Id
File size: 2.7 KB
Line 
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#ifndef EXAMPLES_TUMBLER_OPENGL_CONTEXT_H_
6#define EXAMPLES_TUMBLER_OPENGL_CONTEXT_H_
7
8///
9/// @file
10/// OpenGLContext manages the OpenGL context in the browser that is associated
11/// with a @a pp::Instance instance.
12///
13
14#include <assert.h>
15#include <pthread.h>
16
17#include <algorithm>
18#include <string>
19
20#include <ppapi/c/ppb_opengles2.h>
21#include <ppapi/cpp/graphics_3d_client.h>
22#include <ppapi/cpp/graphics_3d.h>
23#include <ppapi/cpp/instance.h>
24#include <ppapi/cpp/size.h>
25
26#include "platform/nacl/opengl_context_ptrs.h"
27
28namespace lol {
29
30/// OpenGLContext manages an OpenGL rendering context in the browser.
31///
32class OpenGLContext : public pp::Graphics3DClient {
33 public:
34  explicit OpenGLContext(pp::Instance* instance);
35
36  /// Release all the in-browser resources used by this context, and make this
37  /// context invalid.
38  virtual ~OpenGLContext();
39
40  /// The Graphics3DClient interfcace.
41  virtual void Graphics3DContextLost() {
42    assert(!"Unexpectedly lost graphics context");
43  }
44
45  /// Make @a this the current 3D context in @a instance.
46  /// @param instance The instance of the NaCl module that will receive the
47  ///                 the current 3D context.
48  /// @return success.
49  bool MakeContextCurrent(pp::Instance* instance);
50
51  /// Flush the contents of this context to the browser's 3D device.
52  void FlushContext();
53
54  /// Make the underlying 3D device invalid, so that any subsequent rendering
55  /// commands will have no effect.  The next call to MakeContextCurrent() will
56  /// cause the underlying 3D device to get rebound and start receiving
57  /// receiving rendering commands again.  Use InvalidateContext(), for
58  /// example, when resizing the context's viewing area.
59  void InvalidateContext(pp::Instance* instance);
60
61  /// Resize the context.
62  void ResizeContext(const pp::Size& size);
63
64  pp::Size const& GetSize() { return size_; }
65
66  /// The OpenGL ES 2.0 interface.
67  const struct PPB_OpenGLES2* gles2() const {
68    return gles2_interface_;
69  }
70
71  /// The PP_Resource needed to make GLES2 calls through the Pepper interface.
72  PP_Resource gl_context() const {
73    return context_.pp_resource();
74  }
75
76  /// Indicate whether a flush is pending.  This can only be called from the
77  /// main thread; it is not thread safe.
78  bool flush_pending() const {
79    return flush_pending_;
80  }
81  void set_flush_pending(bool flag) {
82    flush_pending_ = flag;
83  }
84
85 private:
86  pp::Size size_;
87  pp::Graphics3D context_;
88  bool flush_pending_;
89
90  const struct PPB_OpenGLES2* gles2_interface_;
91};
92
93}  // namespace lol
94
95#endif  // EXAMPLES_TUMBLER_OPENGL_CONTEXT_H_
96
Note: See TracBrowser for help on using the repository browser.