Is there a way to batch motion streak node?

Is there a way to batch motion streak node?
0

Is there a way to batch a motion streak node? Ive noticed that every motion streak I add, adds a draw call. All of my other sprites I use a texture from sprite atlas.

The motion streak uses a single png image. Ive tried getting the texture from the atlas like:

SpriteFrame* sf = SpriteFrameCache::getInstance()->getSpriteFrameByName("8x8_pixel.png");
Texture2D* tex = sf->getTexture();

this->streak = MotionStreak::create(0.25f, 1, 4, gm.getColorBlue(), tex);

Still a new draw call for every streak and for some reason the streak looks garbled when getting the texture from the atlas.

Anyone? Any ideas on how to reduce draw calls for MotionStreak?

MotionStreak does not batch currently. For v4.0 it should be possible to batch most draw calls that are compatible since there will be one way to submit geometry.

Okay, not a huge deal, just wanted to know if it was possible. Thanks for the response!

I am very interested in this too. The streak looking ‘garbled’ is because it is using the entire texture atlas. I can’t find a way to specify only the needed portion of the big texture. The alternative is to load a new texture from file containing only the streak texture, which works but is not very convenient for me as I am trying to optimize texture memory.

Bringing this back from the dead…
Has anyone attempted this in cocos2d-x v3.x libs?

I have a ton of streak nodes in my new animation refactoring, and was wanting to batch them since they use the same texture…

I was looking around MotionStreak class and was thinking of some way to group the CustomCommands some how based on a MotionStreakBatchNode I was going to build similar to SpriteBatchNode.

Don’t want to reinvent the wheel if someone else has made this work, please let me know. Thanks.
Or if anyone has done batching on other types of CustomCommands in 3.x, any tips would be appreciated.

Ok, so after a long… long… night, I think I have the solution working.

I will likely put my MotionStreakBatchNode on GitHub soon and share in another thread.

Basically… I created a new Node that you add MotionStreak instances to, similar to how Sprites can be added to SpriteBatchNode. It has the same asserts for class type and texture validations.

For the actual rendering, I overrode the visit and draw methods in the new batch node to not propagate to the MotionStreaks themselves. Instead, I let them calculate their vertex array attributes as normal, and then combine all the triangle strips in one glDrawArrays call. A huge issue I ran through and didn’t figure out for a few hours was the ‘degenerate triangle’ use case to where you can separate triangle strips with 0 area triangles in-between the strips. This way, now, many MotionStreak instances using the same texture, can all be doing their own thing in different places, but are drawn as one GL_TRIANGLE_STRIP.

Hard work pays off for the mini win … :rocket:

Reference:
https://developer.apple.com/library/archive/documentation/3DDrawing/Conceptual/OpenGLES_ProgrammingGuide/TechniquesforWorkingwithVertexData/TechniquesforWorkingwithVertexData.html

Figure 8-6 in the guideline shows how I made it work with degenerate triangles, for anyone looking to dig deeper into batching more of the misc/custom nodes that are out there…

1 Like

Sorry for the remark… just wanted to link the solution in case people in the future end up here…
I made the solution a separate thread in case anyone had questions or discussion relating to that specifically…