1 #ifndef DALI_TOOLKIT_GL_VIEW_H
2 #define DALI_TOOLKIT_GL_VIEW_H
4 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
21 #include <dali-toolkit/public-api/controls/control.h>
27 namespace Internal DALI_INTERNAL
33 * @brief GlView is a class for rendering with GL
35 * GlView allows drawing with OpenGL.
36 * GlView creates a GL context, a GL surface and a render thread.
37 * The render thread invokes user's callbacks.
40 class DALI_TOOLKIT_API GlView : public Dali::Toolkit::Control
44 * @brief Enumeration for rendering mode
46 * This Enumeration is used to choose the rendering mode.
48 * One of them is continuous mode. It is rendered continuously.
49 * The other is on demand mode. It is rendered by application.
51 enum class RenderingMode
53 CONTINUOUS, ///< continuous mode
54 ON_DEMAND ///< on demand by application
58 * @brief Enumeration for Graphics API version
60 * This Enumeration is used to set a GLES version for EGL configuration.
62 enum class GraphicsApiVersion
64 GLES_VERSION_2_0 = 0, ///< GLES version 2.0
65 GLES_VERSION_3_0, ///< GLES version 3.0
69 * @brief Enumeration for color buffer format
71 * This Enumeration is used to set a color buffer format of GlView
73 enum class ColorFormat
75 RGB888, ///< 8 red bits, 8 green bits, 8 blue bits
76 RGBA8888 ///< 8 red bits, 8 green bits, 8 blue bits, alpha 8 bits
80 * @brief Creates a GlView control.
81 * @param[in] colorFormat the format of the color buffer.
82 * @return A handle to a GlView control
84 static GlView New(ColorFormat colorFormat);
87 * @brief Creates an uninitialized GlView.
94 * This is non-virtual since derived Handle types must not contain data or virtual methods.
99 * @brief Copy constructor.
101 * @param[in] GlView GlView to copy. The copied GlView will point at the same implementation
103 GlView(const GlView& GlView);
106 * @brief Move constructor
108 * @param[in] rhs A reference to the moved handle
110 GlView(GlView&& rhs);
113 * @brief Assignment operator.
115 * @param[in] GlView The GlView to assign from
116 * @return A reference to this
118 GlView& operator=(const GlView& GlView);
121 * @brief Move assignment
123 * @param[in] rhs A reference to the moved handle
124 * @return A reference to this
126 GlView& operator=(GlView&& rhs);
129 * @brief Downcasts a handle to GlView handle.
131 * If handle points to a GlView, the downcast produces valid handle.
132 * If not, the returned handle is left uninitialized.
134 * @param[in] handle Handle to an object
135 * @return Handle to a GlView or an uninitialized handle
137 static GlView DownCast(BaseHandle handle);
140 * @brief Registers GL callback functions for GlView.
142 * @param[in] initCallback the callback function to create GL resources.
143 * @param[in] renderFrameCallback the callback function to render for the frame.
144 * @param[in] terminateCallback the callback function to clean-up GL resources.
146 * A initCallback of the following type have to be used:
148 * void intializeGL();
150 * This callback will be called before renderFrame callback is called once.
152 * A renderFrameCallback of the following type have to be used:
154 * int renderFrameGL();
156 * If the return value of this callback is not 0, the eglSwapBuffers() will be called.
158 * A terminateCallback of the following type have to be used:
160 * void terminateGL();
162 * This callback is called when GlView is deleted.
164 * @note Ownership of the callbacks is passed onto this class.
165 * <b>You can't call Dali APIs in your callbacks because it is invoked in GlView's own render thread.</b>
166 * And this must be called before adding GlView to the scene.
168 void RegisterGlCallback(CallbackBase* initCallback, CallbackBase* renderFrameCallback, CallbackBase* terminateCallback);
171 * @brief Sets the ResizeCallback of the GlView.
172 * When GlView is resized, ResizeCallback would be invoked.
173 * You can get the resized width and height of the GlView.
175 * @param[in] resizeCallback The ResizeCallback function
177 * A resizeCallback of the following type have to be used:
179 * void resizeCallback(int width, int height);
182 * @note Ownership of the callback is passed onto this class.
183 * <b>You can't call Dali APIs in your callback because it is invoked in GlView's own render thread.</b>
184 * And this must be called before adding GlView to the scene.
186 void SetResizeCallback(CallbackBase* resizeCallback);
189 * @brief Sets the rendering mode.
191 * @param[in] mode the rendering mode for GlView
193 * @note The default Rendering mode is CONTINUOUS.
194 * If ON_DEMAND mode is set, it is rendered by RenderOnce()
196 void SetRenderingMode(RenderingMode mode);
199 * @brief Gets the rendering mode.
201 RenderingMode GetRenderingMode() const;
204 * @brief Sets egl configuration for GlView
206 * @param[in] depth the flag of depth buffer. If the value is true, 24bit depth buffer is enabled.
207 * @param[in] stencil the flag of stencil. If the value is true, 8bit stencil buffer is enabled.
208 * @param[in] msaa the expected sampling number per pixel.
209 * @param[in] version the graphics API version
210 * @return True if the config exists, false otherwise.
212 bool SetGraphicsConfig(bool depth, bool stencil, int msaa, GraphicsApiVersion version);
215 * @brief Renders once more even if GL render functions are not added to idler.
216 * @note Will not work if the window is hidden or GL render functions are added to idler
220 public: // Not intended for application developers
223 * @brief Creates a handle using the Toolkit::Internal implementation.
224 * @param[in] implementation The GlView implementation
226 DALI_INTERNAL GlView(Internal::GlView& implementation);
229 * @brief Allows the creation of this GlView from an Internal::CustomActor pointer.
230 * @param[in] internal A pointer to the internal CustomActor
232 DALI_INTERNAL GlView(Dali::Internal::CustomActor* internal);
236 } // namespace Toolkit
240 #endif // DALI_TOOLKIT_GL_VIEW_H