XNA 和渲染目标

发布于 2024-10-16 21:04:39 字数 824 浏览 5 评论 0原文

我在使用渲染目标时遇到问题,希望有人可以向我解释。 我正在尝试使用渲染目标来渲染一些精灵,然后将所述渲染目标绘制到正常的后台缓冲区 50% 不透明(空)上。它工作得很好,除非我在绘制调用中多次使用目标,在这种情况下,只有最后一组精灵会出现在屏幕上。

这是一些伪代码。

// Normal Sprite Drawing.  
DrawSomeSprites();

SetRenderTarget(CompositeTarget);

// These go on the render target.  
DrawSomeMoreSprites();

SetRenderTarget(null);

// And now I draw onto the back buffer.  
DrawSprite(CompositeTarget);


// So now I want to draw another bunch of sprites via my render target using the same approach.
SetRenderTarget(CompositeTarget);

// These are the only sprites that I can see on the screen.
DrawSomeMoreSprites();             
SetRenderTarget(null);
DrawSprite(CompositeTarget);

我希望这是有道理的。在我看来,每次更改渲染目标时,之前的渲染目标(空)都会因某种原因被清除。我在交换目标之前结束了所有精灵批次,并且没有收到任何错误,所以我不知道在这里要做什么。显然,目标是能够同时在屏幕上看到我的所有精灵组。我在这里缺少什么?

I have a problem with using render targets that I am hoping someone can explain to me.
I am trying to use a render target to render some sprites, and then draw said render target onto the normal back buffer 50% opaque (null). It works great, except if I use the target more than once in a draw call, in which case only the last group of sprites will appear on the screen.

Here is some psuedo code.

// Normal Sprite Drawing.  
DrawSomeSprites();

SetRenderTarget(CompositeTarget);

// These go on the render target.  
DrawSomeMoreSprites();

SetRenderTarget(null);

// And now I draw onto the back buffer.  
DrawSprite(CompositeTarget);


// So now I want to draw another bunch of sprites via my render target using the same approach.
SetRenderTarget(CompositeTarget);

// These are the only sprites that I can see on the screen.
DrawSomeMoreSprites();             
SetRenderTarget(null);
DrawSprite(CompositeTarget);

I hope that makes sense. It seems to me that every time I change the render target, the previous render target (null) is cleared for some reason. I am ending all of my sprite batches before swapping the targets, and I am not getting any errors, so I don't know what to do here. Obviously the goal is to be able to see all of my sprite groups on the screen at the same time. What am I missing here ??

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

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

发布评论

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

评论(1

记忆消瘦 2024-10-23 21:04:39

本文解释了为什么您的渲染目标被清除

基本上这是 Xbox 图形系统工作方式的一个怪癖。 Xbox GPU 只能渲染到一个内存区域,而且非常小。当您更改渲染目标时,该内存就会被破坏。在 XNA 2.0 中(如本文所述),Windows 的默认行为已更改以匹配 Xbox 360 行为,从而保持跨平台的一致性和快速性。

用于选择所需行为的参数是 RenderTargetUsage。请注意,在 Xbox 上保存内容的速度很慢

或者,您也可以更改渲染的顺序,这样就不会遇到此问题。

This article explains why your render targets are being cleared.

Basically it's a quirk of the way the XBox graphics system works. There's only one region of memory the XBox GPU can render into, and it's quite small. When you change render targets, that memory gets clobbered. In XNA 2.0 (as the article explains), the default behaviour of Windows was changed to match the Xbox 360 behaviour to keep things consistent and fast across platforms.

The parameter to select which behaviour you want is RenderTargetUsage. Just be aware that preserving contents on the XBox is slow.

Alternately you may be able to change the order you are doing your rendering so you don't run into this problem.

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