简体   繁体   English

OpenGL的无损纹理压缩

[英]Lossless texture compression for OpenGL

I have several 32-bit(with alpha channel) bitmap images which I'm using as essential information in my game. 我有几个32位(带有alpha通道)位图图像,这些图像在我的游戏中用作基本信息。 Slightest change in RGBA values breaks everything, so I can't use lossy compression methods like S3TC. RGBA值的微小变化会破坏所有内容,因此我不能使用像S3TC这样的有损压缩方法。

Is there any feasible lossless compression algorithms I can use with OpenGL? 我可以在OpenGL中使用任何可行的无损压缩算法吗? I'm using fragment shaders and I want to use the glCompressedTexImage2D() method to define the texture. 我正在使用片段着色器,并且想使用glCompressedTexImage2D()方法定义纹理。 I haven't tried compressing the texture with OpenGL using GL_COMPRESSED_RGBA parameter, is there any chance I can get lossless compression that way? 我没有尝试使用GL_COMPRESSED_RGBA参数用OpenGL压缩纹理,有没有机会以这种方式获得无损压缩?

Texture compression, as opposed to regular image compression, is designed for one specific purpose: being a texture . 与常规图像压缩相反,纹理压缩是针对一种特定目的而设计的: 纹理 And that means fast random access of data. 这意味着可以快速随机访问数据。

Lossless compression formats do not tend to do well when it comes to random access patterns. 当涉及随机访问模式时,无损压缩格式往往效果不佳。 The major lossless compression formats are some form of RLE or table-based encoding. 主要的无损压缩格式是某种形式的RLE或基于表的编码。 These are adequate for decompressing the entire dataset at once, but they're terrible at being able to know in which memory location the value for texel (U,V) is. 这些足以立即解压缩整个数据集,但是它们很糟糕 ,因为它们无法知道texel(U,V)的值在哪个内存位置。

And that question gets asked a lot when accessing textures. 当访问纹理时,这个问题被问了很多

As such, there are no lossless hardware texture compression formats. 因此,没有无损的硬件纹理压缩格式。

Your options are limited to the following: 您的选择仅限于以下几种:

  1. Use texture memory as a kind of cache. 使用纹理内存作为一种缓存。 That is, when you determine that you will need a particular image in this frame, decompress it. 也就是说,当您确定在此帧中需要特定的图像时,请对其进行解压缩。 This could be done on the CPU or GPU (via compute shaders or the like). 这可以在CPU或GPU上完成(通过计算着色器等)。 Note that for fast GPU decompression, you will have to come up with a compression scheme that takes advantage of parallel execution. 请注意,要实现快速的GPU解压缩,您将不得不提出一种利用并行执行优势的压缩方案。 Most lossless compression formats are not particularly parallel. 大多数无损压缩格式不是特别并行。

    If a particular image has not been used in some time, you put it in a "subject to be reused" pile. 如果某个图像在一段时间内未使用,则将其放入“可重复使用的对象”堆中。 And if you need to decompress a new image, you can take the least-recently-used image off of that pile, rather than constantly creating/destroying OpenGL texture objects. 而且,如果需要解压缩新图像,则可以从堆栈中删除最近使用的图像,而不用不断创建/销毁OpenGL纹理对象。

  2. Build your own lossless compression scheme, designed for your specific needs. 建立自己的无损压缩方案,以满足您的特定需求。 If you absolutely need exact texel values from the texture, I assume that you aren't using linear filtering when accessing these textures. 如果您绝对需要纹理中的确切纹理像素值,那么我认为访问这些纹理时没有使用线性滤波。 So these aren't really colors; 所以这些并不是真正的颜色。 they're arbitrary information about a texel. 它们是关于纹理像素的任意信息。

    I might suggest field compression (improved packing of your bits in the available space). 我可能会建议使用字段压缩(在可用空间中改进您的位的打包)。 But without knowing what your data actually is or means, I can't say whether your particular use case is amenable to it. 但是,在不知道您的数据实际是什么或意味着什么的情况下,我不能说您的特定用例是否适合它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM