[NUI] Adding VertexBuffer to replace PropertyBuffer (#1983)
authorDavidIanSteele <david.steele@samsung.com>
Mon, 14 Sep 2020 12:33:28 +0000 (13:33 +0100)
committerGitHub <noreply@github.com>
Mon, 14 Sep 2020 12:33:28 +0000 (13:33 +0100)
* [NUI] Adding VertexBuffer to replace PropertyBuffer

Native PropertyBuffer has been renamed to VertexBuffer.
Creating a new object to mirror this name change.

Changed SetData API to take an array of structs, and create
an unmanaged buffer before passing it to native side.

Signed-off-by: David Steele <david.steele@samsung.com>
* Update src/Tizen.NUI/src/public/Geometry.cs

Co-authored-by: Marcin Macias <40991900+m-macias@users.noreply.github.com>
* Update src/Tizen.NUI/src/public/VertexBuffer.cs

Co-authored-by: Marcin Macias <40991900+m-macias@users.noreply.github.com>
* Update VertexBuffer.cs

Fixed the tizen version in the documentation

* Update Geometry.cs

Changed if() throw style.

Co-authored-by: Marcin Macias <40991900+m-macias@users.noreply.github.com>
Co-authored-by: Adeel Kazmi <adeel.kazmi@samsung.com>
src/Tizen.NUI/src/internal/Interop/Interop.VertexBuffer.cs [new file with mode: 0644]
src/Tizen.NUI/src/public/Geometry.cs
src/Tizen.NUI/src/public/VertexBuffer.cs [new file with mode: 0644]

diff --git a/src/Tizen.NUI/src/internal/Interop/Interop.VertexBuffer.cs b/src/Tizen.NUI/src/internal/Interop/Interop.VertexBuffer.cs
new file mode 100644 (file)
index 0000000..256c7cf
--- /dev/null
@@ -0,0 +1,39 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Tizen.NUI
+{
+    internal static partial class Interop
+    {
+        internal static partial class VertexBuffer
+        {
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_VertexBuffer_SWIGUpcast")]
+            public static extern global::System.IntPtr VertexBuffer_SWIGUpcast(global::System.IntPtr jarg1);
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_VertexBuffer_New")]
+            public static extern global::System.IntPtr VertexBuffer_New(global::System.Runtime.InteropServices.HandleRef jarg1);
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_new_VertexBuffer__SWIG_0")]
+            public static extern global::System.IntPtr new_VertexBuffer__SWIG_0();
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_delete_VertexBuffer")]
+            public static extern void delete_VertexBuffer(global::System.Runtime.InteropServices.HandleRef jarg1);
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_new_VertexBuffer__SWIG_1")]
+            public static extern global::System.IntPtr new_VertexBuffer__SWIG_1(global::System.Runtime.InteropServices.HandleRef jarg1);
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_VertexBuffer_DownCast")]
+            public static extern global::System.IntPtr VertexBuffer_DownCast(global::System.Runtime.InteropServices.HandleRef jarg1);
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_VertexBuffer_Assign")]
+            public static extern global::System.IntPtr VertexBuffer_Assign(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2);
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_VertexBuffer_SetData")]
+            public static extern void VertexBuffer_SetData(global::System.Runtime.InteropServices.HandleRef jarg1, System.IntPtr jarg2, uint jarg3);
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_VertexBuffer_GetSize")]
+            public static extern uint VertexBuffer_GetSize(global::System.Runtime.InteropServices.HandleRef jarg1);
+        }
+    }
+}
\ No newline at end of file
index 93532a3..ebe90a5 100755 (executable)
@@ -97,6 +97,20 @@ namespace Tizen.NUI
         }
 
         /// <summary>
+        /// Adds a VertexBuffer to be used as source of geometry vertices.
+        /// </summary>
+        /// <param name="vertexBuffer">VertexBuffer to be used as source of geometry vertices.</param>
+        /// <returns>Index of the newly added buffer.</returns>
+        /// <since_tizen> 8 </since_tizen>
+        public uint AddVertexBuffer(VertexBuffer vertexBuffer)
+        {
+            uint ret = Interop.Geometry.Geometry_AddVertexBuffer(swigCPtr, VertexBuffer.getCPtr(vertexBuffer));
+            if (NDalicPINVOKE.SWIGPendingException.Pending) 
+                throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            return ret;
+        }
+
+        /// <summary>
         /// Retrieves the number of vertex buffers that have been added to this geometry.
         /// </summary>
         /// <returns>Number of vertex buffers that have been added to this geometry.</returns>
@@ -167,4 +181,4 @@ namespace Tizen.NUI
             Interop.Geometry.delete_Geometry(swigCPtr);
         }
     }
-}
\ No newline at end of file
+}
diff --git a/src/Tizen.NUI/src/public/VertexBuffer.cs b/src/Tizen.NUI/src/public/VertexBuffer.cs
new file mode 100644 (file)
index 0000000..8168720
--- /dev/null
@@ -0,0 +1,94 @@
+/*
+ * Copyright(c) 2020 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;
+using System.ComponentModel;
+using System.Runtime.InteropServices;
+
+namespace Tizen.NUI
+{
+    /// <summary>
+    /// VertexBuffer is a handle to an object that contains a buffer of structured data.<br />
+    /// VertexBuffers can be used to provide data to Geometry objects.
+    /// </summary>
+    /// <since_tizen> 8 </since_tizen>
+    public class VertexBuffer : BaseHandle
+    {
+
+        /// <summary>
+        /// Creates a VertexBuffer.
+        /// </summary>
+        /// <param name="bufferFormat">The map of names and types that describes the components of the buffer.</param>
+        /// <since_tizen> 8 </since_tizen>
+        public VertexBuffer(PropertyMap bufferFormat) : this(Interop.VertexBuffer.VertexBuffer_New(PropertyMap.getCPtr(bufferFormat)), true)
+        {
+            if (NDalicPINVOKE.SWIGPendingException.Pending) 
+                throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+        }
+
+        internal VertexBuffer(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.VertexBuffer.VertexBuffer_SWIGUpcast(cPtr), cMemoryOwn)
+        {
+        }
+
+        /// <summary>
+        /// Updates the whole buffer information.<br />
+        /// This function expects an array of structures with the same format that was given in the construction.
+        /// </summary>
+        /// <param name="vertices">The vertex data that will be copied to the buffer.</param>
+        /// <since_tizen> 8 </since_tizen>
+
+        public void SetData<VertexType>(VertexType[] vertices) where VertexType : struct
+        {
+            int structSize = Marshal.SizeOf<VertexType>();
+            global::System.IntPtr buffer = Marshal.AllocHGlobal(structSize * vertices.Length);
+
+            for (int i = 0; i < vertices.Length; i++)
+            {
+                Marshal.StructureToPtr(vertices[i], buffer + i * structSize, true);
+            }
+
+            Interop.VertexBuffer.VertexBuffer_SetData(swigCPtr, buffer, (uint)vertices.Length);
+            if (NDalicPINVOKE.SWIGPendingException.Pending) 
+                throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+        }
+
+        /// <summary>
+        /// Gets the number of elements in the buffer.
+        /// </summary>
+        /// <returns>Number of elements in the buffer.</returns>
+        /// <since_tizen> 8 </since_tizen>
+        public uint GetSize()
+        {
+            uint ret = Interop.VertexBuffer.VertexBuffer_GetSize(swigCPtr);
+            if (NDalicPINVOKE.SWIGPendingException.Pending) 
+                throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            return ret;
+        }
+
+        internal static global::System.Runtime.InteropServices.HandleRef getCPtr(VertexBuffer obj)
+        {
+            return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
+        }
+
+        /// This will not be public opened.
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
+        {
+            Interop.VertexBuffer.delete_VertexBuffer(swigCPtr);
+        }
+    }
+}