渲染目标视图ID3D11RenderTargetView
2024-11-19
7
0
D3D11在使用某个渲染对象渲染之前,需要先用背景纯色清空渲染目标
md3dImmediateContext->ClearRenderTargetView(mRenderTargetView, reinterpret_cast<const float*>(&(Colors::Blue)));
在OBS中
void render_main_texture(struct obs_core_video *video)
{
...
//设置自定义当前的渲染对象
gs_set_render_target(video->render_texture, NULL);
//调用ClearRenderTargetView对video->render_texture进行背景纯色清空渲染目标
gs_clear(GS_CLEAR_COLOR, &clear_color, 1.0f, 0);
...
}
只不,在OBS中对render_texture因为支持立方体,故可能会有6个渲染纹理。
struct gs_texture_2d : gs_texture {
...
ComPtr<ID3D11RenderTargetView> renderTarget[6];
ComPtr<ID3D11RenderTargetView> renderTargetLinear[6];//非DXGI_FORMAT_UNKNOWN格式时创建
...
ID3D11RenderTargetView的创建可详见void gs_texture_2d::InitRenderTargets()
void gs_texture_2d::InitRenderTargets()
{
if (type == GS_TEXTURE_2D)
{
D3D11_RENDER_TARGET_VIEW_DESC rtv;
rtv.Format = dxgiFormatView;
rtv.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
rtv.Texture2D.MipSlice = 0;
hr = device->device->CreateRenderTargetView(texture, &rtv, renderTarget[0].Assign());
..//错误判断
if (dxgiFormatView == dxgiFormatViewLinear)
{
renderTargetLinear[0] = renderTarget[0];
}
else
{
rtv.Format = dxgiFormatViewLinear;
hr = device->device->CreateRenderTargetView(texture, &rtv,renderTargetLinear[0].Assign());
}
else
{
D3D11_RENDER_TARGET_VIEW_DESC rtv;
rtv.Format = dxgiFormatView;
rtv.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
rtv.Texture2DArray.MipSlice = 0;
rtv.Texture2DArray.ArraySize = 1;
for (UINT i = 0; i < 6; i++)
{
rtv.Texture2DArray.FirstArraySlice = i;
hr = device->device->CreateRenderTargetView(texture, &rtv, renderTarget[i].Assign());
..//错误判断
if (dxgiFormatView == dxgiFormatViewLinear)
{
renderTargetLinear[i] = renderTarget[i];
}
else
{
rtv.Format = dxgiFormatViewLinear;
hr = device->device->CreateRenderTargetView(texture, &rtv,renderTargetLinear[i].Assign());
}
}
}
}