Game Development Community

PrimBuilder with variable size

by Daniel Buckmaster · in Torque 3D Professional · 11/01/2011 (12:40 am) · 3 replies

I'm working on an implementation of Recast's debug draw interface, which you can view here (struct duDebugDraw). It requires implementing functions like begin(), vertex() and end(), all of which are part of the PrimBuild interface. With one exception - Recast never specifies a buffer size, which PrimBuild::begin() expects.

I've decided to circumvent this issue by changing the definition of VERTEX_BOUNDS_CHECK() in primBuilder.cpp to resize mTempVertBuff if necessary - then any value can be passed into begin() when RC gives me an ambiguous call.

Is there anything I should watch out for doing it this way? As far as I can tell, PrimBuild::end() will still work with an underfull buffer, so I don't need to resize tightly.

About the author

Studying mechatronic engineering and computer science at the University of Sydney. Game development is probably my most time-consuming hobby!


#1
11/01/2011 (1:47 pm)
Okay, so I've tested it and the answer is 'yes, it's fine' ;P.
#2
11/01/2011 (11:49 pm)
Yea i think at one time we fixed PrimBuild to work with very large sets of data which it internally batches into individual draw calls.
#3
11/02/2011 (5:43 pm)
New define block for primBuilder.cpp:

U32 mMaxVerts;

static void CheckVertexBounds()
{
   // Grow vertex buffer
   if(mCurVertIndex == mMaxVerts)
   {
      mMaxVerts *= 2;
      mTempVertBuff.setSize(mMaxVerts);
   }
}

#ifdef TORQUE_DEBUG

#define INIT_VERTEX_SIZE(x) mMaxVerts = x;
#define VERTEX_BOUNDS_CHECK() CheckVertexBounds()

// This next check shouldn't really be used a lot unless you are tracking down
// a specific bug. -pw
#define VERTEX_SIZE_CHECK() AssertFatal( mCurVertIndex <= mMaxVerts, "PrimBuilder allocated more verts than you used! Break and debug or rendering artifacts could occur." );

#else

#define INIT_VERTEX_SIZE(x) mMaxVerts = x;
#define VERTEX_BOUNDS_CHECK() CheckVertexBounds()
#define VERTEX_SIZE_CHECK()

#endif
Also, while I'm here, the code for VERTEX_SIZE_CHECK doesn't seem correct to me. Shouldn't it be asserting that mCurVertIndex is equal to mMaxVerts? That would seem to match the assert message given.