[NUI] Implement missing properties for LottieAnimationView.
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / BaseComponents / GLView.cs
1 using System;
2 using System.ComponentModel;
3 using System.Runtime.InteropServices;
4 using Tizen.NUI.Binding;
5 using Tizen.NUI;
6
7 namespace Tizen.NUI.BaseComponents
8 {
9     /// <summary>
10     /// GLView allows drawing with OpenGL.
11     /// GLView creates a context, a surface, and a render thread.
12     /// The render thread invokes user's callbacks.
13     /// </summary>
14     /// <since_tizen> 10 </since_tizen>
15     public class GLView : View
16     {
17         private GLInitializeDelegate glInitializeCallback;
18         private GLRenderFrameDelegate glRenderFrameCallback;
19         private GLTerminateDelegate glTerminateCallback;
20         private ViewResizeDelegate viewResizeCallback;
21         private ViewResizeDelegate internalResizeCallback;
22
23         /// <summary>
24         /// Type of callback to initialize OpenGLES.
25         /// </summary>
26         /// <since_tizen> 10 </since_tizen>
27         public delegate void GLInitializeDelegate();
28
29         /// <summary>
30         /// Type of callback to render the frame with OpenGLES APIs.
31         /// If the return value of this callback is not 0, the eglSwapBuffers() will be called.
32         /// </summary>
33         /// <returns>The return value is not 0, the eglSwapBuffers() will be called.</returns>
34         /// <since_tizen> 10 </since_tizen>
35         public delegate int GLRenderFrameDelegate();
36
37         /// <summary>
38         /// Type of callback to clean up GL resource.
39         /// </summary>
40         /// <since_tizen> 10 </since_tizen>
41         public delegate void GLTerminateDelegate();
42
43         /// <summary>
44         /// Type of resize callback
45         /// </summary>
46         /// <param name="w">The resized width size of the GLView</param>
47         /// <param name="h">The resized height size of the GLView</param>
48         /// <since_tizen> 10 </since_tizen>
49         public delegate void ViewResizeDelegate(int w, int h);
50
51         internal GLView(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
52         {
53         }
54
55         /// <summary>
56         /// Creates an initialized GLView.
57         /// </summary>
58         /// <param name="colorFormat">The format of the color buffer</param>
59         /// <since_tizen> 10 </since_tizen>
60         public GLView(ColorFormat colorFormat) : this(Interop.GLView.New((int)colorFormat), true)
61         {
62             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
63         }
64
65         /// <summary>
66         /// Enumeration for the color format of the color buffer
67         /// </summary>
68         /// <since_tizen> 10 </since_tizen>
69         public enum ColorFormat
70         {
71             /// <summary>
72             /// 8 red bits, 8 green bits, 8 blue bits
73             /// </summary>
74             RGB888 = 0,
75
76             /// <summary>
77             /// 8 red bits, 8 green bits, 8 blue bits, alpha 8 bits
78             /// </summary>
79             RGBA8888
80         }
81
82         /// <summary>
83         /// Gets or sets the rendering mode of the GLView.
84         /// </summary>
85         /// <since_tizen> 10 </since_tizen>
86         public GLRenderingMode RenderingMode
87         {
88             get
89             {
90                 GLRenderingMode ret = (GLRenderingMode)Interop.GLView.GlViewGetRenderingMode(SwigCPtr);
91                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
92                 return ret;
93             }
94             set
95             {
96                 Interop.GLView.GlViewSetRenderingMode(SwigCPtr, (int)value);
97                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
98             }
99         }
100
101         /// <summary>
102         /// Registers GL callback functions to render with OpenGL ES
103         /// </summary>
104         /// <param name="glInit">The callback function for GL initialization</param>
105         /// <param name="glRenderFrame">The callback function to render the frame</param>
106         /// <param name="glTerminate">The callback function to clean up GL resources</param>
107         /// <since_tizen> 10 </since_tizen>
108         public void RegisterGLCallbacks(GLInitializeDelegate glInit, GLRenderFrameDelegate glRenderFrame, GLTerminateDelegate glTerminate)
109         {
110             glInitializeCallback = glInit;
111             HandleRef InitHandleRef = new HandleRef(this, Marshal.GetFunctionPointerForDelegate<Delegate>(glInitializeCallback));
112
113             glRenderFrameCallback = glRenderFrame;
114             HandleRef RenderHandlerRef = new HandleRef(this, Marshal.GetFunctionPointerForDelegate<Delegate>(glRenderFrameCallback));
115
116             glTerminateCallback = glTerminate;
117             HandleRef TerminateHandlerRef = new HandleRef(this, Marshal.GetFunctionPointerForDelegate<Delegate>(glTerminateCallback));
118
119             Interop.GLView.GlViewRegisterGlCallbacks(SwigCPtr, InitHandleRef, RenderHandlerRef, TerminateHandlerRef);
120
121             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
122         }
123
124         private void OnResized(int width, int height)
125         {
126             if (viewResizeCallback != null)
127             {
128                 viewResizeCallback(width, height);
129             }
130         }
131
132         /// <summary>
133         /// Sets the resize callback to the GLView.
134         /// When GLView is resized, the callback is invoked and it passes the width and height.
135         /// </summary>
136         /// <param name="callback">The resize callback function</param>
137         /// <since_tizen> 10 </since_tizen>
138         public void SetResizeCallback(ViewResizeDelegate callback)
139         {
140             viewResizeCallback = callback;
141
142             internalResizeCallback = OnResized;
143             Interop.GLView.GlViewSetResizeCallback(SwigCPtr, new HandleRef(this, Marshal.GetFunctionPointerForDelegate<Delegate>(internalResizeCallback)));
144             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
145         }
146
147         /// <summary>
148         /// Sets graphics configuration for the GLView
149         /// </summary>
150         /// <param name="depth">The flag of depth buffer. When the value is true, 24bit depth buffer is enabled.</param>
151         /// <param name="stencil">The flag of stencil. When the value is true, 8bit stencil buffer is enabled.</param>
152         /// <param name="msaa">The bit of MSAA</param>
153         /// <param name="version">The GLES version</param>
154         /// <returns>True if the config was successfully set, false otherwise.</returns>
155         /// <since_tizen> 10 </since_tizen>
156         public bool SetGraphicsConfig(bool depth, bool stencil, int msaa, GLESVersion version)
157         {
158             bool ret = Interop.GLView.GlViewSetGraphicsConfig(SwigCPtr, depth, stencil, msaa, (int)version);
159             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
160             return ret;
161         }
162
163         /// <summary>
164         /// Renders once more, even when paused.
165         /// </summary>
166         /// <since_tizen> 10 </since_tizen>
167         public void RenderOnce()
168         {
169             Interop.GLView.GlViewRenderOnce(SwigCPtr);
170             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
171         }
172     }
173 }