2 * Copyright(c) 2020 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 using System.ComponentModel;
20 using System.Runtime.InteropServices;
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.
28 /// <since_tizen> 8 </since_tizen>
29 public class VertexBuffer : BaseHandle
33 /// Creates a VertexBuffer.
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)
39 if (NDalicPINVOKE.SWIGPendingException.Pending)
40 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
43 internal VertexBuffer(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.VertexBuffer.VertexBuffer_SWIGUpcast(cPtr), cMemoryOwn)
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.
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>
55 public void SetData<VertexType>(VertexType[] vertices) where VertexType : struct
59 throw new ArgumentNullException(nameof(vertices));
62 int structSize = Marshal.SizeOf<VertexType>();
63 global::System.IntPtr buffer = Marshal.AllocHGlobal(structSize * vertices.Length);
65 for (int i = 0; i < vertices.Length; i++)
67 Marshal.StructureToPtr(vertices[i], buffer + i * structSize, true);
70 Interop.VertexBuffer.VertexBuffer_SetData(swigCPtr, buffer, (uint)vertices.Length);
71 if (NDalicPINVOKE.SWIGPendingException.Pending)
72 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
76 /// Gets the number of elements in the buffer.
78 /// <returns>Number of elements in the buffer.</returns>
79 /// <since_tizen> 8 </since_tizen>
82 uint ret = Interop.VertexBuffer.VertexBuffer_GetSize(swigCPtr);
83 if (NDalicPINVOKE.SWIGPendingException.Pending)
84 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
88 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(VertexBuffer obj)
90 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
93 /// This will not be public opened.
94 [EditorBrowsable(EditorBrowsableState.Never)]
95 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
97 Interop.VertexBuffer.delete_VertexBuffer(swigCPtr);