vertex biuffer and templates

Started by
1 comment, last by Neometron 11 years, 9 months ago
hello.
I wish create a complex structure that is the sum of some other structure.
For do this i wish combine some structure with templates.
for example:
I wish create a vertex buffer , that is the combination of a CPosition, a CNormal and a CColor structures.
the result must works like:
CPosition pos;
vect4f pos;
pos.add(pos)
ecc...
like
CNormal nor;
.
.
CColor col;
.
CVertexBuffer<CPosition, CNormal, CColor>(pos, nor, col);
but the templates don't supports n arguments.
How i can insert n types and n params in a template?
1)I Can add 16 or 1345353458 parameters with default value.
2)i can use the template recursion to generate a list of parameters of any size

but is a trick, there is something of better?
thanks.
Advertisement
Templates are used for unknown objects that could perform the same operation like addition.
What you are looking for is a helper function to fill a specific vertex buffer.

[source lang="cpp"]bool FillVertexBuffer(CVertexBuffer& cVertexBuffer, int BufferSize, const CPosition& cPosition, const CNormal& cNormal, const CColor& cColor)

{

//fill each element in buffer up to BufferSize using cPosition, cNormal, and cColor

return true; //if passed

}
[/source]
If everything is buffers:

[source lang="cpp"]

#include stdarg.h

bool FillVertexBuffer(CVertexBuffer& cVertexBuffer, int nLenght, int nBuffers, ... )
{
va_list params;
va_start(params, nBuffers);

CBuffer* pBuffers[nBuffers];

for(int loop = 0; loop < nBuffers; loop++ )
{
//Get a nList of CBuffer*
pBuffers[loop] = va_arg(params, (CBuffer*));
}

va_end(params);

for(int VertexIndex = 0; VertexIndex < nLenght; VertexIndex++)
{
for(int BufferIndex = 0; BufferIndex < nBuffers; BufferIndex++)
{
//Add to a VB structure
}

//Fill CVertexBuffer at VertexIndex using VB structure
}

return true;
}[/source]

This topic is closed to new replies.

Advertisement