Jump to content

  • Log In with Google      Sign In   
  • Create Account

Converting IDirect3DTexture9 from DXTn to ARGB


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
8 replies to this topic

#1 Tispe   Members   -  Reputation: 1032

Like
0Likes
Like

Posted 09 October 2012 - 04:06 AM

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, 09 October 2012 - 04:43 AM.


Sponsor:

#2 kauna   Crossbones+   -  Reputation: 2506

Like
0Likes
Like

Posted 09 October 2012 - 06:26 AM

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, 09 October 2012 - 06:27 AM.


#3 Tispe   Members   -  Reputation: 1032

Like
0Likes
Like

Posted 09 October 2012 - 07:53 AM

I am not loading from a dds file. I am loading raw data from memory unfortunatly.

#4 Ripiz   Members   -  Reputation: 529

Like
0Likes
Like

Posted 09 October 2012 - 08:18 AM

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.

#5 mhagain   Crossbones+   -  Reputation: 7956

Like
2Likes
Like

Posted 09 October 2012 - 08:20 AM

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.

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#6 Tispe   Members   -  Reputation: 1032

Like
0Likes
Like

Posted 09 October 2012 - 01:42 PM

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?

#7 Tispe   Members   -  Reputation: 1032

Like
0Likes
Like

Posted 09 October 2012 - 02:21 PM

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, 09 October 2012 - 02:22 PM.


#8 mhagain   Crossbones+   -  Reputation: 7956

Like
0Likes
Like

Posted 09 October 2012 - 03:17 PM

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, 09 October 2012 - 03:20 PM.

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#9 Tispe   Members   -  Reputation: 1032

Like
0Likes
Like

Posted 09 October 2012 - 03:26 PM

Thank you!




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS