Exemplo n.º 1
0
 protected override SamplerState CreateSamplerStateCore(
     SamplerAddressMode addressU,
     SamplerAddressMode addressV,
     SamplerAddressMode addressW,
     SamplerFilter filter,
     int maxAnisotropy,
     RgbaFloat borderColor,
     DepthComparison comparison,
     int minimumLod,
     int maximumLod,
     int lodBias)
 {
     return(new VkSamplerState(
                _device,
                addressU,
                addressV,
                addressW,
                filter,
                maxAnisotropy,
                borderColor,
                comparison,
                minimumLod,
                maximumLod,
                lodBias));
 }
Exemplo n.º 2
0
        internal static DepthFunction ConvertDepthComparison(DepthComparison depthComparison)
        {
            switch (depthComparison)
            {
            case DepthComparison.Never:
                return(DepthFunction.Never);

            case DepthComparison.Less:
                return(DepthFunction.Less);

            case DepthComparison.Equal:
                return(DepthFunction.Equal);

            case DepthComparison.LessEqual:
                return(DepthFunction.Lequal);

            case DepthComparison.Greater:
                return(DepthFunction.Greater);

            case DepthComparison.NotEqual:
                return(DepthFunction.Notequal);

            case DepthComparison.GreaterEqual:
                return(DepthFunction.Gequal);

            case DepthComparison.Always:
                return(DepthFunction.Always);

            default:
                throw Illegal.Value <DepthComparison>();
            }
        }
Exemplo n.º 3
0
        public D3DSamplerState(
            Device device,
            SamplerAddressMode addressU,
            SamplerAddressMode addressV,
            SamplerAddressMode addressW,
            SamplerFilter filter,
            int maxAnisotropy,
            RgbaFloat borderColor,
            DepthComparison comparison,
            int minimumLod,
            int maximumLod,
            int lodBias)
        {
            SamplerStateDescription ssd = new SamplerStateDescription();

            ssd.AddressU           = D3DFormats.VeldridToD3DSamplerAddressMode(addressU);
            ssd.AddressV           = D3DFormats.VeldridToD3DSamplerAddressMode(addressV);
            ssd.AddressW           = D3DFormats.VeldridToD3DSamplerAddressMode(addressW);
            ssd.Filter             = D3DFormats.VeldridToD3DSamplerFilter(filter);
            ssd.MaximumAnisotropy  = maxAnisotropy;
            ssd.BorderColor        = new RawColor4(borderColor.R, borderColor.G, borderColor.B, borderColor.A);
            ssd.ComparisonFunction = D3DFormats.VeldridToD3DDepthComparison(comparison);
            ssd.MinimumLod         = minimumLod;
            ssd.MaximumLod         = maximumLod;
            ssd.MipLodBias         = lodBias;
            _d3dSamplerState       = new SharpDX.Direct3D11.SamplerState(device, ssd);
        }
Exemplo n.º 4
0
        public static Comparison VeldridToD3DDepthComparison(DepthComparison dc)
        {
            switch (dc)
            {
            case DepthComparison.Never:
                return(Comparison.Never);

            case DepthComparison.Less:
                return(Comparison.Less);

            case DepthComparison.Equal:
                return(Comparison.Equal);

            case DepthComparison.LessEqual:
                return(Comparison.LessEqual);

            case DepthComparison.Greater:
                return(Comparison.Equal);

            case DepthComparison.NotEqual:
                return(Comparison.NotEqual);

            case DepthComparison.GreaterEqual:
                return(Comparison.GreaterEqual);

            case DepthComparison.Always:
                return(Comparison.Always);

            default:
                throw Illegal.Value <DepthComparison>();
            }
        }
Exemplo n.º 5
0
        public static VkCompareOp VeldridToVkDepthComparison(DepthComparison depthComparison)
        {
            switch (depthComparison)
            {
            case DepthComparison.Never:
                return(VkCompareOp.Never);

            case DepthComparison.Less:
                return(VkCompareOp.Less);

            case DepthComparison.Equal:
                return(VkCompareOp.Equal);

            case DepthComparison.LessEqual:
                return(VkCompareOp.LessOrEqual);

            case DepthComparison.Greater:
                return(VkCompareOp.Greater);

            case DepthComparison.NotEqual:
                return(VkCompareOp.NotEqual);

            case DepthComparison.GreaterEqual:
                return(VkCompareOp.GreaterOrEqual);

            case DepthComparison.Always:
                return(VkCompareOp.Always);

            default:
                throw Illegal.Value <DepthComparison>();
            }
        }
