Texture Switching Question submitted by (09 September 1999) | Return to The Archives

| First of all, I find your column really cool and after some weeks of wracking my brain I have come to the point where I need some help. To put things in context, I'm developing a 3D engine targeted for 3D accelerator platforms and have some decisions to make regarding the implementation. One of my main concerns is texture switching. Say I'd want to use octrees/kd-trees/bsp or a similar mechanism. This means that polygons are thrown at the drawing code in a seeming random fashion (with regard to the texture they use). I did some testing and several hundred switches are okay, but the more polygons get processed the more switching will eventually occur (and performance will go down the drain). A solution I may have come up with is to traverse the structure and store the results in a preliminary structure, which is texture sorted. Then, go ahead and traverse this structure and draw the stuff. Obviously, this preliminary structure will be pre-allocated and not allocated and freed for each frame. Is this aproach good enough, or do you guys know something better? How would you handle lightmaps (to reduce texture switching in the second texture unit)? I guess, if you don't have the second texture unit, a second preliminary structure would suffice... Well, what do you think about all this? |

| Sorting by texture is good, but be careful! If it takes a long time to build that list (i.e. gather up the polygons that will need to be rendered) then you're losing the advantage of having the 3D card render while you work. You might consider sending polygons to the card (including texture switches) while you build the list, but only do this if the card isn't busy. The polygons that came in while the card was busy will get stuck into a list and sorted/rendered last. At least this keeps the card busy while you build & sort the list.
Lightmaps are unique per surface, and simply require the texture switches. Just make sure you have a clever texture caching mechanism.
Response provided by Paul Nettle

This article was originally an entry in flipCode's Fountain of Knowledge, an open Question and Answer column that no longer exists.

Copyright 1999-2008 (C) FLIPCODE.COM and/or the original content author(s). All rights reserved.
Please read our Terms, Conditions, and Privacy information.