DirectX 11比例纹理2d

directX 11 scale texture2D

本文关键字:纹理 2d DirectX      更新时间:2023-10-16

我想缩放我从aceareRenextFrame创建的纹理。这是我的代码:

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辅助库
呈现到纹理

dx11邮政处理模糊

模糊设置与我在说的内容相同,只有使用模糊着色器而不是使用简单的纹理着色器。