Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


#Actualkauna

Posted 07 January 2013 - 04:24 AM

Here is the code I'm using the load textures in texture array. It contains only the important parts, so you can't use it directly.

[Edit]

You'll need to create the texture array separately.

Cheers!



int D3DTexture::LoadTextureInToTextureArray(const char *pAddr,int Index)

{

// pAddr should point to file loaded in memory

// Index is a number between 0 and ArraySize



D3D11_TEXTURE2D_DESC ArrayDesc;


pTextureResource->GetDesc( &ArrayDesc );



D3D11_TEXTURE2D_DESC desc;



    D3DX11_IMAGE_LOAD_INFO ImageloadInfo;

    ZeroMemory( &ImageloadInfo, sizeof( D3DX11_IMAGE_LOAD_INFO ) );


ImageloadInfo.Width = ArrayDesc.Width;

ImageloadInfo.Height  = ArrayDesc.Height;

    ImageloadInfo.Depth  = D3DX11_DEFAULT;

    ImageloadInfo.FirstMipLevel = 0;

ImageloadInfo.MipLevels = ArrayDesc.MipLevels;

    ImageloadInfo.Usage = D3D11_USAGE_STAGING;

    ImageloadInfo.BindFlags = 0;

    ImageloadInfo.CpuAccessFlags = D3D11_CPU_ACCESS_READ;

    ImageloadInfo.MiscFlags = 0;

ImageloadInfo.Format = ArrayDesc.Format;



ImageloadInfo.Filter = D3DX11_FILTER_SRGB_IN | D3DX11_FILTER_NONE;  //<- SRGB flag should be used for gamma correct rendering

ImageloadInfo.MipFilter = D3DX11_FILTER_NONE;


ImageloadInfo.pSrcInfo = NULL;


ID3D11Resource *pRes = NULL;


HRESULT hr = D3DX11CreateTextureFromMemory(DXUTGetD3D11Device(),pAddr,FileSize,&ImageloadInfo,NULL,&pRes,NULL);


if(FAILED(hr))

{

   //Texture creation failed

return 0;

}


if( pRes )

{

ID3D11Texture2D* pTemp;

pRes->QueryInterface( __uuidof( ID3D11Texture2D ), (LPVOID*)&pTemp );

pTemp->GetDesc( &desc );


D3D11_MAPPED_SUBRESOURCE mappedTex2D;


for(UINT i=0; i < desc.MipLevels; i++)

{

HRESULT hr = DXUTGetD3D11DeviceContext()->Map(pRes, i, D3D11_MAP_READ, 0, &mappedTex2D );


if(FAILED(hr))

{

return 0;

}


//pTextureResource should point to a valid and already created 2D Texture Array


if(mappedTex2D.pData)

{

DXUTGetD3D11DeviceContext()->UpdateSubresource( pTextureResource, 

D3D11CalcSubresource( i, Index, ArrayDesc.MipLevels ),

NULL,

mappedTex2D.pData,

mappedTex2D.RowPitch,

0 );


DXUTGetD3D11DeviceContext()->Unmap(pRes,i);

}

}


pTemp->Release();

pRes->Release();

}


}



#11kauna

Posted 07 January 2013 - 04:24 AM

Here is the code I'm using the load textures in texture array. It contains only the important parts, so you can't use it directly.

[Edit]

You'll need to create the texture array separately.

Cheers!



int D3DTexture::LoadTextureInToTextureArray(const char *pAddr,int Index)

