My own little DirectX FAQ

Monday, February 03, 2003
What happens when I set a texture to NULL?

Well, there's a number of different options. There's what should happen, there's what often happens, there's what more frequently happens, and there's what you can rely on happening. So let's address these one by one.

What should happen

According to the refrast source, if you read any texels from a NULL texture, you get opaque black. So that RGB=0.0, and alpha=1.0.

However, if you are using the TextureStateState pipeline (i.e. not a Pixel Shader), and D3DTS_ARG1 is set to D3DTA_TEXTURE, that that TSS stage is effectively set to D3DTOP_DISABLE instead, and this means all the subsequent stages will be ignored. Note this does not happen if it's ARG2 that is set to TEXTURE - then you read opaque black and the stage does what it usually does. Which is a bit arbitrary, but there it is.

Remember - that's according to the refrast source, and in theory that's the official spec. But read on...

What often happens

Some cards get the bit about reading opaque black texels right, but many don't get the bit about disabling that TSStage and all subsequent ones. So you just get normal TSS processing.

What more frequently happens

Most cards actually follow the OpenGL standard which is to read opaque white. And also ignore the thing about disabling stages.

The other common behaviour is to give you random texture data.

What you can rely on

Nothing. Absolutely nothing at all. The D3D spec has changed a few times, the drivers have changed many times, different IHVs implement different things, and frankly anything could happen - you're doing well if it doesn't simply BSOD your machine, call you names and spit in your beer. Well OK - I've never actually had a machine die on me for setting a NULL texture, but you do get fairly unpredictable results on your screen. The best advice is to avoid doing this. Write your Pixel Shaders or TextureStageState setups to do what you want to do, and no more. If that means you need a different shader/TSS for the "NULL texture" case, then do it. Usually that shader/TSS will run a lot faster than using a NULL texture, and it will be a lot more predictable. This is one of those odd little corners of the D3D spec that are very badly supported - best to avoid it.

Warning - some or all of the above my be inaccurate :-)