重用渲染目标“溢出油漆”?

发布于 2024-12-13 19:23:01 字数 1265 浏览 0 评论 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)

I have some code that goes like this:

        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

(note: this is trimmed down to the minimal reproduction code, not quite what i actually use)

If I render aRegularTexture to the screen before the second block of code, it looks fine and untouched. But if I render it out after the second block of code, it's set to the contents of aModifiedTexture, even though I'm never doing anything that would result in that. Why? (Using XNA 3.1)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

峩卟喜欢 2024-12-20 19:23:01

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

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

Via Shawn Hargreaves: "GetTexture returns an alias for the same surface memory as the rendertarget itself, rather than a separate copy of the data"

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文