BitmapMaterial tips

I was making some experiments with Sandy3d and Papervision3d and I realized some tips to increase the performance.

Firstly, with Sandy3d 3.0, when you create a BitmapMaterial, the BitmapData that you used to create the Material, is cloned to create the BitmapMaterial.texture.
So, one think you can do is dispose the BitmapData that you used to create the Material after instantiating it and also, if you want to update your BitmapData use the BitmapMaterial.texture directly.

Something like this:

var bmpData:BitmapData = new BitmapData(100, 100, true, 0×00000000);
var bmpMaterial:BitmapMaterial = new BitmapMaterial(bmpData);

bmpData.dispose();

bmpMaterial.texture.fillRect(new Rectangle(10,10,30,30), 0xffff0000);

This will not work with Papervision3d because it uses the same BitmapData instance (in my opinion, smarter).

Now for both, Sandy3d and Papervision3d.
As you make changes on your BitmapData, it’s updated on every poligon.
So, use the BitmapData.lock() and BitmapData.unlock() when you are redrawing your BitmapData texture.

var bmpData:BitmapData = new BitmapData(100, 100, false, 0×00000000);
var bmpMaterial:BitmapMaterial = new BitmapMaterial(bmpData);

redrawBitmap();

function redrawBitmap(){

bmpData.lock();

bmpData.fillRect(bmpData.rect, 0×00000000);
bmpData.fillRect(new Rectangle(10,10,30,30), 0xffff0000);

var blurFilter:BlurFilter = new BlurFilter(16, 16, 3);

bmpData.applyFilter(bmpData, bmpData.rect, new Point(0,0), blurFilter);

bmpData.unlock();

}

2 Comments »

  1. Thomas P said,

    December 4, 2007 @ 5:50 pm

    Hi,
    Indeed Sandy does a clone of the original texture, for few reasons:
    - avoid an unfortunate dispose call.
    - allowing to have a setTransparency method to dynamically change the transparency without changing the original bitmapdata of the user.

    Concerning the lock() and unclock() are you sure it has a performance impact?
    as far I know, this can’t provide any performance boost since the bitmapdata isn’t attached to the flash display list. When the object is out of stage, there’s no advantage to lock it.
    But I’d be interessted to have your feedback about that, and your performance test.

    Best,
    Thomas

  2. labs.hellokeita.com » BitmapData.lock benchmark said,

    December 4, 2007 @ 7:22 pm

    [...] read the Thomas Pfeiffer aka Kiroukou (the Sandy3D creator and project leader) commented on my previous post. Here’s what he said. Indeed Sandy does a clone of the original texture, for few reasons: - [...]

RSS feed for comments on this post · TrackBack URI

Leave a Comment