[NUI] Fixing the emtpy finalizers(CA1821)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / VertexBuffer.cs
1 /*
2  * Copyright(c) 2020 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 using System;
19 using System.ComponentModel;
20 using System.Runtime.InteropServices;
21
22 namespace Tizen.NUI
23 {
24     /// <summary>
25     /// VertexBuffer is a handle to an object that contains a buffer of structured data.<br />
26     /// VertexBuffers can be used to provide data to Geometry objects.
27     /// </summary>
28     /// <since_tizen> 8 </since_tizen>
29     public class VertexBuffer : BaseHandle
30     {
31
32         /// <summary>
33         /// Creates a VertexBuffer.
34         /// </summary>
35         /// <param name="bufferFormat">The map of names and types that describes the components of the buffer.</param>
36         /// <since_tizen> 8 </since_tizen>
37         public VertexBuffer(PropertyMap bufferFormat) : this(Interop.VertexBuffer.New(PropertyMap.getCPtr(bufferFormat)), true)
38         {
39             if (NDalicPINVOKE.SWIGPendingException.Pending)
40                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
41         }
42
43         internal VertexBuffer(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.VertexBuffer.Upcast(cPtr), cMemoryOwn)
44         {
45         }
46
47         /// <summary>
48         /// Updates the whole buffer information.<br />
49         /// This function expects an array of structures with the same format that was given in the construction.
50         /// </summary>
51         /// <param name="vertices">The vertex data that will be copied to the buffer.</param>
52         /// <exception cref="ArgumentNullException"> Thrown when vertices is null. </exception>
53         /// <since_tizen> 8 </since_tizen>
54
55         public void SetData<VertexType>(VertexType[] vertices) where VertexType : struct
56         {
57             if (null == vertices)
58             {
59                 throw new ArgumentNullException(nameof(vertices));
60             }
61
62             int structSize = Marshal.SizeOf<VertexType>();
63             global::System.IntPtr buffer = Marshal.AllocHGlobal(structSize * vertices.Length);
64
65             for (int i = 0; i < vertices.Length; i++)
66             {
67                 Marshal.StructureToPtr(vertices[i], buffer + i * structSize, true);
68             }
69
70             Interop.VertexBuffer.SetData(SwigCPtr, buffer, (uint)vertices.Length);
71             if (NDalicPINVOKE.SWIGPendingException.Pending)
72                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
73         }
74
75         /// <summary>
76         /// Gets the number of elements in the buffer.
77         /// </summary>
78         /// <returns>Number of elements in the buffer.</returns>
79         /// <since_tizen> 8 </since_tizen>
80         public uint GetSize()
81         {
82             uint ret = Interop.VertexBuffer.GetSize(SwigCPtr);
83             if (NDalicPINVOKE.SWIGPendingException.Pending)
84                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
85             return ret;
86         }
87
88         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(VertexBuffer obj)
89         {
90             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.SwigCPtr;
91         }
92
93         /// This will not be public opened.
94         [EditorBrowsable(EditorBrowsableState.Never)]
95         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
96         {
97             Interop.VertexBuffer.DeleteVertexBuffer(swigCPtr);
98         }
99     }
100 }