Example #1
0
MythRenderOpenGL* MythRenderOpenGL::Create(const QString &painter,
                                           QPaintDevice* device)
{
    QGLFormat format;
    format.setDepth(false);

#if defined(Q_WS_MAC)
    format.setSwapInterval(1);
#endif

#ifdef USING_OPENGLES
    if (device)
        return new MythRenderOpenGL2ES(format, device);
    return new MythRenderOpenGL2ES(format);
#else
    if (painter.contains("opengl2"))
    {
        if (device)
            return new MythRenderOpenGL2(format, device);
        return new MythRenderOpenGL2(format);
    }
    if (device)
        return new MythRenderOpenGL1(format, device);
    return new MythRenderOpenGL1(format);

#endif
}
Example #2
0
QT_BEGIN_NAMESPACE

QGLFormat QGLFormat::fromPlatformWindowFormat(const QPlatformWindowFormat &format)
{
    QGLFormat retFormat;
    retFormat.setAccum(format.accum());
    if (format.accumBufferSize() >= 0)
        retFormat.setAccumBufferSize(format.accumBufferSize());
    retFormat.setAlpha(format.alpha());
    if (format.alphaBufferSize() >= 0)
        retFormat.setAlphaBufferSize(format.alphaBufferSize());
    if (format.blueBufferSize() >= 0)
        retFormat.setBlueBufferSize(format.blueBufferSize());
    retFormat.setDepth(format.depth());
    if (format.depthBufferSize() >= 0)
        retFormat.setDepthBufferSize(format.depthBufferSize());
    retFormat.setDirectRendering(format.directRendering());
    retFormat.setDoubleBuffer(format.doubleBuffer());
    if (format.greenBufferSize() >= 0)
        retFormat.setGreenBufferSize(format.greenBufferSize());
    if (format.redBufferSize() >= 0)
        retFormat.setRedBufferSize(format.redBufferSize());
    retFormat.setRgba(format.rgba());
    retFormat.setSampleBuffers(format.sampleBuffers());
    retFormat.setSamples(format.sampleBuffers());
    retFormat.setStencil(format.stencil());
    if (format.stencilBufferSize() >= 0)
        retFormat.setStencilBufferSize(format.stencilBufferSize());
    retFormat.setStereo(format.stereo());
    retFormat.setSwapInterval(format.swapInterval());
    return retFormat;
}
Example #3
0
/*===========================================================================*/
void ScreenBase::create()
{
    KVS_ASSERT( m_id == -1 );

    // Initialize display mode.
    QGLFormat f = QGLFormat::defaultFormat();
    f.setDoubleBuffer( displayFormat().doubleBuffer() );
    f.setRgba( displayFormat().colorBuffer() );
    f.setDepth( displayFormat().depthBuffer() );
    f.setAccum( displayFormat().accumulationBuffer() );
    f.setStencil( displayFormat().stencilBuffer() );
    f.setStereo( displayFormat().stereoBuffer() );
    f.setSampleBuffers( displayFormat().multisampleBuffer() );
    f.setAlpha( displayFormat().alphaChannel() );
    QGLFormat::setDefaultFormat( f );

    // Set screen geometry.
    QWidget::setGeometry( BaseClass::x(), BaseClass::y(), BaseClass::width(), BaseClass::height() );

    QGLWidget::makeCurrent();

    // Initialize GLEW.
    GLenum result = glewInit();
    if ( result != GLEW_OK )
    {
        const GLubyte* message = glewGetErrorString( result );
        kvsMessageError( "GLEW initialization failed: %s.", message );
    }

    // Create window.
    static int counter = 0;
    m_id = counter++;
}
Example #4
0
void *QGLContext::chooseVisual()
{
    static int bufDepths[] = { 8, 4, 2, 1 };	// Try 16, 12 also?
    //todo: if pixmap, also make sure that vi->depth == pixmap->depth
    void* vis = 0;
    int i = 0;
    bool fail = FALSE;
    QGLFormat fmt = format();
    bool tryDouble = !fmt.doubleBuffer();  // Some GL impl's only have double
    bool triedDouble = FALSE;
    while( !fail && !( vis = tryVisual( fmt, bufDepths[i] ) ) ) {
	if ( !fmt.rgba() && bufDepths[i] > 1 ) {
	    i++;
	    continue;
	}
	if ( tryDouble ) {
	    fmt.setDoubleBuffer( TRUE );
	    tryDouble = FALSE;
	    triedDouble = TRUE;
	    continue;
	}
	else if ( triedDouble ) {
	    fmt.setDoubleBuffer( FALSE );
	    triedDouble = FALSE;
	}
	if ( fmt.stereo() ) {
	    fmt.setStereo( FALSE );
	    continue;
	}
	if ( fmt.accum() ) {
	    fmt.setAccum( FALSE );
	    continue;
	}
	if ( fmt.stencil() ) {
	    fmt.setStencil( FALSE );
	    continue;
	}
	if ( fmt.alpha() ) {
	    fmt.setAlpha( FALSE );
	    continue;
	}
	if ( fmt.depth() ) {
	    fmt.setDepth( FALSE );
	    continue;
	}
	if ( fmt.doubleBuffer() ) {
	    fmt.setDoubleBuffer( FALSE );
	    continue;
	}
	fail = TRUE;
    }
    glFormat = fmt;
    return vis;
}
QGLFormat QtCanvas::getQGLFormat(const Buffers buffers) {
    QGLFormat format = QGLFormat();
    format.setAlpha(buffers & GLCanvas::ALPHA_BUFFER);
    format.setDepth(buffers & GLCanvas::DEPTH_BUFFER);
    format.setDoubleBuffer(buffers & GLCanvas::DOUBLE_BUFFER);
    format.setStencil(buffers & GLCanvas::STENCIL_BUFFER);
    format.setAccum(buffers & GLCanvas::ACCUM_BUFFER);
    format.setStereo(buffers & GLCanvas::STEREO_VIEWING);
    format.setSampleBuffers(buffers & GLCanvas::MULTISAMPLING);

    return format;
}
Example #6
0
void XyzWindow::CreateXYZView()
{
	QFrame *XyFrame;
	QFrame *XzFrame;
	QFrame *ZyFrame;
	QWidget *centralWidget;
	
	centralWidget = new QWidget(this);
	QPalette palette;
	palette.setColor(QPalette::Background , QColor(/*200,200,200*/167, 210, 200));
	centralWidget->setAutoFillBackground(true);
	centralWidget->setPalette(palette);
	
	XzFrame = new QFrame(centralWidget);
	XzFrame->setGeometry(QRect(mXorigin1,mYorigin1 , mx+2*FRAM_BORDER , mz+2*FRAM_BORDER));
	XzFrame->setFrameShape(QFrame::StyledPanel);
	XzFrame->setFrameShadow(QFrame::Raised);
	ZyFrame = new QFrame(centralWidget);
	ZyFrame->setGeometry(QRect(mXorigin2 , mYorigin2 , mz+2*FRAM_BORDER ,my+2*FRAM_BORDER));
	ZyFrame->setFrameShape(QFrame::StyledPanel);
	ZyFrame->setFrameShadow(QFrame::Raised);
	XyFrame = new QFrame(centralWidget);
	XyFrame->setGeometry(QRect(mXorigin1 , mYorigin2 , mx+2*FRAM_BORDER  ,my+2*FRAM_BORDER));
	XyFrame->setFrameShape(QFrame::StyledPanel);
	XyFrame->setFrameShadow(QFrame::Raised);
	
	
	palette.setColor(QPalette::Background , QColor(255,0,0));
	XzFrame->setAutoFillBackground(true);
	XzFrame->setPalette(palette);
	ZyFrame->setAutoFillBackground(true);
	ZyFrame->setPalette(palette);
	XyFrame->setAutoFillBackground(true);
	XyFrame->setPalette(palette);
	setCentralWidget(centralWidget);
	
	QGLFormat glFormat;
	glFormat.setRgba(true);
	glFormat.setDoubleBuffer(true);
	glFormat.setDepth(true);
	mXY_GLw = new XyzGL(glFormat , XY_VIEW , XyFrame , this);
	mXY_GLw->setGeometry(FRAM_BORDER , FRAM_BORDER,mx,my);
	mXY_GLw->setAttribute(Qt::WA_DeleteOnClose);
	
	mXZ_GLw = new XyzGL(glFormat , XZ_VIEW , XzFrame , this);
	mXZ_GLw->setGeometry(FRAM_BORDER , FRAM_BORDER , mx ,mz);
	mXZ_GLw->setAttribute(Qt::WA_DeleteOnClose);
	
	mYZ_GLw = new XyzGL(glFormat , ZY_VIEW , ZyFrame , this);
	mYZ_GLw->setGeometry(FRAM_BORDER , FRAM_BORDER ,mz ,my);
	mYZ_GLw->setAttribute(Qt::WA_DeleteOnClose);
}
Example #7
0
static QGLFormat& getDesiredGLFormat() {
    // Specify an OpenGL 3.3 format using the Core profile.
    // That is, no old-school fixed pipeline functionality
    static QGLFormat glFormat;
    static std::once_flag once;
    std::call_once(once, [] {
        glFormat.setVersion(4, 1);
        glFormat.setProfile(QGLFormat::CoreProfile); // Requires >=Qt-4.8.0
        glFormat.setSampleBuffers(false);
        glFormat.setDepth(false);
        glFormat.setStencil(false);
    });
    return glFormat;
}
Example #8
0
bool VideoOutputOpenGL::SetupContext(void)
{
    QMutexLocker locker(&gl_context_lock);

    if (gl_context)
    {
        VERBOSE(VB_PLAYBACK, LOC + QString("Re-using context"));
        return true;
    }

    MythMainWindow* win = MythMainWindow::getMainWindow();
    if (!win)
    {
        VERBOSE(VB_IMPORTANT, LOC_ERR + "Failed to get MythMainWindow");
        return false;
    }

    //gl_context = dynamic_cast<MythRenderOpenGL*>(win->GetRenderDevice());
    if (gl_context)
    {
        gl_context->UpRef();
        VERBOSE(VB_PLAYBACK, LOC + "Using main UI render context");
        return true;
    }

    QGLFormat fmt;
    fmt.setDepth(false);

    QGLWidget *device = (QGLWidget*)QWidget::find(gl_parent_win);
    if (!device)
    {
        VERBOSE(VB_IMPORTANT, LOC_ERR + "Failed to cast parent to QGLWidget");
        return false;
    }

    gl_context = MythRenderOpenGL::Create(fmt, device);
    if (gl_context && gl_context->create())
    {
        gl_context->Init();
        VERBOSE(VB_GENERAL, LOC + QString("Created MythRenderOpenGL device."));
        return true;
    }

    VERBOSE(VB_IMPORTANT, LOC_ERR + "Failed to create MythRenderOpenGL device.");
    if (gl_context)
        gl_context->DownRef();
    gl_context = NULL;
    return false;
}
Example #9
0
File: main.cpp Project: akva2/BSGUI
int main(int argc, char **argv)
{
    QGLFormat fmt;
    fmt.setRgba(true);
    fmt.setAlpha(true);
    fmt.setDepth(true);
    fmt.setDoubleBuffer(true);
    QGLFormat::setDefaultFormat(fmt);

    QApplication app(argc, argv);

    MainWindow window;
    window.showMaximized();

    for (int i = 1; i < argc; i++)
        window.objectSet()->loadFile(argv[i]);

    return app.exec();
}
Example #10
0
void MapView::setUseOpenGL(bool useOpenGL)
{
#ifndef QT_NO_OPENGL
    if (useOpenGL && QGLFormat::hasOpenGL()) {
        if (!qobject_cast<QGLWidget*>(viewport())) {
            QGLFormat format = QGLFormat::defaultFormat();
            format.setDepth(false); // No need for a depth buffer
            format.setSampleBuffers(true); // Enable anti-aliasing
            setViewport(new QGLWidget(format));
        }
    } else {
        if (qobject_cast<QGLWidget*>(viewport()))
            setViewport(0);
    }

    QWidget *v = viewport();
    v->setAttribute(Qt::WA_StaticContents);
    v->setMouseTracking(true);
#endif
}
Example #11
0
void ConfigManager::Initialize() {
    QGLFormat glf = QGLFormat::defaultFormat();
    glf.setRedBufferSize(8);
    glf.setGreenBufferSize(8);
    glf.setBlueBufferSize(8);
    glf.setAlphaBufferSize(8);
    glf.setSampleBuffers(true);
    glf.setSamples(8);
    glf.setDepth(true);
    glf.setDepthBufferSize(24);
    glf.setVersion(3, 3);
    glf.setProfile(QGLFormat::CompatibilityProfile);
    glf.setSwapInterval(1);
    QGLFormat::setDefaultFormat(glf);

    input_state_ = InputState::SELECT;
    snap_to_grid_ = true;
    grid_minor_color_ = QColor(175, 175, 175);
    grid_major_color_ = QColor(75, 75, 75);
}
Example #12
0
void MapView::setUseOpenGL(bool useOpenGL)
{
#ifndef QT_NO_OPENGL
#if QT_VERSION >= 0x050400
    if (useOpenGL) {
        if (!qobject_cast<QOpenGLWidget*>(viewport())) {
            QSurfaceFormat format = QSurfaceFormat::defaultFormat();
            format.setDepthBufferSize(0);   // No need for a depth buffer
            format.setSamples(4);           // Enable anti-aliasing

            QOpenGLWidget *openGLWidget = new QOpenGLWidget(this);
            openGLWidget->setFormat(format);
            setViewport(openGLWidget);
        }
    } else {
        if (qobject_cast<QOpenGLWidget*>(viewport()))
            setViewport(nullptr);
    }
#else
    if (useOpenGL && QGLFormat::hasOpenGL()) {
        if (!qobject_cast<QGLWidget*>(viewport())) {
            QGLFormat format = QGLFormat::defaultFormat();
            format.setDepth(false);         // No need for a depth buffer
            format.setSampleBuffers(true);  // Enable anti-aliasing
            setViewport(new QGLWidget(format));
        }
    } else {
        if (qobject_cast<QGLWidget*>(viewport()))
            setViewport(nullptr);
    }
#endif

    QWidget *v = viewport();
    if (mMode == StaticContents)
        v->setAttribute(Qt::WA_StaticContents);
    v->setMouseTracking(true);
#else
    Q_UNUSED(useOpenGL)
#endif
}
Example #13
0
    void GridsPlugin::initDockWidget()
    {
        // create and add doc widget
        _dock_widget = new QDockWidget(QObject::tr("Grid Viewer"));
        _dock_widget->setAllowedAreas(Qt::RightDockWidgetArea);
        _dock_widget->setObjectName("gridViewerDock");

        QGLFormat format;
        format.setVersion(2, 1);
        format.setDoubleBuffer(true);
        format.setDepth(true);
        format.setRgba(true);
        format.setAlpha(false);
        format.setAccum(false);
        format.setStencil(false);
        format.setStereo(false);
        format.setDirectRendering(true);
        format.setOverlay(false);

        _viewer = new GridViewer(format);
        _viewer->setMinimumSize(250, 0);
        _viewer->setObjectName("gridViewer");

        QVBoxLayout *layout = new QVBoxLayout();
        layout->addWidget(_viewer);

        QWidget *widget = new QWidget();
        widget->setLayout(layout);

        _dock_widget->setWidget(widget);

        NeuroGui::MainWindow::instance()->addDockWidget(Qt::RightDockWidgetArea, _dock_widget);

        // add to view menu
        NeuroGui::MainWindow::instance()->toolBarsMenu()->addAction(_dock_widget->toggleViewAction());
    }
