Array of textures

Started by
5 comments, last by NEvOl 10 years, 2 months ago

Hi, i have several object ID3D11Texture2D and i need it is transmit in PS, how i can it is realize ?

Advertisement

What language ?

Also, "PS" is in reference to what ?

I am assuming C++, but that is not the only language that can access the Direct 3D framework ...

I cannot remember the books I've read any more than the meals I have eaten; even so, they have made me.

~ Ralph Waldo Emerson

Depends whether you're using effect files or pure shaders.

For effect files just define multiple variables.

For pure shaders you'll have to specify registers (ex. Texture2D texture0 : register(t0);), they go up to t127 or something like that, then use ID3D11DeviceContext::PSSetShaderResources() with proper indexes (0 matching t0 & so on).

Language is C++. In ID3D11DeviceContext::PSSetShaderResources() used ID3D11ShaderResourceView, and i have ID3D11Texture2D, second problem is it i dont know how many i have ID3D11Texture2D, it is created dynamically, so it is number is no constant, can i union all ID3D11Texture2D in texture array and transmit in PS, i use pure shaders.


can i union all ID3D11Texture2D in texture array and transmit in PS

Yes. How do you plan to use them in shader though? Sounds like declaring many registers isn't an option, try to look at Texture2DArray.

D3DX11_IMAGE_LOAD_INFO ili;
ZeroMemory(&ili, sizeof(ili));
ili.BindFlags = 0;
ili.Height = D3DX11_FROM_FILE;
ili.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
ili.Width = D3DX11_FROM_FILE;
ili.Depth = D3DX11_FROM_FILE;
ili.FirstMipLevel = 0;
ili.MipLevels = 1;
ili.BindFlags = 0;
ili.CpuAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
ili.Usage = D3D11_USAGE_STAGING;
ili.MiscFlags = 0;
ili.Filter = D3DX11_FILTER_NONE;
ili.MipFilter =  D3DX11_FILTER_NONE;
ili.pSrcInfo = 0;
 
ID3D11Resource *g_text;
ID3D11Texture2D *pSrcText2D;
 
if(FAILED(D3DX11CreateTextureFromFile(g_pd3d11Device, L"2.jpg", &ili, NULL, (ID3D11Resource**)&pSrcText2D, NULL)))
return 0;
 
 
 
int numMipLevel = CreateMipMap(pSrcText2D);
 
D3D11_TEXTURE2D_DESC td;
pSrcText2D->GetDesc(&td);
 
ID3D11Texture2D *textArray = 0;
D3D11_TEXTURE2D_DESC tdArray;
 
ZeroMemory(&tdArray,sizeof(tdArray));
tdArray.ArraySize = numMipLevel;
tdArray.Format = td.Format;
tdArray.Height = td.Height;
tdArray.Width = td.Width;
tdArray.CPUAccessFlags = 0;
tdArray.MiscFlags = 0;
tdArray.SampleDesc.Count = 1;
tdArray.SampleDesc.Quality = 0;
tdArray.Usage = D3D11_USAGE_DEFAULT;
tdArray.BindFlags = D3D11_BIND_SHADER_RESOURCE;
tdArray.MipLevels = td.MipLevels;
 
D3D11_SUBRESOURCE_DATA *sdArray = new D3D11_SUBRESOURCE_DATA[numMipLevel+1];
 
for(UINT i = 0; i <= numMipLevel; i++)
{
D3D11_MAPPED_SUBRESOURCE ms;
g_pd3d11DeviceContext->Map(g_pMassTextures[i], 0, D3D11_MAP_READ, 0, &ms);
sdArray[i].pSysMem = ms.pData;
sdArray[i].SysMemPitch = ms.RowPitch;
sdArray[i].SysMemSlicePitch = ms.DepthPitch;
g_pd3d11DeviceContext->Unmap(g_pMassTextures[i], 0);
}
 
if(FAILED(g_pd3d11Device->CreateTexture2D(&tdArray, sdArray, &textArray)))
return 0;
 
D3D11_SHADER_RESOURCE_VIEW_DESC srvd;
ZeroMemory(&srvd, sizeof(srvd));
srvd.Format = tdArray.Format;
srvd.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DARRAY;
srvd.Texture2DArray.ArraySize = numMipLevel + 1;
srvd.Texture2DArray.FirstArraySlice = 0;
srvd.Texture2DArray.MipLevels = td.MipLevels;
srvd.Texture2DArray.MostDetailedMip = 0;
 
if(FAILED(g_pd3d11Device->CreateShaderResourceView(textArray, NULL, &g_pShaderResourceView)))
return 0;

i trying creating Texture2DArray, but CreateShaderResourceView returns failed, here i load image from file, generating mip levels(software) and save it is in g_pMassTextures, where g_pMassTextures it is vector<ID3D11Texture2D*>, for each g_pMassTextures
D3D11_TEXTURE2D_DESC is:


D3D11_TEXTURE2D_DESC td;
ZeroMemory(&td, sizeof(td));
    td.Width = width;
    td.Height = height;
    td.MipLevels = 1;
    td.ArraySize = 1;
 
    td.SampleDesc.Count = 1;
    td.SampleDesc.Quality = 0;
    td.Usage = D3D11_USAGE_STAGING;
    td.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
    td.BindFlags = 0;
 
td.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
    td.MiscFlags = 0;

problem is solved, thanks

This topic is closed to new replies.

Advertisement