GLView * GLView::create( NifSkope * window ) { QGLFormat fmt; static QList<QPointer<GLView> > views; QGLWidget * share = nullptr; for ( const QPointer<GLView>& v : views ) { if ( v ) share = v; } // All new windows after the first window will share a format if ( share ) { fmt = share->format(); } else { fmt.setSampleBuffers( Options::antialias() ); } // OpenGL version fmt.setVersion( 2, 1 ); // Ignored if version < 3.2 //fmt.setProfile(QGLFormat::CoreProfile); // V-Sync fmt.setSwapInterval( 1 ); fmt.setDoubleBuffer( true ); fmt.setSamples( Options::antialias() ? 16 : 0 ); fmt.setDirectRendering( true ); fmt.setRgba( true ); views.append( QPointer<GLView>( new GLView( fmt, window, share ) ) ); return views.last(); }
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()); }
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 }
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(); }
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(); }
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); }