i am trying to create another rendertargetview and render it
Before, i just get back buffer from swapchain and then create rtv from it, this works fine. but only when creating rtv from custom resoure, i have a problem.
D3D11_TEXTURE2D_DESC bb_desc;
bb_desc.Width = width;
bb_desc.Height = height;
bb_desc.MipLevels = 1;
bb_desc.ArraySize = 1;
bb_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
bb_desc.Usage = D3D11_USAGE_DEFAULT;
bb_desc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
bb_desc.CPUAccessFlags = 0;
bb_desc.MiscFlags = 0;
bb_desc.SampleDesc.Count = msCount;
bb_desc.SampleDesc.Quality = msQuality;
R_CHECK(device->CreateTexture2D(
&bb_desc,
nullptr,
backBuffer.GetAddressOf()));
D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
rtv_desc.Format = bb_desc.Format;
rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
rtv_desc.Texture2D.MipSlice = 0;
R_CHECK(device->CreateRenderTargetView(
backBuffer.Get(),
&rtv_desc,
bbRTV.GetAddressOf()));
D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
srv_desc.Format = bb_desc.Format;
srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
srv_desc.Texture2D.MostDetailedMip = 0;
srv_desc.Texture2D.MipLevels = 1;
R_CHECK(device->CreateShaderResourceView(
backBuffer.Get(),
&srv_desc,
bbSRV.GetAddressOf()));
dContext->OMSetRenderTargets(1, bbRTV.GetAddressOf(), nullptr);
and i render it
float bgColor[3] = { 1,0,0 };
dContext->ClearRenderTargetView(bbRTV.Get(), bgColor);
swapchain->Present(1, NULL);
expecting red screen, but it is showing just black. and also there's no error logs. any advice would be appreciated~
Second argument to ClearRenderTargetView
is not valid. It must be a pointer to first element of array of 4 float
values. Since you pass a pointer to the first element of array of 3 float
value buffer overrun occurs which causes Undefined Behavior.
But most importantly, when you are rendering to texture it won't be presented on screen when you invoke Present
because it is not a swap chain back buffer. You can inspect texture content using DirectX debugger.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.