Skip to main content
GameDev.net gamedev.net
🔒 Locked

Batching polys.

Started by ktuluorion Jan 31, 2003 at 7:06 PM 2 replies 400+ views
Original Post
ktuluorion
ktuluorion
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.
[Piebert Entertainment] [Ask The All-Knowing Oracle A Question]------------------------------------------------------------GDSFUBY GameDev Society For UnBanning YodaTheCodaIf you want to see yoda unbanned then put this in your sig ------------------------------------------------------------DAIAGA Dave Astle is a God Association. To join, put this in your sig!Founder and High Priest o
ktuluorion
ktuluorion
bump pleeeze
[Piebert Entertainment] [Ask The All-Knowing Oracle A Question]------------------------------------------------------------GDSFUBY GameDev Society For UnBanning YodaTheCodaIf you want to see yoda unbanned then put this in your sig ------------------------------------------------------------DAIAGA Dave Astle is a God Association. To join, put this in your sig!Founder and High Priest o
Namethatnobodyelsetook
Namethatnobodyelsetook
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;
}

ktuluorion
ktuluorion
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.
[Piebert Entertainment] [Ask The All-Knowing Oracle A Question]------------------------------------------------------------GDSFUBY GameDev Society For UnBanning YodaTheCodaIf you want to see yoda unbanned then put this in your sig ------------------------------------------------------------DAIAGA Dave Astle is a God Association. To join, put this in your sig!Founder and High Priest o

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.