DirectX 11 framebuffer capture (C , no Win32 or D3DX)
来源:互联网 发布:软件委托开发合同 编辑:程序博客网 时间:2024/05/18 03:37
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 进行读取。
- DirectX 11 framebuffer capture (C , no Win32 or D3DX)
- DirectX.Capture
- DirectX学习:D3DX矩阵函数
- DirectX学习:D3DX颜色函数
- DirectX学习:D3DX矩阵函数(转载)
- DirectX学习:D3DX中关于平面的函数
- DirectX函数学习:D3DX中关于平面的函数
- Android 模拟器启动报错:android failed to open framebuffer ( no such file or directory )
- C# 摄像头视频捕捉 (使用DirectX.Capture)
- DirectX 教程: DirectX Tutorial - Win32: Basics
- Xvfb or X virtual framebuffer
- DirectX学习笔记(四):利用D3DX网格数据结构绘制可旋转茶壶
- DirectX学习笔记(四):利用D3DX网格数据结构绘制可旋转茶壶
- DirectX+win32最简化模板
- Directx(Win32消息机制)
- gcc: c-parse.c: No such file or directory
- Python cx_Oracle - import not a valid win32 app or ImportError: No module named cx_Oracle Found
- fatal error C1083: 无法打开源文件:“WIN32”: No such file or directory(VS)的解决方法
- android获取应用签名信息
- FAQ_23 设置 Toast 显示时间
- 使用Zend Studio和火狐调试PHP代码
- 带裂纹的动态有限元程序(水平裂纹在中间高度处,从左到中点--即半无限长)
- Coverity的安装使用及常见错误
- DirectX 11 framebuffer capture (C , no Win32 or D3DX)
- Delphi 报表 Quickreport使用
- IE6、IE7下解决Select框不随滚动条滚动的问题
- 构造函数的执行与virtual
- 笔记1
- 二维动态有限差分程序
- VS2008 可执行文件路径选择
- 关于程序员自学的一点心得
- JSON技术介绍