Example #14
0
void System::initializeGL()
{
	// We will destroy and rebuild it with the chosen OpenGL format in the end, but we need to have a valid current OpenGL
	// context for calling some of the methods below.
	//sharedWidget = new QGLWidget;
	//sharedWidget->makeCurrent();

	struct _GLVersion
	{
		unsigned int majorVer;
		unsigned int minorVer;
	};

	// Array of all the OpenGL versions that gtatools-gui might work with. We will try to build a context with the first entry
	// in this array, and if that fails, we go on trying the next one and so on.
	_GLVersion glVersionsToTry[] = {
			{ 4, 3 },
			{ 4, 2 },
			{ 4, 1 },
			{ 4, 0 },
			{ 3, 3 },
			{ 3, 2 },
			{ 3, 1 },
			{ 3, 0 }
	};

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

	QGLFormat defaultGlFormat;
	defaultGlFormat.setDoubleBuffer(true);
	defaultGlFormat.setDirectRendering(true);
	defaultGlFormat.setDepth(true);
	defaultGlFormat.setAlpha(true);

	// NOTE: This line is VERY important. GLEW (tested with version 1.11) does not work with OpenGL 3.2+ Core Contexts,
	// apparently because it calls glGetString(GL_EXTENSIONS), which is deprecated and therefore returns an error on the
	// Core profile, which makes GLEW fail at basically everything.
	// This issue is described in http://www.opengl.org/wiki/OpenGL_Loading_Library. Quote:
	//
	// 		"GLEW has a problem with core contexts. It calls glGetString(GL_EXTENSIONS), which causes GL_INVALID_ENUM on GL
	//		 3.2+ core context as soon as glewInit() is called. It also doesn't fetch the function pointers. The solution
	//		 is for GLEW to use glGetStringi instead. The current version of GLEW is 1.10.0 but they still haven't corrected
	// 		 it. The only fix is to use glewExperimental for now"
	//
	// Instead of using glewExperimental, we simply use the compatibility profile (which is probably a good idea in general,
	// god knows how many "deprecated" (-> compatibility!) features I use in libgta that might fail with a core context...
	defaultGlFormat.setProfile(QGLFormat::CompatibilityProfile);

	int majorVer = 0;
	int minorVer = 0;
	bool foundMatching = false;

	for (size_t i = 0 ; i < sizeof(glVersionsToTry)/sizeof(_GLVersion) ; i++) {
		_GLVersion ver = glVersionsToTry[i];

		defaultGlFormat.setVersion(ver.majorVer, ver.minorVer);

		sharedWidget = new QGLWidget(defaultGlFormat);
		sharedWidget->makeCurrent();

		majorVer = sharedWidget->format().majorVersion();
		minorVer = sharedWidget->format().minorVersion();

		if (majorVer > ver.majorVer  ||  (majorVer == ver.majorVer  &&  minorVer >= ver.minorVer)) {
			foundMatching = true;
			break;
		} else {
			delete sharedWidget;
		}
	}

	if (!foundMatching) {
		fprintf(stderr, "ERROR: OpenGL >= 3.0 seems to be unsupported on the system. gtatools-gui will need at least OpenGL "
				"3.0 to work correctly!\n");
	}

	printf("Using OpenGL version %d.%d\n", majorVer, minorVer);

	QGLFormat::setDefaultFormat(defaultGlFormat);
}
Example #15
0
QGLGraphicsSystem::QGLGraphicsSystem(bool useX11GL)
    : QGraphicsSystem(), m_useX11GL(useX11GL)
{
#if defined(Q_WS_X11) && !defined(QT_OPENGL_ES)
    // only override the system defaults if the user hasn't already
    // picked a visual
    if (X11->visual == 0 && X11->visual_id == -1 && X11->visual_class == -1) {
        // find a double buffered, RGBA visual that supports OpenGL
        // and set that as the default visual for windows in Qt
        int i = 0;
        int spec[16];
        spec[i++] = GLX_RGBA;
        spec[i++] = GLX_DOUBLEBUFFER;

        if (!qgetenv("QT_GL_SWAPBUFFER_PRESERVE").isNull()) {
            spec[i++] = GLX_DEPTH_SIZE;
            spec[i++] = 8;
            spec[i++] = GLX_STENCIL_SIZE;
            spec[i++] = 8;
            spec[i++] = GLX_SAMPLE_BUFFERS_ARB;
            spec[i++] = 1;
            spec[i++] = GLX_SAMPLES_ARB;
            spec[i++] = 4;
        }

        spec[i++] = XNone;

        XVisualInfo *vi = glXChooseVisual(X11->display, X11->defaultScreen, spec);
        if (vi) {
            X11->visual_id = vi->visualid;
            X11->visual_class = vi->c_class;

            QGLFormat format;
            int res;
            glXGetConfig(X11->display, vi, GLX_LEVEL, &res);
            format.setPlane(res);
            glXGetConfig(X11->display, vi, GLX_DOUBLEBUFFER, &res);
            format.setDoubleBuffer(res);
            glXGetConfig(X11->display, vi, GLX_DEPTH_SIZE, &res);
            format.setDepth(res);
            if (format.depth())
                format.setDepthBufferSize(res);
            glXGetConfig(X11->display, vi, GLX_RGBA, &res);
            format.setRgba(res);
            glXGetConfig(X11->display, vi, GLX_RED_SIZE, &res);
            format.setRedBufferSize(res);
            glXGetConfig(X11->display, vi, GLX_GREEN_SIZE, &res);
            format.setGreenBufferSize(res);
            glXGetConfig(X11->display, vi, GLX_BLUE_SIZE, &res);
            format.setBlueBufferSize(res);
            glXGetConfig(X11->display, vi, GLX_ALPHA_SIZE, &res);
            format.setAlpha(res);
            if (format.alpha())
                format.setAlphaBufferSize(res);
            glXGetConfig(X11->display, vi, GLX_ACCUM_RED_SIZE, &res);
            format.setAccum(res);
            if (format.accum())
                format.setAccumBufferSize(res);
            glXGetConfig(X11->display, vi, GLX_STENCIL_SIZE, &res);
            format.setStencil(res);
            if (format.stencil())
                format.setStencilBufferSize(res);
            glXGetConfig(X11->display, vi, GLX_STEREO, &res);
            format.setStereo(res);
            glXGetConfig(X11->display, vi, GLX_SAMPLE_BUFFERS_ARB, &res);
            format.setSampleBuffers(res);
            if (format.sampleBuffers()) {
                glXGetConfig(X11->display, vi, GLX_SAMPLES_ARB, &res);
                format.setSamples(res);
            }

            QGLWindowSurface::surfaceFormat = format;
            XFree(vi);

            printf("using visual class %x, id %x\n", X11->visual_class, X11->visual_id);
        }
    }
#elif defined(Q_WS_WIN)
    QGLWindowSurface::surfaceFormat.setDoubleBuffer(true);

    qt_win_owndc_required = true;
#endif
}
Example #16
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();
}
Example #17
0
CubeWidget::CubeWidget(const QString &name, int pos)
        : ModuleWidget(name, pos)
{
    m_active = false;
    m_varsCount = 0;
    m_cube = Kernel::instance()->getCube();

    // OpenGL format
    QGLFormat fmt;
    fmt.setDepth(true);
    fmt.setAlpha(true);

    // drawer
    m_drawer = new CubeGLDrawer(fmt);
    m_gm = GUIManager::instance();
    // changing one term in drawer
    connect(m_drawer, SIGNAL(cubeChanged(int, OutputValue &)),
            m_gm, SLOT(setTerm(int, OutputValue &)));
    // minimizing formula from drawer
    connect(m_drawer, SIGNAL(minRequested()), m_gm, SLOT(minimizeFormula()));

    // creating new formula
    connect(m_gm, SIGNAL(formulaChanged()), m_drawer, SLOT(reloadCube()));
    connect(m_gm, SIGNAL(formulaChanged()), this, SLOT(updateData()));
    connect(m_gm, SIGNAL(minimalFormulaChanged()), this, SLOT(updateData()));
    connect(m_gm, SIGNAL(minimalFormulaChanged()), m_drawer, SLOT(reloadCube()));
    // request for minimizing cube
    connect(m_gm, SIGNAL(formulaMinimized()), m_drawer, SLOT(minimizeCube()));
    // request for invalidating cube
    connect(m_gm, SIGNAL(formulaInvalidated()), m_drawer, SLOT(invalidateCube()));
    connect(m_gm, SIGNAL(formulaInvalidated()), this, SLOT(invalidateData()));
    // formula representation changed
    connect(m_gm, SIGNAL(repreChanged(bool)), this, SLOT(setRepre(bool)));
    // setting drawer activity
    connect(this, SIGNAL(activated(bool)), m_drawer, SLOT(setActivity(bool)));

    QHBoxLayout *glLayout = new QHBoxLayout;
    glLayout->setMargin(0);
    glLayout->addWidget(m_drawer);

    BorderWidget *borderWidget = new BorderWidget;
    borderWidget->setLayout(glLayout);
    BorderWidget *error1Widget = new BorderWidget(tr("No logic function for Cube."));
    BorderWidget *error2Widget = new BorderWidget(tr("Too many variables (max 3 variables)."));
    m_stack = new QStackedLayout;
    m_stack->addWidget(borderWidget);
    m_stack->addWidget(error1Widget);
    m_stack->addWidget(error2Widget);
    m_stack->setCurrentIndex(1);

    // terms
    m_termsModel = new TermsModel;
    m_termsView = new QTableView;
    m_termsView->setModel(m_termsModel);
    m_termsView->setShowGrid(false);
    m_termsView->horizontalHeader()->hide();
    m_termsView->setMaximumWidth(SIDEBAR_SIZE);
    m_mintermsStr = tr("Minterms");
    m_maxtermsStr = tr("Maxterms");
    m_termsLabel = new QLabel(m_gm->isSoP()? m_mintermsStr: m_maxtermsStr);
    m_termsLabel->setContentsMargins(3, 5, 5, 0);
    m_termsLabel->setBuddy(m_termsView);

    // covers
    m_coversModel = new CoversModel;
    m_coversView = new QTableView;
    m_coversView->setModel(m_coversModel);
    m_coversView->setShowGrid(false);
    m_coversView->horizontalHeader()->hide();
    m_coversView->verticalHeader()->hide();
    m_coversView->setMaximumWidth(SIDEBAR_SIZE);
    m_coversCheckBox = new QCheckBox(tr("Show covers"));
    m_coversCheckBox->setChecked(Constants::CUBE_COVERS_DEFAULT);
    m_drawer->showCovers(Constants::CUBE_COVERS_DEFAULT);
    connect(m_coversCheckBox, SIGNAL(toggled(bool)), this, SLOT(enableCovers(bool)));
    connect(m_coversCheckBox, SIGNAL(toggled(bool)), m_drawer, SLOT(showCovers(bool)));
    connect(m_drawer, SIGNAL(showingCoversChanged(bool)), m_coversCheckBox, SLOT(setChecked(bool)));
    connect(m_termsView->selectionModel(),
            SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
            this, SLOT(selectTerms(QItemSelection, QItemSelection)));
    connect(m_coversView->selectionModel(),
            SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
            this, SLOT(selectCovers(QItemSelection, QItemSelection)));

#if CUBE_TEXTURES
    // covers tour
    m_tourPos = -1;
    QGroupBox *tourGroupBox = new QGroupBox(tr("Covers tour"));
    m_tourStartStr = tr("Start tour");
    m_tourStopStr = tr("Stop tour");
    m_tourBtn = new QPushButton(m_tourStartStr);
    m_tourBtn->setEnabled(false);
    m_tourPrevBtn = new QPushButton(tr("Prev"));
    m_tourPrevBtn->setEnabled(false);
    m_tourNextBtn = new QPushButton(tr("Next"));
    m_tourNextBtn->setEnabled(false);
    QHBoxLayout *tourShiftLayout = new QHBoxLayout;
    tourShiftLayout->setMargin(0);
    tourShiftLayout->addWidget(m_tourPrevBtn);
    tourShiftLayout->addWidget(m_tourNextBtn);
    QVBoxLayout *tourMainLayout = new QVBoxLayout;
    tourMainLayout->setMargin(0);
    tourMainLayout->addWidget(m_tourBtn);
    tourMainLayout->addLayout(tourShiftLayout);
    tourGroupBox->setLayout(tourMainLayout);
    // tour connections with drawer
    connect(m_tourBtn, SIGNAL(clicked()), m_drawer, SLOT(toggleMin()));
    connect(m_tourNextBtn, SIGNAL(clicked()), m_drawer, SLOT(nextMin()));
    connect(m_tourPrevBtn, SIGNAL(clicked()), m_drawer, SLOT(prevMin()));
    connect(m_drawer, SIGNAL(minStarted(int)), this, SLOT(startTour(int)));
    connect(m_drawer, SIGNAL(minStopped()), this, SLOT(stopTour()));
    connect(m_drawer, SIGNAL(minShifted(int)), this, SLOT(shiftTour(int)));
#endif

    // espresso
    EspressoWidget *espressoWidget = new EspressoWidget(CubeGLDrawer::MAX_N);

    QVBoxLayout *sideLayout = new QVBoxLayout;
    sideLayout->addWidget(m_termsLabel);
    sideLayout->addWidget(m_termsView);
    sideLayout->addWidget(m_coversCheckBox);
    sideLayout->addWidget(m_coversView);
#if CUBE_TEXTURES
    sideLayout->addWidget(tourGroupBox);
#endif
    sideLayout->addWidget(espressoWidget);
    sideLayout->setStretchFactor(m_termsView, 5);
    sideLayout->setStretchFactor(m_coversView, 3);

    QHBoxLayout *mainLayout = new QHBoxLayout;
    mainLayout->setMargin(0);
    //mainLayout->addWidget(borderWidget);
    mainLayout->addLayout(m_stack);
    mainLayout->addLayout(sideLayout);

    setLayout(mainLayout);

    setFocusPolicy(Qt::StrongFocus);
}
Example #18
0
int main(int argc, char *argv[])
{
    int i;
    const char *resPath = 0;
    char    override_base_file[MAX_STR_LEN] = "";
    int     override_local_port = 0;
    char    override_remote_host[MAX_STR_LEN] = "";
    int     override_remote_port = 0;
    char    configfile[MAX_STR_LEN] = "mume.ini";
    int     default_local_port = 3000;
    int     default_remote_port = 4242;
    int     mud_emulation = 0;

#ifdef Q_OS_MACX
    CFURLRef pluginRef = CFBundleCopyBundleURL(CFBundleGetMainBundle());
    CFStringRef macPath = CFURLCopyFileSystemPath(pluginRef,
						  kCFURLPOSIXPathStyle);
    const char *appPath = CFStringGetCStringPtr(macPath,
						CFStringGetSystemEncoding());
    resPath = (char *)malloc(strlen(appPath)+25);
    strcpy(resPath, appPath);
    strcat(resPath, "/Contents/Resources/");

    char    default_base_file[MAX_STR_LEN] = "mume.pmf";
    char    default_remote_host[MAX_STR_LEN] = "";
    strcpy(configfile, "configs/default.conf");

    CFRelease(pluginRef);
    CFRelease(macPath);

#else
    resPath = "";
    char    default_base_file[MAX_STR_LEN] = "mume.pmf";
    char    default_remote_host[MAX_STR_LEN] = "129.241.210.221";
#endif
    QApplication::setColorSpec( QApplication::CustomColor );
    QApplication app( argc, argv );

    QPixmap pixmap("images/logo.png");
    QSplashScreen *splash = new QSplashScreen(pixmap);
    splash->show();

    splash->showMessage("Loading configuration and database...");

    for (i=1; i < argc; i++) {

      if ((strcmp(argv[i], "--config") == 0) || ( strcmp(argv[i], "-c") == 0))
      {
        if (i == argc) {
          printf("Too few arguments. Missing config file name.\r\n");
          print_usage();
          exit(1);
        }
        i++;

        strcpy(configfile, argv[i]);
	resPath = ""; // obviously the user has an own config file - including the path
      }

      if ((strcmp(argv[i], "--emulate") == 0) || ( strcmp(argv[i], "-e") == 0))
      {
        printf("Pandora: Starting in MUD emulation mode.\r\n");
        mud_emulation = 1;
      }

      if ((strcmp(argv[i], "--base") == 0) || ( strcmp(argv[i], "-b") == 0))
      {
        if (i == argc) {
          printf("Too few arguments. Missing database.\r\n");
          print_usage();
          exit(1);
        }
        i++;
        strcpy(override_base_file, argv[i]); // overriding the database file is possible even with default config file
      }

      if ((strcmp(argv[i], "--hostname") == 0) || ( strcmp(argv[i], "-hn") == 0))
      {
        if (i == argc) {
          printf("Too few arguments. Wrong hostname given.\r\n");
          print_usage();
          exit(1);
        }
        i++;
        strcpy(override_remote_host, argv[i]);
      }

      if ((strcmp(argv[i], "--localport") == 0) || ( strcmp(argv[i], "-lp") == 0))
      {
        if (i == argc) {
          printf("Too few arguments. Missing localport.\r\n");
          print_usage();
          exit(1);
        }
        i++;
        override_local_port = atoi(argv[i]);
      }

      if ((strcmp(argv[i], "--remoteport") == 0) || ( strcmp(argv[i], "-rp") == 0))
      {
        if (i == argc) {
          printf("Too few arguments. Missing targetport.\r\n");
          print_usage();
          exit(1);
        }
        i++;
        override_remote_port = atoi(argv[i]);
      }


      if ((strcmp(argv[i], "--help") == 0) || ( strcmp(argv[i], "-h") == 0))
      {
        print_usage();
        exit(1);
      }

    }


    /* set analyzer engine defaults */
    //engine_init();
    splash->showMessage(QString("Loading the configuration ") + configfile);
    conf = new Cconfigurator();
    conf->loadConfig(resPath, configfile);
    print_debug(DEBUG_SYSTEM, "starting up...");


    if (override_base_file[0] != 0) {
      conf->setBaseFile(override_base_file);
    } else if ( conf->getBaseFile() == "") {
      conf->setBaseFile(default_base_file);
    }
    print_debug(DEBUG_SYSTEM, "Using database file : %s.", (const char*) conf->getBaseFile() );

    if (override_remote_host[0] != 0) {
      conf->setRemoteHost(override_remote_host);
    } else if ( conf->getRemoteHost().isEmpty() ) {
      conf->setRemoteHost(default_remote_host);
    }
    print_debug(DEBUG_SYSTEM, "Using target hostname : %s.", (const char*) conf->getRemoteHost() );

    if (override_local_port != 0) {
      conf->setLocalPort(override_local_port);
    } else if ( conf->getLocalPort() == 0) {
      conf->setLocalPort(default_local_port);
    }
    print_debug(DEBUG_SYSTEM, "Using local port : %i.", conf->getLocalPort());

    if (override_remote_port != 0) {
      conf->setRemotePort(override_remote_port);
    } else if (conf->getRemotePort() == 0) {
      conf->setRemotePort(default_remote_port);
    }
    print_debug(DEBUG_SYSTEM, "Using target port : %i.", conf->getRemotePort());

    conf->setConfigModified( false );

    splash->showMessage("Starting Analyzer and Proxy...");

    engine = new CEngine(new CRoomManager());
    proxy = new Proxy();

    /* special init for the mud emulation */
    if (mud_emulation) {
        print_debug(DEBUG_SYSTEM, "Starting in MUD emulation mode...");
        engine->initEmulationMode();
    }

    proxy->setMudEmulation( mud_emulation );


    print_debug(DEBUG_SYSTEM, "Starting renderer ...\n");

    if ( !QGLFormat::hasOpenGL() ) {
        qWarning( "This system has no OpenGL support. Quiting." );
        return -1;
    }

    QRect rect = app.desktop()->availableGeometry(-1);
    if (conf->getWindowRect().x() == 0 || conf->getWindowRect().x() >= rect.width() ||
        conf->getWindowRect().y() >= rect.height() ) {
        print_debug(DEBUG_SYSTEM && DEBUG_INTERFACE, "Autosettings for window size and position");
        int x, y, height, width;

        x = rect.width() / 3 * 2;
        y = 0;
        height = rect.height() / 3;
        width = rect.width() - x;

        conf->setWindowRect( x, y, width, height);
    }


    QGLFormat f = QGLFormat::defaultFormat();
    f.setDoubleBuffer( true );
    f.setDirectRendering( true );
    f.setRgba( true );
    f.setDepth( true );
    f.setAlpha( true );

    if (conf->getMultisampling())
   	f.setSampleBuffers( true );
    //f.setSamples(4);

    QGLFormat::setDefaultFormat( f );

    renderer_window = new CMainWindow;

    renderer_window->show();

    splash->finish(renderer_window);
    delete splash;

    proxy->start();
    QObject::connect(proxy, SIGNAL(startEngine()), engine, SLOT(slotRunEngine()), Qt::QueuedConnection );
    QObject::connect(proxy, SIGNAL(startRenderer()), renderer_window->renderer, SLOT(display()), Qt::QueuedConnection);

    // this will be done via mainwindow itself
    //userland_parser->parse_user_input_line("mload");

    return app.exec();
}
Example #19
0
/*
  See qgl.cpp for qdoc comment.
 */
