Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

ktuluorion

Batching polys.

This topic is 5617 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

I know that batching polys together i large groups is supposed to majorly increase speed, but what I am wondering is how I might batch a couple of different meshes into one rendering call. If anyone can help me out or point me in the right direction, I would appreciate it. Thanks.

Share this post


Link to post
Share on other sites
Advertisement
First off, you can only batch things together if all the rendering properties are the same, ie: same texture, material, shader, vertex format, etc. Generally you batch things together at load time that can be batched that are static in your world.

Lets say you have 3 objects

10 verts, 15 indices
12 verts, 18 indices
14 verts, 24 indices

And lets say you want to batch 2 of object 1, and 3 of object 2, and a single object 3.

Lets assume, to make this clearer in a larger scale, that your buffers already have some other meshes in them, and so you won''t be starting at vertexbuffer or indexbuffer offsets of 0



nBaseVertex = 120;
nBaseIndex = 300;
nTotalVertsNeeded = 2*10 + 3*12 + 14;
nTotalIndicesNeeded = 2*15 + 3 * 18 + 24;
vbuffer->Lock(nBaseVertex, nTotalVertsNeeded * stride, &vbuf);
ibuffer->Lock(nBaseIndex, nTotalIndicesNeeded * 2, &ibuf);
nVertexOffset = 0;
nIndexOffset = 0;
Batch(vbuf, ibuf, obj1, &nVertexOffset, &nIndexOffset, xform1);
Batch(vbuf, ibuf, obj1, &nVertexOffset, &nIndexOffset, xform2);
Batch(vbuf, ibuf, obj2, &nVertexOffset, &nIndexOffset, xform3);
Batch(vbuf, ibuf, obj2, &nVertexOffset, &nIndexOffset, xform4);
Batch(vbuf, ibuf, obj2, &nVertexOffset, &nIndexOffset, xform5);
Batch(vbuf, ibuf, obj3, &nVertexOffset, &nIndexOffset, xform6);
...
SetIndices(ibuffer, nBaseVertex);
SetStream(0, vbuffer, stride);
DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, nTotalVertsNeeded, nBaseIndex, nTotalIndicesNeeded/3);
...

Batch(void *vbuf, short *ibuf, Object *pObj, unsigned long *nVertexOffset, unsigned long *nIndexOffset, matrix worldxform)
{
myVertex = (MyVertexStruct *)vbuf;

// Transform vertices into a new space and append to VB.
for (i=0;inNumVerts;i++)
{
TransformCoord(&myVertex[*nVertexOffset+i].position, &obj1->pVerts.position, &worldxform);
TransformNormal(&myVertex[*nVertexOffset+i].normal, &obj1->pVerts[i].normal, &worldxform);
myVertex[*nVertexOffset+i].u1 = obj1->pVerts[i].u1;
myVertex[*nVertexOffset+i].v1 = obj1->pVerts[i].v1;
}

// Copy indices, offset for position their new location in VB.
for (i=0;inNumIndices;i++)
{
ibuf[*nIndexOffset+i] = obj1->pIndices[i] + nVertexOffset;
}

*nVertexOffset += pObj->nNumVerts;
*nIndexOffset += pObj->nNumIndicies;
}

Share this post


Link to post
Share on other sites
Thank you for your help. I had suspected it was somewhat like this, and you have been very helpful in helping me understand this.


Thanks a lot for that answer.. it was really useful.

Share this post


Link to post
Share on other sites

  • 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!