如何在XNA 4.0中取消设置纹理数据

时间:2011-11-16 16:08:06

标签: xna-4.0 pixel-shader

我需要将一些不断变化的数据传达给我的像素着色器。我有一个texture2d,我通过纹理参数传递给我的像素着色器。在我调用着色器之前,我需要更新纹理中的数据。

        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

问题在于,当我这样做时,我得到一个例外:

“在GraphicsDevice上主动设置资源时,您可能无法在资源上调用SetData。在调用SetData之前从设备取消设置。”

如何“从设备中取消设置”?或者我应该采取不同的方法吗?

1 个答案:

答案 0 :(得分:4)

第一个纹理在GraphicsDevice.Textures数组中设置,索引为0。

所以你必须这样做:

 GraphicsDevice.Textures[0] = null;