Exemple #1
0
        public void CreateSampler(VkFilter minFilter             = VkFilter.Linear, VkFilter magFilter = VkFilter.Linear,
                                  VkSamplerMipmapMode mipmapMode = VkSamplerMipmapMode.Linear, VkSamplerAddressMode addressMode = VkSamplerAddressMode.Repeat,
                                  float maxAnisotropy            = 1.0f, float minLod = 0.0f, float maxLod = -1f)
        {
            VkSampler           sampler;
            VkSamplerCreateInfo sampInfo = VkSamplerCreateInfo.New();

            sampInfo.maxAnisotropy = maxAnisotropy;
            sampInfo.maxAnisotropy = 1.0f;            // device->enabledFeatures.samplerAnisotropy ? device->properties.limits.maxSamplerAnisotropy : 1.0f;
            //samplerInfo.anisotropyEnable = device->enabledFeatures.samplerAnisotropy;
            sampInfo.addressModeU = addressMode;
            sampInfo.addressModeV = addressMode;
            sampInfo.addressModeW = addressMode;
            sampInfo.magFilter    = magFilter;
            sampInfo.minFilter    = minFilter;
            sampInfo.mipmapMode   = mipmapMode;
            sampInfo.minLod       = minLod;
            sampInfo.maxLod       = maxLod < 0f ? info.mipLevels : maxLod;

            Utils.CheckResult(vkCreateSampler(Dev.VkDev, ref sampInfo, IntPtr.Zero, out sampler));

            if (Descriptor.sampler.Handle != 0)
            {
                Dev.DestroySampler(Descriptor.sampler);
            }
            Descriptor.sampler = sampler;
        }
Exemple #2
0
 internal static void GetFilterParams(
     SamplerFilter filter,
     out VkFilter minFilter,
     out VkFilter magFilter,
     out VkSamplerMipmapMode mipmapMode)
 {
     switch (filter)
     {
         case SamplerFilter.Anisotropic:
             minFilter = VkFilter.Linear;
             magFilter = VkFilter.Linear;
             mipmapMode = VkSamplerMipmapMode.Linear;
             break;
         case SamplerFilter.MinPoint_MagPoint_MipPoint:
             minFilter = VkFilter.Nearest;
             magFilter = VkFilter.Nearest;
             mipmapMode = VkSamplerMipmapMode.Nearest;
             break;
         case SamplerFilter.MinPoint_MagPoint_MipLinear:
             minFilter = VkFilter.Nearest;
             magFilter = VkFilter.Nearest;
             mipmapMode = VkSamplerMipmapMode.Linear;
             break;
         case SamplerFilter.MinPoint_MagLinear_MipPoint:
             minFilter = VkFilter.Nearest;
             magFilter = VkFilter.Linear;
             mipmapMode = VkSamplerMipmapMode.Nearest;
             break;
         case SamplerFilter.MinPoint_MagLinear_MipLinear:
             minFilter = VkFilter.Nearest;
             magFilter = VkFilter.Linear;
             mipmapMode = VkSamplerMipmapMode.Linear;
             break;
         case SamplerFilter.MinLinear_MagPoint_MipPoint:
             minFilter = VkFilter.Linear;
             magFilter = VkFilter.Nearest;
             mipmapMode = VkSamplerMipmapMode.Nearest;
             break;
         case SamplerFilter.MinLinear_MagPoint_MipLinear:
             minFilter = VkFilter.Linear;
             magFilter = VkFilter.Nearest;
             mipmapMode = VkSamplerMipmapMode.Linear;
             break;
         case SamplerFilter.MinLinear_MagLinear_MipPoint:
             minFilter = VkFilter.Linear;
             magFilter = VkFilter.Linear;
             mipmapMode = VkSamplerMipmapMode.Nearest;
             break;
         case SamplerFilter.MinLinear_MagLinear_MipLinear:
             minFilter = VkFilter.Linear;
             magFilter = VkFilter.Linear;
             mipmapMode = VkSamplerMipmapMode.Linear;
             break;
         default:
             throw Illegal.Value<SamplerFilter>();
     }
 }
Exemple #3
0
 public SamplerDescription(float maxLod, float minLod, VkCompareOp compareOp, bool compareEnable, float mipLodBias,
                           VkSamplerAddressMode addressModeW, VkSamplerAddressMode addressModeV, VkSamplerAddressMode addressModeU,
                           VkSamplerMipmapMode mipmapMode, VkFilter minFilter, VkFilter magFilter, VkBorderColor borderColor, bool unNormalizedCoordinates)
 {
     MaxLod                  = maxLod;
     MinLod                  = minLod;
     CompareOp               = compareOp;
     CompareEnable           = compareEnable;
     MipLodBias              = mipLodBias;
     AddressModeW            = addressModeW;
     AddressModeV            = addressModeV;
     AddressModeU            = addressModeU;
     MipmapMode              = mipmapMode;
     MinFilter               = minFilter;
     MagFilter               = magFilter;
     BorderColor             = borderColor;
     UnNormalizedCoordinates = unNormalizedCoordinates;
 }
