Tobi Reif Posted April 23, 2015 Share Posted April 23, 2015 Am I right in the assumption that calling PIXI.Texture.fromImage often (and inside animation frames) is OK (perf-wise) because the loader (on load) placed the textures in the cache? Or should I continue to create all textures on assets loaded?eg as inhttps://github.com/tobireif/boomchat/blob/master/web/js/main.js#L710 -> function onAssetsLoaded()where I keep the textures in my own array/object, in order to save computation later (for perf). But does this mean that each texture gets generated twice? Once by me and once by Pixi? Should I instead only rely on Pixi's cache, or can there be a performance hit? (eg if the respective texture is not in Pixi's cache anymore) (Info: I'm using Pixi v2 but I plan to switch to v3.) Quote Link to comment Share on other sites More sharing options...
clark Posted April 24, 2015 Share Posted April 24, 2015 Bumped. This is a good question. To me, I see this. Pixi.Texture.fromImage() as a literal process. To take some image, and to convert it into a Pixi Texture (uploading to GPU? Who knows). I do not expect any cache here because I am literally generating a new Texture from an image. And I expect it to do that.But. Lets say:var texture = PIXI.Texture.fromImage()This is a reference to the texture. In a loop..... such as (i < 1000), everything will reference "texture". In other words, reuse texture. PIXI.Texture.fromImage() would create 1000 identical textures, rather than referencing the one that we originally created. I see this as 1000 times slower. I would love clarification. Quote Link to comment Share on other sites More sharing options...
xerver Posted April 25, 2015 Share Posted April 25, 2015 fromImage does cache:https://github.com/GoodBoyDigital/pixi.js/blob/master/src/core/textures/Texture.js#L278-L289This can cause weirdness if you don't know it because many things using the same url there *will* share a texture object.I wish we could remove these convience functions because they are causing more harm than good IMO. Really you should be loading things using the loader, then just use the textures and data it gives to you to create what you need via constructors. The `.from*` methods are really for simple stuff that doesn't even use the loader, or that you don't care about how it is made. Or should I continue to create all textures on assets loaded? Ahh! No! The loader creates textures for you! When you load an image, that resource has a `texture` property that is a shiny new pixi texture for that image, just use it. For example:PIXI.loader.add('derp', 'myimage.png').load(function (loader, resources) { // use the texture that was created for us var derpSprite = new PIXI.Sprite(resources.derp.texture);});These are created for you by the textureParser.js middleware that creates a texture for any loaded Image objects. clark 1 Quote Link to comment Share on other sites More sharing options...
Tobi Reif Posted April 26, 2015 Author Share Posted April 26, 2015 Thanks for the reply! The case where the expected texture is not in Pixi's cache anymore can't occur, right? ("Cache" typically implies that yes it might still be there but otherwise create it.) What I mean is - is the following true?For every loaded image there will be a texture in resources.foo (after load) , and that texture will always be there. Quote Link to comment Share on other sites More sharing options...
xerver Posted April 27, 2015 Share Posted April 27, 2015 The resources you get after the load isn't a cache, it is the things you loaded. If you add something to the loader, it will be in the resources object you get back. Quote Link to comment Share on other sites More sharing options...
Tobi Reif Posted April 27, 2015 Author Share Posted April 27, 2015 Thanks for the explanations! Quote Link to comment Share on other sites More sharing options...
Tobi Reif Posted May 4, 2015 Author Share Posted May 4, 2015 BTW, Chad uses "derp" as a placeholder like "foo" or "bar", it came from an old meme and is not intended to offend the reader Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.