Merge remote-tracking branch 'origin/master' into tizen
[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.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.VertexBuffer_SWIGUpcast(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         /// <since_tizen> 8 </since_tizen>
53
54         public void SetData<VertexType>(VertexType[] vertices) where VertexType : struct
55         {
56             int structSize = Marshal.SizeOf<VertexType>();
57             global::System.IntPtr buffer = Marshal.AllocHGlobal(structSize * vertices.Length);
58
59             for (int i = 0; i < vertices.Length; i++)
60             {
61                 Marshal.StructureToPtr(vertices[i], buffer + i * structSize, true);
62             }
63
64             Interop.VertexBuffer.VertexBuffer_SetData(swigCPtr, buffer, (uint)vertices.Length);
65             if (NDalicPINVOKE.SWIGPendingException.Pending) 
66                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
67         }
68
69         /// <summary>
70         /// Gets the number of elements in the buffer.
71         /// </summary>
72         /// <returns>Number of elements in the buffer.</returns>
73         /// <since_tizen> 8 </since_tizen>
74         public uint GetSize()
75         {
76             uint ret = Interop.VertexBuffer.VertexBuffer_GetSize(swigCPtr);
77             if (NDalicPINVOKE.SWIGPendingException.Pending) 
78                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
79             return ret;
80         }
81
82         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(VertexBuffer obj)
83         {
84             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
85         }
86
87         /// This will not be public opened.
88         [EditorBrowsable(EditorBrowsableState.Never)]
89         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
90         {
91             Interop.VertexBuffer.delete_VertexBuffer(swigCPtr);
92         }
93     }
94 }