liballeg / allegro5

The official Allegro 5 git repository. Pull requests welcome!
https://liballeg.org
Other
1.87k stars 282 forks source link

Support compressed texture uploads to GPU #1033

Open guilt opened 5 years ago

guilt commented 5 years ago

Essentially, this is the matrix of popular, most used texture compression. This means that we may not be able to support all operations on these compressed textures/bitmaps, but they'd be much faster to upload to the GPU, and give us plenty headroom. It is quite helpful on mobile devices and such.

guilt commented 5 years ago

Also see #559

beoran commented 5 years ago

We already have some support for DDS files with textures compressed in the DXT1, DXT3 and DXT5 formats. If the other formats are unencumbered by patent, then we could also implement those. See e.g. https://github.com/liballeg/allegro5/blob/5.2.4/addons/image/dds.c for more information.

SiegeLord commented 5 years ago

Yeah, we already have some support for (blocked) compressed textures. See al_lock_bitmap_blocked for the method to convert to GPU. For OpenGL this uses glCompressedTexSubImage2D under the hood. We'll have to think how to support non-blocked compressed textures and things like ASTC which have variable block size.

guilt commented 5 years ago

ASTC offers varying block sizes, but the block size is still fixed within a file; Just that the total number of bytes per block is a constant = 16 bytes. So, the bits per pixel are different.

Source: https://arm-software.github.io/opengl-es-sdk-for-android/astc_textures.html

ETC1 offers a fixed block size per 4 x 4 pixel block, but varying bit per block (5-5-5+3-3-3) or (4-4-4+4-4-4).

The usecase for this ticket / something like this is to just allow the entire bitmap data to be uploaded as-is compressed into the GPU, and not assumed to be efficient for user modification; This may be like using glCompressedTexImage2D for uploading the texture.