DirectX:在视口中放大绘制位图图像导致质量低下?

DirectX: Draw bitmap image scale up in viewport caused low quality?

我正在使用 DirectX 在缓冲区中绘制带有 RGB 数据的图像。以下是摘要代码:

    // create the vertex buffer
    D3D11_BUFFER_DESC bd;
    ZeroMemory(&bd, sizeof(bd));
    bd.Usage = D3D11_USAGE_DYNAMIC;                // write access access by CPU and GPU
    bd.ByteWidth = sizeOfOurVertices;             // size is the VERTEX struct * pW*pH
    bd.BindFlags = D3D11_BIND_VERTEX_BUFFER;       // use as a vertex buffer
    bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;    // allow CPU to write in buffer
    dev->CreateBuffer(&bd, NULL, &pVBuffer);       // create the buffer

    //Create Sample for texture
    D3D11_SAMPLER_DESC desc;
    desc.Filter = D3D11_FILTER_ANISOTROPIC;
    desc.MaxAnisotropy = 16;
    ID3D11SamplerState *ppSamplerState = NULL;
    dev->CreateSamplerState(&desc, &ppSamplerState);
    devcon->PSSetSamplers(0, 1, &ppSamplerState);

//Create list vertices from RGB data buffer
    pW = bitmapSource->PixelWidth;
    pH = bitmapSource->PixelHeight;
    OurVertices = new VERTEX[pW*pH];    
    vIndex = 0;
    unsigned char* curP = rgbPixelsBuff;
    for (y = 0; y < pH; y++)
    {
        for (x = 0; x < pW; x++)
        {
            OurVertices[vIndex].Color.b = *curP++;
            OurVertices[vIndex].Color.g = *curP++;
            OurVertices[vIndex].Color.r = *curP++;
            OurVertices[vIndex].Color.a = *curP++;
            OurVertices[vIndex].X = x;
            OurVertices[vIndex].Y = y;
            OurVertices[vIndex].Z = 0.0f;
            vIndex++;
        }
    }
    sizeOfOurVertices = sizeof(VERTEX)* pW*pH;

    // copy the vertices into the buffer
    D3D11_MAPPED_SUBRESOURCE ms;
    devcon->Map(pVBuffer, NULL, D3D11_MAP_WRITE_DISCARD, NULL, &ms);    // map the buffer
    memcpy(ms.pData, OurVertices, sizeOfOurVertices);                 // copy the data
    devcon->Unmap(pVBuffer, NULL);     
    // unmap the buffer

    // clear the back buffer to a deep blue
    devcon->ClearRenderTargetView(backbuffer, D3DXCOLOR(0.0f, 0.2f, 0.4f, 1.0f));

    // select which vertex buffer to display
    UINT stride = sizeof(VERTEX);
    UINT offset = 0;
    devcon->IASetVertexBuffers(0, 1, &pVBuffer, &stride, &offset);

    // select which primtive type we are using
    devcon->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);

    // draw the vertex buffer to the back buffer
    devcon->Draw(pW*pH, 0);

    // switch the back buffer and the front buffer
    swapchain->Present(0, 0);

当视口尺寸小于或等于图像尺寸时 => 一切正常。但是当视口的尺寸大于图像的尺寸时=>图像的质量很差。

我搜索并尝试使用 desc.Filter = D3D11_FILTER_ANISOTROPIC; 如上代码(我也尝试使用 D3D11_FILTER_MIN_POINT_MAG_MIP_LINEARD3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT),但结果并不好。以下图片为展示结果:

谁能告诉我解决方法。

非常感谢!

您正在使用 DirectX 将每个像素绘制为一个点。当屏幕尺寸变大时,您的点会分开并且质量会变差,这是正常的。您应该使用用 RGB 数据和像素着色器填充的纹理来绘制带纹理的四边形。