I am working with TypeScript and three.js, and trying to load a compressed texture manually. The texture data is in DXT1 format, and so I have it stored in a Uint16Array. So far I am struggling to create a CompressedTexture from a Uint16Array, so it could be split into a Uint8Array with double size, as I did in the snippet below.
I have tried different combinations of texture formats, and widths and heights, and ways to try and trick the ImageData that the CompressedTexture seems to need as input for the mipmaps. But so far I am simply not getting any results.
This is roughly how I try to create the texture:
const w = this._width / 2; // divide by 2 instead of 4, to account for not using 64 bit pixels but 32 bit
const h = this._height / 4;
// 'data' has (4 * w * h) bytes
const data: Uint8ClampedArray = this.getData();
const mip0: ImageData = new ImageData(data, w, h);
const texture: CompressedTexture = new CompressedTexture([mip0], this._width, this._height, RGB_S3TC_DXT1_Format);
texture.needsUpdate = true;
This is the closest I got to making it work and not complain, but it still doesn't work. I receive the GL_INVALID_VALUE: Invalid compressed image size
warning at runtime when the texture is used in a regular MeshBasicMaterial
.
I have tried loading a DDS texture using the DDSLoader, and that works fine.