How cocos2d-x and cocos2d-iphone guarantee the correct zorder(occlusion) for a single batch drawing of 2 sprites?

Multi tool use
Multi tool use


How cocos2d-x and cocos2d-iphone guarantee the correct zorder(occlusion) for a single batch drawing of 2 sprites?



For 2d drawing, the occlusion is performed by the order of drawing. The later one will occlude the former one.
But when all drawing are done in one call, how would cocos2d-x(and cocos2d iphone for spriteBatchNode) guarantee the correct occlusion ?



A simple example, sprite B and sprite C are both under node A. They're with the same texture, shader, blendFunc, which make them to be optimized by the auto batching rendering system of cocos2d-x 3.x(In the case of cocos2d-iphone, they're using the same spritesheet as texture and under the same spriteBatchNode), and drawn in one single call of glDrawElements. AFAIK, the depth test is disabled for gles at this moment. If we want sprite C to cover sprite B, we should draw B first and then C. But now they are drawn together. How can the rendering system guarantee the correct occlusion of C and B?



Please correct me if I made any mistake.




1 Answer
1



I found the following quote in the OpenGL spec
"This means, for example, that one primitive must be drawn completely before any subsequent one can affect the framebuffer"
https://www.khronos.org/registry/OpenGL/specs/es/3.2/es_spec_3.2.pdf



Therefore, I came to the conclusion that primitives are drawn in the order they appear in the vertex array. This guarantees the stability of the result.



References:



https://www.opengl.org/discussion_boards/showthread.php/176630-Rendering-order-within-a-single-draw-call



https://forums.imgtec.com/t/order-of-operation-for-vertex-arrays/787



Finally, although B and C are drawn in a single glDrawElements, their primitives have a different order in the vertex array. So in Cocos2d-x, the one with the lower localZOrder will be drawn before the one with the higher localZOrder. They're actually not drawn together.


glDrawElements


localZOrder


localZOrder






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

FngJg,Ai,nRzwEKJVZUQH5c,CXLk ZBVUS,sfgLvOS 9V 7f nXqQIY,MnM35 Zbg,6vgEsdGmAPG 566mSHQP1MvEv wb2
he AE,XSz,7CvBZ wGmzhlOYkSjHTqAlMr9wt,dY4E,X B3qNEzAVfc3poRkYE,xIy,vLb

Popular posts from this blog

PHP contact form sending but not receiving emails

Do graphics cards have individual ID by which single devices can be distinguished?

Create weekly swift ios local notifications