|
发表于 2012-4-22 10:10:00
|
显示全部楼层
Re:[DX9]如何将后台缓冲拷贝到IDirect3DTexture9里??
你是出于什么样的目的,需要将后台缓冲拷贝到Texture中呢?
我猜想一下:1,渲染游戏以外的画面,就是渲染第二个画面。2,获取截屏。
但是,这两种目的都有比上面所说的有更好,更高效的解决办法。渲染第二个画面可以使用渲染到纹理的方法,而你所要做的只是切换渲染的目标(RenderTarget):
DWORD usage = D3DUSAGE_RENDERTARGET;
D3DFORMAT format = D3DFMT_A8R8G8B8;
D3DPOOL pool = D3DPOOL_DEFAULT;
if(FAILED(D3DXCreateTexture(pd3dDevice, width, height, 1, usage, format, pool, &pTexOut->texture)))
return 0;
if(FAILED(pd3dDevice->CreateDepthStencilSurface( width, height, D3DFMT_D24S8, D3DMULTISAMPLE_NONE, 0,
TRUE, &pSurface, NULL )))
return 0;
以上是创建可作为渲染目标的纹理,使用的时候和其它纹理没有区别。以下是切换渲染目标:
//store the devie
LPDIRECT3DSURFACE9 pOldRT = NULL;
pd3dDevice->GetRenderTarget(0, &pOldRT);
LPDIRECT3DSURFACE9 pOldDSurface = NULL;
pd3dDevice->GetDepthStencilSurface(&pOldDSurface);
//设置新的目标和DepthStencil
LPDIRECT3DSURFACE9 pDMSurface = NULL;
texture->GetSurfaceLevel(0, &pDMSurface);
pd3dDevice->SetRenderTarget(0, pDMSurface);//set new render target
pd3dDevice->SetDepthStencilSurface(Your DepthStencil Surface);
//开始渲染画面
//切换回默认渲染目标
pd3dDevice->SetDepthStencilSurface(pOldDSurface);
SAFE_RELEASE(pOldDSurface);
pd3dDevice->SetRenderTarget(0, pOldRT);
SAFE_RELEASE(pOldRT); |
|