void *QGLContext::chooseVisual()
{
    Q_D(QGLContext);
    static const int bufDepths[] = { 8, 4, 2, 1 };        // Try 16, 12 also?
    //todo: if pixmap, also make sure that vi->depth == pixmap->depth
    void* vis = 0;
    int i = 0;
    bool fail = false;
    QGLFormat fmt = format();
    bool tryDouble = !fmt.doubleBuffer();  // Some GL impl's only have double
    bool triedDouble = false;
    bool triedSample = false;
    if (fmt.sampleBuffers())
        fmt.setSampleBuffers(QGLExtensions::glExtensions & QGLExtensions::SampleBuffers);
    while(!fail && !(vis = tryVisual(fmt, bufDepths[i]))) {
        if (!fmt.rgba() && bufDepths[i] > 1) {
            i++;
            continue;
        }
        if (tryDouble) {
            fmt.setDoubleBuffer(true);
            tryDouble = false;
            triedDouble = true;
            continue;
        } else if (triedDouble) {
            fmt.setDoubleBuffer(false);
            triedDouble = false;
        }
        if (!triedSample && fmt.sampleBuffers()) {
            fmt.setSampleBuffers(false);
            triedSample = true;
            continue;
        }
        if (fmt.stereo()) {
            fmt.setStereo(false);
            continue;
        }
        if (fmt.accum()) {
            fmt.setAccum(false);
            continue;
        }
        if (fmt.stencil()) {
            fmt.setStencil(false);
            continue;
        }
        if (fmt.alpha()) {
            fmt.setAlpha(false);
            continue;
        }
        if (fmt.depth()) {
            fmt.setDepth(false);
            continue;
        }
        if (fmt.doubleBuffer()) {
            fmt.setDoubleBuffer(false);
            continue;
        }
        fail = true;
    }
    d->glFormat = fmt;
    return vis;
}
Example #20
0
TumblerWindow::TumblerWindow(TumblerStruct *xtum, bool rgba,
            bool doubleBuffer, bool enableDepth, QWidget * parent,
            const char * name, Qt::WindowFlags f)
  : QMainWindow(parent, f)
{
  int j;
  QString str;
  mTum = xtum;
  setAttribute(Qt::WA_DeleteOnClose);
  setAttribute(Qt::WA_AlwaysShowToolTips);

  if (firstTime) 
    utilFileListsToIcons(fileList, icons, MAX_XTUM_TOGGLES);
  firstTime = 0;
  
  // Make central vbox and top frame containing an hboxlayout
  QWidget *central = new QWidget(this);
  setCentralWidget(central);
  QVBoxLayout *cenlay = new QVBoxLayout(central);
  cenlay->setContentsMargins(0,0,0,0);
  cenlay->setSpacing(0);
  QFrame * topFrame = new QFrame(central);
  cenlay->addWidget(topFrame);
  topFrame->setFrameStyle(QFrame::Raised | QFrame::StyledPanel);

  QHBoxLayout *topLayout = new QHBoxLayout(topFrame);
  topLayout->setContentsMargins(2,2,2,2);
  topLayout->setSpacing(3);
  
  QVBoxLayout *topVBox = diaVBoxLayout(topLayout);
  topVBox->setSpacing(4);
  QHBoxLayout *topHBox = diaHBoxLayout(topVBox);
  topHBox->setContentsMargins(0,0,0,0);
  topHBox->setSpacing(3);

  // Add the toolbar widgets
  // Zoom spin box
  // If you try to make a spin box narrower, it makes the arrows tiny
  mZoomBox = (QSpinBox *)diaLabeledSpin(0, 1., XTUM_MAX_ZOOM, 1., "Zoom",
                                        topFrame, topHBox);
  mZoomBox->setValue(xtum->zoom);
  connect(mZoomBox, SIGNAL(valueChanged(int)), this, 
	  SLOT(zoomChanged(int)));
  mZoomBox->setToolTip("Change zoom of display");

  // Make the 2 toggle buttons and their signal mapper
  QSignalMapper *toggleMapper = new QSignalMapper(topFrame);
  connect(toggleMapper, SIGNAL(mapped(int)), this, SLOT(toggleClicked(int)));
  for (j = 0; j < 2; j++) {
    utilSetupToggleButton(topFrame, NULL, topHBox, toggleMapper, icons, 
                          toggleTips, mToggleButs, mToggleStates, j);
    connect(mToggleButs[j], SIGNAL(clicked()), toggleMapper, SLOT(map()));
  }

  // Help button
  mHelpButton = diaPushButton("Help", topFrame, topHBox);
  connect(mHelpButton, SIGNAL(clicked()), this, SLOT(help()));
  setFontDependentWidths();

  topHBox->addStretch();

  // Make second row for size spin boxes, and signal map them
  QHBoxLayout *botHBox = diaHBoxLayout(topVBox);
  botHBox->setContentsMargins(0,0,0,0);
  botHBox->setSpacing(3);
  QSignalMapper *sizeMapper = new QSignalMapper(topFrame);
  connect(sizeMapper, SIGNAL(mapped(int)), this, SLOT(sizeChanged(int)));

  // Make the spin boxes
  for (j = 0; j < 3; j++) {
    str = xyzLabels[j];
    mSizeBoxes[j] = (QSpinBox *)diaLabeledSpin(0, XTUM_SIZE_MIN, XTUM_SIZE_MAX,
                                               XTUM_SIZE_INC, LATIN1(str), 
                                               topFrame, botHBox);
    mSizeBoxes[j]->setValue(XTUM_SIZE_INI);
    sizeMapper->setMapping(mSizeBoxes[j], j);
    connect(mSizeBoxes[j], SIGNAL(valueChanged(int)), sizeMapper, SLOT(map()));
    mSizeBoxes[j]->setToolTip("Change size of box in " + str);
  }

  // Spacer for the second row
  botHBox->addStretch();

  // Add a vertical line
  QFrame *vertLine = new QFrame(topFrame);
  vertLine->setFrameStyle(QFrame::Sunken | QFrame::VLine);
  topLayout->addWidget(vertLine);

  // Threshold sliders
  mSliders = new MultiSlider(topFrame, 2, sliderLabels);
  topLayout->addLayout(mSliders->getLayout());
  connect(mSliders, SIGNAL(sliderChanged(int, int, bool)), this, 
	  SLOT(thresholdChanged(int, int, bool)));
  mSliders->setValue(0, xtum->minval);
  mSliders->setValue(1, xtum->maxval);
  mSliders->getSlider(0)->setToolTip(
		"Level below which pixels will be set to black");
  mSliders->getSlider(1)->setToolTip(
		"Level above which pixels will be set to white");


  QGLFormat glFormat;
  glFormat.setRgba(rgba);
  glFormat.setDoubleBuffer(doubleBuffer);
  glFormat.setDepth(enableDepth);
  mGLw = new TumblerGL(xtum, glFormat, central);
  cenlay->addWidget(mGLw);
  cenlay->setStretchFactor(mGLw, 1);

  resize(XTUM_WIDTH, XTUM_HEIGHT);
  setFocusPolicy(Qt::StrongFocus);
}