Exemplo n.º 1
0
        /// <summary cref="DirectXBuffer.OnMap(DeviceContext)"/>
        protected override unsafe IntPtr OnMap(DeviceContext context)
        {
            Debug.Assert(box.IsEmpty);

            // Copy the texture into the staging texture
            if (ViewFlags != DirectXViewFlags.WriteDiscard)
            {
                context.CopyResource(Texture, stagingTexture);
            }

            var mapMode = CPUDirectXAccelerator.ConvertToMapMode(ViewFlags);

            box = context.MapSubresource(stagingTexture, 0, mapMode, MapFlags.None);

            // Reserve enough space
            var lengthInBytes = box.SlicePitch;

            EnsureSpace(lengthInBytes);

            if (ViewFlags != DirectXViewFlags.WriteDiscard)
            {
                // Copy the contents of the staging texture into the CPU-memory buffer
                System.Buffer.MemoryCopy(
                    box.DataPointer.ToPointer(),
                    cpuMemory.NativePtr.ToPointer(),
                    lengthInBytes,
                    lengthInBytes);
            }
            return(cpuMemory.NativePtr);
        }
Exemplo n.º 2
0
        /// <summary cref="DirectXBuffer.OnMap(DeviceContext)"/>
        protected override unsafe IntPtr OnMap(DeviceContext context)
        {
            Debug.Assert(box.IsEmpty);
            var mapMode = CPUDirectXAccelerator.ConvertToMapMode(ViewFlags);

            // Copy the buffer to the staging buffer
            if (ViewFlags != DirectXViewFlags.WriteDiscard)
            {
                context.CopyResource(Buffer, stagingBuffer);
            }
            box = context.MapSubresource(stagingBuffer, 0, mapMode, MapFlags.None);

            // We have to copy the contents of the DX buffer into the CPU-memory buffer
            if (ViewFlags != DirectXViewFlags.WriteDiscard)
            {
                System.Buffer.MemoryCopy(
                    box.DataPointer.ToPointer(),
                    cpuMemory.NativePtr.ToPointer(),
                    cpuMemory.LengthInBytes,
                    cpuMemory.LengthInBytes);
            }
            return(cpuMemory.NativePtr);
        }