Example #1
0
        public Sampler(SamplerCreateInfo info)
        {
            Handle = GL.GenSampler();

            GL.SamplerParameter(Handle, SamplerParameterName.TextureMinFilter, (int)info.MinFilter.Convert());
            GL.SamplerParameter(Handle, SamplerParameterName.TextureMagFilter, (int)info.MagFilter.Convert());

            GL.SamplerParameter(Handle, SamplerParameterName.TextureWrapS, (int)info.AddressU.Convert());
            GL.SamplerParameter(Handle, SamplerParameterName.TextureWrapT, (int)info.AddressV.Convert());
            GL.SamplerParameter(Handle, SamplerParameterName.TextureWrapR, (int)info.AddressP.Convert());

            GL.SamplerParameter(Handle, SamplerParameterName.TextureCompareMode, (int)info.CompareMode.Convert());
            GL.SamplerParameter(Handle, SamplerParameterName.TextureCompareFunc, (int)info.CompareOp.Convert());

            unsafe
            {
                float *borderColor = stackalloc float[4]
                {
                    info.BorderColor.Red,
                    info.BorderColor.Green,
                    info.BorderColor.Blue,
                    info.BorderColor.Alpha
                };

                GL.SamplerParameter(Handle, SamplerParameterName.TextureBorderColor, borderColor);
            }

            GL.SamplerParameter(Handle, SamplerParameterName.TextureMinLod, info.MinLod);
            GL.SamplerParameter(Handle, SamplerParameterName.TextureMaxLod, info.MaxLod);
            GL.SamplerParameter(Handle, SamplerParameterName.TextureLodBias, info.MipLodBias);

            GL.SamplerParameter(Handle, SamplerParameterName.TextureMaxAnisotropyExt, info.MaxAnisotropy);
        }
