|
|
发表于 2005-12-25 18:27:00
|
显示全部楼层
Re:请问各位如何离屏渲染?
可能这段有些帮助,关于SetRenderTarget的
……
这个技术的关键问题是 render to surface 和 copy surface to DC,render to surface 比较简单:
通过 IDirect3DDevice8.CreateRenderTarget 创建一个 Surface(IDirect3DSurface8),Lockable = TRUE, 使用 IDirect3DDevice8.SetRenderTarget 选取该 Surface 为 render 对象(pNewZStencil = IDirect3DDevice8.GetDepthStencilSurface(),
可能需要另外的 Depth-Stencil Surface ,因为有人说不是所有的显卡驱动都可以在尺寸不同的 RenderTarget 和 DepthStencil 下工作),然后按照正常的方式 Render(BeginScene + ... + EndScene)。
至于传递 copy surface to DC,由于 D3D8 不支持DDraw, 只能以下面的方式实现:调用 IDirect3DSurface8.LockRect(&lr, NULL, D3DLOCK_READONLY) 取得 lpBits, 然后通过 SetDIBits 将 lpBits 数据传给一个位图,A8R8B8G8/X8R8B8G8 的 BITMAPINFOHEADER 大概是这样的:
BITMAPINFOHEADER bih;
memset(&bih, 0, sizeof(BITMAPINFOHEADER));
bih.biSize = sizeof(BITMAPINFOHEADER);
bih.biWidth = desc.Width;
bih.biHeight = desc.Height;
bih.biPlanes = 1;
bih.biBitCount = 32;
bih.biCompression = BI_RGB;
我比较怀疑这种方法的效率,设置 RenderTarget 为 Lockable 将增加额外开销,LockRect 和 SetDIBits 也不够快,而且是在 vedio memory 和 system memory 之间传递数据。可能把 3D 绘图程序直接建立在 IDirect3DDevice8 的窗口模式下会比较快。
如果使用 Direct3D7 应该要方便一些,至少 IDirectDrawSurface7 可以直接 GetDC。 |
|