MCPcopy Create free account
hub / github.com/GPUOpen-Effects/GeometryFX / CaptureFrame

Method CaptureFrame

framework/d3d11/amd_sdk/src/HelperFunctions.cpp:220–274  ·  view source on GitHub ↗

-------------------------------------------------------------------------------------- Captures a frame and dumps it to disk --------------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

218// Captures a frame and dumps it to disk
219//--------------------------------------------------------------------------------------
220void AMD::CaptureFrame( ID3D11Texture2D* pCaptureTexture, WCHAR* pszCaptureFileName )
221{
222 assert( NULL != pCaptureTexture );
223 assert( NULL != pszCaptureFileName );
224
225 // Retrieve RT resource
226 ID3D11Resource *pRTResource;
227 DXUTGetD3D11RenderTargetView()->GetResource( &pRTResource );
228
229 // Retrieve a Texture2D interface from resource
230 ID3D11Texture2D* RTTexture;
231 pRTResource->QueryInterface( __uuidof(ID3D11Texture2D), (LPVOID*)&RTTexture );
232
233 // Check if RT is multisampled or not
234 D3D11_TEXTURE2D_DESC TexDesc;
235 RTTexture->GetDesc( &TexDesc );
236 if (TexDesc.SampleDesc.Count > 1)
237 {
238 // RT is multisampled, need resolving before dumping to disk
239
240 // Create single-sample RT of the same type and dimensions
241 DXGI_SAMPLE_DESC SingleSample = { 1, 0 };
242 TexDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
243 TexDesc.MipLevels = 1;
244 TexDesc.Usage = D3D11_USAGE_DEFAULT;
245 TexDesc.CPUAccessFlags = 0;
246 TexDesc.BindFlags = 0;
247 TexDesc.SampleDesc = SingleSample;
248
249 ID3D11Texture2D *pSingleSampleTexture;
250 DXUTGetD3D11Device()->CreateTexture2D( &TexDesc, NULL, &pSingleSampleTexture );
251
252 DXUTGetD3D11DeviceContext()->ResolveSubresource( pSingleSampleTexture, 0, RTTexture, 0, TexDesc.Format );
253
254 // Copy RT into STAGING texture
255 DXUTGetD3D11DeviceContext()->CopyResource( pCaptureTexture, pSingleSampleTexture );
256
257 DXUTSaveTextureToFile( DXUTGetD3D11DeviceContext(), pCaptureTexture, false, pszCaptureFileName );
258
259 SAFE_RELEASE( pSingleSampleTexture );
260 }
261 else
262 {
263 // Single sample case
264
265 // Copy RT into STAGING texture
266 DXUTGetD3D11DeviceContext()->CopyResource( pCaptureTexture, pRTResource );
267
268 DXUTSaveTextureToFile( DXUTGetD3D11DeviceContext(), pCaptureTexture, false, pszCaptureFileName );
269 }
270
271 SAFE_RELEASE( RTTexture );
272
273 SAFE_RELEASE( pRTResource );
274}
275
276
277//--------------------------------------------------------------------------------------

Callers

nothing calls this directly

Calls 2

DXUTSaveTextureToFileFunction · 0.85
QueryInterfaceMethod · 0.80

Tested by

no test coverage detected