本文介绍了在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.

像previous,但除了要解决问题的动画具有第二渲染目标为每个控制。每当动画开始,交换渲染目标,所以我们有状态的时候动画开始,并与目标状态融合成其他渲染目标。在previous方法这不应该开销增加,我们只是过两倍的渲染目标,其中在任何给定的帧只有一个将被呈现给(在最大)。但这里说到的问题:对于这项工作,我需要有老字号的渲染目标preserve其内容。这应该在Windows性能良好的工作,但似乎有一个严重的性能影响对X-box游戏机360。另一方面,在preserve位仅在必要的,而动画被激活。

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盒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.

然而,当你有多个渲染preserveContents目标10MB,这个属性必须通过不断切换渲染目标回正常内存中模拟的。

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)

中的颜色数据长度为32位的Xbox 360的话,作为一个例子,如果你的库的用户正在开发自己的高清游戏,只有没有其他的渲染目标比主之一,他将使用:

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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 23:07