• Advertisement
Sign in to follow this  

Create Texture Issue

This topic is 752 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello I have a small issue. I'm trying to create a Texture that will be part of my gBuffer for deferred rendering which means I need to flag the resource as D3D11_BIND_SHADER_RESOURCE and D3D11_BIND_RENDER_TARGET.

 

I am storing normals in this particular resource and I want to use the DXGI_FORMAT_R32G32B32_FLOAT type or any other type like it (eg. DXGI_FORMAT_R32G32B32_TYPELESS) . When I try to create the resource it fails. It works if I do DXGI_FORMAT_R32G32B32A32_FLOAT which is something I don't understand.

 

When I only use the D3D11_BIND_SHADER_RESOURCE flag the creation of the texture works but of course the CreateRenderTargetView fails a few lines later.

 

Looking at Microsoft's page D3D11_RENDER_TARGET_VIEW_DESC it says in the remaks that DXGI_FORMAT_R32G32B32_FLOAT  cannot be used if the view will be used to bind a buffer (vertex, index, constant, or stream-out). However, I am not doing any of that so I do not understand why it fails.

 

https://msdn.microsoft.com/en-us/library/windows/desktop/ff476201(v=vs.85).aspx

 

Code I use is below. Thanks.

        const unsigned int clientWidth  = uClient->getAppScreenWidth();
	const unsigned int clientHeight = uClient->getAppScreenHeight();

	releaseGBuffers();

	D3D11_TEXTURE2D_DESC texture2DDesc;

	texture2DDesc.Width = clientWidth;
	texture2DDesc.Height = clientHeight;
	texture2DDesc.MipLevels = 1;
	texture2DDesc.ArraySize = 1;
	texture2DDesc.Format = DXGI_FORMAT_R32G32B32_FLOAT;	
	if (msaaEnabled)
	{
		texture2DDesc.SampleDesc.Count = 4;
		texture2DDesc.SampleDesc.Quality = msaaQuality - 1;
	}
	else
	{
		texture2DDesc.SampleDesc.Count = 1;
		texture2DDesc.SampleDesc.Quality = 0;
	}
	texture2DDesc.Usage = D3D11_USAGE_DEFAULT;
	texture2DDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;	
	texture2DDesc.CPUAccessFlags = 0;
	texture2DDesc.MiscFlags = 0;

	HRESULT hr = d3d11Device->CreateTexture2D(&texture2DDesc, 0, &gBufferOne);

Share this post


Link to post
Share on other sites
Advertisement

DXGI_FORMAT_R32G32B32_FLOAT is very rarely supported as a Render Target on any hardware. To give you an idea of how rarely, even my NVIDIA GTX 970 doesn't support that format as a Render Target.

 

You don't want to be using such a massive format for storing normals in your GBuffer.

 

Give this page a read and pick a format that's 8, 10 or maybe 16bits per channel: http://aras-p.info/texts/CompactNormalStorage.html

Share this post


Link to post
Share on other sites

Okay thanks I understand, I was going to move it down to a lot lower bit count after I got this version working but it appears to not be worth it. 

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement