pixel icon indicating copy to clipboard operation
pixel copied to clipboard

MakePicture methods always create new TargetPicture

Open gwttk opened this issue 5 years ago • 3 comments

Look at batch.go#L82 and canvas.go#L73 All MakePicture methods return new TargetPicture instances. Also every Sprite caches a TargetPicture. So, does that means, for 10k Sprites created from a single Picture, pixel creates 10k TargetPictures? That sounds very inefficient!

gwttk avatar Apr 13 '19 23:04 gwttk

Yep, means exactly that! This can be efficient or inefficient based on what target you're using. If you're drawing directly to the window, then yes, this will be rather inefficient, because a new OpenGL texture will be allocated for each picture. However, if you use Batch, it will be very efficient because TargetPicture for Batch is just a struct of two pointers and the Batch only makes one TargetPicture from its own target (e.g. window).

faiface avatar Apr 14 '19 20:04 faiface

Hmmm, that makes sense. How about... instead of creating new batchPicture everytime, just reuse it, since every Batch uses only one Picture?

gwttk avatar Apr 16 '19 12:04 gwttk

Looking at it, yeah, that could be done. Feel free to make a PR :)

faiface avatar Apr 16 '19 20:04 faiface