Skip to main content
gamedev.net
🔒 Locked

Drawing patch

Started by steg Nov 6, 2004 at 11:07 AM 8 replies 1.5k views
Original Post
steg
steg
Hi all, I want to draw a certain part of my terrain, say for simplicity the terrain is 8x8 quads : |/|/|/|/|/|/|/|/| |/|/|/|/|/|/|/|/| |/|/|/|/|/|/|/|/| |/|/|/|/|/|/|/|/| |/|/|/|/|/|/|/|/| |/|/|/|/|/|/|/|/| |/|/|/|/|/|/|/|/| |/|/|/|/|/|/|/|/| If I wanted to draw say just the top right part of the terrain, say starting at the 5th quad along by 4 quads deep, thus 16 quads, do I just set the BaseVertexIndex in my call to DrawIndexedPrimitive ? DrawIndexedPrimitive(D3DPT_TRIANGLELIST, BaseVertexIndex, 0, 25, 0, 32); What would BaseVertexIndex be ? Is it 4 ? Any help is much appreciated. Steve
If it isn't working, take a bath, have a think and try again...
steg
steg
Hi again,

Ok, I seem to have got the patch to be drawn but had to do it with 4 draw calls :

DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, 0, 5, 0, 8 );
DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 9, 0, 5, 0, 8 );
DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 18, 0, 5, 0, 8 );
DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 27, 0, 5, 0, 8 );

I guess drawing patches can't be done with one draw call ???

Thanks,
Steve
If it isn't working, take a bath, have a think and try again...
steg
steg
Seem to be answering my own posts!

Is it possible to render a patch with one DrawIndexedPrim call ?

Any help is much appreciated,
Steve
If it isn't working, take a bath, have a think and try again...
intransigent-seal
intransigent-seal
Think about how your triangles are arranged in your index buffer. A call to DrawIndexedPrimitive can only render from one block of the index buffer - ie, a set of consecutive triangles.
If you've arranged the triangles in your index buffer in the "obvious" way, then no, you cannot render just a patch of the terrain with a single DrawIndexedPrimitiveCall (at least not generally, patches that satisfy certain constraints can be rendered with a single DIP call)

Why do you want to render just a patch of the terrain? If you're doing it for rendering speed, then I suggest you split your terrain into chunks of a set size (20x20 quads, or whatever), and arrange the indices in your buffer so that you can render any particular chunk with a single DIP call.

John B
The best thing about the internet is the way people with no experience or qualifications can pretend to be completely superior to other people who have no experience or qualifications.
steg
steg
Hi,

I want to render patches for chunk lod. But like I said, I want to be able to do this using on DIP call. I guess I need to set up my indices buffer differently ?

Thanks,
Steve
If it isn't working, take a bath, have a think and try again...
Namethatnobodyelsetook
Namethatnobodyelsetook
If you want to use 1 DIP call, just setup your index buffer to contain the indicies you'd like to draw. Lets give names to the vertices, to help.

The top half...
0123456789ABCDEFGHIJKLMNOPQRSTUVxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx


So, if you want the top right, setup your index buffer like so:

4,5,C, C,5,D, 5,6,D, D,6,E, 6,7,E, E,7,F,
C,D,K, K,D,L, D,E,L, L,E,M, E,F,M, M,F,N,
K,L,S, S,L,T, L,M,T, T,M,U, M,N,U, U,N,V

And you'll get it drawn in one call. What you likely want though, is something to generates the index list on the fly. If you'd rather not generate the indices on the fly, you can at least try to reduce the number of draws using what John's saying. If your map is 512,512, break that into a bunch of 8x8, or 16x16 pieces. Create index lists for each. Perhaps several index lists, one for each LOD level, where some skip vertices. You then draw once for each patch. It's not 1 draw call, but it's still fairly good.

If you want to draw with 1 call though, you'll need to determine which parts are visible, which LOD each part is, and create an index list each frame. Put the results into a dynamic index buffer, and render.

Playing with the arguments to DIP is more meant to select between multiple meshes placed into a VB. You could draw multiple terrain sections that way, but only if each one you wanted was already in the index buffer sequentially without any terrain sections you didn't want in the middle... which will never work for a generic solution.
steg
steg
Thanks all,

Namethatnobodyelsetook - many thanks for your in depth reply. I don't think I really want to generate the index lists on the fly, more of wanting to have patches at differing LODs, one big vertex buffer and seperate index buffer for each LOD patch. I'm still not quite clear how I can draw the patches with one DIP.

Kind regards,
Steve

If it isn't working, take a bath, have a think and try again...
steg
steg
Ok, having re-thought the drawing patch process through again, I've come up with that I will need a seperate index buffer per patch. Thus, if I have a grid of 256 x 256 cells, and patch sizes are 16x16, this will mean 16 x 16 patches in the grid, which means 256 index buffers. Obvioulsy I can re-use the patches index buffer for different LODs.

|/|/|/|/|/|/|/|/|
|/|/|/|/|/|/|/|/| 8x8 grid = 4 patches if patches 4x4
|/|/|/|/|/|/|/|/|
|/|/|/|/|/|/|/|/|
|/|/|/|/|/|/|/|/|
|/|/|/|/|/|/|/|/|
|/|/|/|/|/|/|/|/|
|/|/|/|/|/|/|/|/|

So, for an 8x8 grid, say I use 4x4 patches, thus total of 4 patches which means 4 index buffers, is this correct ? I can't see any other way of rendering a patch with on DIP without using seperate index buffer for each patch.

Sorry to keep going on about this, I just want to get it right.

Thanks,
Steve
If it isn't working, take a bath, have a think and try again...
Namethatnobodyelsetook
Namethatnobodyelsetook
If all you want is to read indices at a different point in the index buffer, then just adjust StartIndex. Here's how the values are used in DIP.

if (type==trilist)  endindex = startindex + primcount * 3;else if (type==tristrip)  endindex = startindex + primcount + 2;for n = startindex to endindex{  index = IB[n] + BaseVertexIndex;  assert(index >= minindex);  assert(index < (minindex + numvertices);  vertex = VB[index]}
steg
steg
Thanks again Namethatnobodyelsetook,

I'm thinking of doing this so I can render a patch with one DIP without having to have multiple index buffers for each patch.

If it isn't working, take a bath, have a think and try again...

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.