Esempio n. 1
0
        /// <summary>
        /// Creates the LinearWrap sampler state.
        /// </summary>
        /// <param name="uv">The Ultraviolet context.</param>
        /// <returns>The sampler state that was created.</returns>
        public static OpenGLSamplerState CreateLinearWrap(UltravioletContext uv)
        {
            var state = new OpenGLSamplerState(uv);

            state.Filter   = TextureFilter.Linear;
            state.AddressU = TextureAddressMode.Wrap;
            state.AddressV = TextureAddressMode.Wrap;
            state.AddressW = TextureAddressMode.Wrap;
            state.MakeImmutable();
            return(state);
        }
Esempio n. 2
0
        /// <summary>
        /// Creates the AnisotropicClamp sampler state.
        /// </summary>
        /// <param name="uv">The Ultraviolet context.</param>
        /// <returns>The sampler state that was created.</returns>
        public static OpenGLSamplerState CreateAnisotropicClamp(UltravioletContext uv)
        {
            var state = new OpenGLSamplerState(uv);

            state.Filter   = TextureFilter.Anisotropic;
            state.AddressU = TextureAddressMode.Clamp;
            state.AddressV = TextureAddressMode.Clamp;
            state.AddressW = TextureAddressMode.Clamp;
            state.MakeImmutable();
            return(state);
        }
Esempio n. 3
0
        /// <summary>
        /// Applies the specified sampler state to this sampler.
        /// </summary>
        /// <param name="state">The sampler state to apply.</param>
        public void ApplySamplerState(SamplerState state)
        {
            Contract.Require(state, nameof(state));

            var textureWrapR = OpenGLSamplerState.GetTextureAddressModeGL(state.AddressW);

            if (textureWrapR != cachedTextureWrapR)
            {
                cachedTextureWrapR = textureWrapR;
                gl.SamplerParameteri(sampler, gl.GL_TEXTURE_WRAP_R, textureWrapR);
                gl.ThrowIfError();
            }

            var textureWrapS = OpenGLSamplerState.GetTextureAddressModeGL(state.AddressU);

            if (textureWrapS != cachedTextureWrapS)
            {
                cachedTextureWrapS = textureWrapS;
                gl.SamplerParameteri(sampler, gl.GL_TEXTURE_WRAP_S, textureWrapS);
                gl.ThrowIfError();
            }

            var textureWrapT = OpenGLSamplerState.GetTextureAddressModeGL(state.AddressV);

            if (textureWrapT != cachedTextureWrapT)
            {
                cachedTextureWrapT = textureWrapT;
                gl.SamplerParameteri(sampler, gl.GL_TEXTURE_WRAP_T, textureWrapT);
                gl.ThrowIfError();
            }

            if (state.MipMapLevelOfDetailBias != 0)
            {
                if (gl.IsMapMapLevelOfDetailBiasAvailable)
                {
                    if (cachedMipMapLODBias != state.MipMapLevelOfDetailBias)
                    {
                        cachedMipMapLODBias = state.MipMapLevelOfDetailBias;
                        gl.SamplerParameterf(sampler, gl.GL_TEXTURE_LOD_BIAS, state.MipMapLevelOfDetailBias);
                        gl.ThrowIfError();
                    }
                }
                else
                {
                    throw new NotSupportedException(OpenGLStrings.UnsupportedLODBiasGLES);
                }
            }

            switch (state.Filter)
            {
            case TextureFilter.Point:
                if (cachedMaxAnisotropy != 1f)
                {
                    cachedMaxAnisotropy = 1f;
                    gl.SamplerParameterf(sampler, gl.GL_TEXTURE_MAX_ANISOTROPY_EXT, 1f);
                    gl.ThrowIfError();
                }

                if (cachedMinFilter != gl.GL_NEAREST)
                {
                    cachedMinFilter = gl.GL_NEAREST;
                    gl.SamplerParameterf(sampler, gl.GL_TEXTURE_MIN_FILTER, (int)gl.GL_NEAREST);
                    gl.ThrowIfError();
                }

                if (cachedMagFilter != gl.GL_NEAREST)
                {
                    cachedMagFilter = gl.GL_NEAREST;
                    gl.SamplerParameterf(sampler, gl.GL_TEXTURE_MAG_FILTER, (int)gl.GL_NEAREST);
                    gl.ThrowIfError();
                }
                break;

            case TextureFilter.Linear:
                if (gl.IsAnisotropicFilteringAvailable)
                {
                    if (cachedMaxAnisotropy != 1f)
                    {
                        cachedMaxAnisotropy = 1f;
                        gl.SamplerParameterf(sampler, gl.GL_TEXTURE_MAX_ANISOTROPY_EXT, 1f);
                        gl.ThrowIfError();
                    }
                }

                if (cachedMinFilter != gl.GL_LINEAR)
                {
                    cachedMinFilter = gl.GL_LINEAR;
                    gl.SamplerParameteri(sampler, gl.GL_TEXTURE_MIN_FILTER, (int)gl.GL_LINEAR);
                    gl.ThrowIfError();
                }

                if (cachedMagFilter != gl.GL_LINEAR)
                {
                    cachedMagFilter = gl.GL_LINEAR;
                    gl.SamplerParameteri(sampler, gl.GL_TEXTURE_MAG_FILTER, (int)gl.GL_LINEAR);
                    gl.ThrowIfError();
                }
                break;

            case TextureFilter.Anisotropic:
                if (gl.IsAnisotropicFilteringAvailable)
                {
                    var maxAnisotropy = Math.Min(1f, state.MaxAnisotropy);
                    if (maxAnisotropy != cachedMaxAnisotropy)
                    {
                        cachedMaxAnisotropy = maxAnisotropy;
                        gl.SamplerParameterf(sampler, gl.GL_TEXTURE_MAX_ANISOTROPY_EXT, maxAnisotropy);
                        gl.ThrowIfError();
                    }
                }

                if (cachedMinFilter != gl.GL_LINEAR)
                {
                    cachedMinFilter = gl.GL_LINEAR;
                    gl.SamplerParameteri(sampler, gl.GL_TEXTURE_MIN_FILTER, (int)gl.GL_LINEAR);
                    gl.ThrowIfError();
                }

                if (cachedMagFilter != gl.GL_LINEAR)
                {
                    cachedMagFilter = gl.GL_LINEAR;
                    gl.SamplerParameteri(sampler, gl.GL_TEXTURE_MAG_FILTER, (int)gl.GL_LINEAR);
                    gl.ThrowIfError();
                }
                break;

            default:
                throw new NotSupportedException();
            }
        }