在项目中使用RTT,渲染场景到Texture时出现了锯齿严重的情况,创建设备时打开D3D的抗锯齿设置:
m_d3dpp.MultiSampleType = D3DMULTISAMPLE_NONMASKABLE;
m_d3dpp.MultiSampleQuality = D3DMULTISAMPLE_2_SAMPLES;
锯齿没有改善而且模型的纹理贴图出现了错误:
![](https://img-my.csdn.net/uploads/201206/07/1339058660_8700.jpg)
跟踪代码发现,由于使用
HRESULT CreateTexture(
UINT Width,
UINT Height,
UINT Levels,
DWORD Usage,
D3DFORMAT Format,
D3DPOOL Pool,
IDirect3DTexture9** ppTexture,
HANDLE* pSharedHandle
);
创建纹理,再使用
调用Device->GetSurfaceLevel(0, &SurfacePtr );获得Surface指针来创建RenderTarget。这样创建的纹理不能实现硬件AA。因此,改用HRESULT CreateRenderTarget(
UINT Width,
UINT Height,
D3DFORMAT Format,
D3DMULTISAMPLE_TYPE MultiSample,
DWORD MultisampleQuality,
BOOL Lockable,
IDirect3DSurface9** ppSurface,
HANDLE* pSharedHandle
);
来创建RenderTarget,创建时
MultiSample和
MultisampleQuality参数来设置抗锯齿系数。RTT后,再StretchRect将surface拷贝到需要的纹理。操作时,
CreateRenderTarget总是失败。最后查阅DXSDK发现:
The creation of lockable, multisampled render targets is not supported.,关闭Lockable。AA成功。
![](https://img-my.csdn.net/uploads/201206/07/1339059122_1825.jpg)