Sign in to follow this  
crshinjin

Saving the backbuffer directly in DX10

Recommended Posts

crshinjin    132
Hi all!

I'm trying to add a sort of screenshot feature to my DX10 app, and it starts to give me a serious headache.

This is my screenshot method:
void Whatever::SaveScreen(const WCHAR* filename)
{
// backbufferSurfDesc is saved at OnResizedSwapChain call
ID3D10Resource *backbufferRes;
_defaultRenderTargetView->GetResource(&backbufferRes);

D3D10_TEXTURE2D_DESC texDesc;
texDesc.ArraySize = 1;
texDesc.BindFlags = 0;
texDesc.CPUAccessFlags = D3D10_CPU_ACCESS_READ;
texDesc.Format = backbufferSurfDesc.Format;
texDesc.Height = backbufferSurfDesc.Height;
texDesc.Width = backbufferSurfDesc.Width;
texDesc.MipLevels = 1;
texDesc.MiscFlags = 0;
texDesc.SampleDesc = backbufferSurfDesc.SampleDesc;
texDesc.Usage = D3D10_USAGE_STAGING;

ID3D10Texture2D *texture;
HRESULT hr;
V( _device->CreateTexture2D(&texDesc, 0, &texture) );
_device->CopyResource(texture, backbufferRes);

V( D3DX10SaveTextureToFile(texture, D3DX10_IFF_PNG, filename) );
texture->Release();
}


Now, obviously I'm doing something the wrong way, because D3DX10SaveTextureToFile fails with E_FAIL (guess E stands for EPIC [wink]).

Is it possible to use D3DX10SaveTextureToFile without a render-to-texture before it?

Thanks,
shinjin

Share this post


Link to post
Share on other sites
coderchris    304
Its possible that it wont save because PNG can only store certain pixel formats. Try using D3DX10_IFF_DDS and see if it saves successfully.

It could also be that filename is invalid and/or you dont have write permission in the directory where you are attempting to save it.

If all else fails you could try saving the back buffer directly without copying it to a staging first?

Share this post


Link to post
Share on other sites
crshinjin    132
Changing the file format to D3DX10_IFF_DDS indeed solved the error part, but I get a corrupted DDS.
I have tried to open it with the DX Texture Tool, with nVidia's texture viewer and even with Gimp's DDS plug-in. All in vain.
I have uploaded the files here, if anyone feels like giving it a try.

BTW, using backbufferRes directly in D3DX10SaveTextureToFile "work" just the same. No error, corrupted DDS.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this