Skip to main content
GameDev.net gamedev.net
🔒 Locked

Saving the backbuffer to ID3D11Texture2D

Started by dotminic Apr 4, 2011 at 4:15 PM 1 replies 9.4k views
Original Post
dotminic
dotminic
Hi,

I'm trying to get the back buffer pixel data in DX11 in order to save it to a file. What I want is to be able to take a capture at various times while the app is running, and save then to files when the app closes to avoid any slow downs cause by D3DX11SaveTextureToFile. Thing is if I just create a bunch of ID3D11Texture2D they all point to the same back buffer pixel data, so I'll just end up saving the last frame that was rendered into each texture onto the file system.
Is there any way to get the pixel data of the back buffer, and actually copy that data to a new ID3D11Texture2D ?

Thanks
bubu LV
bubu LV
You can try using D3DX11LoadTextureFromTexture to make copy of backbuffer texture. But that is most likely not the fastest way how do it. To make it much much faster you will have to deal with texture compression & asynchronous update of texture. Something like this: http://outerra.com/video/

But why are you saying that "if I just create a bunch of ID3D11Texture2D they all point to the same back buffer pixel data". If you create new ID3D11Texture2D object then it doesn't point to same back buffer pixel data. It creates new texture with it's own memory.
dotminic
dotminic
The answer is actually very simple. ID3D11DeviceContext::CopyResource does the trick, and it runs on the GPU. Thanks for the reply anyway.

If you create a texture2D, yes it has it's own memory, but it will be empty since you need to give it a subresource when you create it, and if you use the back buffer subresource, the pixel data for the new textures will point to the back buffer pixel data which is updated every frame. Basically the function I just found in the docs does what I need. I was wanting to memcpy the back buffer subresouce to use it to create the new textures.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.