我最近更新了纹理的加载代码,还添加了一些新功能,如 mipmap 加载(最后一个应用程序只有 2D,所以我不需要它们)。但是加载的 PVRTC 纹理在使用 mipmap 时保持黑色,没有 mipmap 一切都按预期工作,并且在使用像 RGBA8888 纹理这样的纹理时,mipmap 也可以工作。
加载压缩数据:
for (int i = 0; i < source.MipmapCount; i++)
{
data = source.GetData(i);
GLTextures.CompressedTexImage2D(TextureType.TEXTURE_2D, i, Format.CompressedFormat.Value, Width >> i, Height >> i, data.Length, data);
Debug.WriteGLError("Texture2D->CompressedTexImage2D", "MipmapLevel={0}", i);
}
过滤设置:
if (source.MipmapCount == 0)
{
switch (filterQuality)
{
case FilterQuality.Nearest:
GLTextures.TexParameteri(TextureType.TEXTURE_2D, TexParameter.TEXTURE_MIN_FILTER, (Int32)TextureMinFilterParams.NEAREST);
GLTextures.TexParameteri(TextureType.TEXTURE_2D, TexParameter.TEXTURE_MAG_FILTER, (Int32)TextureMagFilterParams.NEAREST);
break;
case FilterQuality.Linear:
GLTextures.TexParameteri(TextureType.TEXTURE_2D, TexParameter.TEXTURE_MIN_FILTER, (Int32)TextureMinFilterParams.LINEAR);
GLTextures.TexParameteri(TextureType.TEXTURE_2D, TexParameter.TEXTURE_MAG_FILTER, (Int32)TextureMagFilterParams.LINEAR);
break;
}
Debug.WriteGLError("Texture2D->TexParameteri without mipmaps");
}
else
{
switch (filterQuality)
{
case FilterQuality.Nearest:
GLTextures.TexParameteri(TextureType.TEXTURE_2D, TexParameter.TEXTURE_MIN_FILTER, (Int32)TextureMinFilterParams.NEAREST_MIPMAP_LINEAR);
GLTextures.TexParameteri(TextureType.TEXTURE_2D, TexParameter.TEXTURE_MAG_FILTER, (Int32)TextureMagFilterParams.NEAREST);
break;
case FilterQuality.Linear:
GLTextures.TexParameteri(TextureType.TEXTURE_2D, TexParameter.TEXTURE_MIN_FILTER, (Int32)TextureMinFilterParams.LINEAR_MIPMAP_LINEAR);
GLTextures.TexParameteri(TextureType.TEXTURE_2D, TexParameter.TEXTURE_MAG_FILTER, (Int32)TextureMagFilterParams.LINEAR);
break;
}
Debug.WriteGLError("Texture2D->TexParameteri with mipmaps");
if (anisotropicQuality > 1f && GL.IsExtensionSupported(Extension.GL_EXT_texture_filter_anisotropic))
{
// GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT
GLTextures.TexParameter(TextureType.TEXTURE_2D, 0x84FF, Mathf.Clamp(anisotropicQuality, 1f, GL.GetFloat(GetFloatName.TEXTURE_MAX_ANISOTROPY)));
Debug.WriteGLError("Texture2D->Anisotropy");
}
}
纹理 的加载 加载是通过修改后的 PVR 文件参考加载器完成的。我检查了每个 mipmap 的字节长度,最后几个数组的大小为 32 个字节( PVRTC 的最小大小)。什么可能导致问题?
编辑
方法“GLTextures.CompressedTexImage2D”。
public static void CompressedTexImage2D(TextureType target, Int32 level, CompressedFormats internalFormat, Int32 width, Int32 height, Int32 imageSize, Byte[] pixels)
{
/* Used for mobile apps for debugging purposes */
Debug.CheckMethodLoaded(glCompressedTexImage2D);
Profiler.IncreaseCallCount("glCompressedTexImage2D");
glCompressedTexImage2D(target, level, internalFormat, width, height, 0, imageSize, pixels);
}
图像格式定义:
PVRTC2RGB = new ImageFormat("PVRTC2RGB", CompressedFormats.COMPRESSED_RGB_PVRTC_2BPPV1_IMG, 16, 8, bitsPerPixel: 2, requiredExtension:Extension.GL_IMG_texture_compression_pvrtc);
PVRTC2RGBA = new ImageFormat("PVRTC2RGBA", CompressedFormats.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG, 16, 8, bitsPerPixel: 2, requiredExtension: Extension.GL_IMG_texture_compression_pvrtc);
PVRTC4RGB = new ImageFormat("PVRTC4RGB", CompressedFormats.COMPRESSED_RGB_PVRTC_4BPPV1_IMG, 8, 8, bitsPerPixel: 4, requiredExtension: Extension.GL_IMG_texture_compression_pvrtc);
PVRTC4RGBA = new ImageFormat("PVRTC4RGBA", CompressedFormats.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG, 8, 8, bitsPerPixel: 4, requiredExtension: Extension.GL_IMG_texture_compression_pvrtc);