Ocean
wxwidgets/WindowContext.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 #ifndef META_OCEAN_PLATFORM_GL_WXWIDGETS_WINDOW_CONTEXT_H
9 #define META_OCEAN_PLATFORM_GL_WXWIDGETS_WINDOW_CONTEXT_H
10 
12 
14 
15 namespace Ocean
16 {
17 
18 namespace Platform
19 {
20 
21 namespace GL
22 {
23 
24 namespace WxWidgets
25 {
26 
27 /**
28  * This class implements an OpenGL context based on a window.
29  * @ingroup platformglwxwidgets
30  */
31 class OCEAN_PLATFORM_GL_WXWIDGETS_EXPORT WindowContext :
32  public wxWindow,
33  public Context
34 {
35  public:
36 
37  /**
38  * Creates a new object without creating the window.
39  */
41 
42  /**
43  * Creates a new object and directly creates the window.
44  * @param parent The parent window, must be valid
45  * @param id The id of the new window
46  * @param pos The position of the window
47  * @param size The size of the window
48  * @param style The style of the window
49  * @param name The name of the window
50  */
51  WindowContext(wxWindow *parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0, const wxString& name = wxString());
52 
53  /**
54  * Destructs the window.
55  */
56  virtual ~WindowContext();
57 
58  /**
59  * Creates the OpenGL context for this framebuffer.
60  * @see Context::createOpenGLContext().
61  */
62  virtual bool createOpenGLContext(const bool initializeOpenGL33, const unsigned int multisamples);
63 
64  /**
65  * Makes the OpenGL rendering context of this framebuffer the calling thread's current rendering context or makes the calling thread's current rendering context not longer current.
66  * @see Context::makeCurrent().
67  */
68  virtual void makeCurrent(const bool state = true);
69 
70  /**
71  * Swaps the foreground and background buffer if this context has two buffers.
72  * @see Context::swapBuffers().
73  */
74  virtual bool swapBuffers();
75 
76  protected:
77 
78  /**
79  * Releases the OpenGL context of this framebuffer.
80  * @return True, if succeeded
81  */
82  virtual bool releaseOpenGLContext();
83 
84  /**
85  * The window resize event function.
86  * @param event The event object
87  */
88  void onResize(wxSizeEvent& event);
89 
90  protected:
91 
92 #ifdef __APPLE__
93  NSOpenGLContext* nsContext_ = nullptr;
94 #endif
95 
96  private:
97 
98  /// WxWidgets event table.
100 };
101 
102 }
103 
104 }
105 
106 }
107 
108 }
109 
110 #endif // META_OCEAN_PLATFORM_GL_WXWIDGETS_WINDOW_CONTEXT_H
This class encapsulates an OpenGL context.
Definition: platform/gl/Context.h:29
This class implements an OpenGL context based on a window.
Definition: wxwidgets/WindowContext.h:34
void onResize(wxSizeEvent &event)
The window resize event function.
virtual bool swapBuffers()
Swaps the foreground and background buffer if this context has two buffers.
WindowContext(wxWindow *parent, wxWindowID id, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=0, const wxString &name=wxString())
Creates a new object and directly creates the window.
virtual ~WindowContext()
Destructs the window.
virtual void makeCurrent(const bool state=true)
Makes the OpenGL rendering context of this framebuffer the calling thread's current rendering context...
virtual bool releaseOpenGLContext()
Releases the OpenGL context of this framebuffer.
WindowContext()
Creates a new object without creating the window.
virtual bool createOpenGLContext(const bool initializeOpenGL33, const unsigned int multisamples)
Creates the OpenGL context for this framebuffer.
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15