Esempio n. 1
0
int main(int argc, char *argv[])
{
	QApplication a(argc, argv);

	// Check whether the current system configuration supports the OpenGL
	if (!QGLFormat::hasOpenGL() ) {
		QMessageBox::information(0, "XmdvTool",
				"This system does not support OpenGL rendering.  XmdvTool cannot start.");
		return -1;
	}

	QGLWidget* tryGLWidget = new QGLWidget( (QWidget*)0 );
	if ( !tryGLWidget->isValid() ) {
		QMessageBox::information(0, "XmdvTool",
				"This system does not support OpenGL rendering.  XmdvTool cannot start.");
		delete tryGLWidget;
		return -1;
	}
	delete tryGLWidget;

	XmdvToolMainWnd w(NULL);
	w.show();
	a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()));
	w.openInitialDatasets();
	return a.exec();
}
Esempio n. 2
0
static void createPlatformGraphicsContext3DFromWidget(QWidget* widget, PlatformGraphicsContext3D* context,
                                                      PlatformGraphicsSurface3D* surface)
{
    *context = 0;
    *surface = 0;
    QAbstractScrollArea* scrollArea = qobject_cast<QAbstractScrollArea*>(widget);
    if (!scrollArea)
        return;

    QGLWidget* glViewport = qobject_cast<QGLWidget*>(scrollArea->viewport());
    if (!glViewport)
        return;
    QGLWidget* glWidget = new QGLWidget(0, glViewport);
    if (glWidget->isValid()) {
        // Geometry can be set to zero because m_glWidget is used only for its QGLContext.
        glWidget->setGeometry(0, 0, 0, 0);
#if HAVE(QT5)
        *surface = glWidget->windowHandle();
        *context = glWidget->context()->contextHandle();
#else
        *surface = glWidget;
        *context = const_cast<QGLContext*>(glWidget->context());
#endif
    } else {
        delete glWidget;
        glWidget = 0;
    }
}
Esempio n. 3
0
void WaveformWidgetFactory::swap() {
    ScopedTimer t("WaveformWidgetFactory::swap() %1waveforms", m_waveformWidgetHolders.size());

    // Do this in an extra slot to be sure to hit the desired interval
    if (!m_skipRender) {
        if (m_type) {   // no regular updates for an empty waveform
            // Show rendered buffer from last render() run
            //qDebug() << "swap() start" << m_vsyncThread->elapsed();
            for (int i = 0; i < m_waveformWidgetHolders.size(); i++) {
                WaveformWidgetAbstract* pWaveformWidget = m_waveformWidgetHolders[i].m_waveformWidget;
                if (pWaveformWidget->getWidth() > 0) {
                    QGLWidget* glw = dynamic_cast<QGLWidget*>(pWaveformWidget->getWidget());
                    // Don't swap invalid or invisible widgets. Prevents
                    // continuous log spew of "QOpenGLContext::swapBuffers()
                    // called with non-exposed window, behavior is undefined" on
                    // Qt5.
                    if (glw && glw->isValid() && glw->isVisible()) {
                        VSyncThread::swapGl(glw, i);
                    }
                }

                //qDebug() << "swap x" << m_vsyncThread->elapsed();
            }
        }
    }
    //qDebug() << "swap end" << m_vsyncThread->elapsed();
    m_vsyncThread->vsyncSlotFinished();
}
Esempio n. 4
0
string glinfo::
        pretty_format(const QGLWidget& w)
{
    stringstream s;

    s << "doubleBuffer=" <<  w.doubleBuffer() << endl
      << "isSharing=" <<  w.isSharing() << endl
      << "isValid=" <<  w.isValid() << endl
      << pretty_format( w.format() );

    return s.str();
}
Esempio n. 5
0
/*!
  Overridden from QGLWidget to render the scenegraph
*/
void QuarterWidget::paintEvent(QPaintEvent* event)
{
    std::clock_t begin = std::clock();

    if(!initialized) {
        glEnable(GL_DEPTH_TEST);
        this->getSoRenderManager()->reinitialize();
        initialized = true;
    }

    getSoRenderManager()->activate();

    glEnable(GL_DEPTH_TEST);
    glMatrixMode(GL_PROJECTION);

    QGLWidget* w = static_cast<QGLWidget*>(this->viewport());
    assert(w->isValid() && "No valid GL context found!");
    // We might have to process the delay queue here since we don't know
    // if paintGL() is called from Qt, and we might have some sensors
    // waiting to trigger (the redraw sensor has a lower priority than a
    // normal field sensor to guarantee that your sensor is processed
    // before the next redraw). Disable autorendering while we do this
    // to avoid recursive redraws.

    // We set the PRIVATE(this)->processdelayqueue = false in redraw()
    // to avoid processing the delay queue when paintGL() is triggered
    // by us, and we don't want to process the delay queue in those
    // cases

    PRIVATE(this)->autoredrawenabled = false;

    if(PRIVATE(this)->processdelayqueue && SoDB::getSensorManager()->isDelaySensorPending()) {
        // processing the sensors might trigger a redraw in another
        // context. Release this context temporarily
        w->doneCurrent();
        SoDB::getSensorManager()->processDelayQueue(false);
        w->makeCurrent();
    }

    assert(w->isValid() && "No valid GL context found!");

    glDrawBuffer(w->doubleBuffer() ? GL_BACK : GL_FRONT);

    w->makeCurrent();
    this->actualRedraw();

    //start the standard graphics view processing for all widgets and graphic items. As 
    //QGraphicsView initaliizes a QPainter which changes the Opengl context in an unpredictable 
    //manner we need to store the context and recreate it after Qt is done.
    glPushAttrib(GL_MULTISAMPLE_BIT_EXT);
    inherited::paintEvent(event);
    glPopAttrib();

    if (w->doubleBuffer()) { w->swapBuffers(); }

    PRIVATE(this)->autoredrawenabled = true;

    // process the delay queue the next time we enter this function,
    // unless we get here after a call to redraw().
    PRIVATE(this)->processdelayqueue = true;

    std::clock_t end = std::clock();
    renderTime = double(double(end-begin)/CLOCKS_PER_SEC)*1000.0;
}