Equivalent for the three.js CompressedTexture

What is the BabylonJs equivalent for the three.js Texture Type of:

CompressedTexture( mipmaps : Array, width : Number, height : Number, format : Constant, type : Constant, mapping : Constant, wrapS : Constant, wrapT : Constant, magFilter : Constant, minFilter : Constant, anisotropy : Number )

Is it RawTexture?
I receive an Int8Array and need to generate a texture from it.
The texture is encoded as RGB_S3TC_DXT1 or RGBA_ASTC_8x8 format.

here is the concrete implementation I have to translate:

new THREE.CompressedTexture(null, textureSizeX, textureSizeY,
THREE.RGB_S3TC_DXT1_Format, THREE.UnsignedByteType, THREE.UVMapping,
THREE.ClampToEdgeWrapping, THREE.ClampToEdgeWrapping,
THREE.LinearFilter, THREE.LinearFilter)

Thanks

You will need to create a RawTexture and then use engine._uploadCompressedDataToTextureDirectly to update the texture with compressed data.

That’s what the KTX2 loader is doing:

The signature of the function is:

internalFormat is the format of the compressed texture. We have a list of predefined values for some formats:

If your format is not in the list, you will need to find the right value. For eg, RGBA_ASTC_8x8 is 0x93B7 (see qopengltexture.h source code [qtbase/src/gui/opengl/qopengltexture.h] - Woboq Code Browser).

@sebavan Maybe we could provide on RawTexture a method to update compressed data?

3 Likes

I think that for WebGL you will also need to call engine._bindTextureDirectly(engine._gl.TEXTURE_2D, texture, true); before calling _uploadCompressedDataToTextureDirectly and engine._bindTextureDirectly(engine._gl.TEXTURE_2D, null); after.

Thanks @Evgeni_Popov. Your solution works! Would love to see a more straight forward solution to update the compressed data like you suggested.

@magicfelix can you provide a sample code in the PG ? I ll use it to add a special update function for compressed texture.