Monday, April 5, 2010

Non-Power of 2 Textures in DirectQ

Quaddicted has just posted another article in it's ongoing series on differences between Software Quake and GLQuake. This one focusses on GLQuake's (rather vile) handling of non-power-of-2 textures, and has motivated me to address the problem a little better in DirectQ. I recommend that you read that article (if you haven't already) before continuing here.

I'll begin by owning up - DirectQ has never handled these too good. A straightforward bilinear interpolation (which is at least better than GLQuake) was as far as I had gone here. Now I've switched it to a dithered triangle filter and have also enabled support for non-power-of-2 texture uploads.

There are 3 types of support available for non-power-of-2 textures. First is the way OpenGL does it, which is not relevant but worth discussing. OpenGL advertises support by means of an extension, but it may or may not be hardware accelerated and you really have no way of knowing. This is the wrong way to do it, for reasons which should be obvious. Direct3D does better by letting you know exactly what the hardware supports (although on the oter hand you need to do more work, but it's a fair tradeoff).

Next there is conditional support. This allows hardware accelerated non-power-of-2 textures provided they're not mipmapped, not compressed and not wrapped. DirectQ will detect this and enable it for HUD and menu graphics, which can meet those conditions.

Finally there is unconditional support which takes priority over conditional, and can be applied to any texture. DirectQ will also detect this and enable it.

The final approach I guess is to pad textures (like FitzQuake does) and I intend doing something along those lines later on.

0 comments: