将数据从 Offscreen-plain 复制到渲染目标

Copy data from Offscreen-plain to Render target

我做错了什么?

我想使用图像中的位图创建多重采样渲染目标。

我的计划是:

  1. 创建 render targetoffscreen-plain 表面
  2. 用位图填充 offscreen 表面
  3. 使用StretchRect将数据从offscreen-plain复制到render target
IDirect3DSurface9* targetSurface;
IDirect3DSurface9* sourceSurface;

device->CreateRenderTarget(width, height, D3DFMT_A8R8G8B8, D3DMULTISAMPLE_4_SAMPLES, 0, false, &targetSurface, NULL);
device->CreateOffscreenPlainSurface(width, height, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &sourceSurface, NULL);

D3DLOCKED_RECT lockedRect;
sourceSurface->LockRect(&lockedRect, NULL, 0);
// Writing data...
sourceSurface->UnlockRect();

// Copy image content to render target
device->StretchRect(sourceSurface, NULL, targetSurface, NULL, D3DTEXF_POINT);

但是渲染出来的结果不是我想要的

问题是错误的位图填充。

RenderTarget 大小是二的幂。

此外,offscreen-plain是多余的,所以代码如下:

IDirect3DSurface9* surface;

device->CreateRenderTarget(width, height, D3DFMT_A8R8G8B8, D3DMULTISAMPLE_4_SAMPLES, 0, true, &surface, NULL);

D3DLOCKED_RECT lockedRect;
surface->LockRect(&lockedRect, NULL, 0);
// Writing data...
surface->UnlockRect();