# Equivalent for the three.js CompressedTexture

**URL:** <https://forum.babylonjs.com/t/equivalent-for-the-three-js-compressedtexture/26374>\
**Category:** Questions\
**Created:** [December 30, 2021, 5:01pm UTC](https://forum.babylonjs.com/t/equivalent-for-the-three-js-compressedtexture/26374 "2021-12-30T17:01:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![magicfelix](https://avatars.discourse-cdn.com/v4/letter/m/c68b51/32.png) [@magicfelix](https://forum.babylonjs.com/u/magicfelix)\
**Post date:** [December 30, 2021, 5:01pm UTC](https://forum.babylonjs.com/t/equivalent-for-the-three-js-compressedtexture/26374/1 "2021-12-30T17:01:58Z")

</div>

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

```auto
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:

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

```

Thanks

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [December 31, 2021, 10:10am UTC](https://forum.babylonjs.com/t/equivalent-for-the-three-js-compressedtexture/26374/2 "2021-12-31T10:10:51Z")

</div>

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:

> <https://github.com/BabylonJS/Babylon.js/blob/master/src/Misc/khronosTextureContainer2.ts#L284>

The signature of the function is:

> <https://github.com/BabylonJS/Babylon.js/blob/d9457c9f840a62c6fbdec32226ec80d18333608e/src/Engines/thinEngine.ts#L4015>

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

> <https://github.com/BabylonJS/Babylon.js/blob/master/src/Engines/constants.ts#L176-L192>

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](https://code.woboq.org/qt5/qtbase/src/gui/opengl/qopengltexture.h.html)).

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

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [December 31, 2021, 10:21am UTC](https://forum.babylonjs.com/t/equivalent-for-the-three-js-compressedtexture/26374/3 "2021-12-31T10:21:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![magicfelix](https://avatars.discourse-cdn.com/v4/letter/m/c68b51/32.png) [@magicfelix](https://forum.babylonjs.com/u/magicfelix)\
**Post date:** [January 1, 2022, 5:53pm UTC](https://forum.babylonjs.com/t/equivalent-for-the-three-js-compressedtexture/26374/4 "2022-01-01T17:53:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [January 3, 2022, 5:13pm UTC](https://forum.babylonjs.com/t/equivalent-for-the-three-js-compressedtexture/26374/6 "2022-01-03T17:13:09Z")

</div>

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