0

我有一些这样的代码:

        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)

4

1 回答 1

1

通过 Shawn Hargreaves:“GetTexture 返回与渲染目标本身相同的表面内存的别名,而不是数据的单独副本”

http://blogs.msdn.com/b/shawnhar/archive/2010/03/26/rendertarget-changes-in-xna-game-studio-4-0.aspx

于 2011-11-04T17:26:58.153 回答