在Qt 5.6中调整Direct3D11小部件的黑色闪烁区域

时间:2016-06-04 21:10:30

标签: winapi directx direct3d window-resize

我正在使用Qt 5.6创建一个GUI应用程序并使用自定义Direct3D11小部件。我按照官方Qt博客的例子: https://blog.qt.io/blog/2016/01/28/qt-and-direct3d-12-first-encounter/ Qt 4的其他人的博客: http://blog.jholewinski.org/direct3d-11-with-qt-4/index.html

在调整小部件大小时,我会得到黑色区域: enter image description here 在QGraphicsView中不会出现这种情况,其中调整大小是完美的,没有拉伸。

我尝试了一些尚未解决的小部件属性组合:

this->setAttribute(Qt::WA_OpaquePaintEvent, true);
this->setAttribute(Qt::WA_PaintOnScreen, true);
this->setAttribute(Qt::WA_DontCreateNativeAncestors, true);
this->setAttribute(Qt::WA_NativeWindow, true);
this->setAttribute(Qt::WA_NoSystemBackground, true);
this->setAttribute(Qt::WA_MSWindowsUseDirect3D, true);
this->setAutoFillBackground(false);

我也尝试过处理WM_ERASEBKGND:

bool D3D11Widget::nativeEvent(const QByteArray& eventType, void *msg, long *result) {
    MSG *message = static_cast<MSG *>(msg);

    switch (message->message) {
    case WM_ERASEBKGND:
        qDebug() << "erase background\n";
        *result = 1L;
        return TRUE;
    }

    return QWidget::nativeEvent(eventType, message, result);
}

我按照以下方式处理调整大小:

void D3D11Widget::resizeEvent(QResizeEvent *evt) {
    Q_UNUSED(evt);
    this->devcon->OMSetRenderTargets(0, NULL, NULL);
    this->rendertarget.Reset();

    this->swapchain->ResizeBuffers(0, 0, 0, DXGI_FORMAT_UNKNOWN, 0);

    ComPtr<ID3D11Texture2D> backbuffer;
    this->swapchain->GetBuffer(0, IID_ID3D11Texture2D, &backbuffer);

    D3D11_RENDER_TARGET_VIEW_DESC rtvd = {};
    rtvd.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
    rtvd.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;

    this->device->CreateRenderTargetView(backbuffer.Get(), &rtvd, &this->rendertarget);

    const QSize size = evt->size();
    D3D11_VIEWPORT viewport = { 0, 0, (float)size.width(), (float)size.height(), 0, 1 };
    this->devcon->RSSetViewports(1, &viewport);
    evt->accept();
}

我设法摆脱闪烁的唯一方法是在我的交换链中设置DXGI_SCALING_STRETCH。但是,调整大小时的拉伸是不合需要的,并且不会出现在QGraphicsView中。那么如何在没有任何闪烁的情况下调整QGraphicsView的大小,我该怎么做呢?

0 个答案:

没有答案