XNA 和渲染目标 [英] XNA and RenderTargets

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

问题描述

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

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.

这是一些伪代码.

// 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 ??

推荐答案

这篇文章解释了为什么您的渲染目标被清除.

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

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.

选择您想要的行为的参数是 RenderTargetUsage.请注意,在 XBox 上保存内容.

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.

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

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