[NUI] Add GLView
authorDaekwang Ryu <dkdk.ryu@samsung.com>
Wed, 20 Oct 2021 04:26:09 +0000 (13:26 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Tue, 9 Nov 2021 05:57:53 +0000 (14:57 +0900)
GLView allows drawing with OpenGL.
It creates a context, a surface and a render thread.
The render thread invokes user's callbacks.

src/Tizen.NUI/src/internal/Interop/Interop.GLView.cs [new file with mode: 0644]
src/Tizen.NUI/src/public/BaseComponents/GLView.cs [new file with mode: 0644]
src/Tizen.NUI/src/public/Common/NUIConstants.cs

diff --git a/src/Tizen.NUI/src/internal/Interop/Interop.GLView.cs b/src/Tizen.NUI/src/internal/Interop/Interop.GLView.cs
new file mode 100644 (file)
index 0000000..a63f325
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * 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);
+        }
+    }
+}
diff --git a/src/Tizen.NUI/src/public/BaseComponents/GLView.cs b/src/Tizen.NUI/src/public/BaseComponents/GLView.cs
new file mode 100644 (file)
index 0000000..fc91f51
--- /dev/null
@@ -0,0 +1,189 @@
+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
index d8b3a6e..65706a3 100755 (executable)
@@ -1950,43 +1950,38 @@ namespace Tizen.NUI
     /// If the device can not support GLES version 3.0 over, the version will be chosen with GLES version 2.0.<br />
     /// It is for GLWindow and GLView.<br />
     /// </summary>
+    /// <since_tizen> 9 </since_tizen>
     [EditorBrowsable(EditorBrowsableState.Never)]
     public enum GLESVersion
     {
       /// <summary>
       /// GLES version 2.0
       /// </summary>
-      [EditorBrowsable(EditorBrowsableState.Never)]
       Version20 = 0,
 
       /// <summary>
       /// GLES version 3.0
       /// </summary>
-      [EditorBrowsable(EditorBrowsableState.Never)]
       Version30
     }
 
     /// <summary>
     /// Enumeration for rendering mode
     /// This Enumeration is used to choose the rendering mode.
-    /// It has two options.
-    /// One of them is continuous mode. It is rendered continuously.
-    /// The other is on demand mode. It is rendered by application.
     /// It is for GLWindow and GLView.
     /// </summary>
+    /// <since_tizen> 9 </since_tizen>
     [EditorBrowsable(EditorBrowsableState.Never)]
     public enum GLRenderingMode
     {
       /// <summary>
-      /// continuous mode
+      /// The render frame delegate is invoked continuously.
       /// </summary>
-      [EditorBrowsable(EditorBrowsableState.Never)]
       Continuous = 0,
 
       /// <summary>
-      /// on demand by application
+      /// The render frame delegate is invoked by user.
       /// </summary>
-      [EditorBrowsable(EditorBrowsableState.Never)]
       OnDemand = 1
     }