Exemple #4
0
        public Sampler(VkFilter filter, VkSamplerMipmapMode mipmapMode,
                       VkSamplerAddressMode addressMode, uint mipLevels, bool anisotropyEnable, VkBorderColor borderColor = VkBorderColor.FloatOpaqueWhite)
        {
            // Create sampler
            var samplerCreateInfo = new VkSamplerCreateInfo
            {
                sType            = VkStructureType.SamplerCreateInfo,
                magFilter        = filter,
                minFilter        = filter,
                mipmapMode       = mipmapMode,
                addressModeU     = addressMode,
                addressModeV     = addressMode,
                addressModeW     = addressMode,
                mipLodBias       = 0.0f,
                compareOp        = VkCompareOp.Never,
                minLod           = 0.0f,
                maxLod           = mipLevels,
                borderColor      = borderColor,
                maxAnisotropy    = anisotropyEnable ? Device.Properties.limits.maxSamplerAnisotropy : 1,
                anisotropyEnable = anisotropyEnable
            };

            handle = Device.CreateSampler(ref samplerCreateInfo);
        }
Exemple #5
0
        private void ConvertMinFilter(TextureFilter filter, out VkFilter minFilter, out VkFilter magFilter, out VkSamplerMipmapMode mipmapMode, out VkBool32 enableComparison, out VkBool32 enableAnisotropy)
        {
            minFilter        = magFilter = VkFilter.Nearest;
            mipmapMode       = VkSamplerMipmapMode.Nearest;
            enableComparison = false;
            enableAnisotropy = false;

            switch (filter)
            {
            // Mip point
            case TextureFilter.Point:
                break;

            case TextureFilter.MinLinearMagMipPoint:
                minFilter = VkFilter.Linear;
                break;

            case TextureFilter.MinPointMagLinearMipPoint:
                magFilter = VkFilter.Linear;
                break;

            case TextureFilter.MinMagLinearMipPoint:
                minFilter = VkFilter.Linear;
                magFilter = VkFilter.Linear;
                break;

            // Mip linear
            case TextureFilter.MinMagPointMipLinear:
                mipmapMode = VkSamplerMipmapMode.Linear;
                break;

            case TextureFilter.MinLinearMagPointMipLinear:
                mipmapMode = VkSamplerMipmapMode.Linear;
                minFilter  = VkFilter.Linear;
                break;

            case TextureFilter.MinPointMagMipLinear:
                mipmapMode = VkSamplerMipmapMode.Linear;
                magFilter  = VkFilter.Linear;
                break;

            case TextureFilter.Linear:
                mipmapMode = VkSamplerMipmapMode.Linear;
                minFilter  = VkFilter.Linear;
                magFilter  = VkFilter.Linear;
                break;

            case TextureFilter.Anisotropic:
                enableAnisotropy = true;
                mipmapMode       = VkSamplerMipmapMode.Linear;
                minFilter        = VkFilter.Linear;
                magFilter        = VkFilter.Linear;
                break;

            // Comparison mip point
            case TextureFilter.ComparisonPoint:
                enableComparison = true;
                break;

            case TextureFilter.ComparisonMinLinearMagMipPoint:
                enableComparison = true;
                minFilter        = VkFilter.Linear;
                break;

            case TextureFilter.ComparisonMinPointMagLinearMipPoint:
                enableComparison = true;
                magFilter        = VkFilter.Linear;
                break;

            case TextureFilter.ComparisonMinMagLinearMipPoint:
                enableComparison = true;
                minFilter        = VkFilter.Linear;
                magFilter        = VkFilter.Linear;
                break;

            // Comparison mip linear
            case TextureFilter.ComparisonMinMagPointMipLinear:
                enableComparison = true;
                mipmapMode       = VkSamplerMipmapMode.Linear;
                break;

            case TextureFilter.ComparisonMinLinearMagPointMipLinear:
                enableComparison = true;
                mipmapMode       = VkSamplerMipmapMode.Linear;
                minFilter        = VkFilter.Linear;
                break;

            case TextureFilter.ComparisonMinPointMagMipLinear:
                enableComparison = true;
                mipmapMode       = VkSamplerMipmapMode.Linear;
                magFilter        = VkFilter.Linear;
                break;

            case TextureFilter.ComparisonLinear:
                enableComparison = true;
                mipmapMode       = VkSamplerMipmapMode.Linear;
                minFilter        = VkFilter.Linear;
                magFilter        = VkFilter.Linear;
                break;

            case TextureFilter.ComparisonAnisotropic:
                enableComparison = true;
                enableAnisotropy = true;
                mipmapMode       = VkSamplerMipmapMode.Linear;
                minFilter        = VkFilter.Linear;
                magFilter        = VkFilter.Linear;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Exemple #6
0
        public static void GetFilterProperties(
            SamplerFilter filter,
            out VkFilter minFilter,
            out VkFilter magFilter,
            out VkSamplerMipmapMode mipMode,
            out bool anisotropyEnable,
            out bool compareEnable)
        {
            anisotropyEnable = false;
            compareEnable    = false;

            switch (filter)
            {
            case SamplerFilter.MinMagMipPoint:
                minFilter = VkFilter.Nearest;
                magFilter = VkFilter.Nearest;
                mipMode   = VkSamplerMipmapMode.Nearest;
                break;

            case SamplerFilter.MinMagPointMipLinear:
                minFilter = VkFilter.Nearest;
                magFilter = VkFilter.Nearest;
                mipMode   = VkSamplerMipmapMode.Linear;
                break;

            case SamplerFilter.MinPointMagLinearMipPoint:
                minFilter = VkFilter.Nearest;
                magFilter = VkFilter.Linear;
                mipMode   = VkSamplerMipmapMode.Nearest;
                break;

            case SamplerFilter.MinPointMagMipLinear:
                minFilter = VkFilter.Nearest;
                magFilter = VkFilter.Linear;
                mipMode   = VkSamplerMipmapMode.Linear;
                break;

            case SamplerFilter.MinLinearMagMipPoint:
                minFilter = VkFilter.Linear;
                magFilter = VkFilter.Nearest;
                mipMode   = VkSamplerMipmapMode.Nearest;
                break;

            case SamplerFilter.MinLinearMagPointMipLinear:
                minFilter = VkFilter.Linear;
                magFilter = VkFilter.Nearest;
                mipMode   = VkSamplerMipmapMode.Linear;
                break;

            case SamplerFilter.MinMagLinearMipPoint:
                minFilter = VkFilter.Linear;
                magFilter = VkFilter.Linear;
                mipMode   = VkSamplerMipmapMode.Nearest;
                break;

            case SamplerFilter.MinMagMipLinear:
                minFilter = VkFilter.Linear;
                magFilter = VkFilter.Linear;
                mipMode   = VkSamplerMipmapMode.Linear;
                break;

            case SamplerFilter.Anisotropic:
                anisotropyEnable = true;
                minFilter        = VkFilter.Nearest;
                magFilter        = VkFilter.Nearest;
                mipMode          = VkSamplerMipmapMode.Nearest;
                break;

            case SamplerFilter.ComparisonMinMagMipPoint:
                compareEnable = true;
                minFilter     = VkFilter.Nearest;
                magFilter     = VkFilter.Nearest;
                mipMode       = VkSamplerMipmapMode.Nearest;
                break;

            case SamplerFilter.ComparisonMinMagPointMipLinear:
                compareEnable = true;
                minFilter     = VkFilter.Nearest;
                magFilter     = VkFilter.Nearest;
                mipMode       = VkSamplerMipmapMode.Linear;
                break;

            case SamplerFilter.ComparisonMinPointMagLinearMipPoint:
                compareEnable = true;
                minFilter     = VkFilter.Nearest;
                magFilter     = VkFilter.Linear;
                mipMode       = VkSamplerMipmapMode.Nearest;
                break;

            case SamplerFilter.ComparisonMinPointMagMipLinear:
                compareEnable = true;
                minFilter     = VkFilter.Nearest;
                magFilter     = VkFilter.Linear;
                mipMode       = VkSamplerMipmapMode.Linear;
                break;

            case SamplerFilter.ComparisonMinLinearMagMipPoint:
                compareEnable = true;
                minFilter     = VkFilter.Linear;
                magFilter     = VkFilter.Nearest;
                mipMode       = VkSamplerMipmapMode.Nearest;
                break;

            case SamplerFilter.ComparisonMinLinearMagPointMipLinear:
                compareEnable = true;
                minFilter     = VkFilter.Linear;
                magFilter     = VkFilter.Nearest;
                mipMode       = VkSamplerMipmapMode.Linear;
                break;

            case SamplerFilter.ComparisonMinMagLinearMipPoint:
                compareEnable = true;
                minFilter     = VkFilter.Linear;
                magFilter     = VkFilter.Linear;
                mipMode       = VkSamplerMipmapMode.Nearest;
                break;

            case SamplerFilter.ComparisonMinMagMipLinear:
                compareEnable = true;
                minFilter     = VkFilter.Linear;
                magFilter     = VkFilter.Linear;
                mipMode       = VkSamplerMipmapMode.Linear;
                break;

            case SamplerFilter.ComparisonAnisotropic:
                compareEnable    = true;
                anisotropyEnable = true;
                minFilter        = VkFilter.Nearest;
                magFilter        = VkFilter.Nearest;
                mipMode          = VkSamplerMipmapMode.Nearest;
                break;

            default:
                throw Illegal.Value <SamplerFilter>();
            }
        }
Exemple #7
0
 public void CreateSampler(VkSamplerAddressMode addressMode, VkFilter minFilter = VkFilter.Linear,
                           VkFilter magFilter  = VkFilter.Linear, VkSamplerMipmapMode mipmapMode = VkSamplerMipmapMode.Linear,
                           float maxAnisotropy = 1.0f, float minLod = 0.0f, float maxLod = -1f)
 {
     CreateSampler(minFilter, magFilter, mipmapMode, addressMode, maxAnisotropy, minLod, maxLod);
 }