Mr Bell
Mr Bell

Reputation: 9368

How to unset texture data in XNA 4.0

I need to communicate some constantly changing data to my pixel shader. I have a texture2d that I am passing to my pixel shader via a texture parameter. Before I call the shader I need to update the data in the texture.

        emittingPositions.SetData(emittingPositionsBuffer); //Set the data on the texture
        animationEffect.Parameters["emittersMap"].SetValue(emittingPositions); //Tell the shader about the texture data
        //go on to do the actual drawing calls to use the pixel shader

The problem is that when I do this I get an exception:

"You may not call SetData on a resource while it is actively set on the GraphicsDevice. Unset it from the device before calling SetData."

How do I "unset it from the device"? Or should I be taking a different approach here?

Upvotes: 2

Views: 3566

Answers (1)

Blau
Blau

Reputation: 5762

The first texture is set in the GraphicsDevice.Textures array with the index 0.

so you have to do this:

 GraphicsDevice.Textures[0] = null;

Upvotes: 5

Related Questions