Flippsor Posted March 11, 2021 Share Posted March 11, 2021 Hey guys, i am using PIXI.js for some months now and i am pretty happy with it. I am building a top down 2D CAD Software which uses a lot of PIXI.Graphics to draw Objects like Arrows/Lines/Rectangles etc. These are often combined in a PIXI.Container with parent/child relationship. So now my questions: Remove PIXI.Container (PIXI.Graphics) the right way If i have to remove a Graphics object, i use removeChild() from parent container. Is this everything i need to do? Or do i have to call .destroy() on the child, too? Redraw Graphics If i need to redraw a Graphic i can choose to either addChild/removeChild a new Graphic or just use the same Graphic with .clear() again. What technique is more performant and should be used? Thanks in advance! Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted March 11, 2021 Share Posted March 11, 2021 > I am building a top down 2D CAD Software > What technique is more performant and should be used? Ideally, you need to read all the source code, understand all the allocation places and decide for yourself whether to use it as is, patch it, or make a new one. destroy() also takes care of videomemory, in case object wasnt small and had a webgl VAO and buffers bound. Its not disposed automatically. clear() kinda empties js arrays, i dont know what else to say about it - there are many places of allocation when you fill the graphics. General optimization is like in all other renderers - separate your scene to graphics objects but not too many Use chunks if you know what is it. Quote Link to comment Share on other sites More sharing options...
Flippsor Posted March 16, 2021 Author Share Posted March 16, 2021 Sorry for my late answer and thanks for your feedback. So to summarize your feedback i should follow these rules ?!? - stick your graphics together when possible. Dont use addchild when sticking graphics together instead draw all in one graphic object - use .clear() to redraw graphics !?! I am not quite sure about to use or not to use destroy(). How do i know if the object had an webgl VAO and buffers bound? Is the solution always to destroy() an object after removeChild()? Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted March 18, 2021 Share Posted March 18, 2021 (edited) > Is the solution always to destroy() an object after removeChild()? Yes, for Graphics. Also, destroy() calls removeChild automatically. Btw, small graphics objects (<100 vertices, no arcs) dont have VAO, they just get batched with sprites. Edited March 18, 2021 by ivan.popelyshev karlbot 1 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.