Hi,
For some reason, I cannot seem to load textures created with astc-encoder (from ARM-software/astc-encoder · GitHub ) using glCompressedTexImage2D on an Android device. (Using the Oculus Mobile SDK)
I am creating the textures with this command:
astcenc -c anim_texture.0001.tga anim_texture.0001.astc 8x8 -thorough
(actually a for loop running this command for a large number of textures, but this illustrates it...)
Here is the output of astcenc encoding one of those textures:
=====
Encoding settings:
2D Block size: 8x8 (2.00 bpp)
3D Block size: 8x8x1 (2.00 bpp)
Radius for mean-and-stdev calculations: 0 texels
RGB power: 1
RGB base-weight: 1
RGB local-mean weight: 0
RGB local-stdev weight: 0
RGB mean-and-stdev mixing across color channels: 0
Alpha power: 1
Alpha base-weight: 1
Alpha local-mean weight: 0
Alpha local-stdev weight: 0
RGB weights scale with alpha: disabled
Color channel relative weighting: R=1 G=1 B=1 A=1
Block-artifact suppression parameter : 0
Number of distinct partitionings to test: 100 (preset)
PSNR decibel limit: 2D: 42.682579 3D: 42.682579 (preset)
1->2 partition limit: 2.500000
Dual-plane color-correlation cutoff: 0.950000 (preset)
Block Mode Percentile Cutoff: 95.000000 (preset)
Max refinement iterations: 4 (preset)
Thread count : 12 (autodetected)
anim_texture.0001.tga: 2D LDR image, 4096 x 4096 x 1, 3 components
262144 blocks to process ..
262143
In my source code, I am loading the texture like this:
glCompressedTexImage2D(GL_TEXTURE_2D, 0, /* target, level */ GL_COMPRESSED_RGBA_ASTC_8x8_KHR, /* internal format */ 4096, 4096, 0, /* width, height, border */ 4194320, /* size */ buffer /* pixels */);
The textures are all exactly 4096x4096 texels in dimension, 4194320 is the length of the compressed texture files astcenc has produced, in bytes, and buffer is a pointer to the contents of one of those texture files, with no modifications.
Running this fails, giving the gl error GL_INVALID_VALUE (0x501) from glGetError().
Meanwhile, a coworker of mine has produced some ASTC compressed textures using the Unity engine, and those work flawlessly with my code. (Although they are upside down for some reason... Not a big deal, though.)
Is there something I'm missing here? Do the texture files created by astcenc maybe contain some kind of header that should not be including when setting the actual texture?
Although they are upside down for some reason...
Known quirk of the encoder - ASTC uses the DirectX coordinate system when compressing (origin = top left) whereas the OpenGL origin uses the bottom left for texture coordinates.
The 8x8 block is a bitrate of 2bpp, so for a 4096x4096 texture you would expect 4194304 bytes for the texture data itself, so it looks like you have a 16 byte header on the data.
EDIT: Yes, confirmed. See this line in the encoder source for the header definition:
astc-encoder/astc_toplevel.cpp at 437f2423fede947a09086f28f547d1897bfe4546 · ARM-software/astc-encoder · GitHub
HTH,
Pete
Thanks, that solved my problem! I now rewrote my texture loader to parse that header; it is actually kinda handy to have if you know about it.
I still find it a bit irritating, though, that the documentation seems to make no mention at all of that header.
Agreed - I'll raise a ticket with our tooling team to get this improved in a future release.
Thanks for the feedback,
Regards, Pete