Converting IDirect3DTexture9 from DXTn to ARGB

Started by
7 comments, last by Tispe 11 years, 6 months ago
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?
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!
I am not loading from a dds file. I am loading raw data from memory unfortunatly.
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.
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.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.


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?
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?

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.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

Thank you!

This topic is closed to new replies.

Advertisement