Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SamplerStateFactory"/> class.
        /// </summary>
        /// <param name="device">The device.</param>
        internal SamplerStateFactory(GraphicsDevice device) : base(device)
        {
            PointWrap      = SamplerState.New(device, new SamplerStateDescription(TextureFilter.Point, TextureAddressMode.Wrap)).DisposeBy(this);
            PointWrap.Name = "SamplerState.PointWrap";

            PointClamp      = SamplerState.New(device, new SamplerStateDescription(TextureFilter.Point, TextureAddressMode.Clamp)).DisposeBy(this);
            PointClamp.Name = "SamplerState.PointClamp";

            LinearWrap      = SamplerState.New(device, new SamplerStateDescription(TextureFilter.Linear, TextureAddressMode.Wrap)).DisposeBy(this);
            LinearWrap.Name = "SamplerState.LinearWrap";

            LinearClamp      = SamplerState.New(device, new SamplerStateDescription(TextureFilter.Linear, TextureAddressMode.Clamp)).DisposeBy(this);
            LinearClamp.Name = "SamplerState.LinearClamp";

            AnisotropicWrap      = SamplerState.New(device, new SamplerStateDescription(TextureFilter.Anisotropic, TextureAddressMode.Wrap)).DisposeBy(this);
            AnisotropicWrap.Name = "SamplerState.AnisotropicWrap";

            AnisotropicClamp      = SamplerState.New(device, new SamplerStateDescription(TextureFilter.Anisotropic, TextureAddressMode.Clamp)).DisposeBy(this);
            AnisotropicClamp.Name = "SamplerState.AnisotropicClamp";
        }
Example #2
0
        private ParameterKey UpdateResourceBindingKey(ref EffectParameterResourceData binding)
        {
            var keyName = binding.Param.KeyName;

            switch (binding.Param.Class)
            {
            case EffectParameterClass.Sampler:
                var newSamplerKey = (ParameterKey <SamplerState>)FindOrCreateResourceKey <SamplerState>(keyName);
                binding.Param.Key = newSamplerKey;
                var samplerBinding = reflection.SamplerStates.FirstOrDefault(x => x.KeyName == keyName);
                if (samplerBinding != null)
                {
                    samplerBinding.Key = newSamplerKey;
                    var samplerDescription = samplerBinding.Description;
                    defaultParameters.Set(newSamplerKey, SamplerState.New(graphicsDeviceDefault, samplerDescription));
                }
                break;

            case EffectParameterClass.ConstantBuffer:
            case EffectParameterClass.TextureBuffer:
            case EffectParameterClass.ShaderResourceView:
            case EffectParameterClass.UnorderedAccessView:
                switch (binding.Param.Type)
                {
                case EffectParameterType.Buffer:
                case EffectParameterType.ConstantBuffer:
                case EffectParameterType.TextureBuffer:
                case EffectParameterType.AppendStructuredBuffer:
                case EffectParameterType.ByteAddressBuffer:
                case EffectParameterType.ConsumeStructuredBuffer:
                case EffectParameterType.StructuredBuffer:
                case EffectParameterType.RWBuffer:
                case EffectParameterType.RWStructuredBuffer:
                case EffectParameterType.RWByteAddressBuffer:
                    binding.Param.Key = FindOrCreateResourceKey <Buffer>(keyName);
                    break;

                case EffectParameterType.Texture:
                case EffectParameterType.Texture1D:
                case EffectParameterType.Texture1DArray:
                case EffectParameterType.RWTexture1D:
                case EffectParameterType.RWTexture1DArray:
                case EffectParameterType.Texture2D:
                case EffectParameterType.Texture2DArray:
                case EffectParameterType.Texture2DMultisampled:
                case EffectParameterType.Texture2DMultisampledArray:
                case EffectParameterType.RWTexture2D:
                case EffectParameterType.RWTexture2DArray:
                case EffectParameterType.TextureCube:
                case EffectParameterType.TextureCubeArray:
                case EffectParameterType.RWTexture3D:
                case EffectParameterType.Texture3D:
                    binding.Param.Key = FindOrCreateResourceKey <Texture>(keyName);
                    break;
                }
                break;
            }

            if (binding.Param.Key == null)
            {
                throw new InvalidOperationException(string.Format("Unable to find/generate key [{0}] with unsupported type [{1}/{2}]", binding.Param.KeyName, binding.Param.Class, binding.Param.Type));
            }

            return(binding.Param.Key);
        }