/// <summary> /// Used to lock a vertex buffer in hardware memory in order to make modifications. /// </summary> /// <param name="offset">Starting index in the buffer to lock.</param> /// <param name="length">Nunber of bytes to lock after the offset.</param> /// <param name="locking">Specifies how to lock the buffer.</param> /// <returns>An array of the <code>System.Type</code> associated with this VertexBuffer.</returns> public virtual IntPtr Lock(int offset, int length, BufferLocking locking) { Debug.Assert(!isLocked, "Cannot lock this buffer because it is already locked."); IntPtr data = IntPtr.Zero; if (useShadowBuffer) { if (locking != BufferLocking.ReadOnly) { // we have to assume a read / write lock so we use the shadow buffer // and tag for sync on Unlock() shadowUpdated = true; } data = shadowBuffer.Lock(offset, length, locking); } else { // lock the real deal and flag it as locked data = this.LockImpl(offset, length, locking); isLocked = true; } lockStart = offset; lockSize = length; return(data); }
/// <summary> /// Copy data from another buffer into this one. /// </summary> /// <param name="srcBuffer">The buffer from which to read the copied data.</param> /// <param name="srcOffset">Offset in the source buffer at which to start reading.</param> /// <param name="destOffset">Offset in the destination buffer to start writing.</param> /// <param name="length">Length of the data to copy, in bytes.</param> /// <param name="discardWholeBuffer">If true, will discard the entire contents of this buffer before copying.</param> public virtual void CopyData(HardwareBuffer srcBuffer, int srcOffset, int destOffset, int length, bool discardWholeBuffer) { // lock the source buffer IntPtr srcData = srcBuffer.Lock(srcOffset, length, BufferLocking.ReadOnly); // write the data to this buffer this.WriteData(destOffset, length, srcData, discardWholeBuffer); // unlock the source buffer srcBuffer.Unlock(); }