/*! \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"); }
void MapNode::updateFBO() { QGLPainter painter; if (!painter.begin()) { qWarning() << "GL graphics system is not active, can not update FBO for map"; return; } painter.pushSurface(m_fboSurface); glClearColor(0.9, 0.9, 0.9, 0.0); glClear(GL_COLOR_BUFFER_BIT); painter.disableEffect(); #ifdef GL_RESCALE_NORMAL // Scale normals by a scale factor derived from modelview matrix. // Note: normals need to be unit length. glEnable(GL_RESCALE_NORMAL); #endif #if !defined(QT_OPENGL_ES_2) glShadeModel(GL_SMOOTH); glEnable(GL_MULTISAMPLE); #endif // Set the default effect for the scene. painter.setStandardEffect(QGL::LitMaterial); painter.setFaceColor(QGL::AllFaces, Qt::white); #if defined(QT_OPENGL_ES) glClearDepthf(1); #else glClearDepth(1); #endif #if defined(GL_LINE_SMOOTH) && defined(GL_LINE_SMOOTH_HINT) glEnable(GL_LINE_SMOOTH); glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); #endif #ifdef QSGSHADEREFFECTSOURCE_AVAILABLE // Update any map objects that may have dirty textures for (int i = 0; i < mapItems_.count(); ++i) { mapItems_.at(i)->updateItem(); } #endif // No stereo rendering, set the eye as neutral painter.setEye(QGL::NoEye); // TODO this needs to be figured out (or confirmed as invalid thing). // Currently applied transforms for this Map3D object - how to get/apply current transforms? // QTransform transform = painter->combinedTransform(); // Then we get the rectangle that is gotten by applying the QTransform on the rect // --> this is the viewport for Map3D // QRect viewport = transform.mapRect(boundingRect()).toRect(); // boundingRect is in local coordinates. We need to map it to the scene coordinates // in order to render to correct area. if (m_map->glCamera()) { painter.setCamera(m_map->glCamera()); } else { QGLCamera defCamera; painter.setCamera(&defCamera); } m_map->paintGL(&painter); restoreDefaults(&painter); // Draw the children items painter.popSurface(); // QSG does not expect anyone to alter gl context state; restore defaults. // Default heaps of things, because we cannot be sure what the Qt3D internally // sets. #if defined(QT_OPENGL_ES) glClearDepthf(0); #else glClearDepth(0); #endif painter.end(); QSGGeometry::updateTexturedRectGeometry(&m_geometry, QRectF(QPointF(0, m_fbo->size().height()), QPointF(m_fbo->size().width(), 0)), QRectF(0, 0, 1, 1)); delete m_texture; m_texture = new QSGPlainTexture(); m_texture->setOwnsTexture(false); m_texture->setTextureSize(m_fbo->size()); m_texture->setTextureId(m_fbo->texture()); m_opaqueMaterial.setTexture(m_texture); m_material.setTexture(m_texture); markDirty(DirtyMaterial); }
/*! Paints this GL graphics viewport onto \a painter, with the specified \a option and \a widget parameters. This override creates a QGLPainter for \a painter and passes it to paintGL(). \sa paintGL() */ void QGLGraphicsViewportItem::paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { Q_D(QGLGraphicsViewportItem); Q_UNUSED(option); Q_UNUSED(widget); if (d->rect.isEmpty()) return; // Initialize a QGLPainter for the surface and bail out if not active. QGLPainter glpainter; if (!glpainter.begin(painter)) { qWarning("GL graphics system is not active; cannot use 3D items"); return; } // Set up the GL viewport to limit drawing to the bounds of this item. QRect viewport = painter->deviceTransform().mapRect(rect()).toRect(); QGLSubsurface surface(glpainter.currentSurface(), viewport); glpainter.pushSurface(&surface); // Set up the desired drawing options. glDisable(GL_CULL_FACE); d->setDefaults(&glpainter); if (d->backgroundColor.isValid()) { // We clear the background by drawing a triangle fan so // that the background color will blend with the underlying // screen content if it has an alpha component. glDisable(GL_DEPTH_TEST); if (d->backgroundColor.alpha() != 255) glEnable(GL_BLEND); else glDisable(GL_BLEND); QVector2DArray array; array.append(-1, -1); array.append(1, -1); array.append(1, 1); array.append(-1, 1); glpainter.projectionMatrix().setToIdentity(); glpainter.modelViewMatrix().setToIdentity(); glpainter.setStandardEffect(QGL::FlatColor); glpainter.setColor(d->backgroundColor); glpainter.setVertexAttribute(QGL::Position, array); glpainter.draw(QGL::TriangleFan, 4); } glClear(GL_DEPTH_BUFFER_BIT); glEnable(GL_DEPTH_TEST); glDisable(GL_BLEND); // Apply the camera. glpainter.setEye(QGL::NoEye); glpainter.setCamera(d->camera); // Paint the GL contents. paintGL(&glpainter); // Disable the current drawing effect so that QGLPainter will // forcibly update the GL context the next time QGLPainter is used. glpainter.disableEffect(); // Try to restore the GL state to something paint-engine compatible. glDisable(GL_CULL_FACE); d->setDefaults(&glpainter); glDisable(GL_DEPTH_TEST); glpainter.popSurface(); }