Archived

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

mother of all buffers

This topic is 5130 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 was reading the dx sdk and they said you should make 1 static buffer for each type of fvf. I have got it that when i put my first data for my model it works fine, but when i go to put on the next chunk/model of data then try rendering the data, both models are screwed up :-/ in my example i have a cube with 8 vertices and 36 vertices so this is what i end up with: //lock and fill.... WORD* index; if( FAILED( buffer->pIndexBuffer->Lock(buffer->indexEnd, (buffer->indexEnd + indices.size()), (void**)&index, 0) )) { ENGINE.GetConsole()->Error(__FILE__, __LINE__, "Failed to lock index buffer"); SAFE_DELETE( att ); return 0; } ENGINE.GetConsole()->Log( " Locking IB: start: %i end: %i", buffer->indexEnd, (buffer->indexEnd + indices.size()) ); for( int i = 0; i < indices.size(); i++ ) { index = indices[i]; ENGINE.GetConsole()->Log("%i) %i", i,index[i]); } buffer->pIndexBuffer->Unlock(); void* vertex; if( FAILED( buffer->pVertexBuffer->Lock(buffer->vertexEnd, (buffer->vertexEnd + noVerts), (void**)&vertex, 0) )) { ENGINE.GetConsole()->Error(__FILE__, __LINE__, "Failed to lock vertex buffer"); SAFE_DELETE( att ); return 0; } ENGINE.GetConsole()->Log( " Locking VB: start: %i end: %i", buffer->vertexEnd, (buffer->vertexEnd + noVerts) ); memcpy( vertex, vertices, (noVerts * buffer->size) ); VERT_POS_NORM_TEX* v = (VERT_POS_NORM_TEX*)malloc( noVerts * buffer->size ); memcpy( v, vertices, (noVerts * buffer->size) ); for( int m = 0; m < noVerts; m++ ) { //v[m] = (VERT_POS_NORM_TEX*)(vertices + m * sizeof(VERT_POS_NORM_TEX)); ENGINE.GetConsole()->Log( "%i) %f %f %f", m, v[m].x, v[m].y, v[m].z ); } buffer->pVertexBuffer->Unlock(); buffer->vertexEnd += noVerts; buffer->indexEnd += indices.size(); im guessing the error is here in the lock, like im doin it wrong if( FAILED( hr = ENGINE.GetDevice()->GetDevice()->DrawIndexedPrimitive( table->renderType, 0, 0, table->noVerts, table->vertexStart, table->noTris ))) { ENGINE.GetConsole()->Error(__FILE__, __LINE__, "DrawIndexedPrimitive failed"); DXTRACE_ERR( "DrawIndexedPrimitive", hr ); return 0; } or it could be in my render function....?

Share this post


Link to post
Share on other sites
A few problems.

The vertex buffer lock is (start, size,...) not (start, end,...). Also the VB lock is in bytes.

Try (vertexEnd * sizeof(MYVERTEX), noVerts * sizeof(MYVERTEX),...)

Same deal with the index buffer too.

Also the drawindexedprimitive call should be changed.

DIP(table->renderType, table->vertexStart, 0, table->noVerts, table->indexStart, table->noTris);

Note that the indices are not changed for the second mesh, but you''d like them to refer to vertices that start later in the buffer. Hence...

BaseVertexIndex offsets indices to the correct place in the VB. This is the vertex number used to specify the start of the vertex buffer lock for this mesh.

The minIndex is the lowest index number this call will use. It''s likely 0, but not necessarily.

NumVertices is the maximum index number used in this call - minIndex + 1. Often just the number of vertices in the mesh.

StartIndex is where to start reading the index buffer. This is the index number you used when calling lock for this mesh''s index buffer.

How does this all really work?

endIndex is based on primCount and primType + startIndex.
D3D will traverse each index from startIndex to endIndex.
For each index, base vertex index is added.
The vertex is fetched from this new index.
minIndex and baseVertexIndex should be the min and max indices ever seen.


for (index=startIndex; index < endIndex; index++)
{
assert((ib[index] + basevertexindex) >= minIndex);
assert((ib[index] + basevertexindex) < minIndex+numVerts);
vertex = vb[ib[index] + basevertexindex];
sendDownPipeline(vertex);
}

Share this post


Link to post
Share on other sites
aw wow! thanks for such a great answer

it made perfect sense and helped made a few things clearer for me.

although.... if i load a cube, then a sphere and render them, the sphere has about 12 polys missing which is the number the cube has, so something might be a miss in my code :-/
it seems the start is right, if i dont draw the cube then i get the same amount of sphere so something must be wrong with the ending of the model?

YUP! its definately the ending, if i add 12 to my primitive count of my sphere it works, where 12 is the number of polys in the cube, but why?


if( FAILED( hr = ENGINE.GetDevice()->GetDevice()->DrawIndexedPrimitive( table->renderType,
table->vertexStart, 0, table->noVerts,
table->indexStart, table->noTris )))
{
ENGINE.GetConsole()->Error(__FILE__, __LINE__, "DrawIndexedPrimitive failed");
DXTRACE_ERR( "DrawIndexedPrimitive", hr );
return 0;
}


[edited by - supagu on November 30, 2003 5:49:35 PM]

[edited by - supagu on November 30, 2003 6:16:42 PM]

[edited by - supagu on November 30, 2003 6:22:08 PM]

Share this post


Link to post
Share on other sites