【问题标题】:libgdx Nearest texture filtering is forced?libgdx 最近的纹理过滤是强制的吗?
【发布时间】:2016-05-18 13:36:06
【问题描述】:

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

http://s10.postimg.org/wgmxoz5fd/issue.png

【问题讨论】:

  • 我认为您没有看到最近的过滤。您会看到缺少各向异性过滤。我不认为 LibGDX 有方便的方法来打开它。您必须直接调用 OpenGL。
  • 感谢您的回复,我尝试使用 .gl 命令启用 mipmapping 和线性过滤器之类的功能 - 我认为它已禁用 - 但没有成功,我将再次尝试查找与各向异性过滤相关的内容。 ..谢谢(Y)
  • 我尽我所能尝试但没有成功-首先各向异性过滤*获得最大各向异性并将其设置为opengl纹理-其次在加载纹理时启用mipmaping这让我感到沮丧,应该是一个简单的问题解决我最后的猜测是着色器中的采样器正在强制某些东西明天会尝试......

标签: java libgdx textures filtering


【解决方案1】:

更新的答案: 从 libGDX 1.9.11 开始,Texture 类有一个setAnisotropicFilter 方法,使用如下:

myTexture.setAnisotropicFilter(16f);

原答案: 我认为 LibGDX 没有可用于打开各向异性过滤的方法,但你可以试试这个帮助类。 OpenGL ES 不保证支持各向异性过滤,因此它必须检查可用性。在过去的一年里我没有用 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;
    }
    
}

【讨论】:

  • 试过了,没有任何改变,原来是我的代码 FloatBuffer buf = BufferUtils.newFloatBuffer(64); Gdx.gl.glGetFloatv(GL20.GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT,buf);浮动 maxAniso = buf.get(0); System.out.println(maxAniso); groundTexture.bind(); Gdx.gl.glTexParameterf(GL20.GL_TEXTURE_2D,GL20.GL_TEXTUR_MAX_ANISOTROPY_EXT, Math.min(16, maxAniso));无论如何感谢您的帮助
  • 您是否生成了 mipmap?
  • 是的,我尝试了给定的代码 TextureAttribute myTex =(TextureAttribute)GroundInstance.materials.get(0).get(TextureAttribute.Diffuse);纹理groundTexture = new Texture(Gdx.files.internal("badlogic.jpg"), Pixmap.Format.RGB565,true); groundTexture.setWrap(myTex.textureDescription.uWrap,myTex.textureDescription.vWrap); groundTexture.setFilter(Texture.TextureFilter.MipMapLinearLinear, Texture.TextureFilter.MipMapLinearLinear); myTex.textureDescription.texture.load(groundTexture.getTextureData());
  • 我正在覆盖导入模型 ~g3db 中的纹理,并将纹理更改为新的“badlogic.jpg”,但问题是同样的问题是在被 返回 true ,而不是原始 g3db 纹理中的 false
猜你喜欢
  • 1970-01-01
  • 2013-09-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多