I supposed the magic was in the shader, but I was not sure.
The weird thing is that it seems that DrawNode is using the same shader for all the shapes (dot, polygon, etc), so I think that for other shapes a lot of performance can be gained by setting the “basic” or “default” shader instead of the current one.
Do you know how to set the basic shader to DrawNode?
You can’t set a separate shader for polygons and other primitives. DrawNode is being drawn with one draw call, it means that all the primitives are being drawn with that single draw call, thus it’s necessary to use a common shader (you can’t use more than one shader during one draw call).
Actually, the overhead is not so big. I’m pretty sure that if you separate DrawNode into two parts: dot and other primitives, you’ll have a purer performance because of two draw calls.
Moreover, premature optimization is the root of all evil.
You can’t set a separate shader for polygons and other primitives. DrawNode is being drawn with one draw call, it means that all the primitives are being drawn with that single draw call, thus it’s necessary to use a common shader (you can’t use more than one shader during one draw call).
Actually, the overhead is not so big. I’m pretty sure that if you separate DrawNode into two parts: dot and other primitives, you’ll have a purer performance because of two draw calls.
I know that you can’t set more than one shader per node.
What i’m doing is learning how DrawNode works to create a lighter, faster version of it.
With this new node I only want to draw raw polygons (not rounded ones), so I think it would be beneficial for this new node to have a basic shader instead of the DrawNode one.
So…
Do you know which is the most simple shader available in cocos2d-x?
It depends on the requirements to your implementation of DrawNode. Probably you don’t need a texture (currently it’s being used for drawing smooth circles). So I guess POSITION_COLOR will fit your needs.
Dots drawing performance with POSITION_COLOR is the same than drawing with the DrawNode shader.
It seems CPU limited because CPU core usage is at 100%, although most of the time is spent on EGLView::swapBuffers().
This is the test code:
auto draw = DrawNode::create();
addChild(draw, 10);
for(int index = 0, limit = 1000; index < limit; index++)
{
// Draw 10 circles
for( int i=0; i < 10; i++)
{
draw->drawDot(Point(s.width/2, s.height/2), 10*(10-i), Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 1));
}
}
By the way, on my PC (with a Radeon HD 5850) this test runs at 23fps.
Is this normal?