0
votes

I would like to scale a texture I created from 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). I would like to decrease the resolution (1280x720 for example) because I need to send source over network. 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 ?

Thanks

1

1 Answers

1
votes

Create a smaller resolution texture, render the texture2d to the smaller texture using a fullscreen quad (but shrinking to the new size). Make sure bilinear filtering is on.

Then copy and map the smaller texture. CopyResource needs the same dimensions.

Some resources:

DX11 Helper Library
Render To Texture

DX11 Post Processing blur

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.