public void Bind( D3D9.Device dev, D3D9.Volume volume, D3D9.BaseTexture mipTex ) { //Entering critical section LockDeviceAccess(); var bufferResources = GetBufferResources( dev ); var isNewBuffer = false; if ( bufferResources == null ) { bufferResources = new BufferResources(); this.mapDeviceToBufferResources.Add( dev, bufferResources ); isNewBuffer = true; } bufferResources.MipTex = mipTex; bufferResources.Volume = volume; var desc = volume.Description; width = desc.Width; height = desc.Height; depth = desc.Depth; format = D3D9Helper.ConvertEnum( desc.Format ); // Default rowPitch = Width; slicePitch = Height*Width; sizeInBytes = PixelUtil.GetMemorySize( Width, Height, Depth, Format ); if ( isNewBuffer && this.ownerTexture.IsManuallyLoaded ) { foreach ( var it in this.mapDeviceToBufferResources ) { if ( it.Value != bufferResources && it.Value.Volume != null && it.Key.TestCooperativeLevel().Success && dev.TestCooperativeLevel().Success ) { var fullBufferBox = new BasicBox( 0, 0, 0, Width, Height, Depth ); var dstBox = new PixelBox( fullBufferBox, Format ); var data = new byte[sizeInBytes]; using ( var d = BufferBase.Wrap( data ) ) { dstBox.Data = d; BlitToMemory( fullBufferBox, dstBox, it.Value, it.Key ); BlitFromMemory( dstBox, fullBufferBox, bufferResources ); Array.Clear( data, 0, sizeInBytes ); } break; } } } //Leaving critical section UnlockDeviceAccess(); }