{

// pAddr should point to file loaded in memory

// Index is a number between 0 and ArraySize



D3D11_TEXTURE2D_DESC ArrayDesc;


pTextureResource->GetDesc( &ArrayDesc );



D3D11_TEXTURE2D_DESC desc;



    D3DX11_IMAGE_LOAD_INFO ImageloadInfo;

    ZeroMemory( &ImageloadInfo, sizeof( D3DX11_IMAGE_LOAD_INFO ) );


ImageloadInfo.Width = ArrayDesc.Width;

ImageloadInfo.Height  = ArrayDesc.Height;

    ImageloadInfo.Depth  = D3DX11_DEFAULT;

    ImageloadInfo.FirstMipLevel = 0;

ImageloadInfo.MipLevels = ArrayDesc.MipLevels;

    ImageloadInfo.Usage = D3D11_USAGE_STAGING;

    ImageloadInfo.BindFlags = 0;

    ImageloadInfo.CpuAccessFlags = D3D11_CPU_ACCESS_READ;

    ImageloadInfo.MiscFlags = 0;

ImageloadInfo.Format = ArrayDesc.Format;



ImageloadInfo.Filter = D3DX11_FILTER_SRGB_IN | D3DX11_FILTER_NONE;  //<- SRGB flag should be used for gamma correct rendering

ImageloadInfo.MipFilter = D3DX11_FILTER_NONE;


ImageloadInfo.pSrcInfo = NULL;


ID3D11Resource *pRes = NULL;


HRESULT hr = D3DX11CreateTextureFromMemory(DXUTGetD3D11Device(),pAddr,FileSize,&ImageloadInfo,NULL,&pRes,NULL);


if(FAILED(hr))

{

   //Texture creation failed

return 0;

}


if( pRes )

{

ID3D11Texture2D* pTemp;

pRes->QueryInterface( __uuidof( ID3D11Texture2D ), (LPVOID*)&pTemp );

pTemp->GetDesc( &desc );


D3D11_MAPPED_SUBRESOURCE mappedTex2D;


for(UINT i=0; i < desc.MipLevels; i++)

{

HRESULT hr = DXUTGetD3D11DeviceContext()->Map(pRes, i, D3D11_MAP_READ, 0, &mappedTex2D );


if(FAILED(hr))

{

return 0;

}


//pTextureResource should point to a valid and already created 2D Texture Array


if(mappedTex2D.pData)

{

DXUTGetD3D11DeviceContext()->UpdateSubresource( pTextureResource, 

D3D11CalcSubresource( i, Index, ArrayDesc.MipLevels ),

NULL,

mappedTex2D.pData,

mappedTex2D.RowPitch,

0 );


DXUTGetD3D11DeviceContext()->Unmap(pRes,i);

}

}


pTemp->Release();

pRes->Release();

}


}



#10kauna

Posted 07 January 2013 - 04:24 AM

Here is the code I'm using the load textures in texture array. It contains only the important parts, so you can't use it directly.

[Edit]

You'll need to create the texture array separately.

Cheers!



int D3DTexture::LoadTextureInToTextureArray(const char *pAddr,int Index)

{

// pAddr should point to file loaded in memory

// Index is a number between 0 and ArraySize



D3D11_TEXTURE2D_DESC ArrayDesc;


pTextureResource->GetDesc( &ArrayDesc );



D3D11_TEXTURE2D_DESC desc;



    D3DX11_IMAGE_LOAD_INFO ImageloadInfo;

    ZeroMemory( &ImageloadInfo, sizeof( D3DX11_IMAGE_LOAD_INFO ) );


ImageloadInfo.Width = ArrayDesc.Width;

ImageloadInfo.Height  = ArrayDesc.Height;

    ImageloadInfo.Depth  = D3DX11_DEFAULT;

    ImageloadInfo.FirstMipLevel = 0;

ImageloadInfo.MipLevels = ArrayDesc.MipLevels;

    ImageloadInfo.Usage = D3D11_USAGE_STAGING;

    ImageloadInfo.BindFlags = 0;

    ImageloadInfo.CpuAccessFlags = D3D11_CPU_ACCESS_READ;

    ImageloadInfo.MiscFlags = 0;

ImageloadInfo.Format = ArrayDesc.Format;



ImageloadInfo.Filter = D3DX11_FILTER_SRGB_IN | D3DX11_FILTER_NONE;  //<- SRGB flag should be used for gamma correct rendering

ImageloadInfo.MipFilter = D3DX11_FILTER_NONE;


ImageloadInfo.pSrcInfo = NULL;


ID3D11Resource *pRes = NULL;


HRESULT hr = D3DX11CreateTextureFromMemory(DXUTGetD3D11Device(),pAddr,FileSize,&ImageloadInfo,NULL,&pRes,NULL);


if(FAILED(hr))

{

   //Texture creation failed

return 0;

}


if( pRes )

{

ID3D11Texture2D* pTemp;

pRes->QueryInterface( __uuidof( ID3D11Texture2D ), (LPVOID*)&pTemp );

pTemp->GetDesc( &desc );


D3D11_MAPPED_SUBRESOURCE mappedTex2D;


for(UINT i=0; i < desc.MipLevels; i++)

{

HRESULT hr = DXUTGetD3D11DeviceContext()->Map(pRes, i, D3D11_MAP_READ, 0, &mappedTex2D );


if(FAILED(hr))

{

return 0;

}


//pTextureResource should point to a valid and already created 2D Texture Array


if(mappedTex2D.pData)

{

DXUTGetD3D11DeviceContext()->UpdateSubresource( pTextureResource, 

D3D11CalcSubresource( i, Index, ArrayDesc.MipLevels ),

NULL,

mappedTex2D.pData,

mappedTex2D.RowPitch,

0 );


DXUTGetD3D11DeviceContext()->Unmap(pRes,i);

}

}


pTemp->Release();

pRes->Release();

}


}



