Ocean
quest/openxr/GLESWindowFramebuffer.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_RENDERING_GLES_QUEST_OPENXR_GLES_WINDOW_FRAMEBUFFER_H
9 #define META_OCEAN_RENDERING_GLES_QUEST_OPENXR_GLES_WINDOW_FRAMEBUFFER_H
10 
15 
16 #ifdef OCEAN_RENDERING_GLES_QUEST_PLATFORM_OPENXR
17 
19 
21 
22 namespace Ocean
23 {
24 
25 namespace Rendering
26 {
27 
28 namespace GLESceneGraph
29 {
30 
31 namespace Quest
32 {
33 
34 // Forward declaration.
35 class GLESEngineQuest;
36 
37 namespace OpenXR
38 {
39 
40 /**
41  * This class is the base class for all GLESceneGraph window framebuffers for Quest platforms.
42  * @ingroup renderinggles
43  */
44 class OCEAN_RENDERING_GLES_EXPORT GLESWindowFramebuffer :
45  virtual public GLESFramebuffer,
46  virtual public WindowFramebuffer
47 {
48  friend class Quest::GLESEngineQuest;
49 
50  public:
51 
52  /// The number of framebuffers used.
53  static constexpr size_t numberEyes_ = 2;
54 
55  public:
56 
57  /**
58  * Initializes the framebuffer based on the platform specific id.
59  * For Quest platforms, the id is the pointer to the OpenXR::Session object.
60  * @see WindowFramebuffer::initializeById().
61  */
62  bool initializeById(const size_t id, const FramebufferRef& shareFramebuffer = FramebufferRef()) override;
63 
64  /**
65  * Renders the next frame into the framebuffer.
66  * @see Framebuffer::render().
67  */
68  void render() override;
69 
70  /**
71  * Returns the width of an individual framebuffer.
72  * @param eyeIndex The index of the eye for which the width will be returned, with range [0, numberEyes_ - 1]
73  * @return The width of the framebuffer, in pixel, with range [0, infinity)
74  */
75  inline unsigned int width(const size_t eyeIndex) const;
76 
77  /**
78  * Returns the height of an individual framebuffer.
79  * @param eyeIndex The index of the eye for which the height will be returned, with range [0, numberEyes_ - 1]
80  * @return The height of the framebuffer, in pixel, with range [0, infinity)
81  */
82  inline unsigned int height(const size_t eyeIndex) const;
83 
84  /**
85  * Returns OpenXR's swap chain for the individual eyes/framebuffers.
86  * @param eyeIndex The index of the eye for which the swap chain will be returned, with range [0, numberEyes_ - 1]
87  * @return The requested swap chain
88  */
89  inline XrSwapchain xrSwapchain(const size_t eyeIndex) const;
90 
91  /**
92  * Returns the index of the current texture of OpenXR's swap chain for the individual eyes/framebuffers.
93  * @param eyeIndex The index of the eye for which the index will be returned, with range [0, numberEyes_ - 1]
94  * @return The requested swap chain
95  */
96  inline size_t textureSwapChainIndex(const size_t eyeIndex) const;
97 
98  protected:
99 
100  /**
101  * Creates a new window framebuffer.
102  */
104 
105  /**
106  * Destructs a window framebuffer.
107  */
109 
110  /**
111  * Initialize the OpenGL ES dispaly and context.
112  * @return True, if succeeded
113  */
114  bool initializeContext() override;
115 
116  /**
117  * Releases the framebuffer.
118  */
119  void release() override;
120 
121  protected:
122 
123  /// The actual implementation of the Quest specific framebuffer(s).
125 
126  /// The index of the next eye to be rendered first, with range [0, 1]
127  size_t nextRenderFirstEyeIndex_ = 0;
128 
129  /// The traverser which is used for rendering.
131 
132  /// The framebuffer's id which is a pointer to the ovrJava object.
133  size_t id_ = 0;
134 
135  /// The configuration to be used.
137 };
138 
139 inline unsigned int GLESWindowFramebuffer::width(const size_t eyeIndex) const
140 {
141  ocean_assert(eyeIndex < numberEyes_ && eyeIndex < glesFramebuffers_.size());
142 
143  if (eyeIndex < glesFramebuffers_.size())
144  {
145  return glesFramebuffers_[eyeIndex].width();
146  }
147 
148  ocean_assert(false && "Invalid eye index!");
149  return 0u;
150 }
151 
152 inline unsigned int GLESWindowFramebuffer::height(const size_t eyeIndex) const
153 {
154  ocean_assert(eyeIndex < numberEyes_ && eyeIndex < glesFramebuffers_.size());
155 
156  if (eyeIndex < glesFramebuffers_.size())
157  {
158  return glesFramebuffers_[eyeIndex].height();
159  }
160 
161  ocean_assert(false && "Invalid eye index!");
162  return 0u;
163 }
164 
165 inline XrSwapchain GLESWindowFramebuffer::xrSwapchain(const size_t eyeIndex) const
166 {
167  ocean_assert(eyeIndex < numberEyes_ && eyeIndex < glesFramebuffers_.size());
168 
169  if (eyeIndex < glesFramebuffers_.size())
170  {
171  return glesFramebuffers_[eyeIndex].xrSwapchain();
172  }
173 
174  ocean_assert(false && "Invalid eye index!");
175  return XR_NULL_HANDLE;
176 }
177 
178 inline size_t GLESWindowFramebuffer::textureSwapChainIndex(const size_t eyeIndex) const
179 {
180  ocean_assert(eyeIndex < numberEyes_ && eyeIndex < glesFramebuffers_.size());
181 
182  if (eyeIndex < glesFramebuffers_.size())
183  {
184  return glesFramebuffers_[eyeIndex].textureSwapChainIndex();
185  }
186 
187  ocean_assert(false && "Invalid eye index!");
188  return 0;
189 }
190 
191 }
192 
193 }
194 
195 }
196 
197 }
198 
199 }
200 
201 #endif // OCEAN_RENDERING_GLES_QUEST_PLATFORM_OPENXR
202 
203 #endif // META_OCEAN_RENDERING_GLES_QUEST_OPENXR_GLES_WINDOW_FRAMEBUFFER_H
This class holds framebuffer configurations.
Definition: rendering/Framebuffer.h:94
This class implements a base for all GLESceneGraph framebuffers.
Definition: rendering/glescenegraph/GLESFramebuffer.h:34
This class implements a traverser for renderables.
Definition: GLESTraverser.h:39
This class implements the engine for Quest platforms.
Definition: GLESEngineQuest.h:31
This class is the base class for all GLESceneGraph window framebuffers for Quest platforms.
Definition: quest/openxr/GLESWindowFramebuffer.h:47
static constexpr size_t numberEyes_
The number of framebuffers used.
Definition: quest/openxr/GLESWindowFramebuffer.h:53
bool initializeContext() override
Initialize the OpenGL ES dispaly and context.
bool initializeById(const size_t id, const FramebufferRef &shareFramebuffer=FramebufferRef()) override
Initializes the framebuffer based on the platform specific id.
Platform::Meta::Quest::OpenXR::GLESFramebuffers glesFramebuffers_
The actual implementation of the Quest specific framebuffer(s).
Definition: quest/openxr/GLESWindowFramebuffer.h:124
unsigned int height(const size_t eyeIndex) const
Returns the height of an individual framebuffer.
Definition: quest/openxr/GLESWindowFramebuffer.h:152
~GLESWindowFramebuffer() override
Destructs a window framebuffer.
GLESTraverser traverser_
The traverser which is used for rendering.
Definition: quest/openxr/GLESWindowFramebuffer.h:130
void render() override
Renders the next frame into the framebuffer.
XrSwapchain xrSwapchain(const size_t eyeIndex) const
Returns OpenXR's swap chain for the individual eyes/framebuffers.
Definition: quest/openxr/GLESWindowFramebuffer.h:165
GLESWindowFramebuffer(const Framebuffer::FramebufferConfig &config)
Creates a new window framebuffer.
size_t textureSwapChainIndex(const size_t eyeIndex) const
Returns the index of the current texture of OpenXR's swap chain for the individual eyes/framebuffers.
Definition: quest/openxr/GLESWindowFramebuffer.h:178
Framebuffer::FramebufferConfig config_
The configuration to be used.
Definition: quest/openxr/GLESWindowFramebuffer.h:136
unsigned int width(const size_t eyeIndex) const
Returns the width of an individual framebuffer.
Definition: quest/openxr/GLESWindowFramebuffer.h:139
This class is the base class for all window framebuffers.
Definition: rendering/WindowFramebuffer.h:55
std::vector< GLESFramebuffer > GLESFramebuffers
Definition of a vector holding framebuffer objects.
Definition: platform/meta/quest/openxr/GLESFramebuffer.h:46
SmartObjectRef< Framebuffer > FramebufferRef
Definition of a smart object reference holding a framebuffer.
Definition: rendering/Framebuffer.h:31
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15