libgdx最近的纹理过滤是强制的吗?

时间:2016-02-08 19:04:30

标签: java libgdx textures filtering

嗨我正在从blender进行简单的导入,我在纹理过滤方面遇到了问题。 纹理似乎被最近的最小过滤器过滤 nearest min filter , linear mag filter issue 但质疑其纹理描述属性表示其线性。 将其设置为线性过滤也不会改变情况

enter image description here http://s10.postimg.org/wgmxoz5fd/issue.png

1 个答案:

答案 0 :(得分:0)

我认为LibGDX没有可用于打开各向异性过滤的方法,但您可以尝试这个帮助程序类。 OpenGL ES不保证支持Aniostropic过滤,因此必须检查可用性。在过去的一年里,我没有用LibGDX测试过这个,所以我不肯定它仍能正常工作。

public class Anisotropy {

    private static boolean anisotropySupported = false;
    private static boolean checkComplete = false;
    private static float maxAnisotropySupported = 1.0f;

    /**Applies the given anisotropic level to the texture. Returns the anisotropy value that was applied, 
     * based on device's maximum capability.
     * @param texture The texture to apply anisotropy to.
     * @param anisotropy The anisotropic level to apply. (Will be reduced if device capability is less.)
     * @return The anisotropic level that was applied, or -1.0 if anisotropy is not supported by the device.
     */
    public static float setTextureAnisotropy(Texture texture, float anisotropy){
        if (isSupported()) {
            texture.bind();
            float valueApplied = Math.min(maxAnisotropySupported, anisotropy);
            Gdx.gl20.glTexParameterf(GL20.GL_TEXTURE_2D, GL20.GL_TEXTURE_MAX_ANISOTROPY_EXT, valueApplied);
            return valueApplied;
        } else {
            return -1f;
        }
    }

    public static boolean isSupported(){
        if (!checkComplete){
            GL20 gl = Gdx.gl;
            if (gl != null){
                if (Gdx.graphics.supportsExtension("GL_EXT_texture_filter_anisotropic")){
                    anisotropySupported = true;
                    FloatBuffer buffer = BufferUtils.newFloatBuffer(16);
                    Gdx.gl20.glGetFloatv(GL20.GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, buffer);
                    maxAnisotropySupported = buffer.get(0);
                }
                checkComplete = true;
            } else 
                throw new UnsupportedOperationException("cannot check GL state before libgdx initialized");
        }
        return anisotropySupported;
    }

}