#9kauna

Posted 07 January 2013 - 04:24 AM

Here is the code I'm using the load textures in texture array. It contains only the important parts, so you can't use it directly.

[Edit]

You'll need to create the texture array separately.

Cheers!



int D3DTexture::LoadTextureInToTextureArray(const char *pAddr,int Index)

{

// pAddr should point to file loaded in memory

// Index is a number between 0 and ArraySize



D3D11_TEXTURE2D_DESC ArrayDesc;


pTextureResource->GetDesc( &ArrayDesc );



D3D11_TEXTURE2D_DESC desc;



    D3DX11_IMAGE_LOAD_INFO ImageloadInfo;

    ZeroMemory( &ImageloadInfo, sizeof( D3DX11_IMAGE_LOAD_INFO ) );


ImageloadInfo.Width = ArrayDesc.Width;

ImageloadInfo.Height  = ArrayDesc.Height;

    ImageloadInfo.Depth  = D3DX11_DEFAULT;

    ImageloadInfo.FirstMipLevel = 0;

ImageloadInfo.MipLevels = ArrayDesc.MipLevels;

    ImageloadInfo.Usage = D3D11_USAGE_STAGING;

    ImageloadInfo.BindFlags = 0;

    ImageloadInfo.CpuAccessFlags = D3D11_CPU_ACCESS_READ;

    ImageloadInfo.MiscFlags = 0;

ImageloadInfo.Format = ArrayDesc.Format;



ImageloadInfo.Filter = D3DX11_FILTER_SRGB_IN | D3DX11_FILTER_NONE;  //<- SRGB flag should be used for gamma correct rendering

ImageloadInfo.MipFilter = D3DX11_FILTER_NONE;


ImageloadInfo.pSrcInfo = NULL;


ID3D11Resource *pRes = NULL;


HRESULT hr = D3DX11CreateTextureFromMemory(DXUTGetD3D11Device(),pAddr,FileSize,&ImageloadInfo,NULL,&pRes,NULL);


if(FAILED(hr))

{

   //Texture creation failed

return 0;

}


if( pRes )

{

ID3D11Texture2D* pTemp;

pRes->QueryInterface( __uuidof( ID3D11Texture2D ), (LPVOID*)&pTemp );

pTemp->GetDesc( &desc );


D3D11_MAPPED_SUBRESOURCE mappedTex2D;


for(UINT i=0; i < desc.MipLevels; i++)

{

HRESULT hr = DXUTGetD3D11DeviceContext()->Map(pRes, i, D3D11_MAP_READ, 0, &mappedTex2D );


if(FAILED(hr))

{

return 0;

}


//pTextureResource should point to a valid and already created 2D Texture Array


if(mappedTex2D.pData)

{

DXUTGetD3D11DeviceContext()->UpdateSubresource( pTextureResource, 

D3D11CalcSubresource( i, Index, ArrayDesc.MipLevels ),

NULL,

mappedTex2D.pData,

mappedTex2D.RowPitch,

0 );


DXUTGetD3D11DeviceContext()->Unmap(pRes,i);

}

}


pTemp->Release();

pRes->Release();

}


}



#8kauna

Posted 07 January 2013 - 04:24 AM

Here is the code I'm using the load textures in texture array. It contains only the important parts, so you can't use it directly.

[Edit]

You'll need to create the texture array separately.

Cheers!



int D3DTexture::LoadTextureInToTextureArray(const char *pAddr,int Index)

