PDA

View Full Version : Textures Slowing App



Swiftless
05-30-2005, 07:41 PM
In my app, I have a function called Init that has the code for loading my textures. Now everything was working fine, until I started implementing multiple textures.

I am using the following code to map my textures:


if (height > 25)
{
glBindTexture(GL_TEXTURE_2D, texture[1]);
}
if (height < 25)
{
glBindTexture(GL_TEXTURE_2D, texture[0]);
}
if (height > 28)
{
glBindTexture(GL_TEXTURE_2D, texture[2]);
}
This is where it slows down the application, this is in a loop along with the code for drawing my terrain, which is all kept in a Display List. Is there any other way I can use to speed it up? I was getting about 80+fps, now I am getting 20 on average.

dorbie
05-30-2005, 07:55 PM
This has the potential to change the texture a LOT, it will also bind the same texture again and again when it doesn't need to, you can't rely on implementations to optimize this for you, it's bad code. On some hardware there is a very small performance impact for binds. You should try to sort stuff with the same texture and draw it all at once with a single bind.

Also remember you can't bind between begin end pairs.

Swiftless
05-30-2005, 10:25 PM
I realised it was bad code, but I am not sure how I would call it once, and once only. I have tried a few ways, but none seem to work, because I don't know where to call it from to call it once only.

And I am not binding between the Begin and End pairs. I am binding beforehand.

jide
05-31-2005, 01:32 AM
try to compute your terrain inside a display list so that it will force you to bind only once.

05-31-2005, 07:41 PM
It is in a display list, and the code to do the binding is in the same display list.

plasmonster
05-31-2005, 09:22 PM
Are you doing any LOD here? If not, why not, and why not use static/dynamic VBOs instead?

:-)

dvm
05-31-2005, 10:50 PM
What method do you use to create the terrain, a heightmap? You could properly compute texture coordinates so that one large texture can be either repeated or stretched over the entire area.
I suppose you should repeat the texture, as it would have to be smaller in size, this way.

Swiftless
06-01-2005, 10:40 PM
LOD? VBO?
I am a tad lost. I am new to this and dont know much OpenGL jargon.

dvm, I am not using a heightmap yet, at the moment it is only random, but I probably will implement a heightmap feature later on.

PickleWorld
06-02-2005, 05:15 AM
LoD = Level of Detail

Basically means the closer you are to something the higher the detail, the further away you are you use less detail. This makes it so you are not wasting time trying to render stuff thats too far away to be really seen anyway.

VBO = Vertex Buffer Object.

Basically this allows you to put all your coordinates into a buffer and send them to the card all at once (instead of making hundreds of glVertex, glTexCoord, etc calls). It reduces overhead and makes things faster.

Those are the basics, there is of course a lot more to those :)