Slow rendering?

Started by
6 comments, last by J-Fox 15 years, 4 months ago
Hello, im rendering a 150*150 vertex map. Here's my vertex

D3DVERTEX quad[] =
{
		{1.0f, -1.0f, tilez, D3DCOLOR_ARGB(255,255,255,255),1,0},
		{3.0f, -1.0f, tilez, D3DCOLOR_ARGB(255,255,255,255),0,0},
		{1.0f, 1.0f, tilez, D3DCOLOR_ARGB(255,255,255,255),1,1},
		{3.0f, 1.0f, tilez, D3DCOLOR_ARGB(255,255,255,255),0,1}
};
Here's what i use for the map rendering:

 for(int i = 0; i < 150; i++)
	 {

		 for(int c = 0; c < 150; c++)
		 {

			 D3DXMatrixTranslation(&pos, tilex, tiley, 10.0f);

			 d3ddev->SetTransform(D3DTS_WORLD, &pos);

			 d3ddev->SetStreamSource(0, vbuffer, 0, sizeof(D3DVERTEX));

			 d3ddev->SetTexture(0, text);

			 d3ddev->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
			 tilex += 2.0f;
			 d3ddev->Present(NULL, NULL, NULL, NULL);
		 }

		 tilex = 0.0f;
		 tiley += 2.0f;
	 }
Do you guys know what's causing this slow rendering? Rendering 100*100 doesn't render slow..but i need way more tiles the this...hope you can help me.
Advertisement
Alright, rendering got a bit faster doing this:

	 d3ddev->SetStreamSource(0, vbuffer, 0, sizeof(D3DVERTEX));	 d3ddev->SetTexture(0, text);	 for(int i = 0; i < 150; i++)	 {		 for(int c = 0; c < 150; c++)		 {			 D3DXMatrixTranslation(&pos, tilex, tiley, 10.0f);			 d3ddev->SetTransform(D3DTS_WORLD, &pos);			 d3ddev->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);			 tilex += 2.0f;		 }		 tilex = 0.0f;		 tiley += 2.0f;	 }


But how to make it even faster? i think using alot DrawPrimitive isn't good.
Quote:Original post by kevinawad
But how to make it even faster? i think using alot DrawPrimitive isn't good.


You're right. Change it so it only makes 1 draw call.
How :P
Build a big list of the verts in world space and send it up all at once.

Or use instancing to do it and upload all of the transforms and do the local to world transform in the shader.
Here's my code

	D3DVERTEX quad[20000] = {		{1.0f, -1.0f, tilez, D3DCOLOR_ARGB(255,255,255,255),1,0},		{3.0f, -1.0f, tilez, D3DCOLOR_ARGB(255,255,255,255),0,0},		{1.0f, 1.0f, tilez, D3DCOLOR_ARGB(255,255,255,255),1,1},		{3.0f, 1.0f, tilez, D3DCOLOR_ARGB(255,255,255,255),0,1}	};	float qx, qy;	DWORD qcolor =  D3DCOLOR_ARGB(255,255,255,255);	float u, v;	qx = 1.0f;	qy = -1.0f;	u = 1.0f;	v = 0.0f;	for(int i = 0; i < 20000; i += 4)	{			quad.color = qcolor;			quad.U = u;			quad.V = v;			quad.x = qx;			quad.y = qy;			quad.z = tilez;			qx += 2.0f;			u -= 1.0f;			quad[i+1].color = qcolor;			quad[i+1].U = u;			quad[i+1].V = v;			quad[i+1].x = qx;			quad[i+1].y = qy;			quad[i+1].z = tilez;			qx -= 2.0f;			qy += 2.0f;			u += 1.0f;			v += 1.0f;			quad[i+2].color = qcolor;			quad[i+2].U = u;			quad[i+2].V = v;			quad[i+2].x = qx;			quad[i+2].y = qy;			quad[i+2].z = tilez;			qx += 2.0f;			u -= 1.0f;			quad[i+3].color = qcolor;			quad[i+3].U = u;			quad[i+3].V = v;			quad[i+3].x = qx;			quad[i+3].y = qy;			quad[i+3].z = tilez;		   qx += 2.0f;	       qy += 2.0f;	       u = 1.0f;	       v = 0.0f;	}


All i can see is one quad in the world...hmm
Can anyone help me please? how is it possible to create only one vertex buffer having all the tile info?
I just recommend to go back one step and think about the problem and the solution

You want to position each vertex of the quad like this:

01
23

Where the first face is 123 and the second is 234

0 is x+0|y+0
1 is x+1|y+0
2 is x+0|y+1
3 is x+1|y+1

OR in other words:

01
2-

and

-3
45

0 is x+0|y+0
1 is x+1|y+0
2 is x+0|y+1
3 is x+1|y+0
4 is x+0|y+1
5 is x+1|y+1

3 = 1
4 = 2

You should try to do it with a TRIANGLELIST first, which is 3 vertices per face
So if you want a 3x3 matrix you want this:

9 quad * 6 vertices = 54 vertices in total

every row has 4 vertices in them, so you want to skip 4 vertices per row:

for x = 0 to 3 for y = 0 to 3  offset = 4*y+x;  //6 vertices for each face  vertex[offset*6+0].x = x+0;  vertex[offset*6+0].y = y+0;  vertex[offset*6+1].x = x+1;  vertex[offset*6+1].y = y+0;  vertex[offset*6+2].x = x+0;  vertex[offset*6+2].y = y+1;  vertex[offset*6+5].x = x+1;  vertex[offset*6+5].y = y+1;  vertex[offset*6+3] = vertex[offset*6+1];  vertex[offset*6+4] = vertex[offset*6+2]; next ynext x//3x3 and each quad is 2 facesDrawPrimitve(TRIANGLELIST,3*3*2);


I didn't test this and its not a perfect solution, but this should work

//Edit: I'll never get used to gamedevs formating of posts :P

This topic is closed to new replies.

Advertisement