我有一些代码如下:
GraphicsDevice.SetRenderTarget(0, myRenderTarget);
GraphicsDevice.Clear(Color.Black);
spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate, SaveStateMode.None);
myEffect.Begin();
myEffectCurrentTechnique.Passes[0].Begin();
spriteBatch.Draw(aRegularTexture, Vector2.Zero, Color.White);
spriteBatch.End();
myEffect.CurrentTechnique.Passes[0].End();
myEffect.End();
GraphicsDevice.SetRenderTarget(0, backBuffer);
Texture2D bloomTexture = myRenderTarget.GetTexture();
...
GraphicsDevice.SetRenderTarget(0, myRenderTarget);
GraphicsDevice.Clear(Color.Black);
spriteBatch.Begin();
spriteBatch.Draw(aRegularTexture, Vector2.Zero, Color.White);
spriteBatch.End();
GraphicsDevice.SetRenderTarget(0, backBuffer);
aRegularTexture = myRenderTarget.GetTexture();
//SHOULD be doing nothing, since I'm just rendering said texture into a render target and pulling it back out
(注意:这被修剪为最小的再现代码,而不是我实际使用的)
如果我在第二段代码之前将aRegularTexture渲染到屏幕上,它看起来很好并且不受影响。但是如果我在第二个代码块之后将其渲染出来,它就会被设置为aModifiedTexture的内容,即使我从未做过任何导致这种情况的事情。为什么? (使用XNA 3.1)
答案 0 :(得分:1)
通过Shawn Hargreaves:“GetTexture返回与rendertarget本身相同的表面内存的别名,而不是单独的数据副本”
http://blogs.msdn.com/b/shawnhar/archive/2010/03/26/rendertarget-changes-in-xna-game-studio-4-0.aspx