读取ID3D11ShaderResourceView、ID3D11Texture2D

void SaveD3D11ResourceView(ID3D11Device *device, ID3D11DeviceContext *deviceContext, ID3D11ShaderResourceView *srv)
{
	ID3D11Resource *res;
	ID3D11Texture2D *tex;
	srv->GetResource(&res);
	res->QueryInterface(&tex);
	SaveD3D11Texture(device, deviceContext, tex);
	res->Release();
	res = 0;
	tex->Release();
	tex = 0;
	deviceContext->Flush();
}
void SaveD3D11Texture(ID3D11Device *device, ID3D11DeviceContext *deviceContext, ID3D11Texture2D *src)
{
	D3D11_TEXTURE2D_DESC texDesc;
	src->GetDesc(&texDesc);
	texDesc.Usage = D3D11_USAGE_STAGING;
	texDesc.BindFlags = 0;
	texDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
	texDesc.MiscFlags = 0;

	ID3D11Texture2D *des = 0;
	HR_NO_RETURN(device->CreateTexture2D(&texDesc, NULL, &des));

	deviceContext->CopyResource(des, src);

	D3D11_MAPPED_SUBRESOURCE mapped;
	HR_NO_RETURN(deviceContext->Map(des, 0, D3D11_MAP_READ, 0, &mapped));

	int c = 0;
	if (texDesc.Format == DXGI_FORMAT_R8_UNORM) 
		c = 1;
	else
		c = 4;
	int w = mapped.RowPitch / c;
	int h = mapped.DepthPitch / mapped.RowPitch;

#if 1
    QImage pImage(w, h, QImage::Format_RGBA8888);
    memcpy(pImage.bits(), mapped.pData, w * h * c);
    pImage.save("d:/aaa.png");
#else
	uint8_t *buf = (uint8_t*)mlt_pool_alloc(w * h * c);

	memcpy(buf, mapped.pData, w * h * c);
	QImage img = QImage(buf, w, h, QImage::Format_RGBA8888);
	img.save("e:/dump.png", "PNG");
	//FILE *fp = fopen("d:/aaa.rgba", "wb");
	//fwrite(buf, 1, w * h * c, fp);
	//fclose(fp);
	mlt_pool_release(buf);
#endif

	deviceContext->Unmap(des, 0);

	des->Release();
	des = 0;
}

 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值