2 using System.ComponentModel;
3 using System.Runtime.InteropServices;
4 using Tizen.NUI.Binding;
7 namespace Tizen.NUI.BaseComponents
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.
14 /// <since_tizen> 10 </since_tizen>
15 public class GLView : View
17 private GLInitializeDelegate glInitializeCallback;
18 private GLRenderFrameDelegate glRenderFrameCallback;
19 private GLTerminateDelegate glTerminateCallback;
20 private ViewResizeDelegate viewResizeCallback;
21 private ViewResizeDelegate internalResizeCallback;
24 /// Type of callback to initialize OpenGLES.
26 /// <since_tizen> 10 </since_tizen>
27 public delegate void GLInitializeDelegate();
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.
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();
38 /// Type of callback to clean up GL resource.
40 /// <since_tizen> 10 </since_tizen>
41 public delegate void GLTerminateDelegate();
44 /// Type of resize callback
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);
51 internal GLView(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
56 /// Creates an initialized GLView.
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)
62 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
66 /// Enumeration for the color format of the color buffer
68 /// <since_tizen> 10 </since_tizen>
69 public enum ColorFormat
72 /// 8 red bits, 8 green bits, 8 blue bits
77 /// 8 red bits, 8 green bits, 8 blue bits, alpha 8 bits
83 /// Gets or sets the rendering mode of the GLView.
85 /// <since_tizen> 10 </since_tizen>
86 public GLRenderingMode RenderingMode
90 GLRenderingMode ret = (GLRenderingMode)Interop.GLView.GlViewGetRenderingMode(SwigCPtr);
91 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
96 Interop.GLView.GlViewSetRenderingMode(SwigCPtr, (int)value);
97 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
102 /// Registers GL callback functions to render with OpenGL ES
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)
110 glInitializeCallback = glInit;
111 HandleRef InitHandleRef = new HandleRef(this, Marshal.GetFunctionPointerForDelegate<Delegate>(glInitializeCallback));
113 glRenderFrameCallback = glRenderFrame;
114 HandleRef RenderHandlerRef = new HandleRef(this, Marshal.GetFunctionPointerForDelegate<Delegate>(glRenderFrameCallback));
116 glTerminateCallback = glTerminate;
117 HandleRef TerminateHandlerRef = new HandleRef(this, Marshal.GetFunctionPointerForDelegate<Delegate>(glTerminateCallback));
119 Interop.GLView.GlViewRegisterGlCallbacks(SwigCPtr, InitHandleRef, RenderHandlerRef, TerminateHandlerRef);
121 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
124 private void OnResized(int width, int height)
126 if (viewResizeCallback != null)
128 viewResizeCallback(width, height);
133 /// Sets the resize callback to the GLView.
134 /// When GLView is resized, the callback is invoked and it passes the width and height.
136 /// <param name="callback">The resize callback function</param>
137 /// <since_tizen> 10 </since_tizen>
138 public void SetResizeCallback(ViewResizeDelegate callback)
140 viewResizeCallback = callback;
142 internalResizeCallback = OnResized;
143 Interop.GLView.GlViewSetResizeCallback(SwigCPtr, new HandleRef(this, Marshal.GetFunctionPointerForDelegate<Delegate>(internalResizeCallback)));
144 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
148 /// Sets graphics configuration for the GLView
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)
158 bool ret = Interop.GLView.GlViewSetGraphicsConfig(SwigCPtr, depth, stencil, msaa, (int)version);
159 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
164 /// Renders once more, even when paused.
166 /// <since_tizen> 10 </since_tizen>
167 public void RenderOnce()
169 Interop.GLView.GlViewRenderOnce(SwigCPtr);
170 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();