Speed issues caused by textures?

Started by elias4444, December 29, 2004, 22:54:40

Previous topic - Next topic

elias4444

Yet another question from the soon-to-no-longer-be a newbie:

I've been running benchmarks on my game. On a laptop with a Geforce2Go, I'm getting about 50fps. If I vsync (which makes it look better), I get 30fps. On that same machine, I run the square heads quake demo, and get like 150fps. His game is WAY more advanced than mine could ever hope to be. So, what's causing my slow down?

I did stumble onto one thing - I stopped drawing the background, and it doubled my FPS. The background is simply a 1024x768 png image (111kb in size) that I texture map onto a quad of the same size. It's drawn before anything else. Are there issues using PNGs for textures? Or is my texture use just really bad?

I've also tried removing all collision logic just to see if perhaps I was processing too much - the FPS stayed the same however.
=-=-=-=-=-======-=-=-=-=-=-
http://www.tommytwisters.com

the2bears

Quote from: "elias4444"Are there issues using PNGs for textures? Or is my texture use just really bad?

Shouldn't make a difference what type of file the image was, it's going to be some block of data once it's bound to a texture.  But you do have a rather large texture... I'm not surprised you see a slow down.  Could try tiling the background.  Others with more experience will hopefully have better ideas.

I chose black for my background;)

Bill
the2bears - the indie shmup blog

elias4444

Well, I tried a couple different things, but the biggest improvements were made by either:

A) Not drawing the background at all.

or

B) Making a much smaller texture and then stretching it out to fill the screen's background.

B is looking like the best option for now, although the image doesn't look nearly as nice anymore. How small should an texture be? I went down to 256x256. Are there general guidelines on these things?
=-=-=-=-=-======-=-=-=-=-=-
http://www.tommytwisters.com

CaptainJester

You might want to tile the background as the2bears said.  Try using 4 256x256 textures with 4 quads.
The problems of this world cannot possibly be solved by skeptics or cynics whose horizons are limited by the obvious realities.  We need men and women who can dream of things that never were. - John Fitzgerald Kennedy(35th US President)
8)

princec

I bet he's just left blending on when he draws the background :)
And in fact, if you're going to blit the entire screen every frame there's no need to even clear the colour buffer either.

Cas :)

elias4444

I actually tried turning off alpha blending entirely, but it made almost no difference with the frame rate. Same thing with not clearing the color buffer bit.  Or are you talking about something that I'm not understanding?
=-=-=-=-=-======-=-=-=-=-=-
http://www.tommytwisters.com

elias4444

For those interested, here's the function I use to draw the background:

public void drawtexture(Texture texture, float x, float y, float z, float a) {

	GL11.glPushMatrix();
	
	texture.bind();
	
	//// Translate Size //////////
	float imgwidth = texture.getImageWidth();
	float imgheight = texture.getImageHeight();
	float texwidth = texture.getWidth();
	float texheight = texture.getHeight();
	
	GL11.glTranslatef(x, y, z);	
	GL11.glColor4f(1,1,1,a);

	GL11.glBegin(GL11.GL_QUADS);
	{
		GL11.glTexCoord2f(0, 0);
		GL11.glVertex2f(0, 0);
		GL11.glTexCoord2f(0, texheight);
		GL11.glVertex2f(0, imgheight);
		GL11.glTexCoord2f(texwidth, texheight);
		GL11.glVertex2f(imgwidth,imgheight);
		GL11.glTexCoord2f(texwidth, 0);
		GL11.glVertex2f(imgwidth,0);
	}
	GL11.glEnd();
		
	GL11.glPopMatrix();
}


Am I doing something wrong? Or worse, forgetting something?

For the rendering loop, I'm basically doing the following:


GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);

for (int i = 0;i<4;i++) {
	for (int k = 0;k<4;k++) {
		drawtools.drawtexture(bgpicture,(bgpicture.getImageWidth()*k)-2,(bgpicture.getImageHeight()*i)-2,backgroundz,1.0f);
	}
}

Display.update();


Those are each different methods and whatnot, but you get the idea for just the background. I noticed that with this tiling method, I'm getting the same slowdown I did when drawing just one big texture.
=-=-=-=-=-======-=-=-=-=-=-
http://www.tommytwisters.com

princec

What I don't see there, is you explicitly setting the blending state, which means it's just as likely something else you have drawn has set it to something odd. Try adding

glDisable(GL_BLEND);

in before you draw the background.

Cas :)

elias4444

Well, I just tried disabling GL_BLEND before drawing the background, but it didn't change anything in the slightest.

I'm starting to wonder what else I must be doing wrong? It seems like everytime I draw one more quad with a texture on it, my framerate goes down by like 10fps - the background cuts it down by 100fps (tiled or not).

Each of my sprites are drawn the same way as the background actually, using GL_QUADS to make a square and slap the texture on top of it. Is this a bad way of doing it?

At any given time, I have upwards of 70 "sprites" on the screen. Each sprite cycles through a list of textures for it's animation (and some of those sprites I mentioned are particle-effect sprites sitting behind other sprites for special fx).

Am I doing this right?

Update: I just commented out half of my sprite drawing routines, but the FPS stayed exactly the same. This is just strange.
=-=-=-=-=-======-=-=-=-=-=-
http://www.tommytwisters.com

elias4444

Of course, lowering the resolution from 1024x768, down to 800x600 gives me back about 100fps.  :P

Maybe I should add the option of what resolution to use, rather than hard coding it at 1024.  :?:
=-=-=-=-=-======-=-=-=-=-=-
http://www.tommytwisters.com

tomb

Could be that your running out of texture memory. Then some textures are moved to and from the card every frame, wich slows things down alot. How many and how big are the other textures your using?

QuoteThe background is simply a 1024x768 png image (111kb in size) that I texture map onto a quad of the same size.

1024x768 is not power of two. Are you using GLU buildmipmap or are you using the non power of two extension? Also the size of the png do not matter. Once it is decompressed it uses 1024*768*3=2.6MB. Even more if your using mipmaps.

You also say your using a laptop. They often got crappy graphics cards. Even though it is a Geforce, it might have some wierd performance issues.

elias4444

Yeah, most textures are 16x16. I take any size image and then map it to a power-of-2 texture (so 1024x768 actually gets mapped to 1024x1024, and then I use a texture ratio to let the blank area bleed off the quad).

The odd thing is, even when I shrank the background down to tiled images of 256x256, it's still causing me some solid slowdown. Also, I'm using the same textures over and over again. i.e., all the "bad-guys" are using the same texture set, etc..
=-=-=-=-=-======-=-=-=-=-=-
http://www.tommytwisters.com