示例#1
0
        private void PlatformConstruct(
            GraphicsDevice graphicsDevice,
            ResourceUploadBatch uploadBatch,
            T[] data,
            uint sizeInBytes)
        {
            DeviceBuffer = AddDisposable(graphicsDevice.Device.CreateCommittedResource(
                                             new HeapProperties(HeapType.Default),
                                             HeapFlags.None,
                                             ResourceDescription.Buffer(SizeInBytes),
                                             ResourceStates.CopyDestination));

            uploadBatch.Upload(
                DeviceBuffer,
                new[]
            {
                new ResourceUploadData <T>
                {
                    Data        = data,
                    BytesPerRow = (int)sizeInBytes
                }
            });

            uploadBatch.Transition(
                DeviceBuffer,
                ResourceStates.CopyDestination,
                ResourceStates.VertexAndConstantBuffer);
        }
示例#2
0
        private void PlatformConstruct(
            GraphicsDevice graphicsDevice,
            ResourceUploadBatch uploadBatch,
            PixelFormat pixelFormat,
            int width,
            int height,
            TextureMipMapData[] mipMapData)
        {
            var resourceDescription = ResourceDescription.Texture2D(
                pixelFormat.ToDxgiFormat(),
                width,
                height,
                mipLevels: (short)mipMapData.Length);

            DeviceResource = AddDisposable(graphicsDevice.Device.CreateCommittedResource(
                                               new HeapProperties(HeapType.Default),
                                               HeapFlags.None,
                                               resourceDescription,
                                               ResourceStates.CopyDestination));

            var uploadData = new ResourceUploadData <byte> [mipMapData.Length];

            for (var i = 0; i < mipMapData.Length; i++)
            {
                uploadData[i] = new ResourceUploadData <byte>
                {
                    Data        = mipMapData[i].Data,
                    BytesPerRow = mipMapData[i].BytesPerRow
                };
            }

            uploadBatch.Upload(
                DeviceResource,
                uploadData);

            uploadBatch.Transition(
                DeviceResource,
                ResourceStates.CopyDestination,
                ResourceStates.NonPixelShaderResource | ResourceStates.PixelShaderResource);
        }