--- /dev/null
+/*
+ * Copyright(c) 2021 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+using System.Runtime.InteropServices;
+
+namespace Tizen.NUI
+{
+ internal static partial class Interop
+ {
+ internal static partial class GLView
+ {
+ [DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_GlView_New_SWIG")]
+ public static extern global::System.IntPtr New(int nuiColorFormat);
+
+ [DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_new_GlView_SWIG_0")]
+ public static extern global::System.IntPtr NewGlView();
+
+ [DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_new_GlView_SWIG_1")]
+ public static extern global::System.IntPtr NewGlView(HandleRef nuiGlView);
+
+ [DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_delete_GlView")]
+ public static extern void DeleteGlView(HandleRef nuiGlView);
+
+ [DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_GlView_Assign")]
+ public static extern global::System.IntPtr GlViewAssign(HandleRef nuiGlView1, HandleRef nuiGlView2);
+
+ [DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_GlView_RegisterGlCallbacks")]
+ public static extern void GlViewRegisterGlCallbacks(HandleRef nuiGlView, HandleRef nuiInitCB, HandleRef nuiRenderFrameCB, HandleRef nuiTerminateCB);
+
+ [DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_GlView_SetResizeCallback")]
+ public static extern void GlViewSetResizeCallback(HandleRef nuiGlView, HandleRef nuiResizeCB);
+
+ [DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_GlView_SetGraphicsConfig")]
+ [return: global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.U1)]
+ public static extern bool GlViewSetGraphicsConfig(HandleRef nuiGlView, bool nuiDepth, bool nuiStencil, int nuiMsaa, int nuiVersion);
+
+ [DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_GlView_SetRenderingMode")]
+ public static extern void GlViewSetRenderingMode(HandleRef nuiGlView, int nuiRenderingMode);
+
+ [DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_GlView_GetRenderingMode")]
+ public static extern global::System.IntPtr GlViewGetRenderingMode(HandleRef nuiGlView);
+
+ [DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_GlView_RenderOnce")]
+ public static extern void GlViewRenderOnce(HandleRef nuiGlView);
+ }
+ }
+}
--- /dev/null
+using System;
+using System.ComponentModel;
+using System.Runtime.InteropServices;
+using Tizen.NUI.Binding;
+using Tizen.NUI;
+
+namespace Tizen.NUI.BaseComponents
+{
+ /// <summary>
+ /// GLView allows drawing with OpenGL.
+ /// GLView creates a context, a surface, and a render thread.
+ /// The render thread invokes user's callbacks.
+ /// </summary>
+ /// <since_tizen> 9 </since_tizen>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public class GLView : View
+ {
+ private GLInitializeDelegate glInitializeCallback;
+ private GLRenderFrameDelegate glRenderFrameCallback;
+ private GLTerminateDelegate glTerminateCallback;
+ private ViewResizeDelegate viewResizeCallback;
+ private ViewResizeDelegate internalResizeCallback;
+
+ /// <summary>
+ /// Type of callback to initialize OpenGLES.
+ /// </summary>
+ /// <since_tizen> 9 </since_tizen>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public delegate void GLInitializeDelegate();
+
+ /// <summary>
+ /// Type of callback to render the frame with OpenGLES APIs.
+ /// If the return value of this callback is not 0, the eglSwapBuffers() will be called.
+ /// </summary>
+ /// <returns>The return value is not 0, the eglSwapBuffers() will be called.</returns>
+ /// <since_tizen> 9 </since_tizen>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public delegate int GLRenderFrameDelegate();
+
+ /// <summary>
+ /// Type of callback to clean up GL resource.
+ /// </summary>
+ /// <since_tizen> 9 </since_tizen>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public delegate void GLTerminateDelegate();
+
+ /// <summary>
+ /// Type of resize callback
+ /// </summary>
+ /// <param name="w">The resized width size of the GLView</param>
+ /// <param name="h">The resized height size of the GLView</param>
+ /// <since_tizen> 9 </since_tizen>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public delegate void ViewResizeDelegate(int w, int h);
+
+ internal GLView(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
+ {
+ }
+
+ /// <summary>
+ /// Creates an initialized GLView.
+ /// </summary>
+ /// <param name="colorFormat">The format of the color buffer</param>
+ /// <since_tizen> 9 </since_tizen>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public GLView(ColorFormat colorFormat) : this(Interop.GLView.New((int)colorFormat), true)
+ {
+ if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+ }
+
+ /// <summary>
+ /// Enumeration for the color format of the color buffer
+ /// </summary>
+ /// <since_tizen> 9 </since_tizen>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public enum ColorFormat
+ {
+ /// <summary>
+ /// 8 red bits, 8 green bits, 8 blue bits
+ /// </summary>
+ /// <since_tizen> 9 </since_tizen>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ RGB888 = 0,
+
+ /// <summary>
+ /// 8 red bits, 8 green bits, 8 blue bits, alpha 8 bits
+ /// </summary>
+ /// <since_tizen> 9 </since_tizen>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ RGBA8888
+ }
+
+ /// <summary>
+ /// Gets or sets the rendering mode of the GLView.
+ /// </summary>
+ /// <since_tizen> 9 </since_tizen>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public GLRenderingMode RenderingMode
+ {
+ get
+ {
+ GLRenderingMode ret = (GLRenderingMode)Interop.GLView.GlViewGetRenderingMode(SwigCPtr);
+ if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+ return ret;
+ }
+ set
+ {
+ Interop.GLView.GlViewSetRenderingMode(SwigCPtr, (int)value);
+ if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+ }
+ }
+
+ /// <summary>
+ /// Registers GL callback functions to render with OpenGL ES
+ /// </summary>
+ /// <param name="glInit">The callback function for GL initialization</param>
+ /// <param name="glRenderFrame">The callback function to render the frame</param>
+ /// <param name="glTerminate">The callback function to clean up GL resources</param>
+ /// <since_tizen> 9 </since_tizen>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public void RegisterGLCallbacks(GLInitializeDelegate glInit, GLRenderFrameDelegate glRenderFrame, GLTerminateDelegate glTerminate)
+ {
+ glInitializeCallback = glInit;
+ HandleRef InitHandleRef = new HandleRef(this, Marshal.GetFunctionPointerForDelegate<Delegate>(glInitializeCallback));
+
+ glRenderFrameCallback = glRenderFrame;
+ HandleRef RenderHandlerRef = new HandleRef(this, Marshal.GetFunctionPointerForDelegate<Delegate>(glRenderFrameCallback));
+
+ glTerminateCallback = glTerminate;
+ HandleRef TerminateHandlerRef = new HandleRef(this, Marshal.GetFunctionPointerForDelegate<Delegate>(glTerminateCallback));
+
+ Interop.GLView.GlViewRegisterGlCallbacks(SwigCPtr, InitHandleRef, RenderHandlerRef, TerminateHandlerRef);
+
+ if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+ }
+
+ private void OnResized(int width, int height)
+ {
+ if (viewResizeCallback != null)
+ {
+ viewResizeCallback(width, height);
+ }
+ }
+
+ /// <summary>
+ /// Sets the resize callback to the GLView.
+ /// When GLView is resized, the callback is invoked and it passes the width and height.
+ /// </summary>
+ /// <param name="callback">The resize callback function</param>
+ /// <since_tizen> 9 </since_tizen>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public void SetResizeCallback(ViewResizeDelegate callback)
+ {
+ viewResizeCallback = callback;
+
+ internalResizeCallback = OnResized;
+ Interop.GLView.GlViewSetResizeCallback(SwigCPtr, new HandleRef(this, Marshal.GetFunctionPointerForDelegate<Delegate>(internalResizeCallback)));
+ if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+ }
+
+ /// <summary>
+ /// Sets graphics configuration for the GLView
+ /// </summary>
+ /// <param name="depth">The flag of depth buffer. When the value is true, 24bit depth buffer is enabled.</param>
+ /// <param name="stencil">The flag of stencil. When the value is true, 8bit stencil buffer is enabled.</param>
+ /// <param name="msaa">The bit of MSAA</param>
+ /// <param name="version">The GLES version</param>
+ /// <returns>True if the config was successfully set, false otherwise.</returns>
+ /// <since_tizen> 9 </since_tizen>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public bool SetGraphicsConfig(bool depth, bool stencil, int msaa, GLESVersion version)
+ {
+ bool ret = Interop.GLView.GlViewSetGraphicsConfig(SwigCPtr, depth, stencil, msaa, (int)version);
+ if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+ return ret;
+ }
+
+ /// <summary>
+ /// Renders once more, even when paused.
+ /// </summary>
+ /// <since_tizen> 9 </since_tizen>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public void RenderOnce()
+ {
+ Interop.GLView.GlViewRenderOnce(SwigCPtr);
+ if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+ }
+ }
+}
\ No newline at end of file