XNA 窗口系统的渲染策略(RenderTarget 性能) [英] Rendering strategy for a window system in XNA (RenderTarget performance)

查看:30
本文介绍了XNA 窗口系统的渲染策略(RenderTarget 性能)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在从头开始为 XNA 游戏创建一个窗口系统.我主要为 Windows 开发,但谁知道我将来可能支持哪些平台.如果您知道本机 Direct3D 的这一点,请随时回答,因为性能语义应该相似.如果可能,请考虑如果目标平台是 X-Box 360 会发生什么变化.

I'm currently creating a window system for XNA games from scratch. I'm developing primarily for Windows, but who knows what platforms I might support in the future. Feel free to answer if you know this for native Direct3D, since the performance semantics should be similar. If possible, consider what would change if the target platform was X-Box 360.

我取得了很好的进展,但现在我不确定如何准确地渲染窗口.我想出了四种方法:

I'm making good progress, but now I am unsure on how to exactly render the windows. I came up with four approaches:

  • 只需将所有控件直接渲染到屏幕上即可.这就是我现在所做的.只要控件不是半透明的,就可以通过在状态之间混合来制作动画.我没有找到在任意数量的状态之间设置动画的好方法(假设一个按钮当前正在从按钮向上到按钮向下以及从鼠标移出到鼠标悬停进行动画处理,然后它被禁用.它应该平滑地从它的最后一个状态混合到新状态.使用这种方法,只有在最后一个动画完成后才播放一个动画,否则你会在动画中跳跃.

  • Just render all controls directly onto the screen. This is what I do now. Controls can be animated by blending between states as long as they are not semi-transparent. I did not find a good way to animate between an arbitrary number of states (suppose a button that is currently animating from button-up to button-down and from mouse-out to mouse-over, and then it is being disabled. It should smoothly blend from its last state to the new state. With this approach, this only works if one animation is played after the last one finished, or you'll have jumps in animation.

将每个顶级窗口和所有控件渲染到一个渲染目标中,然后使用它以半透明的方式将顶级窗口渲染到屏幕上.这使得顶层工作变得半透明,易于管理,但不会改变动画.

Render each top-level window and all controls into a render target, and then use that to render the top-level windows with semi-transparency onto the screen. This makes semi-transparency at top-level work and is easy to manage, but doesn't change the thing with the animations.

将每个控件渲染到渲染目标中,该目标仅在控件变脏时更新(即必须设置动画或文本已更改).这样,每个控件的半透明将起作用.

Render each control into a render target, which is only updated when the control becomes dirty (i.e. must animate or the text has been changed). This way, per-control semi-transparency would work.

和前面一样,但是除了解决动画问题之外,每个控件都有第二个渲染目标.每当动画开始时,交换渲染目标,这样我们就有了动画开始时的状态,并将其与目标状态混合到另一个渲染目标中.这不应该增加前一种方法的开销,我们只有两倍的渲染目标,在任何给定的帧中,只有一个渲染目标(最多).但问题来了:要使其正常工作,我需要让旧"渲染目标保留其内容.这在 Windows 上应该具有良好的性能,但似乎对 X-Box 360 有严重的性能影响.另一方面,只有在动画处于活动状态时才需要保留"位.

Like the previous, but in addition to solve the animation problem have a second render target for each control. Whenever an animation starts, swap render targets, so we have the state when the animation starts, and blend it with the destination state into the other render target. This should not add overhead over the previous approach, we just had twice as many render targets, of which in any given frame only one would be rendered to (at maximum). But here comes the problem: For this to work, I would need to have the "old" render target preserve its contents. This should work with good performance on Windows, but appears to have a serious performance impact on X-Box 360. On the other hand, the "preserve" bit is only necessary while an animation is active.

实际问题来了.任何澄清的东西都是受欢迎的.对于性能问题,请记住这只是游戏的窗口系统 - 背后的游戏可能会使用许多渲染目标并吸收性能,而且可能比窗口系统要多得多.假设在绝对最坏的情况下,我们可能有五个顶级窗口,每个窗口都有 20-40 个控件.

And here come the actual questions. Anything that clarifies is welcome. With the performance questions, remember that this would just be the window system of a game - the game behind might use many render targets and suck up performance as well, and likely much more than the window system. Assume that we might have five top-level windows with 20-40 controls each on the screen in absolute worst-case.

  • 您会推荐以下哪些方法(如果有)?为什么?当然,您可以随意添加另一种方法.
  • 假设有 200 或 400 个可用的渲染目标(假设每帧可能只有 20 个渲染目标被渲染)是否会对性能产生影响?
  • PreserveContents 对 X-Box 360 的性能影响真的那么严重吗?在 Windows 上有多糟糕?
  • 可以写入 RenderTarget2D.RenderTargetUsage 属性.在运行时切换它是否是一个好主意,仅在需要时启用 PreserveContents?
  • 您(作为玩家)是否会介意控制动画在某些情况下是否会跳跃,例如悬停在按钮上,将鼠标移出然后再次移入,因此正常->悬停"动画从一开始就播放两次因为它比你慢?

推荐答案

如果您正在为 Xbox 360 进行开发,则必须小心渲染目标.Xbox 360 有一个特殊的内存 (10MB) 来保存渲染目标,包括用于在屏幕上渲染的目标.

If you're developing for Xbox 360, you must be careful with render targets. The Xbox 360 has a special memory (10MB) to hold render targets, including the one used to render on the screen.

只要不超过 10MB,从一个渲染目标切换到另一个渲染目标没有任何影响,即使使用 PreserveContents,因为所有渲染目标都存储在这个特殊的内存中.

As long as you don't exceed 10MB, switching from one render target to another has no impact, even with PreserveContents, because all the render targets are stored in this special memory.

但是,当您有超过 10MB 的带有 PreserveContents 的渲染目标时,必须通过不断地将渲染目标切换回正常内存来模拟此属性.

However, when you have more than 10MB of render targets with PreserveContents, this attribute must be emulated by constantly switching a render target back and from normal memory.

因此渲染目标的数量并不像那些目标的总大小那么重要.您可以使用此公式了解渲染目标的大小:

So the # of render targets is not as important as the total size of those ones. You can know the size of a render target with this formula :

size (bits) = width  x height x color data size (bits)

Xbox 360 上的颜色数据大小为 32 位,因此,例如,如果您库的用户正在开发高清游戏,除了主要渲染目标之外没有其他渲染目标,他将使用:

The color data size is 32 bits on Xbox 360 so, as an example, if the user of your library is developing his game in HD with only no other render target than the main one, he will use :

3,515625MB = 29491200 bits = 1280 x 760 x 32 bits

此外,您应该避免动态创建渲染目标.成本太高了.您应该创建一个在游戏开始时分配的静态渲染目标池,并让您的 GUI 组件请求它们.

Also, you should avoid creating render targets dynamically. It cost too much. You should create a pool of static render targets allocated at the beginning of the game and have your GUI components request them.

这篇关于XNA 窗口系统的渲染策略(RenderTarget 性能)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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