Ejemplo n.º 1
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;
    }
}
Ejemplo n.º 2
0
void setSwapInterval(QGLWidget const &glWidget, int *interval)
{
	typedef int (WINAPI * PFNWGLGETSWAPINTERVALEXTPROC)(void);
	typedef BOOL (WINAPI * PFNWGLSWAPINTERVALEXTPROC)(int);
	PFNWGLGETSWAPINTERVALEXTPROC wglGetSwapIntervalEXT;
	PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT;
	QGLContext const &context = *glWidget.context();

	wglGetSwapIntervalEXT = (PFNWGLGETSWAPINTERVALEXTPROC) context.getProcAddress("wglGetSwapIntervalEXT");
	wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC) context.getProcAddress("wglSwapIntervalEXT");

	if (wglGetSwapIntervalEXT && wglSwapIntervalEXT)
	{
		if (*interval < 0)
		{
			*interval = 0;
		}
		wglSwapIntervalEXT(*interval);
		*interval = wglGetSwapIntervalEXT();
	}
	else
	{
		*interval = -1;
	}
}
Ejemplo n.º 3
0
bool checkOpenGL(){

    QGLWidget *glWidget = new QGLWidget;

    QGLContext* glContext = (QGLContext *) glWidget->context();
    GLCHK( glContext->makeCurrent() );

    qDebug() << "Running the " + QString(AWESOME_BUMP_VERSION);
    qDebug() << "Checking OpenGL version...";
    qDebug() << "Widget OpenGL: " << glContext->format().majorVersion() << "." << glContext->format().minorVersion() ;
    qDebug() << "Context valid: " << glContext->isValid() ;
    qDebug() << "OpenGL information: " ;
    qDebug() << "VENDOR: "       << (const char*)glGetString(GL_VENDOR) ;
    qDebug() << "RENDERER: "     << (const char*)glGetString(GL_RENDERER) ;
    qDebug() << "VERSION: "      << (const char*)glGetString(GL_VERSION) ;
    qDebug() << "GLSL VERSION: " << (const char*)glGetString(GL_SHADING_LANGUAGE_VERSION) ;

    float version = glContext->format().majorVersion() + 0.1 * glContext->format().minorVersion();

    delete glWidget;

    qDebug() << "Version:" << version;
    // check openGL version
    if( version < 4.0 )
    {
       qDebug() << "Error: AwesomeBump does not support openGL versions lower than 4.0 :(" ;
       return false;
    }
    return true;

}
Ejemplo n.º 4
0
QEglGLPixmapData::~QEglGLPixmapData()
{
    TRACE();

    QGLWidget *shareWidget = qt_gl_share_widget();
    if (!shareWidget)
        return;

    delete m_engine;

    if (m_fbo) {
        QGLShareContextScope ctx(shareWidget->context());
        glDeleteFramebuffers(1, &m_fbo);
    }

    if (m_texture.id) {
        QGLShareContextScope ctx(shareWidget->context());
        glDeleteTextures(1, &m_texture.id);
    }    
}
Ejemplo n.º 5
0
void QGLTexturePool::releaseTexture(QGLPixmapData *data, GLuint texture)
{
    // Very simple strategy at the moment: just destroy the texture.
    if (data)
        removeFromLRU(data);

    QGLWidget *shareWidget = qt_gl_share_widget();
    if (shareWidget) {
        QGLShareContextScope ctx(shareWidget->context());
        glDeleteTextures(1, &texture);
    }
}
QGLPixmapData::~QGLPixmapData()
{
    QGLWidget *shareWidget = qt_gl_share_widget();
    if (!shareWidget)
        return;

    delete m_engine;

    if (m_texture.id) {
        QGLShareContextScope ctx(shareWidget->context());
        glDeleteTextures(1, &m_texture.id);
    }
}
Ejemplo n.º 7
0
int main(int argc, char **argv)
{
    QApplication app(argc, argv);

    if ((QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_Version_1_5) == 0) {
        QMessageBox::critical(0, "OpenGL features missing",
            "OpenGL version 1.5 or higher is required to run this demo.\n"
            "The program will now exit.");
        return -1;
    }

    int maxTextureSize = 1024;
    QGLWidget *widget = new QGLWidget(QGLFormat(QGL::SampleBuffers));
    widget->makeCurrent();

    if (!necessaryExtensionsSupported()) {
        QMessageBox::critical(0, "OpenGL features missing",
            "The OpenGL extensions required to run this demo are missing.\n"
            "The program will now exit.");
        delete widget;
        return -2;
    }

    // Check if all the necessary functions are resolved.
    if (!getGLExtensionFunctions().resolve(widget->context())) {
        QMessageBox::critical(0, "OpenGL features missing",
            "Failed to resolve OpenGL functions required to run this demo.\n"
            "The program will now exit.");
        delete widget;
        return -3;
    }

    // TODO: Make conditional for final release
    QMessageBox::information(0, "For your information",
        "This demo can be GPU and CPU intensive and may\n"
        "work poorly or not at all on your system.");

    widget->makeCurrent(); // The current context must be set before calling Scene's constructor
    Scene scene(1024, 768, maxTextureSize);
    GraphicsView view;
    view.setViewport(widget);
    view.setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
    view.setScene(&scene);
    view.show();

    return app.exec();
}
Ejemplo n.º 8
0
bool checkOpenGL(){

    QGLWidget *glWidget = new QGLWidget;

    QGLContext* glContext = (QGLContext *) glWidget->context();
    GLCHK( glContext->makeCurrent() );

    qDebug() << "Running the " + QString(AWESOME_BUMP_VERSION);
    qDebug() << "Checking OpenGL version...";
    qDebug() << "Widget OpenGL:" << QString("%1.%2").arg(glContext->format().majorVersion()).arg(glContext->format().minorVersion());
    qDebug() << "Context valid:" << glContext->isValid() ;
    qDebug() << "OpenGL information:" ;
    qDebug() << "VENDOR:"       << (const char*)glGetString(GL_VENDOR) ;
    qDebug() << "RENDERER:"     << (const char*)glGetString(GL_RENDERER) ;
    qDebug() << "VERSION:"      << (const char*)glGetString(GL_VERSION) ;
    qDebug() << "GLSL VERSION:" << (const char*)glGetString(GL_SHADING_LANGUAGE_VERSION) ;

    float version = glContext->format().majorVersion() + 0.1 * glContext->format().minorVersion();
    Performance3DSettings::openGLVersion = version;
    #ifdef USE_OPENGL_330
        Performance3DSettings::openGLVersion = 3.3;
    #endif

    delete glWidget;

    qDebug() << "Version:" << version;

    #ifdef USE_OPENGL_330
        // check openGL version
        if( version < 3.3 )
        {
           qDebug() << "Error: This version of AwesomeBump does not support openGL versions lower than 3.3 :(" ;
           return false;
        }
    #else
        // check openGL version
        if( version < 4.0 )
        {
           qDebug() << "Error: AwesomeBump does not support openGL versions lower than 4.0 :(" ;
           return false;
        }
    #endif
    return true;

}
Ejemplo n.º 9
0
void QGLPixmapData::destroyTexture()
{
    if (inTexturePool) {
        QGLTexturePool *pool = QGLTexturePool::instance();
        if (m_texture.id)
            pool->releaseTexture(this, m_texture.id);
    } else {
        if (m_texture.id) {
            QGLWidget *shareWidget = qt_gl_share_widget();
            if (shareWidget) {
                QGLShareContextScope ctx(shareWidget->context());
                glDeleteTextures(1, &m_texture.id);
            }
        }
    }
    m_texture.id = 0;
    inTexturePool = false;

    releaseNativeImageHandle();
}
Ejemplo n.º 10
0
void MythOpenGLPainter::Begin(QPaintDevice *parent)
{
    MythPainter::Begin(parent);

    if (!realRender)
    {
        QGLWidget *glw = dynamic_cast<QGLWidget *>(realParent);
        if (!glw)
            glw = dynamic_cast<QGLWidget *>(parent);

        if (!glw)
        {
            LOG(VB_GENERAL, LOG_ERR,
                "FATAL ERROR: Failed to cast parent to QGLWidget");
            return;
        }

        realRender = (MythRenderOpenGL*)(glw->context());
        if (!realRender)
        {
            LOG(VB_GENERAL, LOG_ERR,
                "FATAL ERROR: Failed to get MythRenderOpenGL");
            return;
        }
    }

    DeleteTextures();
    realRender->makeCurrent();

    if (target || swapControl)
    {
        realRender->BindFramebuffer(target);
        realRender->SetViewPort(QRect(0, 0, realParent->width(), realParent->height()));
        realRender->SetColor(255, 255, 255, 255);
        realRender->SetBackground(0, 0, 0, 0);
        realRender->ClearFramebuffer();
    }
}
Ejemplo n.º 11
0
bool checkOpenGL(){

    QGLWidget *glWidget = new QGLWidget;

    QGLContext* glContext = (QGLContext *) glWidget->context();
    GLCHK( glContext->makeCurrent() );

    int glMajorVersion, glMinorVersion;

    glMajorVersion = glContext->format().majorVersion();
    glMinorVersion = glContext->format().minorVersion();

    qDebug() << "Running the " + QString(AWESOME_BUMP_VERSION);
    qDebug() << "Checking OpenGL version...";
    qDebug() << "Widget OpenGL:" << QString("%1.%2").arg(glMajorVersion).arg(glMinorVersion);
    qDebug() << "Context valid:" << glContext->isValid() ;
    qDebug() << "OpenGL information:" ;
    qDebug() << "VENDOR:"       << (const char*)glGetString(GL_VENDOR) ;
    qDebug() << "RENDERER:"     << (const char*)glGetString(GL_RENDERER) ;
    qDebug() << "VERSION:"      << (const char*)glGetString(GL_VERSION) ;
    qDebug() << "GLSL VERSION:" << (const char*)glGetString(GL_SHADING_LANGUAGE_VERSION) ;

    Display3DSettings::openGLVersion = GL_MAJOR + (GL_MINOR * 0.1);

    delete glWidget;

    qDebug() << QString("Version: %1.%2").arg(glMajorVersion).arg(glMinorVersion);

    // check openGL version
    if( glMajorVersion < GL_MAJOR || (glMajorVersion == GL_MAJOR && glMinorVersion < GL_MINOR))
    {

        qDebug() << QString("Error: This version of AwesomeBump does not support openGL versions lower than %1.%2 :(").arg(GL_MAJOR).arg(GL_MINOR) ;
           return false;
    }
    return true;

}
Ejemplo n.º 12
0
	//! Set the default painter to use when not drawing to FBO.
	//!
	//! This is the only place where we might be getting a painter from outside world,
	//! so we require that it uses a GL or GL2 paint engine.
	//!
	//! @param painter Painter to set.
	//! @param context GL context used by the renderer, for error checking.
	void setDefaultPainter(QPainter* const painter, const QGLContext* const context)
	{
		invariant();

#ifndef NDEBUG
		if(NULL != painter)
		{
			Q_ASSERT_X(painter->paintEngine()->type() == QPaintEngine::OpenGL ||
			           painter->paintEngine()->type() == QPaintEngine::OpenGL2,
			           Q_FUNC_INFO, 
			           "QGL StelRenderer backends need a QGLWidget to be set as the "
			           "viewport on the graphics view");
			QGLWidget* widget = dynamic_cast<QGLWidget*>(painter->device());
			Q_ASSERT_X(NULL != widget && widget->context() == context, Q_FUNC_INFO,
			           "Painter used with QGL StelRenderer backends needs to paint on a QGLWidget "
			           "with the same GL context as the one used by the renderer");
		}
#else
		Q_UNUSED(context);
#endif

		defaultPainter = painter;
		invariant();
	}
