/* * 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 { /// /// VertexBuffer is a handle to an object that contains a buffer of structured data.
/// VertexBuffers can be used to provide data to Geometry objects. ///
/// 8 public class VertexBuffer : BaseHandle { /// /// Creates a VertexBuffer. /// /// The map of names and types that describes the components of the buffer. /// 8 public VertexBuffer(PropertyMap bufferFormat) : this(Interop.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.Upcast(cPtr), cMemoryOwn) { } /// /// Updates the whole buffer information.
/// This function expects an array of structures with the same format that was given in the construction. ///
/// The vertex data that will be copied to the buffer. /// Thrown when vertices is null. /// 8 public void SetData(VertexType[] vertices) where VertexType : struct { if (null == vertices) { throw new ArgumentNullException(nameof(vertices)); } int structSize = Marshal.SizeOf(); 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.SetData(SwigCPtr, buffer, (uint)vertices.Length); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } /// /// Gets the number of elements in the buffer. /// /// Number of elements in the buffer. /// 8 public uint GetSize() { uint ret = Interop.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.DeleteVertexBuffer(swigCPtr); } } }