Fast Texture Switching

Started by
7 comments, last by Mulligan 21 years, 11 months ago
What is the fastest way to switch the current texture? I''m currently building an engine for practice and when I display 1 triangle with 1 texture my FPS is 92 now when i do 15 triangles with 15 textures (one on each triangle) my FPS is 32 Is this normal, or does it appear on the surface that I could be optomizing something?
Advertisement
Absolutely normal. Texture switches are expensive, and should be avoided when possible. When rendering, try to batch your geometry into groups of triangles having the same texture, so that texture changes are kept to a minimum.

The fastest way to switch textures is glBindTexture().

Edit: although your FPS drop seems a bit excessive. How do you manage textures ?

/ Yann

[edited by - Yann L on May 17, 2002 5:06:58 PM]
As of now, I just display a list of polygons and switch textures whenever required by the polygon. What you said about grouping had been a consideration, but I''ll do that later. Thanks for the response.
Also try to put small textures together (if they aren''t supposed to tile), I do this with my gui. I have one skin texture that contains the images for buttons, borders and so on. I get over 100 fps with several windows (on my TNT2, so I think it''s quite good =) ). Good luck!
You shouldn''t be getting a speed drop of that much . Texture switching is expensive, but it''s not _that_ expensive. Are you sure you''re not calling glTexImage to switch textures or anything like that?

____________________________________________________________
www.elf-stone.com

____________________________________________________________www.elf-stone.com | Automated GL Extension Loading: GLee 5.00 for Win32 and Linux

Sounds to me as if he''s in software mode.
This is what I do when changing textures.

glBindTexture( GL_TEXTURE_2D, m_Textures[ID] );

By the way, when I create my list of textures in the m_Textures[], do I have to release them manualy, or is it automatic? Seems to me it should be manual, but I can''t find any source code that does it that way.
From OpenGL Programming Guide:

As you bind and unbind texture objects, their data still sits around somewhere among your texture resources. If texture resources are limited, deleting textures may be one way to free up resources.

void glDeleteTextures(GLsizei n, const GLuint *textureNames);

Deletes n texture objects, named by elements in the array textureNames. The freed texture names may now be reused (for example, by glGenTextures()).

If a texture that is currently bound is deleted, the binding reverts to the default texture, as if glBindTexture() were called with zero for the value of textureName. Attempts to delete nonexistent texture names or the texture name of zero are ignored without generating an error.
thanks

This topic is closed to new replies.

Advertisement