Ejemplo n.º 1
0
        private SamplerState(GraphicsDevice device, SamplerStateDescription samplerStateDescription) : base(device)
        {
            Description = samplerStateDescription;

            textureWrapS = samplerStateDescription.AddressU.ToOpenGL();
            textureWrapT = samplerStateDescription.AddressV.ToOpenGL();
            textureWrapR = samplerStateDescription.AddressW.ToOpenGL();

            compareMode = TextureCompareMode.None;

            // ComparisonPoint can act as a mask for Comparison filters (0x80)
            if ((samplerStateDescription.Filter & ComparisonMask) != 0)
            {
                compareMode = TextureCompareMode.CompareRefToTexture;
            }

            compareFunc = samplerStateDescription.CompareFunction.ToOpenGLDepthFunction();
            borderColor = samplerStateDescription.BorderColor.ToArray();
            // TODO: How to do MipLinear vs MipPoint?
            switch (samplerStateDescription.Filter & ~(ComparisonMask | AnisotropicMask)) // Ignore comparison (128) and anisotropic (64) part
            {
            case TextureFilter.MinMagLinearMipPoint:
                minFilter = TextureMinFilter.LinearMipmapNearest;
                magFilter = TextureMagFilter.Linear;
                break;

            case TextureFilter.Linear:
                minFilter = TextureMinFilter.LinearMipmapLinear;
                magFilter = TextureMagFilter.Linear;
                break;

            case TextureFilter.MinPointMagMipLinear:
                minFilter = TextureMinFilter.NearestMipmapLinear;
                magFilter = TextureMagFilter.Linear;
                break;

            case TextureFilter.Point:
                minFilter = TextureMinFilter.NearestMipmapNearest;
                magFilter = TextureMagFilter.Nearest;
                break;

            case TextureFilter.MinPointMagLinearMipPoint:
                minFilter = TextureMinFilter.NearestMipmapNearest;
                magFilter = TextureMagFilter.Linear;
                break;

            case TextureFilter.MinLinearMagMipPoint:
                minFilter = TextureMinFilter.LinearMipmapNearest;
                magFilter = TextureMagFilter.Nearest;
                break;

            case TextureFilter.MinMagPointMipLinear:
                minFilter = TextureMinFilter.NearestMipmapLinear;
                magFilter = TextureMagFilter.Nearest;
                break;

            case TextureFilter.MinLinearMagPointMipLinear:
                minFilter = TextureMinFilter.LinearMipmapLinear;
                magFilter = TextureMagFilter.Nearest;
                break;

            default:
                throw new NotImplementedException();
            }

            maxAnisotropy = ((samplerStateDescription.Filter & AnisotropicMask) != 0) ? Description.MaxAnisotropy : 1;

#if STRIDE_GRAPHICS_API_OPENGLES
            // On OpenGL ES, we need to choose the appropriate min filter ourself if the texture doesn't contain mipmaps (done at PreDraw)
            minFilterNoMipmap = minFilter;
            if (minFilterNoMipmap == TextureMinFilter.LinearMipmapLinear)
            {
                minFilterNoMipmap = TextureMinFilter.Linear;
            }
            else if (minFilterNoMipmap == TextureMinFilter.NearestMipmapLinear)
            {
                minFilterNoMipmap = TextureMinFilter.Nearest;
            }
#endif
        }
        private SamplerState(GraphicsDevice device, SamplerStateDescription samplerStateDescription) : base(device)
        {
            Description = samplerStateDescription;

            textureWrapS = samplerStateDescription.AddressU.ToOpenGL();
            textureWrapT = samplerStateDescription.AddressV.ToOpenGL();
            textureWrapR = samplerStateDescription.AddressW.ToOpenGL();

            compareMode = TextureCompareMode.None;

            // ComparisonPoint can act as a mask for Comparison filters (0x80)
            if ((samplerStateDescription.Filter & ComparisonMask) != 0)
                compareMode = TextureCompareMode.CompareRefToTexture;

            compareFunc = samplerStateDescription.CompareFunction.ToOpenGLDepthFunction();
            borderColor = samplerStateDescription.BorderColor.ToArray();
            // TODO: How to do MipLinear vs MipPoint?
            switch (samplerStateDescription.Filter & ~(ComparisonMask | AnisotropicMask)) // Ignore comparison (128) and anisotropic (64) part
            {
                case TextureFilter.MinMagLinearMipPoint:
                    minFilter = TextureMinFilter.LinearMipmapNearest;
                    magFilter = TextureMagFilter.Linear;
                    break;
                case TextureFilter.Linear:
                    minFilter = TextureMinFilter.LinearMipmapLinear;
                    magFilter = TextureMagFilter.Linear;
                    break;
                case TextureFilter.MinPointMagMipLinear:
                    minFilter = TextureMinFilter.NearestMipmapLinear;
                    magFilter = TextureMagFilter.Linear;
                    break;
                case TextureFilter.Point:
                    minFilter = TextureMinFilter.NearestMipmapNearest;
                    magFilter = TextureMagFilter.Nearest;
                    break;
                case TextureFilter.MinPointMagLinearMipPoint:
                    minFilter = TextureMinFilter.NearestMipmapNearest;
                    magFilter = TextureMagFilter.Linear;
                    break;
                case TextureFilter.MinLinearMagMipPoint:
                    minFilter = TextureMinFilter.LinearMipmapNearest;
                    magFilter = TextureMagFilter.Nearest;
                    break;
                case TextureFilter.MinMagPointMipLinear:
                    minFilter = TextureMinFilter.NearestMipmapLinear;
                    magFilter = TextureMagFilter.Nearest;
                    break;
                case TextureFilter.MinLinearMagPointMipLinear:
                    minFilter = TextureMinFilter.LinearMipmapLinear;
                    magFilter = TextureMagFilter.Nearest;
                    break;
                default:
                    throw new NotImplementedException();
            }

            maxAnisotropy = ((samplerStateDescription.Filter & AnisotropicMask) != 0) ? Description.MaxAnisotropy : 1;

#if SILICONSTUDIO_XENKO_GRAPHICS_API_OPENGLES
            // On OpenGL ES, we need to choose the appropriate min filter ourself if the texture doesn't contain mipmaps (done at PreDraw)
            minFilterNoMipmap = minFilter;
            if (minFilterNoMipmap == TextureMinFilter.LinearMipmapLinear)
                minFilterNoMipmap = TextureMinFilter.Linear;
            else if (minFilterNoMipmap == TextureMinFilter.NearestMipmapLinear)
                minFilterNoMipmap = TextureMinFilter.Nearest;
#endif
        }