Example #2
0
        public unsafe Sampler(Api api, SamplerConfig config)
        {
            _api = api;

            // Wrap textures
            // TODO: make texture-specific
            config.AddressModeU = SamplerAddressMode.Repeat;
            config.AddressModeV = SamplerAddressMode.Repeat;
            config.AddressModeW = SamplerAddressMode.Repeat;

            var samplerInfo = new SamplerCreateInfo();

            samplerInfo.SType                   = StructureType.SamplerCreateInfo;
            samplerInfo.MagFilter               = config.MagFilter;
            samplerInfo.MinFilter               = config.MinFilter;
            samplerInfo.AddressModeU            = config.AddressModeU;
            samplerInfo.AddressModeV            = config.AddressModeV;
            samplerInfo.AddressModeW            = config.AddressModeW;
            samplerInfo.AnisotropyEnable        = config.AnisotropyEnable;
            samplerInfo.MaxAnisotropy           = config.MaxAnisotropy;
            samplerInfo.BorderColor             = config.BorderColor;
            samplerInfo.UnnormalizedCoordinates = config.UnnormalizedCoordinates;
            samplerInfo.CompareEnable           = config.CompareEnable;
            samplerInfo.CompareOp               = config.CompareOp;
            samplerInfo.MipmapMode              = config.MipmapMode;
            samplerInfo.MipLodBias              = config.MipLodBias;
            samplerInfo.MinLod                  = config.MinLod;
            samplerInfo.MaxLod                  = config.MaxLod;

            Util.Verify(_api.Vk.CreateSampler(_api.Device.VkDevice, samplerInfo, default, out _vkSampler), $"{nameof(Sampler)}: Failed to create sampler");
Example #3
0
        public void CreateSampler()
        {
            var createInfo = new SamplerCreateInfo();

            using (Device.CreateSampler(createInfo)) { }
            using (Device.CreateSampler(createInfo, CustomAllocator)) { }
        }
Example #4
0
        Sampler CreateSampler()
        {
            var createInfo = new SamplerCreateInfo();

            createInfo.MagFilter        = Filter.Linear;
            createInfo.MinFilter        = Filter.Linear;
            createInfo.MipmapMode       = SamplerMipmapMode.Linear;
            createInfo.MaxLod           = 1;
            createInfo.AnisotropyEnable = true;
            createInfo.BorderColor      = BorderColor.FloatOpaqueWhite;
            return(device.CreateSampler(createInfo));
        }
Example #5
0
        public Sampler(Filter magFilter, Filter minFilter, SamplerMipmapMode mipmapMode, SamplerAddressMode addressModeU, SamplerAddressMode addressModeV, SamplerAddressMode addressModeW, float mipLodBias, float maxAnisotropy, float minLod, float maxLod, BorderColor aBorderColor)
        {
            SamplerCreateInfo sampler = new SamplerCreateInfo();

            sampler.MagFilter     = magFilter;
            sampler.MinFilter     = minFilter;
            sampler.MipmapMode    = mipmapMode;
            sampler.AddressModeU  = addressModeU;
            sampler.AddressModeV  = addressModeV;
            sampler.AddressModeW  = addressModeW;
            sampler.MipLodBias    = mipLodBias;
            sampler.MaxAnisotropy = maxAnisotropy;
            sampler.MinLod        = minLod;
            sampler.MaxLod        = maxLod;
            sampler.BorderColor   = aBorderColor;
            VulkanRenderer.SelectedLogicalDevice.CreateSampler(this, sampler);
        }
Example #6
0
        private unsafe void CreateNativeSampler()
        {
            var createInfo = new SamplerCreateInfo
            {
                StructureType    = StructureType.SamplerCreateInfo,
                AddressModeU     = ConvertAddressMode(Description.AddressU),
                AddressModeV     = ConvertAddressMode(Description.AddressV),
                AddressModeW     = ConvertAddressMode(Description.AddressW),
                MipLodBias       = Description.MipMapLevelOfDetailBias,
                MaxAnisotropy    = Description.MaxAnisotropy,
                CompareOperation = VulkanConvertExtensions.ConvertComparisonFunction(Description.CompareFunction),
                MinLod           = Description.MinMipLevel,
                MaxLod           = Description.MaxMipLevel,
                BorderColor      = BorderColor.FloatOpaqueBlack // TODO VULKAN: How to handle BorderColor
            };

            ConvertMinFilter(Description.Filter, out createInfo.MinFilter, out createInfo.MagFilter, out createInfo.MipmapMode, out createInfo.CompareEnable, out createInfo.AnisotropyEnable);

            NativeSampler = GraphicsDevice.NativeDevice.CreateSampler(ref createInfo);
        }
        private unsafe void CreateNativeSampler()
        {
            var createInfo = new SamplerCreateInfo
            {
                StructureType = StructureType.SamplerCreateInfo,
                AddressModeU = ConvertAddressMode(Description.AddressU),
                AddressModeV = ConvertAddressMode(Description.AddressV),
                AddressModeW = ConvertAddressMode(Description.AddressW),
                MipLodBias = Description.MipMapLevelOfDetailBias,
                MaxAnisotropy = Description.MaxAnisotropy,
                CompareOperation = VulkanConvertExtensions.ConvertComparisonFunction(Description.CompareFunction),
                MinLod = Description.MinMipLevel,
                MaxLod = Description.MaxMipLevel,
                BorderColor = BorderColor.FloatOpaqueBlack // TODO VULKAN: How to handle BorderColor
            };

            ConvertMinFilter(Description.Filter, out createInfo.MinFilter, out createInfo.MagFilter, out createInfo.MipmapMode, out createInfo.CompareEnable, out createInfo.AnisotropyEnable);

            NativeSampler = GraphicsDevice.NativeDevice.CreateSampler(ref createInfo);
        }
Example #8
0
        protected void CreateTextureSampler()
        {
            var samplerInfo = new SamplerCreateInfo
            {
                MagFilter               = Filter.Linear,
                MinFilter               = Filter.Linear,
                AddressModeU            = SamplerAddressMode.Repeat,
                AddressModeV            = SamplerAddressMode.Repeat,
                AddressModeW            = SamplerAddressMode.Repeat,
                AnisotropyEnable        = true,
                MaxAnisotropy           = 16,
                BorderColor             = BorderColor.IntOpaqueBlack,
                UnnormalizedCoordinates = false,
                CompareEnable           = false,
                CompareOp               = CompareOp.Always,
                MipmapMode              = SamplerMipmapMode.Linear,
            };

            textureSampler = device.CreateSampler(samplerInfo);
        }
Example #9
0
        private Sampler CreateSampler()
        {
            var createInfo = new SamplerCreateInfo
            {
                MagFilter  = Filter.Linear,
                MinFilter  = Filter.Linear,
                MipmapMode = SamplerMipmapMode.Linear
            };

            // We also enable anisotropic filtering. Because that feature is optional, it must be
            // checked if it is supported by the device.
            if (Context.Features.SamplerAnisotropy)
            {
                createInfo.AnisotropyEnable = true;
                createInfo.MaxAnisotropy    = Context.Properties.Limits.MaxSamplerAnisotropy;
            }
            else
            {
                createInfo.MaxAnisotropy = 1.0f;
            }
            return(Context.Device.CreateSampler(createInfo));
        }
Example #10
0
        public static Sampler CreateSampler(Context ctx, Filter magFilter, Filter minFilter, SamplerMipmapMode mipmapMode)
        {
            var createInfo = new SamplerCreateInfo
            {
                MagFilter  = magFilter,
                MinFilter  = minFilter,
                MipmapMode = mipmapMode
            };

            // We also enable anisotropic filtering. Because that feature is optional, it must be
            // checked if it is supported by the device.
            if (ctx.Features.SamplerAnisotropy)
            {
                createInfo.AnisotropyEnable = true;
                createInfo.MaxAnisotropy    = ctx.Properties.Limits.MaxSamplerAnisotropy;
            }
            else
            {
                createInfo.MaxAnisotropy = 1.0f;
            }
            return(ctx.Device.CreateSampler(createInfo));
        }
Example #11
0
 public ISampler CreateSampler(SamplerCreateInfo info)
 {
     return(new Sampler(info));
 }
Example #12
0
 public unsafe Sampler CreateSampler(ref SamplerCreateInfo createInfo, AllocationCallbacks* allocator = null)
 {
     Sampler sampler;
     fixed (SamplerCreateInfo* __createInfo__ = &createInfo)
     {
         vkCreateSampler(this, __createInfo__, allocator, &sampler).CheckError();
     }
     return sampler;
 }
Example #13
0
 internal static unsafe extern Result vkCreateSampler(Device device, SamplerCreateInfo* createInfo, AllocationCallbacks* allocator, Sampler* sampler);
Example #14
0
 public void Set(TableRef <ThreadedSampler> sampler, SamplerCreateInfo info)
 {
     _sampler = sampler;
     _info    = info;
 }