How to unset texture data in XNA 4.0

不羁的心 提交于 2019-12-08 01:28:24

问题


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?


回答1:


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

so you have to do this:

 GraphicsDevice.Textures[0] = null;


来源:https://stackoverflow.com/questions/8154784/how-to-unset-texture-data-in-xna-4-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!