Ejemplo n.º 1
0
/*!
    \internal
*/
void QGLView::paintGL()
{
    d->logEnter("QGLView::paintGL");
    // We may need to regenerate the pick buffer on the next mouse event.
    d->pickBufferMaybeInvalid = true;

    // Paint the scene contents.
    QGLPainter painter;
    QGLAbstractSurface *surface;
    painter.begin();
    if ( (d->options & QGLView::ShowPicking) &&
            d->stereoType == QGLView::RedCyanAnaglyph) {
        // If showing picking, then render normally.  This really
        // only works if we aren't using hardware or double stereo.
        painter.setPicking(true);
        painter.clearPickObjects();
        painter.setEye(QGL::NoEye);
        earlyPaintGL(&painter);
        painter.setCamera(d->camera);
        paintGL(&painter);
        painter.setPicking(false);
    } else if (d->camera->eyeSeparation() == 0.0f &&
               (surface = d->bothEyesSurface()) != 0) {
        // No camera separation, so render the same image into both buffers.
        painter.pushSurface(surface);
        painter.setEye(QGL::NoEye);
        earlyPaintGL(&painter);
        painter.setCamera(d->camera);
        paintGL(&painter);
        painter.popSurface();
    } else {
        // Paint the scene twice, from the perspective of each camera.
        QSize size(this->size());
        painter.setEye(QGL::LeftEye);
        if (d->stereoType != QGLView::Hardware)
            earlyPaintGL(&painter);     // Clear both eyes at the same time.
        painter.pushSurface(d->leftEyeSurface(size));
        if (d->stereoType == QGLView::Hardware)
            earlyPaintGL(&painter);     // Clear the left eye only.
        earlyPaintGL(&painter);
        painter.setCamera(d->camera);
        paintGL(&painter);
        if (d->stereoType == QGLView::RedCyanAnaglyph)
            glClear(GL_DEPTH_BUFFER_BIT);
        painter.setEye(QGL::RightEye);
        painter.setSurface(d->rightEyeSurface(size));
        if (d->stereoType == QGLView::Hardware)
            earlyPaintGL(&painter);     // Clear the right eye only.
        painter.setCamera(d->camera);
        paintGL(&painter);
        painter.popSurface();
    }
    d->logLeave("QGLView::paintGL");
}
Ejemplo n.º 2
0
/*!
    \internal
*/
void QGLView::paintGL()
{
    d->logEnter("QGLView::paintGL");
    // We may need to regenerate the pick buffer on the next mouse event.
    d->pickBufferMaybeInvalid = true;

    // Paint the scene contents.
    QGLPainter painter;
    painter.begin();
    painter.resetViewport();
    if (d->options & QGLView::ShowPicking &&
            d->stereoType == QGLView::RedCyanAnaglyph) {
        // If showing picking, then render normally.  This really
        // only works if we aren't using hardware or double stereo.
        painter.setPicking(true);
        painter.clearPickObjects();
        painter.setEye(QGL::NoEye);
        earlyPaintGL(&painter);
        painter.setCamera(d->camera);
        paintGL(&painter);
        painter.setPicking(false);
    } else if (d->camera->eyeSeparation() == 0.0f &&
                    (d->stereoType == QGLView::Hardware ||
                     d->stereoType == QGLView::RedCyanAnaglyph)) {
        // No camera separation, so draw without stereo.  If the hardware
        // has stereo buffers, then render the same image into both buffers.
#if defined(GL_BACK_LEFT) && defined(GL_BACK_RIGHT)
        if (d->stereoType == QGLView::Hardware) {
            bool doubleBuffered = doubleBuffer();
            if (doubleBuffered)
                glDrawBuffer(GL_BACK);
            else
                glDrawBuffer(GL_FRONT);
            painter.setEye(QGL::NoEye);
            earlyPaintGL(&painter);
            painter.setCamera(d->camera);
            paintGL(&painter);
        } else
#endif
        {
            painter.setEye(QGL::NoEye);
            earlyPaintGL(&painter);
            painter.setCamera(d->camera);
            paintGL(&painter);
        }
    } else {
        // Paint the scene twice, from the perspective of each camera.
        // In RedCyanAnaglyph mode, the color mask is set each time to only
        // extract the color planes that we want to see through that eye.
        if (d->stereoType == QGLView::RedCyanAnaglyph) {
            painter.setEye(QGL::LeftEye);
            glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
            earlyPaintGL(&painter);

            glColorMask(GL_TRUE, GL_FALSE, GL_FALSE, GL_TRUE);
            painter.setCamera(d->camera);
            paintGL(&painter);

            painter.setEye(QGL::RightEye);
            glColorMask(GL_FALSE, GL_TRUE, GL_TRUE, GL_TRUE);
            glClear(GL_DEPTH_BUFFER_BIT);
            painter.setCamera(d->camera);
            paintGL(&painter);

            glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
        } else if (d->stereoType != QGLView::Hardware) {
            // Render the stereo images into the two halves of the window.
            QSize sz = size();
            painter.setEye(QGL::LeftEye);
            qt_qglview_left_viewport(&painter, sz, d->stereoType);
            earlyPaintGL(&painter);
            painter.setCamera(d->camera);
            paintGL(&painter);
            painter.setEye(QGL::RightEye);
            qt_qglview_right_viewport(&painter, sz, d->stereoType);
            painter.setCamera(d->camera);
            paintGL(&painter);
            painter.setViewportOffset(QPoint(0, 0));
        }
#if defined(GL_BACK_LEFT) && defined(GL_BACK_RIGHT)
        else {
            bool doubleBuffered = doubleBuffer();
            if (doubleBuffered)
                glDrawBuffer(GL_BACK_LEFT);
            else
                glDrawBuffer(GL_FRONT_LEFT);
            painter.setEye(QGL::LeftEye);
            earlyPaintGL(&painter);
            painter.setCamera(d->camera);
            paintGL(&painter);

            if (doubleBuffered)
                glDrawBuffer(GL_BACK_RIGHT);
            else
                glDrawBuffer(GL_FRONT_RIGHT);
            painter.setEye(QGL::RightEye);
            earlyPaintGL(&painter);
            painter.setCamera(d->camera);
            paintGL(&painter);
        }
#endif
    }
    d->logLeave("QGLView::paintGL");
}