///<summary>
/// Internal implementation of <see cref="HardwareBuffer.Lock"/>.
///</summary>
protected override PixelBox LockImpl(BasicBox lockBox, BufferLocking options)
{
_lockedBox = lockBox;
// Set extents and format
var rval = new PixelBox(lockBox, Format);
var sizeInBytes = PixelUtil.GetMemorySize(lockBox.Width, lockBox.Height, lockBox.Depth,
XnaHelper.Convert(surface.Format));
if (_bufferBytes == null || _bufferBytes.Length != sizeInBytes)
{
_bufferBytes = new byte[sizeInBytes];
#if !SILVERLIGHT
if (surface != null)
{
surface.GetData(mipLevel, XnaHelper.ToRectangle(lockBox), _bufferBytes, 0, _bufferBytes.Length);
}
else if (cube != null)
{
cube.GetData(face, mipLevel, XnaHelper.ToRectangle(lockBox), _bufferBytes, 0, _bufferBytes.Length);
}
else
{
volume.GetData(mipLevel, lockBox.Left, lockBox.Top, lockBox.Right, lockBox.Bottom,
lockBox.Front, lockBox.Back, _bufferBytes, 0, _bufferBytes.Length);
}
#endif
}
rval.Data = BufferBase.Wrap(_bufferBytes);
return(rval);
}