Primitives and sprites. Cocos2D-x 3.0 Z index not consistent?

I have two layers. Each layer has a primitive drawing in it with OpenGL as follows:

void Layer1::drawPolygon() { glLineWidth(1); DrawPrimitives::setDrawColor4B(255,255,255,255); DrawPrimitives::setPointSize(1); // Anti-Aliased glEnable(GL_LINE_SMOOTH); // filled poly glLineWidth(1); Point filledVertices[] = { Point(10,120), Point(50,120), Point(50,170), Point(25,200), Point(10,170) }; DrawPrimitives::drawSolidPoly(filledVertices, 5, Color4F(0.5f, 0.5f, 1, 1 ) ); } 

When I add these layers to the scene and set the Z-orders 1 and 2, I see that I can bring one primitive on top of the other and vice versa - when I exchange values ​​of the Z order. Strange things start when I add a sprite sprite to one of these layers. If I add a sprite to a sprite, then the sprite lies on top of the primitive of this layer, and not just this layer. Even if the layer has a lower index Z, in any case, its sprite is on top of a primitive of a different level, and its primitive is below another primitive form - as expected. This is normal? How should I understand that? What if I want to draw primitives on top of all sprites?

EDIT:

I could manipulate their order, but not the drawing order, with the following:

 CCDirector::getInstance()->setDepthTest(true); myLayer->setVertexZ(-1); 

But I don’t understand why sprites in a layer with a lower Z-order are drawn later than primitives of a layer with a higher Z-order. In other words, it seems that all primitives from all layers are drawn in accordance with their order, the same thing is done for sprites.

+1
source share
2 answers

Thanks to the new multithreaded rendering on cocos2d-x 3.0, a different approach is required for drawing with primitives. Take a look at my answer in this thread:

fooobar.com/questions/531899 / ...

+2
source

I believe there is a bug in cocos2d-x V3 beta 2 that makes a primitive drawing always below all layers. It is fixed (I understand) in V3.0 RC

This is wrong - there is no mistake (I was misled by other posts - my apologies).

See the post below for a link explaining what needs to happen in order to get the primitives to draw in the "correct" z-order.

The summary is that all drawing operations are added to the queue in the game loop, then the queue is processed, so you need to add your primitive drawing to the queue, and not draw immediately.

+1
source

All Articles