I was just curious as to why S3DVertex, S3DVertex2TCoords and S3dVertexTangents were all made separate structs. Wouldn't it be simpler if S3dVertex was a base class, from which the other two were derived?
For example, in the constructor for CTriangleSelector, there's a switch statement for a MeshBuffer's vertex type that wouldn't be necessary if 2TCoords were derived from S3DVertex, since in either case, it's only concerned with the Pos property of each vertex.
Are there issues which the current implimentation avoids, that I'm not seeing?
Vertex types
There was some discussion related to this last week... http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=10987
It could be done, but it would be easier for people to screw up. The problem is that the S3DVertex array would probably be passed around by pointer...That would be all fine and dandy if you pass an actual S3DVertex array...
If you passed an array of S3DVertex2TCoords it would wreak havok on the vertex buffer.That is because the size of the two structures are different, and the ++v above would not step past the S3DVertex2TCoords, it would step into the middle of it.
In my post I mentioned two possible solutions, templates and a stride size. The template solution is used in several places in Irrlicht. I don't know why the stride isn't used as frequently. It works quite well and reduces the total code.
Travis
It could be done, but it would be easier for people to screw up. The problem is that the S3DVertex array would probably be passed around by pointer...
Code: Select all
void setVertexColor(S3DVertex* verticies, u32 count, SColor color)
{
for (u32 v = 0; v < count; ++v)
verticies[v]->Color = color;
}Code: Select all
S3DVertex vertexBuffer[8];
// ...
setVertexColor(vertexBuffer, 8, SColor(255, 255, 32, 0)); // all is well
Code: Select all
S3DVertex2TCoords vertexBuffer[8];
//...
setVertexColor(vertexBuffer, 8, SColor(255, 255, 32, 0)); // oops!
In my post I mentioned two possible solutions, templates and a stride size. The template solution is used in several places in Irrlicht. I don't know why the stride isn't used as frequently. It works quite well and reduces the total code.
Travis