Ejemplo n.º 13
0
WaveformWidgetFactory::WaveformWidgetFactory() :
        m_type(WaveformWidgetType::Count_WaveformwidgetType),
        m_config(0),
        m_skipRender(false),
        m_frameRate(30),
        m_defaultZoom(3),
        m_zoomSync(false),
        m_overviewNormalized(false),
        m_openGLAvailable(false),
        m_openGLShaderAvailable(false),
        m_vsyncThread(NULL),
        m_frameCnt(0),
        m_actualFrameRate(0) {

    m_visualGain[All] = 1.5;
    m_visualGain[Low] = 1.0;
    m_visualGain[Mid] = 1.0;
    m_visualGain[High] = 1.0;

    if (QGLFormat::hasOpenGL()) {
        QGLFormat glFormat;
        glFormat.setDirectRendering(true);
        glFormat.setDoubleBuffer(true);
        glFormat.setDepth(false);
        // Disable waiting for vertical Sync
        // This can be enabled when using a single Threads for each QGLContext
        // Setting 1 causes QGLContext::swapBuffer to sleep until the next VSync
#if defined(__APPLE__)
        // On OS X, syncing to vsync has good performance FPS-wise and
        // eliminates tearing.
        glFormat.setSwapInterval(1);
#else
        // Otherwise, turn VSync off because it could cause horrible FPS on
        // Linux.
        // TODO(XXX): Make this configurable.
        // TOOD(XXX): What should we do on Windows?
        glFormat.setSwapInterval(0);
#endif


        glFormat.setRgba(true);
        QGLFormat::setDefaultFormat(glFormat);

        QGLFormat::OpenGLVersionFlags version = QGLFormat::openGLVersionFlags();

        int majorVersion = 0;
        int minorVersion = 0;
        if (version == QGLFormat::OpenGL_Version_None) {
            m_openGLVersion = "None";
        } else if (version & QGLFormat::OpenGL_Version_3_0) {
            majorVersion = 3;
        } else if (version & QGLFormat::OpenGL_Version_2_1) {
            majorVersion = 2;
            minorVersion = 1;
        } else if (version & QGLFormat::OpenGL_Version_2_0) {
            majorVersion = 2;
            minorVersion = 0;
        } else if (version & QGLFormat::OpenGL_Version_1_5) {
            majorVersion = 1;
            minorVersion = 5;
        } else if (version & QGLFormat::OpenGL_Version_1_4) {
            majorVersion = 1;
            minorVersion = 4;
        } else if (version & QGLFormat::OpenGL_Version_1_3) {
            majorVersion = 1;
            minorVersion = 3;
        } else if (version & QGLFormat::OpenGL_Version_1_2) {
            majorVersion = 1;
            minorVersion = 2;
        } else if (version & QGLFormat::OpenGL_Version_1_1) {
            majorVersion = 1;
            minorVersion = 1;
        }

        if (majorVersion != 0) {
            m_openGLVersion = QString::number(majorVersion) + "." +
                    QString::number(minorVersion);
        }

        m_openGLAvailable = true;

        QGLWidget* glWidget = new QGLWidget(); // create paint device
        // QGLShaderProgram::hasOpenGLShaderPrograms(); valgind error
        m_openGLShaderAvailable = QGLShaderProgram::hasOpenGLShaderPrograms(glWidget->context());
        delete glWidget;
    }

    evaluateWidgets();
    m_time.start();
}
Ejemplo n.º 14
0
void setSwapInterval(QGLWidget const &glWidget, int *interval)
{
	typedef void (* PFNGLXQUERYDRAWABLEPROC)(Display *, GLXDrawable, int, unsigned int *);
	typedef void (* PFNGLXSWAPINTERVALEXTPROC)(Display *, GLXDrawable, int);
	typedef int (* PFNGLXGETSWAPINTERVALMESAPROC)(void);
	typedef int (* PFNGLXSWAPINTERVALMESAPROC)(unsigned);
	typedef int (* PFNGLXSWAPINTERVALSGIPROC)(int);
	PFNGLXSWAPINTERVALEXTPROC glXSwapIntervalEXT;
	PFNGLXQUERYDRAWABLEPROC glXQueryDrawable;
	PFNGLXGETSWAPINTERVALMESAPROC glXGetSwapIntervalMESA;
	PFNGLXSWAPINTERVALMESAPROC glXSwapIntervalMESA;
	PFNGLXSWAPINTERVALSGIPROC glXSwapIntervalSGI;
	QGLContext const &context = *glWidget.context();
	QX11Info const &xinfo = glWidget.x11Info();

	glXSwapIntervalEXT = (PFNGLXSWAPINTERVALEXTPROC) context.getProcAddress("glXSwapIntervalEXT");
	glXQueryDrawable = (PFNGLXQUERYDRAWABLEPROC) context.getProcAddress("glXQueryDrawable");
	if (glXSwapIntervalEXT && glXQueryDrawable)
	{
		unsigned clampedInterval;
		if (*interval < 0)
		{
			*interval = 0;
		}
		glXSwapIntervalEXT(xinfo.display(), glWidget.winId(), *interval);
		glXQueryDrawable(xinfo.display(), glWidget.winId(), GLX_SWAP_INTERVAL_EXT, &clampedInterval);
		*interval = clampedInterval;
		return;
	}

	glXSwapIntervalMESA = (PFNGLXSWAPINTERVALMESAPROC) context.getProcAddress("glXSwapIntervalMESA");
	glXGetSwapIntervalMESA = (PFNGLXGETSWAPINTERVALMESAPROC) context.getProcAddress("glXGetSwapIntervalMESA");
	if (glXSwapIntervalMESA && glXGetSwapIntervalMESA)
	{
		if (*interval < 0)
		{
			*interval = 0;
		}
		glXSwapIntervalMESA(*interval);
		*interval = glXGetSwapIntervalMESA();
		return;
	}

	glXSwapIntervalSGI = (PFNGLXSWAPINTERVALSGIPROC) context.getProcAddress("glXSwapIntervalSGI");
	if (glXSwapIntervalSGI)
	{
		if (*interval < 1)
		{
			*interval = 1;
		}
		if (glXSwapIntervalSGI(*interval))
		{
			// Error, revert to default
			*interval = 1;
			glXSwapIntervalSGI(1);
		}
		return;
	}

	*interval = -1;
}
Ejemplo n.º 15
0
static void createGLSurface (QString qmlName, QDeclarativeView * view) {
  QmlPainterVideoSurface * timelineSurface = new QmlPainterVideoSurface;
  QGLWidget * g = (QGLWidget *) view->viewport();
  timelineSurface->setGLContext((QGLContext *) g->context());
  view->rootContext()->setContextProperty(qmlName, timelineSurface);
}
Ejemplo n.º 16
0
void Layer::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
                  QWidget *widget)
{
  QtPainter *qvpainter = NULL;
#ifdef QT_OPENGL_LIB
  QPainter *fboPainter;
  QGLFramebufferObject *fbo = NULL;
  QGLWidget *qglWidget = qobject_cast<QGLWidget *>(widget);
  if (qglWidget) { // on-screen OpenGL
    QGLContext *context = const_cast<QGLContext *>(qglWidget->context());
    qvpainter = new OpenGLPainter(painter, context);
  } else if (cacheMode() != QGraphicsItem::NoCache &&
             QGLFramebufferObject::hasOpenGLFramebufferObjects()) {
    // caching, try FBO
    // if we have direct rendering and FBO support, make use of
    // FBO, but this could still just be in software

    // NOTE: In Qt 4.6, 'painter' would already target an FBO, if we
    // were using the 'OpenGL2' paint engine. We have decided to stick
    // with the original engine for now, as the OpenGL2 engine relies
    // heavily on shaders, which is slow for our use case.
    
    // Apparently, we must use the QGLContext associated with
    // the view being painted. Thus, PlotView tracks whether it is
    // inside a paintEvent, so we can get the current QGLWidget.
    OverlayScene *overlayScene = qobject_cast<OverlayScene *>(scene());
    if (overlayScene)
      qglWidget = qobject_cast<QGLWidget *>(overlayScene->view()->viewport());
    else {
      QList<QGraphicsView *> views = scene()->views();
      for (int i = 0; i < views.size() && !qglWidget; i++) {
        PlotView *view = qobject_cast<PlotView *>(views[i]);
        if (view && view->isPainting())
          qglWidget = qobject_cast<QGLWidget *>(view->viewport());
      }
    }
    if (qglWidget) {
      QSize size(painter->device()->width(), painter->device()->height());
      QGLContext *context = const_cast<QGLContext *>(qglWidget->context());
      // GC during paint callback may have reset this
      if (qglWidget->context() != QGLContext::currentContext())
        qglWidget->makeCurrent();
      // NOTE: need Qt 4.6 for antialiasing to work with FBOs
#if QT_VERSION >= 0x40600
      if (!fboMultisamplingFailed) {
        QGLFramebufferObjectFormat fboFormat;
        fboFormat.setAttachment(QGLFramebufferObject::CombinedDepthStencil);
        fboFormat.setSamples(4); // 4X antialiasing should be enough?
        qInstallMsgHandler(fboDebugMsgCatcher);
        fbo = new QGLFramebufferObject(size, fboFormat);
        qInstallMsgHandler(0);
        if (fboMultisamplingFailed) {
          delete fbo;
          fbo = NULL;
        }
      }
#endif
      if (!fbo)
        fbo = new QGLFramebufferObject(size);
      // clear the FBO
      fboPainter = new QPainter(fbo);
      fboPainter->setCompositionMode(QPainter::CompositionMode_Source);
      fboPainter->fillRect(0, 0, size.width(), size.height(), Qt::transparent);
      fboPainter->setCompositionMode(QPainter::CompositionMode_SourceOver);
      qvpainter = new OpenGLPainter(fboPainter, context);
      qvpainter->setTransform(painter->worldTransform());
    }
  }
#endif
  
  if (!qvpainter) // fallback to Qt renderer
    qvpainter = new QtPainter(painter);

  // NOTE: in QT 4.6 exposedRect will just be the bounding rect, by default
  paintPlot(qvpainter, option->exposedRect);

  delete qvpainter;
#ifdef QT_OPENGL_LIB
  if (fbo) { // silliness: download to image, only to upload to texture
    painter->setWorldMatrixEnabled(false);
    qglWidget->makeCurrent(); // gc during callback may have cleared this
    // need to tell Qt that 'fboImage' is actually premultiplied
    QImage fboImage = fbo->toImage();
    const uchar *data = fboImage.bits(); // no deep copy
    QImage premultImage = QImage(data,
                                 fboImage.width(),
                                 fboImage.height(),
                                 QImage::Format_ARGB32_Premultiplied);
    // Not sure why this can't be (0, 0)...
    painter->drawImage(QPointF(1, -1), premultImage);
    delete fboPainter;
    delete fbo;
  }
#endif
}