Sign in to follow this  
Bastich-666

DrawIndexedPrimitive

Recommended Posts

Hello.
This has been driving me mad over the last couple of days.
Basically I have a cube model with 2 textures on it (half and half).
This is stored in a vertex buffer and an index buffer.
If I call DrawIndexedPrimitive and render the buffer in one go all triangles appear but if I do 2 calls to DrawIndexedPrimitive (split according to texture) only a few of the second section appear?

This works:
<set texture>
DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, 0, 24, 0, 12 );

This does not (first call fine second only partially renders):
<set texture>
DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, 0, 12, 0, 6 );
<set texture>
DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, 12, 12, 6, 6 );

Vertices used:
0 - -1.69 5.00 1.92
1 - -1.69 0.00 -3.08
2 - -1.75 0.00 1.81
3 - -1.69 5.00 -3.08
4 - -1.69 5.00 -3.08
5 - 3.31 5.00 -3.08
6 - 3.31 5.00 1.92
7 - -1.69 5.00 1.92
8 - -1.69 0.00 -3.08
9 - 3.31 0.00 -3.08
10 - 3.31 5.00 -3.08
11 - -1.69 5.00 -3.08
12 - 3.31 0.00 -3.08
13 - 3.25 0.00 1.81
14 - 3.31 5.00 1.92
15 - 3.31 5.00 -3.08
16 - 3.25 0.00 1.81
17 - -1.75 0.00 1.81
18 - -1.69 5.00 1.92
19 - 3.31 5.00 1.92
20 - 3.25 0.00 1.81
21 - -1.75 0.00 1.81
22 - 3.31 0.00 -3.08
23 - -1.69 0.00 -3.08

Index buffer info:
0 - 2 0 11
1 - 8 3 10
2 - 6 5 4
3 - 4 7 6
4 - 10 9 8
5 - 11 1 2
6 - 12 15 14
7 - 18 17 16
8 - 16 19 18
9 - 14 13 12
10 - 23 22 20
11 - 20 21 23

Share this post


Link to post
Share on other sites
In your second call, you're changing both the minIndex for the vertex buffer and the startIndex for the index buffer. I think you want to just draw the second set of triangles, starting at index buffer 6, correct?

Try: DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, 0, 12, 6, 6 );

Share this post


Link to post
Share on other sites
You have a strange Index Buffer structure. Normally, Index Buffers are a 1 Dimensional array of Ints. You seem to have a 1-Dimensional Array of Vectors, am I right?

The problem is, DirectX 9 doesn't know that. Yes, it works in the first case, because your Indexes are ( more out of luck ) stored behind each other in memory.

The reason why it doesn't work with your new call's, is, that Index number 6 isn't Vector number 6. It's value number six.

To make this more clear, your Index Buffer as you expect it:

0 - 2 0 11
1 - 8 3 10
2 - 6 5 4
etc..

How Direct3D sees it:

0 - 2
1 - 0
2 - 11
3 - 8
4 - 3
5 - 10
6 - 6
7 - 5
8 - 4
etc...

You can still keep your structure, just make sure that it's always stored in an uninterupted sequence.

Try something like this, I think it should work:

<set texture>
DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, 0, 12, 0, 6 );
<set texture>
DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, 12, 12, 18, 6 );

Share this post


Link to post
Share on other sites
@m1old1: I think you're a bit confused. The indexbuffer, as DirectX sees it, is an array of 3 WORDs per index, each index representing the vertices comprising a "face" or triangle. They may be arranged in memory "serially," but they are not accessed that way.

What Bastich posted is (or appears to be) the correct interpretation of the index buffer data.

Share this post


Link to post
Share on other sites
Hello

Thanks for all your help I have solved the problem now. It was due to the start index as m1o1d1 mentioned. I was indexing it as groups of faces rather than total number of index's. Nice easy fix as all I needed to do was x3 the start index that my model converter outputs. My face index's are stored as an array of structs each having 3 DWORDs (needed for the big / hi-detail models used). Provided structure alignment (packing) is set correctly there are no problems. Now that this is solved I can carry on updating the graphics engine over to shaders from the older FVF system.

Thanks again for the help :-)

James (www.maelstrom.com)

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