Advertisement Jump to content
Sign in to follow this  
NEvOl

Array of textures

This topic is 1811 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

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

Share this post


Link to post
Share on other sites
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 ...

Edited by Shippou

Share this post


Link to post
Share on other sites

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).

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites


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.

Share this post


Link to post
Share on other sites

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;

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!