作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在尝试在 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 调用的返回值)。我究竟做错了什么?
最佳答案
您不需要额外的表面,您可以直接渲染到多重采样后备缓冲区。对我来说,像这样使用 StretchRect()
的唯一原因是获取场景的非多重采样拷贝以用于后处理(因为多重采样渲染目标是糟糕的纹理,因此您需要场景数据在解析的纹理中)。如果你想这样做,你不需要为后备缓冲区指定多重采样。将场景渲染到的多重采样渲染目标就足够了。
关于c++ - 在 Direct3D9 中启用抗锯齿(多采样渲染目标),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2307534/
我是一名优秀的程序员,十分优秀!