Skip to main content
gamedev.net
🔒 Locked

Terrain rendering problem

Started by peter86 4 replies 450+ views
Original Post
peter86
peter86
I have a terrain map (256x256 units) which is too big to render in just one DrawPrimitive call. Some cards succeed in rendering it all at a time and some does not, though they have the same MaxPrimitiveCount in the device caps, how can that be? Anyway, what I really want to know is how should I render all this? By calling DrawPrimitive multiple times a loose a lot of speed. I tried with multiple DrawPrimitive calls, but less than half of the terrain is rendered, any ideas of why? See code below.
while( nRenderedPrimitives<g_nPrimitives )
{
	if( nRenderedPrimitives + nPrimitivesToRender>g_nPrimitives)
	{
		g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLELIST, nRenderedPrimitives, 
			g_nPrimitives-nRenderedPrimitives);
		nRenderedPrimitives += g_nPrimitives-nRenderedPrimitives;
	}
	else
	{
		g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLELIST, nRenderedPrimitives, 
			nPrimitivesToRender );
		nRenderedPrimitives += nPrimitivesToRender;
	}
}
[edited by - peter86 on November 26, 2003 4:03:45 AM]
z80
z80
2nd parameter to IDirect3DDevice9::DrawPrimitive() is start vertex number, so you probably wanna do something like nRenderedPrimitives * 3 for D3DPT_TRIANGLELIST.
z80
z80
Regarding the problem with rendering all primitives in one batch, then perhaps you have more vertices than you''re allowed according to D3DCAPS9::MaxVertexIndex. Otherwise I dunno.
peter86
peter86
quote:
Original post by z80
2nd parameter to IDirect3DDevice9::DrawPrimitive() is start vertex number, so you probably wanna do something like nRenderedPrimitives * 3 for D3DPT_TRIANGLELIST.


Thanks, I did never notice that there was vertex numer in the second parameter and primitives in the third.

quote:
Original post by z80
Regarding the problem with rendering all primitives in one batch, then perhaps you have more vertices than you're allowed according to D3DCAPS9::MaxVertexIndex. Otherwise I dunno.

Yep, but it renders fine on on my TNT2 card though it has a MaxVertexIndex of 65535 and I have 390150 vertices for my terrain.

Anyway I loose a lot of speed by using multiple DrawPrimitive calls, any ideas how I could speed things up?

[edited by - peter86 on November 26, 2003 10:46:39 AM]
z80
z80
quote:
Original post by peter86
Yep, but it renders fine on on my TNT2 card though it has a MaxVertexIndex of 65535 and I have 390150 vertices for my terrain.



Strange. That is not a proof that other cards/drivers will do the same though. I''d stick with what MaxVertexIndex says even if it seems to work with more.

quote:
Original post by peter86
Anyway I loose a lot of speed by using multiple DrawPrimitive calls, any ideas how I could speed things up?



Didnt think a few more calls to DrawPrimitive() would have a huge performance hit. How much slowdown do you experience?
peter86
peter86
quote:
Original post by z80
Didnt think a few more calls to DrawPrimitive() would have a huge performance hit. How much slowdown do you experience?


About 50%, might be because I''m rendering more terrain, didn''t think of that before

Topic Locked

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

Sign in to reply to this topic.