Sign in to follow this  
RavNaz

IndexBuffer Offsetting woes....

Recommended Posts

Hi guys, I'm rendering some 2D stuff using an indexbuffer...easy peasy...however, some polys that share the same texture aren't neccesarily next to each other in the vertex buffer. example: VB IB Poly1 -> uses texture1 0, 1, 2, 1, 3, 2 Poly2 -> uses texture2 4, 5, 6, 5, 7, 6 Poly3 -> uses texture1 8, 9, 10,9, 11,12 So what I do is re-goanise the IB( pre-lock and fill) so that Poly1 and Poly3's indices are next to each other, then I call a settexture( 1 ), then render the polys for that texture....that way I dont have to have multiple settexture calls. So from above, the IB now looks like this: IB Settexture( 1 ) RenderIB -> 0, 1, 2, 1, 3, 2, 8, 9, 10, 9, 11, 12, Settexture( 2 ) RenderIB -> 4, 5, 6, 5, 7, 6 I'm getting problems though, in that the second poly ( 8, 9, 10... ), doesn't get rendered. I can fix this if the polys that use the same texture are grouped in numerical order in the IB....but I dont want this..... I thought the whole point of using the offset paramet of the IB was to do this?? not sure I've explained very well...I hope I have.

Share this post


Link to post
Share on other sites
Please also post your parameters to the DrawIndexedPrimitives call.
the problem is problably located there.
using dx9 or dx8?

Share this post


Link to post
Share on other sites
using dx9

g_pd3dDevice->SetIndices(m_IB);
g_pd3dDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST,
0,
0,
noverts,
offset,
noprimitives
);

any ideas?

Share this post


Link to post
Share on other sites
 HRESULT DrawIndexedPrimitive(          
D3DPRIMITIVETYPE Type,
INT BaseVertexIndex,
UINT MinIndex,
UINT NumVertices,
UINT StartIndex,
UINT PrimitiveCount
);






g_pd3dDevice->DrawIndexedPrimitive(
D3DPT_TRIANGLELIST, // the type
0, // BaseVertex, is most the times 0.
0, // Min Index. this is the min index in your index array(m_IB), this should
// not be 0 in both of your cases. when rendering poly 1 and 3 it
// should be 0 but rendering poly 2 it should be 4, 4 is the min index in
// that DIP call.
noverts, // this parameter should be caluclate as Maxindex-Minindex + 1,
// when rendering poly 1 and 3 it should be 12-0+1 == 13
// when rendering poly 2 it should be 6-4 + 1 == 3

offset, // the first index position in your array, first render: 0 and the
// second one 7, assuming your ib is something like : 0,1,2,1,3,2,4...
// , here is 4 on the 7th position.
noprimitives // the number of primitives.
);





i hope you get it. try to hardcode these values and try the out.

Share this post


Link to post
Share on other sites
mmm....ok got it working, without making any changes to the drawindexedprimitive call.

turns out my index offsetting was incorrectly being calculated.
although out of intrest.....aren't those parameters for the DIP call only useful for directx internally optimizing stuff? I'm going to implement those parameters because of this....just want to make sure that I am correct.

Thanks Keba for the description of those, the parameters weren't really clear to me what they actually were. The dx help files on this function isn't great.

Share this post


Link to post
Share on other sites
Yes, the DX SDK ain't that clear on thoose parameters :D
...hmm i'm maybe not the right person to talk about "directx internally optimizing stuff", but i think your right.
However i'm not sure if you could just put any number in thoose parameters, but for exampel when you set minindex to 0 for both your render call, then the effect would be more vertex processing...

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