コード例 #1
0
        private void PlatformSetTexture(int index, Texture texture)
        {
            var deviceResource = texture?.DeviceResource;
            var format         = deviceResource?.Description.Format ?? SharpDX.DXGI.Format.BC1_UNorm;
            var dimension      = deviceResource?.Description.Dimension ?? ResourceDimension.Texture2D;

            var description = new ShaderResourceViewDescription
            {
                Shader4ComponentMapping = ComponentMappingUtility.DefaultComponentMapping(),
                Format = format
            };

            switch (dimension)
            {
            case ResourceDimension.Texture2D:
                description.Dimension           = ShaderResourceViewDimension.Texture2D;
                description.Texture2D.MipLevels = -1;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            GraphicsDevice.Device.CreateShaderResourceView(
                deviceResource,
                description,
                _cbvUavSrvPoolEntry.GetCpuHandle(index));
        }
コード例 #2
0
        private void PlatformSetStructuredBuffer <T>(int index, StaticBuffer <T> buffer)
            where T : struct
        {
            var deviceResource = buffer?.DeviceBuffer;

            var description = new ShaderResourceViewDescription
            {
                Shader4ComponentMapping = ComponentMappingUtility.DefaultComponentMapping(),
                Format = buffer != null
                    ? SharpDX.DXGI.Format.Unknown
                    : SharpDX.DXGI.Format.R32_UInt,
                Dimension = ShaderResourceViewDimension.Buffer,
                Buffer    =
                {
                    FirstElement        =                                      0,
                    ElementCount        = (int)(buffer?.ElementCount ?? 0),
                    StructureByteStride = (int)(buffer?.ElementSizeInBytes ?? 0),
                    Flags               = BufferShaderResourceViewFlags.None
                }
            };

            GraphicsDevice.Device.CreateShaderResourceView(
                deviceResource,
                description,
                _cbvUavSrvPoolEntry.GetCpuHandle(index));
        }