Copy compressed texture to another BitmapData or Texture

Hi

I ran into an issue recently. While compressed textures can be perfectly displayed with Texture.uploadCompressedTextureFromByteArray() and BitmapData.fromTexture(), I’m not able to copy the once rendered texture to another BitmapData.

I tried the followings:

  • new BitmapData(), BitmapData.copyPixels() is empty and additionally the BitmapData is rendered on Canvas (should be WebGL I think)
  • If I create an empty Texture and a BitmapData from that Texture first and copy from the original BitmapData to this new instance, the BitmapData is still empty
  • Tileset, Tilemap also produce empty results for Compressed Textures.

Is there any way to effectively and successfully copy compressed textures to another texture or bitmapdata? I’m trying to use texture atlases and I’m not able to create multiple display objects based on a single texture because of this issue.

Code:

tex2 = context.createTexture(4096, 2048, Context3DTextureFormat.COMPRESSED_ALPHA, false);
tex2.uploadCompressedTextureFromByteArray( atf2, 0 );
bmpd2 = BitmapData.fromTexture( tex2 );
bmp2 = new Bitmap( bmpd2 );
this.addChild( bmp2 ); // success

text4 = context.createTexture(4096, 2048, Context3DTextureFormat.COMPRESSED_ALPHA, false);
// note the empty texture
bmpd4 = BitmapData.fromTexture( text4 );
bmpd4.copyPixels( bmpd2, bmpRect, new Point( 0, 0 ), null, null, true );
bmp4 = new Bitmap( bmpd4 );
this.addChild( bmp4); // fail, the BitmapData is empty

ts = new Tileset( bmpd2, [ bmpRect ] );
tm = new Tilemap( 4096, 2048, ts );
this.addChild( tm ); // this also produces an empty object

Thank you

Hmm we should look into the Tilemap render issue

I also would like to see additional optimizations around bitmap.scrollRect since we should be able to handle that simply with UVs rather than using a stencil (so you can use the same BitmapData for multiple Bitmap objects)

Is Tilemap not working on the develop branch or the latest release?

The Tilemap is now working fine, I re-created the code from scratch to clean up my mess, looks like I forgot to include addTile(Tile). Texture atlases with hardware accelerated textures are now working beautifully.

BitmapData.copyPixels is still empty though, might be something else, maybe I should listen to rendertexture event?

I’m not really into this 3D thing yet, any other way to copy from one compressedtexture to another?

Thank you.

We currently treat compressed textures as a black box, however it would be possible to make a new texture and bitmapData.draw (I believe) to it… though it would no longer be compressed at that point

1 Like

It’s very low priority at the moment, I can totally live without it.

Thanks for looking into it!