简体   繁体   English

directX 11缩放Texture2D

[英]directX 11 scale texture2D

I would like to scale a texture I created from AcquireNextFrame. 我想缩放从AcquireNextFrame创建的纹理。 Here is my code : 这是我的代码:

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

Problem is that it is in Full HD Resolution (1920x1080). 问题是它处于全高清分辨率(1920x1080)。 I would like to decrease the resolution (1280x720 for example) because I need to send source over network. 我想降低分辨率(例如1280x720),因为我需要通过网络发送source And I don't really need a Full HD image. 而且我真的不需要全高清图像。

Is it possible to do it with DirectX easily before I get the pixel buffer ? 在获得像素缓冲区之前,是否可以使用DirectX轻松做到这一点?

Thanks 谢谢

Create a smaller resolution texture, render the texture2d to the smaller texture using a fullscreen quad (but shrinking to the new size). 创建较小分辨率的纹理,使用全屏四边形将texture2d渲染为较小的纹理(但缩小到新的大小)。 Make sure bilinear filtering is on. 确保打开了双线性过滤。

Then copy and map the smaller texture. 然后复制并映射较小的纹理。 CopyResource needs the same dimensions. CopyResource需要相同的尺寸。

Some resources: 一些资源:

DX11 Helper Library DX11帮助器库
Render To Texture 渲染到纹理

DX11 Post Processing blur DX11后处理模糊

The blur setup is the same as what I'm talking about, only instead of using a blur shader you use a simple texture shader. 模糊设置与我所说的相同,只是使用简单的纹理着色器代替使用模糊着色器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM