Batching polys.
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.
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
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.normal, &worldxform);<br> myVertex[*nVertexOffset+i].u1 = obj1->pVerts.u1;<br> myVertex[*nVertexOffset+i].v1 = obj1->pVerts.v1;<br> }<br><br> // Copy indices, offset for position their new location in VB.<br> for (i=0;i<pObj->nNumIndices;i++)<br> {<br> ibuf[*nIndexOffset+i] = obj1->pIndices + nVertexOffset;<br> }<br><br> *nVertexOffset += pObj->nNumVerts;<br> *nIndexOffset += pObj->nNumIndicies;<br>}<br><br> </pre> </i>
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement