UsdRenderEngineGL leaves GL state that breaks QPainter overlays in QOpenGLWidget

Hello,

I’m integrating a UsdImagingGLEngine into a Qt’s OpenGL viewport. After calling UsdImagingGLEngine::render(…) inside QOpenGLWidget::paintGL(), any attempt to draw overlay text using QPainter on the widget produces unreadable or corrupted output (clipped, or partially missing).

If I comment out the render() call, the QPainter text draws fine. This leads me to think that UsdImagingGLEngine leaves the GL context in a state that breaks QPainter’s paint engine?

I’ve worked around it by mimicking Pixar’s usdview HUD approach (render text to a QImage and draw a screen-space quad), but I’d like to understand what specific GL state changes in UsdImagingGLEngine cause QPainter to misbehave?

void UsdGLViewport::paintGL()
{
	.....

    // USD Draw
    m_imagingGLEngine->render(m_stage, m_usdCamera.get(), m_width, m_height);
   
    // Draw Overlay
    QPainter p(this);
    p.setPen(Qt::white);
    p.drawText(10, 20, "Dummy HUD");
}

I also tried wrapping the render call in beginNativePainting()/endNativePainting() but overlay is still comes out corrupted.

void UsdGLViewport::paintGL()
{
	QPainter painter(this);

	painter.beginNativePainting();

    // USD Draw
    m_imagingGLEngine->render(m_stage, m_usdCamera.get(), m_width, m_height);

    painter.endNativePainting();
   
    // Draw Text
    painter.setPen(Qt::white);
    painter.drawText(10, 20, "Dummy HUD");
}

Any help is appreciated.

In my experience (Qt not USD), this sort of thing is usually down to GL_UNPACK_ALIGNMENT and its friends which mess up Qt’s text-drawing code.

Jerry