Sign in to follow this  
Mumsfilibaba

Black screen after creating msaa Rendertarget

Recommended Posts

Hi, I get only a black screen after trying to create a rendertarget with msaa. It worked perfectly before creating it. Here is the code:

 
bool D3DHandle::CreateRenderTarget()
{
	//retrive BackBuffer
	ID3D11Texture2D* backBuffer = nullptr;
	HRESULT result = this->swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (void**)&backBuffer);

	if (FAILED(result))
	{
		MessageBoxW(this->outputWindow->GetWindowHandle(), L"Could not retrive BackBuffer from SwapChain", L"ERROR", MB_OK | MB_ICONERROR);
		return false;
	}

	//get backbuffer description and set multisampling
	D3D11_TEXTURE2D_DESC backBufferDesc;
	RtlSecureZeroMemory(&backBufferDesc, sizeof(D3D11_TEXTURE2D_DESC));

	backBuffer->GetDesc(&backBufferDesc);
	this->sampleCount = backBufferDesc.SampleDesc.Count = 8;
	this->sampleQuality = backBufferDesc.SampleDesc.Quality = 32;
	this->renderHeight = backBufferDesc.Height;
	this->renderWidth = backBufferDesc.Width;

	backBuffer->Release();
	backBuffer = nullptr;

	//create the backbuffer with multisampling 
	result = this->device->CreateTexture2D(&backBufferDesc, nullptr, &backBuffer);
	if (FAILED(result))
	{
		MessageBoxW(this->outputWindow->GetWindowHandle(), L"Could not create Backbuffer", L"ERROR", MB_OK | MB_ICONERROR);
		return false;
	}

	//create RenderTarget
	result = this->device->CreateRenderTargetView(backBuffer, nullptr, &renderTarget);
	if (FAILED(result))
	{
		MessageBoxW(this->outputWindow->GetWindowHandle(), L"Could not create RenderTarget", L"ERROR", MB_OK | MB_ICONERROR);
		return false;
	}

	//release backbuffer
	backBuffer->Release();
	backBuffer = nullptr;

	return true;
}
 

I'm I not setting it correctly after creation?

 

Im calling this function after I created the depthbuffer:

void D3DHandle::SetBuffers()
{
	//set RenderTarget and DepthStencil
	this->immediateContext->OMSetRenderTargets(1, &this->renderTarget, this->depthStencil);
}
Edited by Mumsfilibaba

Share this post


Link to post
Share on other sites
Is the depth stencil multisampled as well? Do you resolve this multisampled render target into the backbuffer? Did you enable the debug layer? Edited by Mona2000

Share this post


Link to post
Share on other sites
The debuglayer is on, so I'm pretty sure it would have warned me if I tried to use a depthstencil that weren't multisampled.

I'm not resolving the rendertarget. Is that really necessary when I create the rendertargetview with the multisampled texture? And in that case, why is that needed?

Could it be that I only create one texture? I mean aren't there two, one front and back?

Share this post


Link to post
Share on other sites
You can't just create a new texture and name it backbuffer, the backbuffer is a special texture that D3D creates for you. You have two options:
1) draw to a multisampled texture like you already do and resolve it into the backbuffer
2) ask D3D for a multisampled backbuffer (in DXGI_SWAP_CHAIN_DESC) and draw to it directly

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this