DirectX 11 framebuffer capture (C , no Win32 or D3DX)
2012-11-27 11:27
447 查看
DirectX 11 framebuffer capture (C , no Win32 or D3DX) ID3D11Texture2D* pSurface; HRESULT hr = m_swapChain->GetBuffer( 0, __uuidof( ID3D11Texture2D ), reinterpret_cast< void** >( &pSurface ) ); if( pSurface ) { const int width = static_cast<int>(m_window->Bounds.Width * m_dpi / 96.0f); const int height = static_cast<int>(m_window->Bounds.Height * m_dpi / 96.0f); unsigned int size = width * height; if( m_captureData ) { freeFramebufferData( m_captureData ); } m_captureData = new unsigned char[ width * height * 4 ]; ID3D11Texture2D* pNewTexture = NULL; D3D11_TEXTURE2D_DESC description = { width, height, 1, 1, DXGI_FORMAT_R8G8B8A8_UNORM, { 1, 0 }, // DXGI_SAMPLE_DESC D3D11_USAGE_STAGING, 0, D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE, 0 }; HRESULT hr = m_d3dDevice->CreateTexture2D( &description, NULL, &pNewTexture ); if( pNewTexture ) { m_d3dContext->CopyResource( pNewTexture, pSurface ); D3D11_MAPPED_SUBRESOURCE resource; unsigned int subresource = D3D11CalcSubresource( 0, 0, 0 ); HRESULT hr = m_d3dContext->Map( pNewTexture, subresource, D3D11_MAP_READ, 0, &resource ); //resource.pData; // TEXTURE DATA IS HERE const int pitch = width << 2; const unsigned char* source = static_cast< const unsigned char* >( resource.pData ); unsigned char* dest = m_captureData; for( int i = 0; i < height; ++i ) { memcpy( dest, source, width * 4 ); source += pitch; dest += pitch; } m_captureSize = size; m_captureWidth = width; m_captureHeight = height; return; } freeFramebufferData( m_captureData ); } ID3D11Texture2D* pSurface; HRESULT hr = m_swapChain->GetBuffer( 0, __uuidof( ID3D11Texture2D ), reinterpret_cast< void** >( &pSurface ) ); if( pSurface ) { const int width = static_cast<int>(m_window->Bounds.Width * m_dpi / 96.0f); const int height = static_cast<int>(m_window->Bounds.Height * m_dpi / 96.0f); unsigned int size = width * height; if( m_captureData ) { freeFramebufferData( m_captureData ); } m_captureData = new unsigned char[ width * height * 4 ]; ID3D11Texture2D* pNewTexture = NULL; D3D11_TEXTURE2D_DESC description; pSurface->GetDesc( &description ); description.BindFlags = 0; description.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE; description.Usage = D3D11_USAGE_STAGING; HRESULT hr = m_d3dDevice->CreateTexture2D( &description, NULL, &pNewTexture ); if( pNewTexture ) { m_d3dContext->CopyResource( pNewTexture, pSurface ); D3D11_MAPPED_SUBRESOURCE resource; unsigned int subresource = D3D11CalcSubresource( 0, 0, 0 ); HRESULT hr = m_d3dContext->Map( pNewTexture, subresource, D3D11_MAP_READ_WRITE, 0, &resource ); //resource.pData; // TEXTURE DATA IS HERE const int pitch = width << 2; const unsigned char* source = static_cast< const unsigned char* >( resource.pData ); unsigned char* dest = m_captureData; for( int i = 0; i < height; ++i ) { memcpy( dest, source, width * 4 ); source += pitch; dest += pitch; } m_captureSize = size; m_captureWidth = width; m_captureHeight = height; return; } freeFramebufferData( m_captureData ); }
原理:创建一个新的texture2D,允许写入。利用
m_d3dContext->CopyResource
进行写入。利用
m_d3dContext->Map 进行读取。
相关文章推荐
- Android 模拟器启动报错:android failed to open framebuffer ( no such file or directory )
- cocos2d-x-2.2中编译cocos2d-win32.vc2010 C1083 pthread.h No such file or director错误的解决办法
- Python cx_Oracle - import not a valid win32 app or ImportError: No module named cx_Oracle Found
- A Mainframe IDE Powered By Unix Technology [11] - Submit JCL from ftp command or shell script
- error C1083 :无法打开包括文件:“D3DX9.h" No such file or directory
- [11]缺少动态连接库.so--cannot open shared object file: No such file or directory
- The Beauty of DirectX 11 --- constant buffer, buffered/structure buffer
- wpsapi.tlh(11) : fatal error C1083: 无法打开包括文件:“”: No such file or directory
- 开发错误记录11:git报错 fatal:open /dev/null or dup failed: No such file or directory
- fatal error C1083: 无法打开源文件:“WIN32”: No such file or directory(VS)的解决方法
- The Beauty of DirectX 11 (3) --- constant buffer, buffered/structure buffer
- Xvfb or X virtual framebuffer
- The Beauty of DirectX 11 (4) -- Append/Consume,Byte Address and Indirect Argument Buffer
- coc 4000 os2d-x-2.2中编译cocos2d-win32.vc2010.sln出现:C1083 pthread.h No such file or director错误的解决办法
- 打开/dev/fb0时“No such device”错误解决方法:激活 VESA FrameBuffer 驱动程序
- The Beauty of DirectX 11 (2) --- Resource View & Vertex Buffer
- solaris 11 stdio.h: No such file or directory
- DE2 framebuffer and video capture interface for SOPC (altera9.1)
- DE2 framebuffer and video capture interface for SOPC (altera11.0)
- fatal error: vector: No such file or directory