{

// pAddr should point to file loaded in memory

// Index is a number between 0 and ArraySize



D3D11_TEXTURE2D_DESC ArrayDesc;


pTextureResource->GetDesc( &ArrayDesc );



D3D11_TEXTURE2D_DESC desc;



    D3DX11_IMAGE_LOAD_INFO ImageloadInfo;

    ZeroMemory( &ImageloadInfo, sizeof( D3DX11_IMAGE_LOAD_INFO ) );


ImageloadInfo.Width = ArrayDesc.Width;

ImageloadInfo.Height  = ArrayDesc.Height;

    ImageloadInfo.Depth  = D3DX11_DEFAULT;

    ImageloadInfo.FirstMipLevel = 0;

ImageloadInfo.MipLevels = ArrayDesc.MipLevels;

    ImageloadInfo.Usage = D3D11_USAGE_STAGING;

    ImageloadInfo.BindFlags = 0;

    ImageloadInfo.CpuAccessFlags = D3D11_CPU_ACCESS_READ;

    ImageloadInfo.MiscFlags = 0;

ImageloadInfo.Format = ArrayDesc.Format;



ImageloadInfo.Filter = D3DX11_FILTER_SRGB_IN | D3DX11_FILTER_NONE;  //<- SRGB flag should be used for gamma correct rendering

ImageloadInfo.MipFilter = D3DX11_FILTER_NONE;


ImageloadInfo.pSrcInfo = NULL;


ID3D11Resource *pRes = NULL;


HRESULT hr = D3DX11CreateTextureFromMemory(DXUTGetD3D11Device(),pAddr,FileSize,&ImageloadInfo,NULL,&pRes,NULL);


if(FAILED(hr))

{

   //Texture creation failed

return 0;

}


if( pRes )

{

ID3D11Texture2D* pTemp;

pRes->QueryInterface( __uuidof( ID3D11Texture2D ), (LPVOID*)&pTemp );

pTemp->GetDesc( &desc );


D3D11_MAPPED_SUBRESOURCE mappedTex2D;


for(UINT i=0; i < desc.MipLevels; i++)

{

HRESULT hr = DXUTGetD3D11DeviceContext()->Map(pRes, i, D3D11_MAP_READ, 0, &mappedTex2D );


if(FAILED(hr))

{

return 0;

}


//pTextureResource should point to a valid and already created 2D Texture Array


if(mappedTex2D.pData)

{

DXUTGetD3D11DeviceContext()->UpdateSubresource( pTextureResource, 

D3D11CalcSubresource( i, Index, ArrayDesc.MipLevels ),

NULL,

mappedTex2D.pData,

mappedTex2D.RowPitch,

0 );


DXUTGetD3D11DeviceContext()->Unmap(pRes,i);

}

}


pTemp->Release();

pRes->Release();

}


}



#7kauna

Posted 07 January 2013 - 04:24 AM

Here is the code I'm using the load textures in texture array. It contains only the important parts, so you can't use it directly.

[Edit]

You'll need to create the texture array separately.

Cheers!



int D3DTexture::LoadTextureInToTextureArray(const char *pAddr,int Index)

{

// pAddr should point to file loaded in memory

// Index is a number between 0 and ArraySize



D3D11_TEXTURE2D_DESC ArrayDesc;


pTextureResource->GetDesc( &ArrayDesc );



D3D11_TEXTURE2D_DESC desc;



    D3DX11_IMAGE_LOAD_INFO ImageloadInfo;

    ZeroMemory( &ImageloadInfo, sizeof( D3DX11_IMAGE_LOAD_INFO ) );


ImageloadInfo.Width = ArrayDesc.Width;

ImageloadInfo.Height  = ArrayDesc.Height;

    ImageloadInfo.Depth  = D3DX11_DEFAULT;

    ImageloadInfo.FirstMipLevel = 0;

ImageloadInfo.MipLevels = ArrayDesc.MipLevels;

    ImageloadInfo.Usage = D3D11_USAGE_STAGING;

    ImageloadInfo.BindFlags = 0;

    ImageloadInfo.CpuAccessFlags = D3D11_CPU_ACCESS_READ;

    ImageloadInfo.MiscFlags = 0;

ImageloadInfo.Format = ArrayDesc.Format;



ImageloadInfo.Filter = D3DX11_FILTER_SRGB_IN | D3DX11_FILTER_NONE;  //<- SRGB flag should be used for gamma correct rendering

ImageloadInfo.MipFilter = D3DX11_FILTER_NONE;


ImageloadInfo.pSrcInfo = NULL;


ID3D11Resource *pRes = NULL;


HRESULT hr = D3DX11CreateTextureFromMemory(DXUTGetD3D11Device(),pAddr,FileSize,&ImageloadInfo,NULL,&pRes,NULL);


if(FAILED(hr))

{

   //Texture creation failed

return 0;

}


if( pRes )

{

ID3D11Texture2D* pTemp;

pRes->QueryInterface( __uuidof( ID3D11Texture2D ), (LPVOID*)&pTemp );

pTemp->GetDesc( &desc );


D3D11_MAPPED_SUBRESOURCE mappedTex2D;


for(UINT i=0; i < desc.MipLevels; i++)

{

HRESULT hr = DXUTGetD3D11DeviceContext()->Map(pRes, i, D3D11_MAP_READ, 0, &mappedTex2D );


if(FAILED(hr))

{

return 0;

}


//pTextureResource should point to a valid and already created 2D Texture Array


if(mappedTex2D.pData)

{

DXUTGetD3D11DeviceContext()->UpdateSubresource( pTextureResource, 

D3D11CalcSubresource( i, Index, ArrayDesc.MipLevels ),

NULL,

mappedTex2D.pData,

mappedTex2D.RowPitch,

0 );


DXUTGetD3D11DeviceContext()->Unmap(pRes,i);

}

}


pTemp->Release();

pRes->Release();

}


}



PARTNERS