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:
throw new Error("KTX2 container - could not transcode one of the image");
}
if (data.transcodedFormat === 0x8058 /* RGBA8 */) {
// uncompressed RGBA
internalTexture.width = mipmap.width; // need to set width/height so that the call to _uploadDataToTextureDirectly uses the right dimensions
internalTexture.height = mipmap.height;
this._engine._uploadDataToTextureDirectly(internalTexture, mipmap.data, 0, t, undefined, true);
} else {
this._engine._uploadCompressedDataToTextureDirectly(internalTexture, data.transcodedFormat, mipmap.width, mipmap.height, mipmap.data, 0, t);
}
}
internalTexture._extension = ".ktx2";
internalTexture.width = data.mipmaps[0].width;
internalTexture.height = data.mipmaps[0].height;
internalTexture.isReady = true;
this._engine._bindTextureDirectly(oglTexture2D, null);
}
The signature of the function is:
gl.texParameteri(target, gl.TEXTURE_COMPARE_FUNC, Constants.LEQUAL);
gl.texParameteri(target, gl.TEXTURE_COMPARE_MODE, gl.NONE);
}
else {
gl.texParameteri(target, gl.TEXTURE_COMPARE_FUNC, comparisonFunction);
gl.texParameteri(target, gl.TEXTURE_COMPARE_MODE, gl.COMPARE_REF_TO_TEXTURE);
}
}
/** @hidden */
public _uploadCompressedDataToTextureDirectly(texture: InternalTexture, internalFormat: number, width: number, height: number, data: ArrayBufferView, faceIndex: number = 0, lod: number = 0) {
var gl = this._gl;
var target = gl.TEXTURE_2D;
if (texture.isCube) {
target = gl.TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex;
}
if (texture._useSRGBBuffer) {
switch (internalFormat) {
case Constants.TEXTUREFORMAT_COMPRESSED_RGBA_BPTC_UNORM:
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.