These are chat archives for pixijs/pixi.js

24th
Feb 2016
Bar Ziony
@bartzy
Feb 24 2016 13:14
How does PIXI know what sprites of type A can it draw in a batch and which it cannot (since it will result in wrong zIndex) ?
I'm looking at the SpriteRenderer.js file
Micheal Winger
@mordof
Feb 24 2016 13:42
isn't it based on order of added children?
ohh i see what you mean i think
easiest way to implement i would imagine is just first child encountered in list of children, batch all others like it together, draw those.. then continue to next differing child
with that said, i have no idea how they've actually done it
Chad Engler
@englercj
Feb 24 2016 16:10
How does PIXI know what sprites of type A can it draw in a batch and which it cannot (since it will result in wrong zIndex) ?
It iterates the scene and at each sprite, the sprite calls the sprite renderer to "render" it
the renderer checks if the sprite has a different texture or shader than those before it that were added in, if it is the same it adds its data to the vertex buffer and does nothing. If it is different, it flushes the vertex buffer with a draw for all the sprites it had batched up, resets, and adds the new sprite.
If during the scene walk we change to a different renderer (e.g. it starts rendering a Mesh object) then the active renderer is flushed, and we activate the new renderer.
when the scene walk is complete, the active renderer is flushed.
Joris Slagter
@Jorisslagter
Feb 24 2016 16:17
If you add a child to the container, you're adding different kinds of sprites?
Chad Engler
@englercj
Feb 24 2016 16:17
?
If you add a child to the container
that has a different class, texture, shader, or a mask
then you break the batch
if it is a sprite, with the same base texture as others, uses the same shader as others, and has no mask
it doesn't break the batch
Joris Slagter
@Jorisslagter
Feb 24 2016 16:21

In case A: you have a class called Bus with a texture, shader and mask.
In case B: you have a class called Car with a texture, shader and mask.

When both are added to the container, you can iterate the children and check the type of the child. Right?

Chad Engler
@englercj
Feb 24 2016 16:21
but we don't
because this is javascript
if they are using the sprite renderer, we assume they are sprites
and if they have the right properties, they are
but if they have a mask
that breaks the batch
we have to do special rendering for masks
Joris Slagter
@Jorisslagter
Feb 24 2016 16:24
Then it might be good to do an extra check to see what kind "instanceof" this.children[i] is.
Chad Engler
@englercj
Feb 24 2016 16:24
why>
Joris Slagter
@Jorisslagter
Feb 24 2016 16:25
To make sure it is a sprite
Chad Engler
@englercj
Feb 24 2016 16:25
why
don't call spriteRenderer.render() if it isn't a sprite
which, nothing but sprite calls
SpriteRenderer.render() takes a sprite, passing anything else is a user error
Joris Slagter
@Jorisslagter
Feb 24 2016 16:28
I don't fully understand what this has to do with the z-index :D
Chad Engler
@englercj
Feb 24 2016 16:29
?
Absolutely nothing
no one asked about z-index
He asked how do we draw in a batch
How does PIXI know what sprites of type A can it draw in a batch and which it cannot
Joris Slagter
@Jorisslagter
Feb 24 2016 16:29

Bug? ::

Englercj > How does PIXI know what sprites of type A can it draw in a batch and which it cannot (since it will result in wrong zIndex) ?

Chad Engler
@englercj
Feb 24 2016 16:29
batching and z-index are in no way related
the z-index is correct, because we stop the batch when things are different
and they are still drawn in the same order, just in a single shader pass
Joris Slagter
@Jorisslagter
Feb 24 2016 16:30
Did you replay on somebody else? :D
Chad Engler
@englercj
Feb 24 2016 16:30
batching doesn't effect z-index (when done correctly)
Joris Slagter
@Jorisslagter
Feb 24 2016 16:30
Indead
Chad Engler
@englercj
Feb 24 2016 16:31
I was replying to the how do we do batching part
hopefully after explaining, it is obvious how z-index is uneffected
especially since technically there is no z-index :)
Joris Slagter
@Jorisslagter
Feb 24 2016 16:32
Sorry for the confusion :)
Chad Engler
@englercj
Feb 24 2016 16:32
np
Joris Slagter
@Jorisslagter
Feb 24 2016 16:34
But what is the problem with batching, I never used it. I believe.
I would like to contribute, is there a way to help?