Sign in to follow this  
kevinawad

Slow rendering?

Recommended Posts

kevinawad    123
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.

Share this post


Link to post
Share on other sites
kevinawad    123
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.

Share this post


Link to post
Share on other sites
RDragon1    1205
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.

Share this post


Link to post
Share on other sites
RDragon1    1205
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.

Share this post


Link to post
Share on other sites
kevinawad    123
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[i].color = qcolor;
quad[i].U = u;
quad[i].V = v;
quad[i].x = qx;
quad[i].y = qy;
quad[i].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

Share this post


Link to post
Share on other sites
J-Fox    174
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 y
next x

//3x3 and each quad is 2 faces
DrawPrimitve(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

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