繁体   English   中英

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数据和像素着色器的纹理。

暂无
暂无

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

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