• Advertisement
Sign in to follow this  

Converting IDirect3DTexture9 from DXTn to ARGB

This topic is 1931 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 a IDirect3DTexture9 texture created in DXT3 and I copy raw compressed data to it from memory. I only have one surface level and need to generate mipmaps. Since GenerateMipSubLevels() does not work on compressed textures in hardware I need to do it on a D3DFMT_A8R8G8B8 texture.

What methods are there for converting a IDirect3DTexture9 texture in DXTn to another IDirect3DTexture9 texture in D3DFMT_A8R8G8B8?

I'd like to implement a simple function like this:

bool ConvertTextureDTXnToARGB(LPDIRECT3DTEXTURE9 pTexture)
{
//Same resource is used, only altered
}


or


bool ConvertTextureDTXnToARGB(LPDIRECT3DTEXTURE9 pSrcTexture, LPDIRECT3DTEXTURE9 pDstTexture)
{
//copy data from one to the other, uncompressing between
}



Any tips? Edited by Tispe

Share this post


Link to post
Share on other sites
Advertisement
I think that D3DXCreateTextureFromFileEx command has the capability to change the format and resolution.

Check : http://msdn.microsof...2(v=vs.85).aspx or http://msdn.microsoft.com/en-us/library/windows/desktop/bb172804(v=vs.85).aspx

Of course, it is a good practice not to change the format since it makes loading times longer in general.

Cheers! Edited by kauna

Share this post


Link to post
Share on other sites
You could find decompression algorithm and implement it yourself.

Another alternative is to create A8R8G8B8 render target, draw texture into it and you'll have converted texture.

Share this post


Link to post
Share on other sites
You can call GetSurfaceLevel on each texture then use D3DXLoadSurfaceFromSurface (which is specified to handle conversion to and from compressed formats). Don't forget to Release the surfaces obtained via GetSurfaceLevel when done otherwise you'll have a resource leak.

Share this post


Link to post
Share on other sites

You can call GetSurfaceLevel on each texture then use D3DXLoadSurfaceFromSurface (which is specified to handle conversion to and from compressed formats). Don't forget to Release the surfaces obtained via GetSurfaceLevel when done otherwise you'll have a resource leak.


Do you have sample code, I don't want to tread in the dark atm?

Share this post


Link to post
Share on other sites
Hi again

I think I might get away with using D3DXLoadSurfaceFromMemory directly. Would this work? LPCVOID pSrcMemory is the pointer to the Raw Compressed DXTn data. I guess I can just create a texture in ARGB and copy DXTn data directly into it using D3DXLoadSurfaceFromMemory? Edited by Tispe

Share this post


Link to post
Share on other sites

Do you have sample code, I don't want to tread in the dark atm?


Untested, but should work:
HRESULT LoadRGBAFromDXT (LPDIRECT3DTEXTURE9 dst, LPDIRECT3DTEXTURE9 src)
{
assert (dst);
assert (src);

HRESULT ret = E_FAIL;
LPDIRECT3DSURFACE9 dstsurf = NULL;
LPDIRECT3DSURFACE9 srcsurf = NULL;

if (SUCCEEDED (dst->GetSurfaceLevel (0, &dstsurf)))
{
if (SUCCEEDED (src->GetSurfaceLevel (0, &srcsurf)))
{
ret = D3DXLoadSurfaceFromSurface (
dstsurf,
NULL,
NULL,
srcsurf,
NULL,
NULL,
D3DX_DEFAULT,
0
);
}
}

if (dstsurf) dstsurf->Release ();
if (srcsurf) srcsurf->Release ();

return ret;
}


Despite the name this isn't restricted to just DXT to RGBA but can be used to convert between any formats (and sizes).


I think I might get away with using D3DXLoadSurfaceFromMemory directly. Would this work? LPCVOID pSrcMemory is the pointer to the Raw Compressed DXTn data. I guess I can just create a texture in ARGB and copy DXTn data directly into it using D3DXLoadSurfaceFromMemory?


That would also do it, yes. Edited by mhagain

Share this post


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

  • Advertisement