Ocean
GLFrameView.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_ANDROID_APPLICATION_GL_FRAME_VIEW_H
9 #define META_OCEAN_PLATFORM_ANDROID_APPLICATION_GL_FRAME_VIEW_H
10 
13 
14 #include "ocean/math/RGBAColor.h"
15 
17 
18 #include "ocean/rendering/Engine.h"
21 
22 namespace Ocean
23 {
24 
25 namespace Platform
26 {
27 
28 namespace Android
29 {
30 
31 namespace Application
32 {
33 
34 /**
35  * This class implements the main view of an OpenGLES frame for Android platform applications.
36  * The main view is implemented as singleton object.
37  * @ingroup platformandroidapplication
38  */
39 class OCEAN_PLATFORM_ANDROID_APPLICATION_EXPORT GLFrameView : public GLView
40 {
41  public:
42 
43  /**
44  * Initializes the view.
45  * @return True, if succeeded
46  */
47  bool initialize() override;
48 
49  /**
50  * Releases the view.
51  * @return True, if succeeded
52  */
53  bool release() override;
54 
55  /**
56  * Sets the horizontal field of view for this view.
57  * @param fovx Field of view to set in radian
58  * @return True, if succeeded
59  */
60  virtual bool setFovX(const Scalar fovx);
61 
62  /**
63  * Sets the background color of this view.
64  * @param color Background color to set
65  * @return True, if succeeded
66  */
67  virtual bool setBackgroundColor(const RGBAColor& color);
68 
69  /**
70  * Sets the background medium of this view by the medium's url and several further parameters.
71  * @param url URL of the media object to be used as background medium
72  * @param type Hint defining the media object in more detail, possible values are "LIVE_VIDEO", "IMAGE", "MOVIE", "IMAGE_SEQUENCE" or "FRAME_STREAM", if no hint is given the first possible media object will be created
73  * @param preferredWidth Preferred width of the medium in pixel, use 0 to use the default width
74  * @param preferredHeight Preferred height of the medium in pixel, use 0 to use the default height
75  * @param adjustFov True, to adjust the view's field of view to the field of the background automatically
76  * @return True, if succeeded
77  */
78  virtual bool setBackgroundMedium(const std::string& url, const std::string& type, const int preferredWidth, const int preferredHeight, const bool adjustFov);
79 
80  /**
81  * Sets the background medium of this view.
82  * @param frameMedium Background media object to set
83  * @param adjustFov True, to adjust the view's field of view to the field of view of the medium automatically
84  * @return True, if succeeded
85  */
86  virtual bool setBackgroundMedium(const Media::FrameMediumRef& frameMedium, const bool adjustFov = false);
87 
88  /**
89  * Returns the background medium.
90  * @return The view's background medium, if any
91  */
93 
94  /**
95  * View resize event function.
96  * @param width New view width, with range [1, infinity)
97  * @param height New view height, with range [1, infinity)
98  * @return True, if succeeded
99  */
100  bool resize(const int width, const int height) override;
101 
102  /**
103  * Renders the next frame.
104  * @return True, if succeeded
105  */
106  bool render() override;
107 
108  /**
109  * Converts the given screen positions into frame positions.
110  * @param xScreen Horizontal screen position, with range [0, infinity)
111  * @param yScreen Vertical screen position, with range [0, infinity)
112  * @param xFrame Resulting horizontal frame position, with range [0, infinity)
113  * @param yFrame Resulting vertical frame position, with range [0, infinity)
114  * @return True, if succeeded
115  */
116  bool screen2frame(const Scalar xScreen, const Scalar yScreen, Scalar& xFrame, Scalar& yFrame) override;
117 
118  /**
119  * Touch down event function.
120  * @param x Horizontal touch position
121  * @param y Vertical touch position
122  */
123  void onTouchDown(const float x, const float y) override;
124 
125  /**
126  * Touch move event function.
127  * @param x Horizontal touch position
128  * @param y Vertical touch position
129  */
130  void onTouchMove(const float x, const float y) override;
131 
132  /**
133  * Touch move event function.
134  * @param x Horizontal touch position
135  * @param y Vertical touch position
136  */
137  void onTouchUp(const float x, const float y) override;
138 
139  /**
140  * Creates an instance of this object.
141  * @return The new instance
142  */
143  static inline GLView* createInstance();
144 
145  protected:
146 
147  /**
148  * Creates a new view object.
149  */
150  GLFrameView() = default;
151 
152  /**
153  * Destructs a view object.
154  */
155  ~GLFrameView() override;
156 
157  protected:
158 
159  /// Rendering engine object.
161 
162  /// Rendering framebuffer object.
164 
165  /// Rendering undistorted background object.
167 
168  /// Initial viewport width.
169  unsigned int initialViewportWidth_ = (unsigned int)(-1);
170 
171  /// Initial viewport height.
172  unsigned int initialViewportHeight_ = (unsigned int)(-1);
173 
174  /// Previous horizontal touch position.
175  float previousTouchX_ = -1.0f;
176 
177  /// Previous vertical touch position.
178  float previousTouchY_ = -1.0f;
179 
180  /// Rendering start timestamp.
182 
183  /// Rendering iterations.
184  unsigned int renderingIterations_ = 0u;
185 
186  /// State determining that the view's field of view has to be adjusted to the background's field of view.
188 
189  /// The frame medium of the background which is stored as long as the view hasn't been initialized.
191 
192  /// True, to adjust the field of view of the view automatically so that the background medium is entirely covered.
193  bool intermediateBackgroundAdjustFov_ = false;
194 
195  /// View lock object.
196  mutable Lock lock_;
197 };
198 
200 {
201  return new GLFrameView();
202 }
203 
204 }
205 
206 }
207 
208 }
209 
210 }
211 
212 #endif // META_OCEAN_PLATFORM_ANDROID_APPLICATION_GL_FRAME_VIEW_H
This class implements a recursive lock object.
Definition: Lock.h:31
This class implements the main view of an OpenGLES frame for Android platform applications.
Definition: GLFrameView.h:40
bool screen2frame(const Scalar xScreen, const Scalar yScreen, Scalar &xFrame, Scalar &yFrame) override
Converts the given screen positions into frame positions.
void onTouchMove(const float x, const float y) override
Touch move event function.
virtual bool setBackgroundMedium(const Media::FrameMediumRef &frameMedium, const bool adjustFov=false)
Sets the background medium of this view.
bool initialize() override
Initializes the view.
virtual Media::FrameMediumRef backgroundMedium() const
Returns the background medium.
Lock lock_
View lock object.
Definition: GLFrameView.h:196
static GLView * createInstance()
Creates an instance of this object.
Definition: GLFrameView.h:199
Rendering::UndistortedBackgroundRef background_
Rendering undistorted background object.
Definition: GLFrameView.h:166
bool adjustFovXToBackground_
State determining that the view's field of view has to be adjusted to the background's field of view.
Definition: GLFrameView.h:187
bool release() override
Releases the view.
~GLFrameView() override
Destructs a view object.
bool resize(const int width, const int height) override
View resize event function.
virtual bool setBackgroundMedium(const std::string &url, const std::string &type, const int preferredWidth, const int preferredHeight, const bool adjustFov)
Sets the background medium of this view by the medium's url and several further parameters.
Media::FrameMediumRef intermediateBackgroundFrameMedium_
The frame medium of the background which is stored as long as the view hasn't been initialized.
Definition: GLFrameView.h:190
Rendering::FramebufferRef framebuffer_
Rendering framebuffer object.
Definition: GLFrameView.h:163
void onTouchUp(const float x, const float y) override
Touch move event function.
void onTouchDown(const float x, const float y) override
Touch down event function.
virtual bool setFovX(const Scalar fovx)
Sets the horizontal field of view for this view.
Rendering::EngineRef engine_
Rendering engine object.
Definition: GLFrameView.h:160
bool render() override
Renders the next frame.
Timestamp renderingStartTimestamp_
Rendering start timestamp.
Definition: GLFrameView.h:181
virtual bool setBackgroundColor(const RGBAColor &color)
Sets the background color of this view.
GLFrameView()=default
Creates a new view object.
This class implements the base class for all OpenGL-ES-based views.
Definition: GLView.h:35
This class implements a color defined by red, green, blue and alpha parameters.
Definition: RGBAColor.h:41
This class implements a timestamp.
Definition: Timestamp.h:36
float Scalar
Definition of a scalar type.
Definition: Math.h:128
SmartMediumRef< FrameMedium > FrameMediumRef
Definition of a smart medium reference holding a frame medium object.
Definition: FrameMedium.h:32
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15