重用渲染目标“溢出油漆”?
我有一些像这样的代码:(
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过 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