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

Last change on this file since 1084 was 1084, checked in by sam, 12 years ago

nacl: the Mandelbrot zoomer is starting to work on NaCl.

  • 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  /// The OpenGL ES 2.0 interface.
65  const struct PPB_OpenGLES2* gles2() const {
66    return gles2_interface_;
67  }
68
69  /// The PP_Resource needed to make GLES2 calls through the Pepper interface.
70  const PP_Resource gl_context() const {
71    return context_.pp_resource();
72  }
73
74  /// Indicate whether a flush is pending.  This can only be called from the
75  /// main thread; it is not thread safe.
76  bool flush_pending() const {
77    return flush_pending_;
78  }
79  void set_flush_pending(bool flag) {
80    flush_pending_ = flag;
81  }
82
83 private:
84  pp::Size size_;
85  pp::Graphics3D context_;
86  bool flush_pending_;
87
88  const struct PPB_OpenGLES2* gles2_interface_;
89};
90
91}  // namespace lol
92
93#endif  // EXAMPLES_TUMBLER_OPENGL_CONTEXT_H_
94
Note: See TracBrowser for help on using the repository browser.