我正在尝试在D3D9应用程序中启用AA,但我不确定如何正确设置表面。到目前为止,我有:
IDirect3DDevice9* m_pd3dDevice;
IDirect3DSurface9* screen;
IDirect3DSurface9* msaasurf;
D3DPRESENT_PARAMETERS m_presentationParameters;
初始化:
m_presentationParameters.Windowed = TRUE;
m_presentationParameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
m_presentationParameters.MultiSampleType = D3DMULTISAMPLE_2_SAMPLES;
m_presentationParameters.MultiSampleQuality = 0;
m_presentationParameters.BackBufferFormat = D3DFMT_UNKNOWN;
m_presentationParameters.EnableAutoDepthStencil = TRUE;
m_presentationParameters.AutoDepthStencilFormat = D3DFMT_D16;
m_presentationParameters.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
// create d3d device
m_pD3D->CreateDevice(
D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL,
hWnd,
D3DCREATE_HARDWARE_VERTEXPROCESSING,
&m_presentationParameters, &m_pd3dDevice
)
// save screen surface
m_pd3dDevice->GetRenderTarget(0, &screen);
D3DSURFACE_DESC desc;
screen->GetDesc(&desc);
// Create multisample render target
m_pd3dDevice->CreateRenderTarget(
800, 600,
D3DFMT_A8R8G8B8,
desc.MultiSampleType, desc.MultiSampleQuality,
false,
&msaasurf,
NULL
);
然后,对于每一帧:
// render to multisample surface
m_pd3dDevice->SetRenderTarget(0, msaasurf);
m_pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB( 0, 0, 0 ), 1.0f, 0 );
m_pd3dDevice->BeginScene();
// render stuff here
m_pd3dDevice->EndScene();
m_pd3dDevice->SetRenderTarget(0, screen);
// get back buffer
IDirect3DSurface9* backBuffer = NULL;
m_pd3dDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &backBuffer);
// copy rendertarget to backbuffer
m_pd3dDevice->StretchRect(msaasurf, NULL, backBuffer, NULL, D3DTEXF_NONE);
backBuffer->Release();
// Present the backbuffer contents to the display
m_pd3dDevice->Present(NULL, NULL, NULL, NULL);
但是,屏幕上没有任何内容(全黑)。没有发生错误(我检查所有d3d调用的返回值)。我究竟做错了什么?
答案 0 :(得分:1)
您不需要额外的表面,可以直接渲染到多重采样的后备缓冲区。对我来说,使用StretchRect()
这样的唯一理由是获取场景的非多重采样副本以用于后处理(因为多重采样渲染目标是坏纹理,因此您需要解析纹理中的场景数据) 。如果要执行此操作,则无需为后备缓冲区指定多重采样。用于渲染场景的多重采样渲染目标就足够了。