Jump to content
  • Advertisement
Sign in to follow this  
giugio

vertex biuffer and templates

This topic is 2166 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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] Edited by Neometron

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!