XNA何时丢弃渲染目标内容? [英] When does XNA discard Render Target contents?

查看:108
本文介绍了XNA何时丢弃渲染目标内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解XNA中的渲染目标是易变的,但是它们的易变性是什么?我找不到任何文档来说明确切的时间



我想只绘制一次渲染目标,然后将其用作绘制对象。



无限期地Texture2D。这可能吗?我是否需要启用 RenderTargetUsage.PreserveContents 才能正常工作?我读过PreserveContents在Xbox和电话硬件上非常慢。

解决方案

乔纳森(Jonathan)对<$ c $作了很好的解释c> RenderTargetUsage ,但我想澄清一些有关原始问题的内容,包括使用 RenderTarget2D 作为 Texture2D



简单地说, RenderTargetUsage 控制当在设备上将其设置为渲染目标时,将显示曲面。如果未设置为保留内容,则将其清除。在Xbox 360上,这是对硬件的古怪(出于性能考虑)。在Windows上,通过在设置时清除表面即可模拟出与Xbox 360相匹配的东西。



但是,如果您将其用作纹理,这就是。这只是一个问题,您想要多次渲染到一个表面(每次将其设置到设备上)而不丢失先前的内容。



如果您只将其设置为渲染目标一次,则在游戏开始时,保留设置是什么都无所谓,因为它永远不会再设置为渲染目标。



您关心的是 IsContentLost 属性( MSDN )或 ContentLost 事件(MSDN )。如果您渲染到渲染目标的内容丢失(由于设备更改,例如:全屏显示),则会设置/提高这些值。



如果在每帧重新渲染渲染目标,则无需检查内容丢失。但是,如果您希望在游戏开始时创建渲染目标并在整个过程中继续使用它们,则需要确保在创建目标之后它们不会丢失。



(请注意,您不必担心在 Draw 调用过程中会发生内容丢失的情况。我可以肯定地说,它只能曾经在帧之间发生过。)


I understand that Render Targets in XNA are volatile, but how volatile are they? I can't find any documentation that tells when exactly their contents are discarded. Is it just when you start drawing to them, or could it be at any time?

I would like to simply draw to a render target once and then use it as a Texture2D indefinitely. Is this possible? Would I need to enable RenderTargetUsage.PreserveContents for this to work properly? I have read that PreserveContents is very slow on Xbox and phone hardware.

解决方案

Jonathan has given a great explanation of RenderTargetUsage, but I'd like to clarify some things with regard to the original question, involving the use of a RenderTarget2D as a Texture2D:

Put simply, RenderTargetUsage controls the behaviour of the surface when it is set on the device as a render target. If it is not set to preserve the contents, they will be cleared. On Xbox 360 this happens as a quirk of the hardware (for performance). On Windows this is emulated to match Xbox 360 by simply clearing the surface when you set it.

But, if you are using it as a texture, this is irrelevant. It's only an issue when you want to render to the one surface multiple times (setting it to the device each time) without losing the previous contents.

If you only set it as the render target once, at the start of your game, it won't matter what the preserve setting is because it never gets set as a render target again.

What you do care about is the IsContentLost property (MSDN) or the ContentLost event (MSDN). These will be set/raised if the contents that you rendered to the render target were lost (due to device changes, eg: going full-screen).

If you're re-rendering the render target each frame, then you don't need to check for content-lost. But if you expect to create your render targets at the start of your game and continue using them throughout, you need to ensure they haven't been lost after the frame on which they were created.

(Note that you don't need to worry about content-lost happening part-way through your Draw call. I'm reasonably certain that it can only ever happen between frames.)

这篇关于XNA何时丢弃渲染目标内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