我想缩放我从 AcquireNextFrame 创建的纹理。 这是我的代码:
if (gRealTexture == nullptr) {
D3D11_TEXTURE2D_DESC description;
texture2D->GetDesc(&description);
description.BindFlags = 0;
description.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
description.Usage = D3D11_USAGE_STAGING;
description.MiscFlags = 0;
hr = gDevice->CreateTexture2D(&description, NULL, &gRealTexture);
if (FAILED(hr)) {
if (gRealTexture) {
gRealTexture->Release();
gRealTexture = nullptr;
}
return NULL;
}
}
gImmediateContext->CopyResource(gRealTexture, texture2D);
D3D11_MAPPED_SUBRESOURCE mapped;
hr = gImmediateContext->Map(gRealTexture, 0, D3D11_MAP_READ_WRITE, 0, &mapped);
if (FAILED(hr)) {
gRealTexture->Release();
gRealTexture = NULL;
return NULL;
}
unsigned char *source = static_cast<unsigned char *>(mapped.pData); //Here I get the pixel buffer data
问题是它是全高清分辨率 (1920x1080)。我想降低分辨率(例如 1280x720),因为我需要通过网络发送 source
。而且我真的不需要全高清图像。
在获得像素缓冲区之前,是否可以使用 DirectX 轻松完成此操作?
谢谢
最佳答案
创建一个较小分辨率的纹理,使用全屏四边形将 texture2d
渲染为较小的纹理(但缩小到新尺寸)。确保双线性过滤已打开。
然后复制并映射较小的纹理。 CopyResource 需要相同的维度。
一些资源:
DX11 Helper Library
Render To Texture
模糊设置与我所说的相同,只是您使用简单的纹理着色器而不是使用模糊着色器。
关于c++ - directX 11 比例纹理 2D,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44265856/