您的位置:首页 > 其它

Render to Texture2DArray slices in DirectX11?(转自GAMEDEV)

2014-03-06 18:19 190 查看
5

down vote
favorite

I would like to set a slice of a Texture2DArray as a render target in D3D/DirectX11. It's not clear how to do this.

What I'm looking for is the DirectX equivalent of glFramebufferTextureLayer(), which sets a slice of a GL_TEXTURE_2D_ARRAY_EXT as a texture resource of a Framebuffer Object.

In D3D11, you set a render target using ID3D11DeviceContext::OMSetRenderTargets, and you can set a Texture2DArray resource view as a render target. However, the only way I see to select which slice of the texture is painted is to use the
SV_RenderTargetArrayIndex semantic in an HLSL geometry shader. (The semantic is only available in a geometry shader).

My pipline doesn't have a geometry shader, and I don't know at compile time which primitive type I will be rendering - I'm reading models out of input files. It seems like, to add a passthrough geometry shader I would need one shader program for every possible
primitive type (terrible).

The desired output slice will not change between rendering passes. Is there no way to set a slice of a Texture2DArray as a render target without using a geometry shader?

2
down vote

accepted
You can create separate render target views for every slice and then set it using ID3D11DeviceContext::OMSetRenderTargets.

[code]D3D11_RENDER_TARGET_VIEW_DESC desc;
desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
desc.Texture2D.MipSlice = D3D11CalcSubresource(0, arraySlice, mipLevels);

Information about subresources http://msdn.microsoft.com/en-us/library/ff476901%28v=vs.85%29.aspx
share|improve
this answer
edited
Jul 22 '11 at 16:27

answered
Jul 22 '11 at 16:18




KindDragon

21728

Yup, that works. Thanks! edit: what I actually did was create an array of Texture2DArray targets, with the start slice set to the i'th slice: RenderTarget = new ID3D11RenderTargetView*[targets];
for(USHORT i=0;i<targets; i++) { srtDesc.Format = sTexDesc.Format; srtDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY; srtDesc.Texture2DArray.MipSlice = 0; srtDesc.Texture2DArray.ArraySize = 1; srtDesc.Texture2DArray.FirstArraySlice = i; hr = m_pd3dDevice->CreateRenderTargetView(m_pInputView,
&srtDesc, &RenderTarget[i]); } –
matth Jul
25 '11 at 17:24

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: