Sign in to follow this  
Halsafar

IndexBuffer size reflect primitive count?

Recommended Posts

I am creating an IndexBuffer at a necessary size to hold every triangle in my terrain. Although only a few triangles will be drawn do to culling. I can verify that the primitive count is only 975, the vertices are correct, but the index buffer is causing an error at vertice 52685 which means the DrawIndexedPrimitive is trying to draw primitives for the entire size of the index buffer....

Share this post


Link to post
Share on other sites
Remember, there are three vertices per primitive (triangle). That means with 975 primitives, you should have 2925 indices. Can you post your DIP() code? Perhaps you have some parameters wrong.

Share this post


Link to post
Share on other sites
m_terrainIBuffer.SetBufferIndices();
m_terrainVBuffer.Stream();
::Graphics()->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, m_iNumVertices, 0, m_iNumVertices/3);


Is that the code you wanted to see?
I can't really post my whole quadtree, heightmap and terrain class' and expect you to debug it.

Fortunetly my problem has changed, I no longer recieve the error. I wasn't setting the buffer I use to copy into the index buffer to zero. I cannot be to sure why that fixed it...


See my only Q is, if I INIT an INDEX BUFFER to a size of 65534 and I use that index buffer to render only 975 primitives will DX be (i'm sure it is) smart enough to only look through 975*3 indices or will it just try and go for the whole batch for some dumb reason...

Share this post


Link to post
Share on other sites
Yea, you are calculating the last parameter incorrectly. It should be the number of faces/triangles, not numVertices / 3. numVertices / 3 is not necessarily the number of faces/triangles, since the primitive types are arranged differently.

Share this post


Link to post
Share on other sites
Thanks for the article it was worth a refresh/comparison to Dx7 which I've used for 2 years.


Now, Primitive count with triangle_list can be easily expressed as:
iNumIndices / 3???

Share this post


Link to post
Share on other sites
Quote:
Now, Primitive count with triangle_list can be easily expressed as:
iNumIndices / 3???

Yep. When dealing with indices/faces/primitives, you almost always use index buffer values. When you deal with vertices, it's almost definitely going to be relative to the vertex buffer.

Share this post


Link to post
Share on other sites
Well now that all these questions have been answered I cannot seem to find my problem.

I have a big vertex buffer and a big index buffer.
I have made sure that my vertices and indices match up properly for at least the first 32 triangles which are the only 32 I am trying to render.

They are being rendered with a basic world matrix, they should be appearing at 0,0,0.

I see obsolutely nothing, I've tried everything.
My frame-rate is jumping as if I was rendering the triangles but they are clearly not there. It has been rather frusterating.

If I turn back on my culling and attempt to render the batch's the quad tree provides I can watch my frame rate jump around a bit as I approach where the center of the world should be the place with the highest number of vertices/indices... My frame-time clearly shows rendering is taking place but nothing is showing.

I have tried with D3DCULL_NONE.
I have lighting off, I have 0xFFFFFFFF set for ambient.

I'm out of idea's....

Share this post


Link to post
Share on other sites
Try taking your vertex buffer and, just for testing, render it out as a bunch of points with a DrawPrimitiveUP call. That should give you some reference point for various question marks coming up.
Still glancing at this thread. =) Best of luck.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this