Hi,
Render primitive was working now.
It was opened in pull request: https://github.com/cocos2d/cocos2d-x/pull/7701
The current status are listed here
FEATURES:
1. Encapsulate openGL call, user do not need to worry about glcalls
2. Support GL_POINTS, GL_LINES, GL_TRIANGLES type
3. Support int32 and short16 indices
4. Support VertexBuffer and IndexBuffer sharing across multiple primitives
5. Support multiple streams for rendering.
USAGE and RENDERING:
The creation of primitive has several steps:
//create vertexBuffer and vertexData
vertexBuffer1 = VertexBuffer:create(…)
vertexBuffer2 = VertexBuffer:create(…)
vertexData = VertexData::create()
vertexData->setStream(vertexBuffer1, VertexStreamAttribute(0, GLProgram::VERTEX_ATTRIB_POSITION, GL_FLOAT, 3))
vertexData->setStream(vertexBuffer1, VertexStreamAttribute(12, GLProgram::VERTEX_ATTRIB_NORMAL, GL_FLOAT, 3))
vertexData->setStream(vertexBuffer1, VertexStreamAttribute(0, GLProgram::VERTEX_ATTRIB_TEXCOORD, GL_FLOAT, 2))
//createIndexBuffer if has one
indexBuffer = indexBuffer:create()
//createPrimitive
//using null instead of indexbuffer if no indices
primitive =Primitve:create(vertexData, indexBuffer, GL_POINTS)
primitive =Primitve:create(vertexData, null, GL_TRIANGLES)
//set begin and count, because we may only using a part of indexbuffer and vertexbuffer for rendering
primitive->setBegin(begin);
primitive->setCount(count);
Thanks, Riq
Here are my feedbacks.
We have mesh command, Quad command and batch command for submitting renderable geometries (Triangles, Quads etc). Other renderable geometries can only be rendered as CustomCommand, these custom command could be replaced by Primitive command.
a. can not be batched
b. vertices and indices must be pre allocated.
So the answers of your questions:
a) and b) : They can not be batched. due to the constrains listed above.
Far more, multiple streams supporting make batching much more difficult.
c) Quad Command can be replaced, but the performance could be worse than Quad Command.
Vertices and Indices could be added on the fly.
Add Batch support for primitive. The core of batching is that we can merge two primitives into one.
In order to do this, multiple stream support will be removed temporarily, which will make batching much more complex and increasing the overhead for batching computation, and there is no requirements for multiple stream support in our engine now.
Primitive could be batched only when they have the same vertex specification.
BTW, Thanks for your comments, I will adjust code as you suggested.
Yes,
It seems that Batch command and Custom command in LayerColor can be replaced by primitive command.
And 3D team is migrating into Primitive to support submesh.
For batching support. How about trying the second option (- or create a new command that supports that.)? Which will not affect the current features of Primitive.
Thanks, Riq
Progess for requirements 1) and 2)
After discussing with minggo. We found that supporting batching in Primitive and PrimitiveCommand is difficult because there are so many factors involved.
These factors include:
1. Vertex Semantic: some primitive may have GLProgram:VERTEX_ATTRIB_COLOR, some may not.
2. Same Semantic, but with different data types: Some may use 3 float for position, some use 4 float.
3. Same Semantic, but with different streams: Given they have same Semantic, one use interleaved array, another one use seperate array.
4. Some Primitive Type can not be Batched: If we want to support GL_TRIANGLE_STRIP, primitives batches can not be supported.
Given these, we decide that if we want to batch Primitive, a new wrapper need to be placed on top of primitive, Managing the vertices and indices, generate primitves and primitiveCommands for rendering.
Eg, In Particle system, A Particle Renderer which is hold by particle systems can be used to batch Particles, and provide primitive and primitive command for rendering.
So the role the primitive and primitive Command is to wrapper complex meshes for rendering, which need to be done by custom command or other commands.
And in those days, I did some work to improve our auto batching, it now support more types than QuadCommand.
A new command called TrianglesCommand is introduced, which will support Triangles for rendering. Triangles are defined like this.
// pointers are weak reference
struct Triangles
{
V3F_C4B_T2F* verts;
unsigned short* indices;
ssize_t vertCount;
ssize_t indexCount;
};