Exemplo n.º 6
0
            public unsafe InternalSamplerState(
                SamplerAddressMode addressU,
                SamplerAddressMode addressV,
                SamplerAddressMode addressW,
                SamplerFilter filter,
                int maxAnisotropy,
                RgbaFloat borderColor,
                DepthComparison comparison,
                int minLod,
                int maxLod,
                int lodBias,
                bool mip)
            {
                _samplerID = GL.GenSampler();

                GL.SamplerParameter(_samplerID, SamplerParameterName.TextureWrapR, (int)OpenGLFormats.VeldridToGLTextureWrapMode(addressU));
                Utilities.CheckLastGLError();
                GL.SamplerParameter(_samplerID, SamplerParameterName.TextureWrapS, (int)OpenGLFormats.VeldridToGLTextureWrapMode(addressV));
                Utilities.CheckLastGLError();
                GL.SamplerParameter(_samplerID, SamplerParameterName.TextureWrapT, (int)OpenGLFormats.VeldridToGLTextureWrapMode(addressW));
                Utilities.CheckLastGLError();

                if (addressU == SamplerAddressMode.Border || addressV == SamplerAddressMode.Border || addressW == SamplerAddressMode.Border)
                {
                    GL.SamplerParameter(_samplerID, SamplerParameterName.TextureBorderColor, (float *)&borderColor);
                    Utilities.CheckLastGLError();
                }

                GL.SamplerParameter(_samplerID, SamplerParameterName.TextureMinLod, (float)minLod);
                Utilities.CheckLastGLError();
                GL.SamplerParameter(_samplerID, SamplerParameterName.TextureMaxLod, (float)maxLod);
                Utilities.CheckLastGLError();
                GL.SamplerParameter(_samplerID, SamplerParameterName.TextureLodBias, (float)lodBias);
                Utilities.CheckLastGLError();

                if (filter == SamplerFilter.Anisotropic || filter == SamplerFilter.ComparisonAnisotropic)
                {
                    GL.SamplerParameter(_samplerID, SamplerParameterName.TextureMaxAnisotropyExt, (float)maxAnisotropy);
                    GL.SamplerParameter(_samplerID, SamplerParameterName.TextureMinFilter, mip ? (int)TextureMinFilter.LinearMipmapLinear : (int)TextureMinFilter.Linear);
                    GL.SamplerParameter(_samplerID, SamplerParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
                    Utilities.CheckLastGLError();
                }
                else
                {
                    OpenGLFormats.VeldridToGLTextureMinMagFilter(filter, mip, out TextureMinFilter min, out TextureMagFilter mag);
                    GL.SamplerParameter(_samplerID, SamplerParameterName.TextureMinFilter, (int)min);
                    Utilities.CheckLastGLError();
                    GL.SamplerParameter(_samplerID, SamplerParameterName.TextureMagFilter, (int)mag);
                    Utilities.CheckLastGLError();
                }

                if (s_comparisonFilters.Contains(filter))
                {
                    GL.SamplerParameter(_samplerID, SamplerParameterName.TextureCompareMode, (int)TextureCompareMode.CompareRefToTexture);
                    Utilities.CheckLastGLError();
                    GL.SamplerParameter(_samplerID, SamplerParameterName.TextureCompareFunc, (int)OpenGLFormats.ConvertDepthComparison(comparison));
                    Utilities.CheckLastGLError();
                }
            }
Exemplo n.º 7
0
 protected abstract SamplerState CreateSamplerStateCore(
     SamplerAddressMode addressU,
     SamplerAddressMode addressV,
     SamplerAddressMode addressW,
     SamplerFilter filter,
     int maxAnisotropy,
     RgbaFloat borderColor,
     DepthComparison comparison,
     int minimumLod,
     int maximumLod,
     int lodBias);
Exemplo n.º 8
0
        public VkSamplerState(
            VkDevice device,
            SamplerAddressMode addressU,
            SamplerAddressMode addressV,
            SamplerAddressMode addressW,
            SamplerFilter filter,
            int maxAnisotropy,
            RgbaFloat borderColor,
            DepthComparison comparison,
            int minimumLod,
            int maximumLod,
            int lodBias)
        {
            _device           = device;
            AddressU          = addressU;
            AddressV          = addressV;
            AddressW          = addressW;
            Filter            = filter;
            MaximumAnisotropy = maxAnisotropy;
            BorderColor       = borderColor;
            Comparison        = comparison;
            MinimumLod        = minimumLod;
            MaximumLod        = maximumLod;
            LodBias           = lodBias;

            VkSamplerCreateInfo samplerCI = VkSamplerCreateInfo.New();

            samplerCI.addressModeU = VkFormats.VeldridToVkSamplerAddressMode(addressU);
            samplerCI.addressModeV = VkFormats.VeldridToVkSamplerAddressMode(addressV);
            samplerCI.addressModeW = VkFormats.VeldridToVkSamplerAddressMode(addressW);
            VkFormats.GetFilterProperties(
                filter,
                out VkFilter minFilter,
                out VkFilter magFilter,
                out VkSamplerMipmapMode mipmapMode,
                out bool anisotropyEnable,
                out bool compareEnable);
            samplerCI.minFilter        = minFilter;
            samplerCI.magFilter        = magFilter;
            samplerCI.mipmapMode       = mipmapMode;
            samplerCI.maxAnisotropy    = maxAnisotropy;
            samplerCI.anisotropyEnable = anisotropyEnable;
            samplerCI.compareEnable    = compareEnable;
            samplerCI.minLod           = minimumLod;
            samplerCI.maxLod           = maximumLod;
            samplerCI.mipLodBias       = lodBias;
            samplerCI.compareOp        = VkFormats.VeldridToVkDepthComparison(comparison);
            samplerCI.borderColor      = VkBorderColor.FloatOpaqueWhite;
            VkResult result = vkCreateSampler(_device, ref samplerCI, null, out VkSampler sampler);

            CheckResult(result);
            Sampler = sampler;
        }
Exemplo n.º 9
0
        public D3DDepthStencilState(Device device, bool isDepthEnabled, DepthComparison comparison, bool isDepthWriteEnabled)
        {
            _device             = device;
            IsDepthEnabled      = IsDepthEnabled;
            IsDepthWriteEnabled = isDepthWriteEnabled;
            DepthComparison     = comparison;

            DepthStencilStateDescription desc = DepthStencilStateDescription.Default();

            desc.DepthComparison = D3DFormats.ConvertDepthComparison(comparison);
            desc.IsDepthEnabled  = isDepthEnabled;
            desc.DepthWriteMask  = isDepthWriteEnabled ? DepthWriteMask.All : DepthWriteMask.Zero;

            _deviceState = new SharpDX.Direct3D11.DepthStencilState(device, desc);
        }
Exemplo n.º 10
0
 public unsafe OpenGLSamplerState(
     SamplerAddressMode addressU,
     SamplerAddressMode addressV,
     SamplerAddressMode addressW,
     SamplerFilter filter,
     int maxAnisotropy,
     RgbaFloat borderColor,
     DepthComparison comparison,
     int minLod,
     int maxLod,
     int lodBias)
 {
     AddressU          = addressU;
     AddressV          = addressV;
     AddressW          = addressW;
     Filter            = filter;
     MaximumAnisotropy = maxAnisotropy;
     BorderColor       = borderColor;
     Comparison        = comparison;
     MinimumLod        = minLod;
     MaximumLod        = maxLod;
     LodBias           = lodBias;
 }
Exemplo n.º 11
0
 /// <summary>
 /// Creates a new <see cref="SamplerState"/> with the given properties.
 /// </summary>
 /// <param name="addressU">A value controlling U-coordinate (R-coordinate in OpenGL) sampling.</param>
 /// <param name="addressV">A value controlling V-coordinate (S-coordinate in OpenGL) sampling.</param>
 /// <param name="addressW">A value controlling W-coordinate (T-coordinate in OpenGL) sampling.</param>
 /// <param name="filter">The filter kind to use.</param>
 /// <param name="maxAnisotropy">If <paramref name="filter"/> is equal to Anisotropic, then this parameter
 /// controls the level of anisotropic filtering used.</param>
 /// <param name="borderColor">When a border-type filter is used, this controls the sampled border color.</param>
 /// <param name="comparison">Controls the comparison used when a Comparison-type filter is used.</param>
 /// <param name="minimumLod">The highest-quality LOD level (lowest level) the sampler will access.</param>
 /// <param name="maximumLod">The lowerst-quality LOD level (lowest level) the sampler will access.</param>
 /// <param name="lodBias">A bias to use when choosing which LOD level to sample from.</param>
 /// <returns>A new <see cref="SamplerState"/> which supports the given properties.</returns>
 public SamplerState CreateSamplerState(
     SamplerAddressMode addressU,
     SamplerAddressMode addressV,
     SamplerAddressMode addressW,
     SamplerFilter filter,
     int maxAnisotropy,
     RgbaFloat borderColor,
     DepthComparison comparison,
     int minimumLod,
     int maximumLod,
     int lodBias)
 {
     return(CreateSamplerStateCore(
                addressU,
                addressV,
                addressW,
                filter,
                maxAnisotropy,
                borderColor,
                comparison,
                minimumLod,
                maximumLod,
                lodBias));
 }
Exemplo n.º 12
0
 /// <summary>
 /// Initializes a new ConsoleBuffer3D instance with the specified dimensions.
 /// </summary>
 /// <param name="width">The width of the buffer, in units.</param>
 /// <param name="height">The height of the buffer, in units.</param>
 public ConsoleBuffer3D(int width, int height)
     : base(width, height)
 {
     _depthBuffer = new double[height, width];
     _depthComp   = DepthComparison.Less;
 }
Exemplo n.º 13
0
 /// <summary>
 /// Creates a new <see cref="DepthStencilState"/>, used to control depth and stencil comparisons in the device's output merger.
 /// </summary>
 /// <param name="isDepthEnabled">A value indicating whether depth testing is enabled in the new state.</param>
 /// <param name="comparison">The kind of <see cref="DepthComparison"/> to use in the new state.</param>
 /// <param name="isDepthWriteEnabled">A value indicating whether the depth buffer is written to when drawing.</param>
 /// <returns>A new <see cref="DepthStencilState"/>.</returns>
 protected abstract DepthStencilState CreateDepthStencilStateCore(bool isDepthEnabled, DepthComparison comparison, bool isDepthWriteEnabled);
Exemplo n.º 14
0
 /// <summary>
 /// Creates a new <see cref="DepthStencilState"/>, used to control depth and stencil comparisons in the device's output merger.
 /// </summary>
 /// <param name="isDepthEnabled">A value indicating whether depth testing is enabled in the new state.</param>
 /// <param name="comparison">The kind of <see cref="DepthComparison"/> to use in the new state.</param>
 /// <param name="isDepthWriteEnabled">A value indicating whether the depth buffer is written to when drawing.</param>
 /// <returns>A new <see cref="DepthStencilState"/>.</returns>
 public DepthStencilState CreateDepthStencilState(bool isDepthEnabled, DepthComparison comparison, bool isDepthWriteEnabled)
 {
     return(CreateDepthStencilStateCore(isDepthWriteEnabled, comparison, isDepthWriteEnabled));
 }
Exemplo n.º 15
0
 /// <summary>
 /// Creates a new <see cref="DepthStencilState"/>, used to control depth and stencil comparisons in the device's output merger.
 /// </summary>
 /// <param name="isDepthEnabled">A value indicating whether depth testing is enabled in the new state.</param>
 /// <param name="comparison">The kind of <see cref="DepthComparison"/> to use in the new state.</param>
 /// <returns>A new <see cref="DepthStencilState"/>.</returns>
 public DepthStencilState CreateDepthStencilState(bool isDepthEnabled, DepthComparison comparison)
 {
     return(CreateDepthStencilState(isDepthEnabled, comparison, true));
 }
Exemplo n.º 16
0
 /// <summary>
 /// Creates a new <see cref="DepthStencilState"/>, used to control depth and stencil comparisons in the device's output merger.
 /// </summary>
 /// <param name="isDepthEnabled">A value indicating whether depth testing is enabled in the new state.</param>
 /// <param name="comparison">The kind of <see cref="DepthComparison"/> to use in the new state.</param>
 /// <param name="isDepthWriteEnabled">A value indicating whether the depth buffer is written to when drawing.</param>
 /// <returns>A new <see cref="DepthStencilState"/>.</returns>
 public abstract DepthStencilState CreateDepthStencilState(bool isDepthEnabled, DepthComparison comparison, bool isDepthWriteEnabled);
 protected override DepthStencilState CreateDepthStencilStateCore(bool isDepthEnabled, DepthComparison comparison, bool isDepthWriteEnabled)
 {
     return(new OpenGLDepthStencilState(isDepthEnabled, comparison, isDepthWriteEnabled));
 }
Exemplo n.º 18
0
 public VkDepthStencilState(bool isDepthEnabled, DepthComparison comparison, bool isDepthWriteEnabled)
 {
     IsDepthEnabled      = isDepthEnabled;
     IsDepthWriteEnabled = isDepthWriteEnabled;
     DepthComparison     = comparison;
 }
Exemplo n.º 19
0
 public DepthStencilStateCacheKey(bool isDepthEnabled, bool isDepthWriteEnabled, DepthComparison comparison)
 {
     IsDepthEnabled      = isDepthEnabled;
     IsDepthWriteEnabled = isDepthWriteEnabled;
     Comparison          = comparison;
 }
Exemplo n.º 20
0
 public override DepthStencilState CreateDepthStencilState(bool isDepthEnabled, DepthComparison comparison, bool isDepthWriteEnabled)
 {
     return(new D3DDepthStencilState(_device, isDepthEnabled, comparison, isDepthWriteEnabled));
 }
Exemplo n.º 21
0
 /// <summary>
 /// Initializes a new ConsoleBuffer3D instance with the specified dimensions.
 /// </summary>
 /// <param name="width">The width of the buffer, in units.</param>
 /// <param name="height">The height of the buffer, in units.</param>
 public ConsoleBuffer3D(int width, int height)
     : base(width, height)
 {
     _depthBuffer = new double[height, width];
     _depthComp = DepthComparison.Less;
 }