如何在XNA 4.0中取消设置纹理数据 [英] How to unset texture data in XNA 4.0
问题描述
我需要向我的像素着色器传达一些不断变化的数据.我有一个texture2d通过纹理参数传递给我的像素着色器.在调用着色器之前,我需要更新纹理中的数据.
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:
在GraphicsDevice上主动设置资源时,您不能在资源上调用SetData.在调用SetData之前,请先从设备上取消设置."
"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?
推荐答案
第一个纹理是在GraphicsDevice.Textures数组中设置的,索引为0.
The first texture is set in the GraphicsDevice.Textures array with the index 0.
所以您必须这样做:
GraphicsDevice.Textures[0] = null;
这篇关于如何在XNA 4.0中取消设置纹理数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!