Esempio n. 1
0
QSurfaceFormat q_glFormatFromConfig(EGLDisplay display, const EGLConfig config, const QSurfaceFormat &referenceFormat)
{
    QSurfaceFormat format;
    EGLint redSize     = 0;
    EGLint greenSize   = 0;
    EGLint blueSize    = 0;
    EGLint alphaSize   = 0;
    EGLint depthSize   = 0;
    EGLint stencilSize = 0;
    EGLint sampleCount = 0;
    EGLint renderableType = 0;

    eglGetConfigAttrib(display, config, EGL_RED_SIZE,     &redSize);
    eglGetConfigAttrib(display, config, EGL_GREEN_SIZE,   &greenSize);
    eglGetConfigAttrib(display, config, EGL_BLUE_SIZE,    &blueSize);
    eglGetConfigAttrib(display, config, EGL_ALPHA_SIZE,   &alphaSize);
    eglGetConfigAttrib(display, config, EGL_DEPTH_SIZE,   &depthSize);
    eglGetConfigAttrib(display, config, EGL_STENCIL_SIZE, &stencilSize);
    eglGetConfigAttrib(display, config, EGL_SAMPLES,      &sampleCount);
    eglGetConfigAttrib(display, config, EGL_RENDERABLE_TYPE, &renderableType);

    if (referenceFormat.renderableType() == QSurfaceFormat::OpenVG && (renderableType & EGL_OPENVG_BIT))
        format.setRenderableType(QSurfaceFormat::OpenVG);
#ifdef EGL_VERSION_1_4
    else if (referenceFormat.renderableType() == QSurfaceFormat::OpenGL
             && (renderableType & EGL_OPENGL_BIT))
        format.setRenderableType(QSurfaceFormat::OpenGL);
    else if (referenceFormat.renderableType() == QSurfaceFormat::DefaultRenderableType
#ifndef QT_NO_OPENGL
             && QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL
#endif
             && (renderableType & EGL_OPENGL_BIT))
        format.setRenderableType(QSurfaceFormat::OpenGL);
#endif
    else
        format.setRenderableType(QSurfaceFormat::OpenGLES);

    format.setRedBufferSize(redSize);
    format.setGreenBufferSize(greenSize);
    format.setBlueBufferSize(blueSize);
    format.setAlphaBufferSize(alphaSize);
    format.setDepthBufferSize(depthSize);
    format.setStencilBufferSize(stencilSize);
    format.setSamples(sampleCount);
    format.setStereo(false);         // EGL doesn't support stereo buffers
    format.setSwapInterval(referenceFormat.swapInterval());

    // Clear the EGL error state because some of the above may
    // have errored out because the attribute is not applicable
    // to the surface type.  Such errors don't matter.
    eglGetError();

    return format;
}
Esempio n. 2
0
int main(int argc, char *argv[])
{
  qInstallMessageHandler(&handleMessageOutput);
  QApplication app(argc, argv);
  std::vector<QSurfaceFormat> formats;

#if !defined(QT_OPENGL_ES)
  {
    QSurfaceFormat glFormat;
    glFormat.setRenderableType(QSurfaceFormat::OpenGL);
    glFormat.setProfile(QSurfaceFormat::CoreProfile);
    glFormat.setVersion(4,3);
    formats.push_back(glFormat);
  }
#endif

#if defined(QT_OPENGL_ES)
  {
    QSurfaceFormat glesFormat;
    glesFormat.setRenderableType(QSurfaceFormat::OpenGLES);
    glesFormat.setProfile(QSurfaceFormat::CoreProfile);
    glesFormat.setVersion(3,0);
    formats.push_back(glesFormat);
  }
#endif

  // Find out which version we support
  QSurfaceFormat *format = getFirstSupported(formats);
  if (format == NULL)
  {
    QMessageBox::critical(0, "Critical Error", "No valid supported version of OpenGL found on device!");
    exit(-1);
  }

#ifdef    GL_DEBUG
  format->setOption(QSurfaceFormat::DebugContext);
#endif // GL_DEBUG
  format->setDepthBufferSize(0);

  // Set the widget up
  MainWidget *widget = new MainWidget;
  widget->setFormat(*format);

  // Set the window up
  MainWindow *window = new MainWindow;
  window->show();

  return app.exec();
}
Esempio n. 3
0
static QSurfaceFormat
    qSurfaceFormatFromPixelFormat(const PIXELFORMATDESCRIPTOR &pfd,
                                         QWindowsOpenGLAdditionalFormat *additionalIn = 0)
{
    QSurfaceFormat format;
    format.setRenderableType(QSurfaceFormat::OpenGL);
    if (pfd.dwFlags & PFD_DOUBLEBUFFER)
        format.setSwapBehavior(QSurfaceFormat::DoubleBuffer);
    format.setDepthBufferSize(pfd.cDepthBits);

    if (pfd.iPixelType == PFD_TYPE_RGBA)
        format.setAlphaBufferSize(pfd.cAlphaBits);
    format.setRedBufferSize(pfd.cRedBits);
    format.setGreenBufferSize(pfd.cGreenBits);
    format.setBlueBufferSize(pfd.cBlueBits);
    format.setStencilBufferSize(pfd.cStencilBits);
    format.setStereo(pfd.dwFlags & PFD_STEREO);
    if (additionalIn) {
        QWindowsOpenGLAdditionalFormat additional;
        if (isDirectRendering(pfd))
            additional.formatFlags |= QWindowsGLDirectRendering;
        if (hasGLOverlay(pfd))
            additional.formatFlags |= QWindowsGLOverlay;
        if (pfd.cAccumRedBits)
            additional.formatFlags |= QWindowsGLAccumBuffer;
        if (testFlag(pfd.dwFlags, PFD_DRAW_TO_BITMAP)) {
            additional.formatFlags |= QWindowsGLRenderToPixmap;
            additional.pixmapDepth = pfd.cColorBits;
        }
        *additionalIn = additional;
    }
    return format;
}
Esempio n. 4
0
RenderWidget::RenderWidget(QWidget *parent) :
  QOpenGLWidget(parent),
  renderFunctions(nullptr),
  render(nullptr),
  quad(nullptr),
  quadShader(nullptr),
  openglDebugLogger(nullptr),
  captureMouse(false),
  onlyShowTexture(false),
  textureDisplayed(color)
{
  // Widget config
  setUpdateBehavior(QOpenGLWidget::NoPartialUpdate);
  setFocusPolicy(Qt::ClickFocus);

  // Update Timer config
  connect(&updateTimer, SIGNAL(timeout()), this, SLOT(update()));
  startUpdateLoop();

  // Open GL Context config
  QSurfaceFormat f;
  f.setRenderableType(QSurfaceFormat::OpenGL);
  f.setMajorVersion(4);
  f.setMinorVersion(5);
  f.setProfile(QSurfaceFormat::CoreProfile);
  f.setOptions(QSurfaceFormat::DebugContext | f.options());
  setFormat(f);
}
static QSurfaceFormat formatFromConfig(EGLDisplay dpy, EGLConfig config)
{
    QSurfaceFormat format;
    EGLint value = 0;
#define HELPER(__egl__, __qt__) \
    eglGetConfigAttrib(dpy, config, EGL_##__egl__, &value); \
    format.set##__qt__(value); \
    value = 0;

#define BUFFER_HELPER(__eglColor__, __color__) \
    HELPER(__eglColor__##_SIZE, __color__##BufferSize)

    BUFFER_HELPER(RED, Red)
    BUFFER_HELPER(GREEN, Green)
    BUFFER_HELPER(BLUE, Blue)
    BUFFER_HELPER(ALPHA, Alpha)
    BUFFER_HELPER(STENCIL, Stencil)
    BUFFER_HELPER(DEPTH, Depth)
#undef BUFFER_HELPER
    HELPER(SAMPLES, Samples)
#undef HELPER
    format.setRenderableType(isOpenGLES() ? QSurfaceFormat::OpenGLES : QSurfaceFormat::OpenGL);
    format.setStereo(false);

    return format;
}
Esempio n. 6
0
File: main.cpp Progetto: JJ/ARehab
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    Q_INIT_RESOURCE(ARehab_vTerapeuta);

    QSurfaceFormat format;
    format.setVersion(4, 3);
    format.setProfile(QSurfaceFormat::CoreProfile);
    format.setOption(QSurfaceFormat::DebugContext);
    format.setRenderableType(QSurfaceFormat::OpenGL);
    format.setDepthBufferSize(24);
    format.setStencilBufferSize(8);
    format.setSamples(4);
    format.setSwapInterval(0); //Disable VSync
    QSurfaceFormat::setDefaultFormat(format);

    ARehabGUIDesigner::ARehabMainWindow w;

    QFile styleFile(":/styles/main.qss");
    styleFile.open(QFile::ReadOnly);
    app.setStyleSheet(QLatin1String(styleFile.readAll()));
    styleFile.close();

    w.show();
    return (app.exec());
}
Esempio n. 7
0
const QSurfaceFormat& getDefaultOpenGLSurfaceFormat() {
    static QSurfaceFormat format;
    static std::once_flag once;
    std::call_once(once, [] {
#if defined(USE_GLES)
        format.setRenderableType(QSurfaceFormat::OpenGLES);
        format.setRedBufferSize(8);
        format.setGreenBufferSize(8);
        format.setBlueBufferSize(8);
        format.setAlphaBufferSize(8);
#else
        format.setProfile(QSurfaceFormat::OpenGLContextProfile::CoreProfile);
#endif
        if (gl::Context::enableDebugLogger()) {
            format.setOption(QSurfaceFormat::DebugContext);
        }
        // Qt Quick may need a depth and stencil buffer. Always make sure these are available.
        format.setDepthBufferSize(DEFAULT_GL_DEPTH_BUFFER_BITS);
        format.setStencilBufferSize(DEFAULT_GL_STENCIL_BUFFER_BITS);
        int major, minor;
        ::gl::getTargetVersion(major, minor);
        format.setMajorVersion(major);
        format.setMinorVersion(minor);
    });
    return format;
}
Esempio n. 8
0
ContextPoolContext::ContextPoolContext(QOpenGLContext* share_context, bool reserved)
    : reserved(reserved), count(0), surface(NULL), context(NULL)
{
    QSurfaceFormat format;
    format.setMajorVersion(3);
    format.setMinorVersion(2);
    format.setSwapInterval(0);
    format.setSwapBehavior(QSurfaceFormat::SingleBuffer);
    format.setRenderableType(QSurfaceFormat::OpenGL);
    format.setProfile(QSurfaceFormat::CoreProfile);
    format.setOption(QSurfaceFormat::DebugContext);
    surface = new QOffscreenSurface();
    surface->setFormat(format);
    surface->create();
    if (!surface->isValid()) {
        throw;
    }

    context = new QOpenGLContext();
    context->setShareContext(share_context);
    context->setFormat(surface->requestedFormat());

    if (!context->create()) {
        throw;
    }

    context->makeCurrent(surface);
    gl = context->versionFunctions<QOpenGLFunctions_3_2_Core>();
    if (gl == nullptr || !gl->initializeOpenGLFunctions()) {
        throw;
    }
    indirect = new QOpenGLExtension_ARB_multi_draw_indirect();
    if (!indirect->initializeOpenGLFunctions()) {
        throw;
    }
    vab = new QOpenGLExtension_ARB_vertex_attrib_binding();
    if (!vab->initializeOpenGLFunctions()) {
        throw;
    }
    sso = new QOpenGLExtension_ARB_separate_shader_objects();
    if (!sso->initializeOpenGLFunctions()) {
        throw;
    }
    tex = new QOpenGLExtension_ARB_texture_buffer_object();
    if (!tex->initializeOpenGLFunctions()) {
        throw;
    }
    buffer = (QOpenGLExtension_ARB_buffer_storage)context->getProcAddress("glBufferStorage");
    debug = new QOpenGLExtension_ARB_debug_output();
    if (!debug->initializeOpenGLFunctions()) {
        throw;
    }
    debug->glDebugMessageCallbackARB(debug_callback, nullptr);
    debug->glDebugMessageControlARB(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, 0, GL_FALSE);
    debug->glDebugMessageControlARB(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_MEDIUM, 0, 0, GL_TRUE);
    context->doneCurrent();
    context->moveToThread(nullptr);
}
Esempio n. 9
0
int main(int argc, char ** argv)
{
	ShowWindow(GetConsoleWindow(), SW_HIDE);

	QApplication app(argc, argv);

	QSurfaceFormat format;
	format.setDepthBufferSize(4);
	format.setSamples(24);
	format.setVersion(4, 4);
	format.setRenderableType(QSurfaceFormat::OpenGL);

	OpenGLWidget window;
	window.setFormat(format);
	window.resize(WINDOW_WIDTH, WINDOW_HEIGHT);

	selector = new ShaderFinder();

	pane = new CollapsiblePanelWidget(&window);
	pane->setStyleSheet("background-color:white");
	pane->setWidgetResizable(true);
	pane->setGeometry(0, 0, WINDOW_WIDTH / 5, WINDOW_HEIGHT);
	pane->duration = 500;
	pane->config(QRect(0, 0, WINDOW_WIDTH / 5, WINDOW_HEIGHT), QRect(-WINDOW_WIDTH / 5, 0, WINDOW_WIDTH / 5, WINDOW_HEIGHT));

	paneBox = new QGroupBox();
	pane->setWidget(paneBox);

	paneLayout = new QVBoxLayout();
	paneLayout->setSpacing(10);
	paneLayout->setAlignment(Qt::AlignTop);
	paneLayout->addWidget(selector);

	pane->widget()->setLayout(paneLayout);
	pane->show();

	anim = new CollapsiblePanelWidget(&window);
	anim->setStyleSheet("background-color:white");
	anim->setWidgetResizable(true);
	anim->setGeometry(WINDOW_WIDTH * 0.8, 0, WINDOW_WIDTH / 5, WINDOW_HEIGHT);
	anim->duration = 500;
	anim->config(QRect(WINDOW_WIDTH * 0.8, 0, WINDOW_WIDTH / 5, WINDOW_HEIGHT), QRect(WINDOW_WIDTH, 0, WINDOW_WIDTH / 5, WINDOW_HEIGHT));

	animBox = new QGroupBox();
	anim->setWidget(animBox);

	animLayout = new QVBoxLayout();
	animLayout->setSpacing(10);
	animLayout->setAlignment(Qt::AlignTop);

	anim->widget()->setLayout(animLayout);
	anim->show();

	window.show();

	return app.exec();
}
Esempio n. 10
0
File: widget.cpp Progetto: RSATom/Qt
void Widget::start()
{
    QSurfaceFormat fmt;

    int idx = m_version->currentIndex();
    if (idx < 0)
        return;
    fmt.setVersion(versions[idx].major, versions[idx].minor);

    for (size_t i = 0; i < sizeof(profiles) / sizeof(Profile); ++i)
        if (static_cast<QRadioButton *>(m_profiles->itemAt(int(i))->widget())->isChecked()) {
            fmt.setProfile(profiles[i].profile);
            break;
        }

    bool forceGLSL110 = false;
    for (size_t i = 0; i < sizeof(options) / sizeof(Option); ++i)
        if (static_cast<QCheckBox *>(m_options->itemAt(int(i))->widget())->isChecked()) {
            if (options[i].option)
                fmt.setOption(options[i].option);
            else if (i == 3)
                forceGLSL110 = true;
        }

    for (size_t i = 0; i < sizeof(renderables) / sizeof(Renderable); ++i)
        if (static_cast<QRadioButton *>(m_renderables->itemAt(int(i))->widget())->isChecked()) {
            fmt.setRenderableType(renderables[i].renderable);
            break;
        }

    // The example rendering will need a depth buffer.
    fmt.setDepthBufferSize(16);

    m_output->clear();
    m_extensions->clear();
    qDebug() << "Requesting surface format" << fmt;

    m_renderWindowLayout->removeWidget(m_renderWindowContainer);
    delete m_renderWindowContainer;

    RenderWindow *renderWindow = new RenderWindow(fmt);
    if (!renderWindow->context()) {
        m_output->append(tr("Failed to create context"));
        delete renderWindow;
        m_renderWindowContainer = new QWidget;
        addRenderWindow();
        return;
    }
    m_surface = renderWindow;

    renderWindow->setForceGLSL110(forceGLSL110);
    connect(renderWindow, &RenderWindow::ready, this, &Widget::renderWindowReady);
    connect(renderWindow, &RenderWindow::error, this, &Widget::renderWindowError);

    m_renderWindowContainer = QWidget::createWindowContainer(renderWindow);
    addRenderWindow();
}
Esempio n. 11
0
void HsQMLContextControl::controlContext()
{
    // Do nothing if no window
    if (!mWindow) {
        return;
    }

    // Do nothing if changes are being deferred
    if (mDefer || !mWhen) {
        mPending = true;
        return;
    }
    mPending = false;

    QSurfaceFormat fmt = mOriginal;
    if (mMajorVersion >= 0) {
        fmt.setMajorVersion(mMajorVersion);
    }
    if (mMinorVersion >= 0) {
        fmt.setMinorVersion(mMinorVersion);
    }
    if (mContextType >= 0) {
        fmt.setRenderableType(static_cast<QSurfaceFormat::RenderableType>(
            mContextType));
    }
    if (mContextProfile >= 0) {
        fmt.setProfile(static_cast<QSurfaceFormat::OpenGLContextProfile>(
            mContextProfile));
    }
    if (mDeprecatedFunctionsSet) {
#if QT_VERSION >= 0x050300
        fmt.setOption(QSurfaceFormat::DeprecatedFunctions,
            mDeprecatedFunctions);
#else
        if (mDeprecatedFunctions) {
            fmt.setOption(QSurfaceFormat::DeprecatedFunctions);
        }
#endif
    }
    fmt.setDepthBufferSize(qMax(fmt.depthBufferSize(), mDepthBufferSize));
    fmt.setStencilBufferSize(qMax(fmt.stencilBufferSize(), mStencilBufferSize));
    if (fmt == mWindow->requestedFormat()) {
        return;
    }
    mWindow->setFormat(fmt);

    // Recreate OpenGL context
    mWindow->setPersistentOpenGLContext(false);
    mWindow->setPersistentSceneGraph(false);
    bool visible = mWindow->isVisible();
    mWindow->destroy();
    mWindow->releaseResources();
    mWindow->setVisible(visible);
    mWindow->setPersistentOpenGLContext(true);
    mWindow->setPersistentSceneGraph(true);
}
Esempio n. 12
0
int main(int argc, char** argv) {
    QSurfaceFormat format;
#if defined(Q_OS_IOS) || defined(Q_OS_ANDROID)
    format.setRenderableType(QSurfaceFormat::OpenGLES);
    format.setVersion(3, 0);
#else
    format.setRenderableType(QSurfaceFormat::OpenGL);
    format.setProfile(QSurfaceFormat::CoreProfile);
    format.setVersion(3, 3);
#endif
    format.setDepthBufferSize(16);
    format.setStencilBufferSize(8);
    QSurfaceFormat::setDefaultFormat(format);

    QApplication a(argc, argv);

    ncMainWindow w;
    w.show();

    return a.exec();
}
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QSurfaceFormat format;
    format.setDepthBufferSize( 4 );
    format.setSamples(24);
    format.setRenderableType(QSurfaceFormat::OpenGL);
    a.setStyle(QStyleFactory::create("Android"));
    MainWindow w;
    w.showMaximized();

    return a.exec();
}
Esempio n. 14
0
int main(int argc, char* argv[])
{
    QSurfaceFormat format;
    format.setRenderableType(QSurfaceFormat::OpenGL);
    format.setProfile(QSurfaceFormat::CoreProfile);
    format.setVersion(3,3);
    Magick::InitializeMagick(*argv);
    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    return a.exec();
}
Esempio n. 15
0
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QSurfaceFormat format;
    format.setRenderableType(QSurfaceFormat::OpenGL);
    format.setProfile(QSurfaceFormat::CoreProfile);
    format.setOption(QSurfaceFormat::DebugContext);
    format.setVersion(4,1);
    QSurfaceFormat::setDefaultFormat(format);

    MGLWidgetUniformBlock widget(NULL,"UniformBlock",false);
    widget.show();
    
    return a.exec();
}
int main(int argc, char *argv[])
{
    QApplication application(argc, argv);
    // Specify an OpenGL 3.3 format using the Core profile.
    // That is, no old-school fixed pipeline functionality
    QSurfaceFormat glFormat;
    glFormat.setVersion( 3, 3 );
    glFormat.setProfile(QSurfaceFormat::OpenGLContextProfile::CoreProfile);
    glFormat.setRenderableType(QSurfaceFormat::RenderableType::OpenGL);
    QSurfaceFormat::setDefaultFormat(glFormat);

    // MainWindow is a singleton class
    MainWindow::getInstance().showNormal();
    //main_window.showMaximized();

    return application.exec();
}
Esempio n. 17
0
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QSurfaceFormat format;
    format.setRenderableType(QSurfaceFormat::OpenGL);
    format.setProfile(QSurfaceFormat::CoreProfile);
    format.setOption(QSurfaceFormat::DebugContext);
    format.setVersion(4,1);
    QSurfaceFormat::setDefaultFormat(format);

    MGLWidgetDrawInstanced widget(NULL,"DrawCMD",false);
    //GInstanceArray widget(NULL,"GInstanceArray",false);
    //TestVBObject widget(NULL,"TestVBObject",false);
    widget.show();
    
    return a.exec();
}
Esempio n. 18
0
OpenGLWindow::OpenGLWindow( QWindow *parent )
    : QWindow( parent ), d( new Private(this) )
{
    setSurfaceType( QWindow::OpenGLSurface );

    QSurfaceFormat format;
    //format.setDepthBufferSize( 24 );
    //format.setSamples( 4 );
    //format.setMajorVersion( 3 );
    //format.setMinorVersion( 3 );
    format.setSwapBehavior( QSurfaceFormat::DoubleBuffer );
    format.setRenderableType( QSurfaceFormat::OpenGL );
    format.setProfile( QSurfaceFormat::CompatibilityProfile );
    setFormat( format );
    create();

    d->thread = OpenGLRenderThread::instance();
    d->renderId = d->thread->registerSurface( this );
    d->thread->update( d->renderId );
}
Esempio n. 19
0
int main(int argc, char *argv[]) {
	QGuiApplication app(argc, argv);

	// Set OpenGL Version information
	// Note: This format must be set before show() is called.
	QSurfaceFormat format;
	format.setRenderableType(QSurfaceFormat::OpenGL);
	format.setProfile(QSurfaceFormat::CoreProfile);
	format.setSamples(8);
	//If no format is specified it uses the highest available possible
	//In my case 4.5
	//format.setVersion(3, 3);

	Window window;
	window.setTitle("Qt and OpenGL Simple Window");
	window.setFormat(format);
	window.resize(QSize(800, 600));
	window.show();

	return app.exec();
}
Esempio n. 20
0
OpenGLWindow::OpenGLWindow(QWindow *parent)
    : QWindow(parent)
    , m_update_pending(false)
    , m_animating(false)
    , m_context(0)
    , m_device(0)
    , m_frames(0)
    , m_fps(0)
{
    setSurfaceType(QWindow::OpenGLSurface);

    QSurfaceFormat format;
    format.setSamples(4); // multi-sampling
    format.setRenderableType(QSurfaceFormat::OpenGL); // change to opengles on mobile
    format.setProfile(QSurfaceFormat::CompatibilityProfile);
    format.setMajorVersion(3);
    format.setMinorVersion(2);
    format.setDepthBufferSize(24);
    setFormat(format);

    // Hide the cursor since this is a fullscreen app
    setCursor(Qt::BlankCursor);
}
Esempio n. 21
0
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QSurfaceFormat format;
    format.setMajorVersion(4);
    format.setMinorVersion(1);
    format.setProfile(QSurfaceFormat::CoreProfile);
    format.setRenderableType(QSurfaceFormat::OpenGL);
    format.setSwapBehavior(QSurfaceFormat::DoubleBuffer);
    format.setSamples(2);
    format.setDepthBufferSize(24);
    format.setRedBufferSize(8);
    format.setGreenBufferSize(8);
    format.setBlueBufferSize(8);
    format.setAlphaBufferSize(0);
    format.setStencilBufferSize(8);
    QSurfaceFormat::setDefaultFormat(format);

    DemoGLWindow window;
    window.show();

    return a.exec();
}
int main(int argc, char** argv)
{
    QApplication app(argc, argv);
    QMainWindow* mw{new QMainWindow()};
    mw->setWindowTitle("scroll event compression test case");
    QToolBar* toolbar{mw->addToolBar("toolbar")};
    QAction* sleep_a_lot_action{new QAction("Sleep A Lot", mw)};
    sleep_a_lot_action->setCheckable(true);
    sleep_a_lot_action->setChecked(false);
    sleep_a_lot_action->setToolTip("When activated, the main thread will attempt to sleep for 999ms intervals with 1ms gaps between naps.\n"
                                   "Shortcut: spacebar");
    sleep_a_lot_action->setShortcut(QKeySequence(Qt::Key_Space));
    sleep_a_lot_action->setShortcutContext(Qt::WindowShortcut);
    QTimer* sleep_a_lot_timer{new QTimer(mw)};
    QObject::connect(sleep_a_lot_action, &QAction::toggled, [&](const bool& is_on){
        if(is_on) sleep_a_lot_timer->start();
        else sleep_a_lot_timer->stop();});
    sleep_a_lot_timer->setSingleShot(false);
    sleep_a_lot_timer->setInterval(1);
    QObject::connect(sleep_a_lot_timer, &QTimer::timeout, [&](){
        std::this_thread::sleep_for(std::chrono::milliseconds(999));
        if(sleep_a_lot_action->isChecked()) sleep_a_lot_timer->start();
    });
    toolbar->addAction(sleep_a_lot_action);
    toolbar->addSeparator();
    QGraphicsScene* gs{new QGraphicsScene(mw)};
    QGraphicsSimpleTextItem* sti{gs->addSimpleText("Move the mouse wheel a few clicks up or down with various combinations of:\n"
                                                   "* \"Sleep A Lot\" enabled/disabled (shortcut to toggle: spacebar).\n"
                                                   "* Mouse held still/mouse moved about.\n\n"
                                                   "Questions whose answers differ for the same version of Qt on various\n"
                                                   "platforms (eg, Win32, X11, Aqua):\n"
                                                   "* With \"Sleep A Lot\" active, are mouse wheel events compressed?\n"
                                                   "* With \"Sleep A Lot\" active, does moving the mouse and the mouse wheel\n"
                                                   "  cause scroll wheel events to be thrown away by compression that are not\n"
                                                   "  thrown away when just the mouse wheel is manipulated?\n"
                                                   "* With \"Sleep A Lot\" active, is it necessary to move the mouse in order\n"
                                                   "  to provoke processing of buffered mouse wheel events?")};
    sti->setBrush(QBrush(Qt::black));
    sti->setPen(QPen(Qt::white));
    {
        QFont f(sti->font());
        f.setBold(true);
        f.setPointSize(36);
        sti->setFont(f);
    }
    gs->setSceneRect(sti->boundingRect());
    QGraphicsEllipseItem* mc{gs->addEllipse(0, 0, 25, 25, QPen(QColor(0, 255, 0, 200)), QBrush(QColor(0, 0, 0, 100)))};
    mc->setFlag(QGraphicsItem::ItemIgnoresTransformations);
    QGraphicsSimpleTextItem* mcsti{gs->addSimpleText("0\n0")};
    mcsti->setBrush(QBrush(Qt::white));
    mcsti->setParentItem(mc);
    mcsti->moveBy(23, 22);
    QGraphicsDropShadowEffect* mcstige{new QGraphicsDropShadowEffect(gs)};
    mcstige->setBlurRadius(10);
    mcstige->setOffset(0, 0);
    mcstige->setColor(Qt::black);
    mcsti->setGraphicsEffect(mcstige);
    TestView* gv{new TestView(gs, mw)};
    QOpenGLWidget* gl_widget = new QOpenGLWidget;
    {
        QSurfaceFormat fmt;
        fmt.setRenderableType(QSurfaceFormat::OpenGL);
        fmt.setProfile(QSurfaceFormat::CompatibilityProfile);
        fmt.setVersion(2, 1);
        fmt.setSamples(4);
        gl_widget->setFormat(fmt);
    }
    gv->setViewport(gl_widget);
    QObject::connect(gv, &TestView::mouse_moved, [&](const QPointF& scene_pos){
        mcsti->setText(QString("%1\n%2").arg(scene_pos.x()).arg(scene_pos.y()));
        qreal zoom{gv->transform().m22()};
        qreal delta{12.5 / zoom};
        mc->setPos(scene_pos.x() - delta, scene_pos.y() - delta);
    });
    gv->setDragMode(QGraphicsView::ScrollHandDrag);
    {
        QLinearGradient g;
        g.setSpread(QGradient::ReflectSpread);
        QGradientStops grad_stops;
        grad_stops.push_back(QGradientStop(0, QColor(Qt::red)));
        grad_stops.push_back(QGradientStop(0.5, QColor(Qt::green)));
        grad_stops.push_back(QGradientStop(1, QColor(Qt::blue)));
        g.setStops(grad_stops);
        QBrush b(g);
        gs->setBackgroundBrush(b);
    }
    mw->setCentralWidget(gv);
    mw->resize(2045, 838);
    mw->show();
    return app.exec();
}
void WebApplicationWindow::createAndSetup()
{
    if (mTrustScope == TrustScopeSystem) {
        mUserScripts.append(QUrl("qrc:///qml/webos-api.js"));
        createDefaultExtensions();
    }

    if (mWindowType == "dashboard")
        mLoadingAnimationDisabled = true;

    if (mHeadless) {
        qDebug() << __PRETTY_FUNCTION__ << "Creating application container for headless ...";

        mEngine = new QQmlEngine;
        configureQmlEngine();

        QQmlComponent component(mEngine, QUrl(QString("qrc:///qml/ApplicationContainer.qml")));
        mRootItem = qobject_cast<QQuickItem*>(component.create());
    }
    else {
        QQuickWebViewExperimental::setFlickableViewportEnabled(mApplication->desc().flickable());

        mWindow = new QQuickView;
        mWindow->installEventFilter(this);


        mEngine = mWindow->engine();
        configureQmlEngine();

        connect(mWindow, &QObject::destroyed,  [=](QObject *obj) {
            qDebug() << "Window destroyed";
        });

        mWindow->setColor(Qt::transparent);

        mWindow->reportContentOrientationChange(QGuiApplication::primaryScreen()->primaryOrientation());

        mWindow->setSurfaceType(QSurface::OpenGLSurface);
        QSurfaceFormat surfaceFormat = mWindow->format();
        surfaceFormat.setAlphaBufferSize(8);
        surfaceFormat.setRenderableType(QSurfaceFormat::OpenGLES);
        mWindow->setFormat(surfaceFormat);

        // make sure the platform window gets created to be able to set it's
        // window properties
        mWindow->create();

        // set different information bits for our window
        setWindowProperty(QString("_LUNE_WINDOW_TYPE"), QVariant(mWindowType));
        setWindowProperty(QString("_LUNE_WINDOW_PARENT_ID"), QVariant(mParentWindowId));
        setWindowProperty(QString("_LUNE_WINDOW_LOADING_ANIMATION_DISABLED"), QVariant(mApplication->loadingAnimationDisabled()));
        setWindowProperty(QString("_LUNE_APP_ICON"), QVariant(mApplication->icon()));
        setWindowProperty(QString("_LUNE_APP_ID"), QVariant(mApplication->id()));

        connect(mWindow, SIGNAL(visibleChanged(bool)), this, SLOT(onVisibleChanged(bool)));

        QPlatformNativeInterface *nativeInterface = QGuiApplication::platformNativeInterface();
        connect(nativeInterface, SIGNAL(windowPropertyChanged(QPlatformWindow*, const QString&)),
                this, SLOT(onWindowPropertyChanged(QPlatformWindow*, const QString&)));

        mWindow->setSource(QUrl(QString("qrc:///qml/ApplicationContainer.qml")));

        mRootItem = mWindow->rootObject();

        mWindow->resize(mSize);
    }
}
Esempio n. 24
0
  //----------------------------------------------------------------------------
  GLWidget::GLWidget(int& argc, char *argv[]):
    Configurable("QGLWidget"),
    _cur_fbo(0),
    _do_drag(false),
    _flags(0),
    _server(&_mutex_slot_links, &_cond_render, this)
  {
    QApplication::setOrganizationDomain("icg.tugraz.at");
    QApplication::setOrganizationName("icg.tugraz.at");
    QApplication::setApplicationName("VisLinks");

    const QDir config_dir =
      QStandardPaths::writableLocation(QStandardPaths::DataLocation);
    const QString user_config = config_dir.filePath("config.xml");

    {
      // Ensure config path and user config file exist
      QDir().mkpath(config_dir.path());
      QFile file( user_config );
      if( !file.open(QIODevice::ReadWrite | QIODevice::Text) )
        LOG_ERROR("Failed to open user config!");
      else if( !file.size() )
      {
        LOG_INFO("Creating empty user config in '" << user_config << "'");
        file.write(
          "<!-- VisLinks user config (overrides config file) -->\n"
          "<config/>"
        );
      }
    }

    //--------------------------------
    // Setup opengl and window
    //--------------------------------

    // fullscreen
    setGeometry( QGuiApplication::primaryScreen()->availableVirtualGeometry() );

    // don't allow user to change the window size
    setFixedSize( size() );

    // transparent, always on top window without any decoration
    setWindowFlags( Qt::WindowStaysOnTopHint
                  | Qt::FramelessWindowHint
                  | Qt::MSWindowsOwnDC
                  | Qt::WindowTransparentForInput
                  //| Qt::X11BypassWindowManagerHint
                  );
    setAttribute(Qt::WA_ShowWithoutActivating);
    setAttribute(Qt::WA_TranslucentBackground);
#ifdef USE_DESKTOP_BLEND1
    //setAttribute(Qt::WA_TranslucentBackground);
#else
    //setWindowOpacity(0.5);
#endif

#if 0
#if defined(WIN32) || defined(_WIN32)
    setMask(QRegion(size().width() - 2, size().height() - 2, 1, 1));
#else
    setMask(QRegion(-1, -1, 1, 1));
#endif
#endif
    setMouseTracking(true);

    //--------------------------------
    // Setup component system
    //--------------------------------

    if( argc != 2 )
      qFatal("Usage: %s <config>", argv[0]);

    assert(argc == 2 && argv && argv[1]);

    publishSlots(_core.getSlotCollector());

    if( !_config.initFrom(argv[1]) )
      qFatal("Failed to read config");
    _user_config.initFrom( to_string(user_config) );

    _core.startup();
    _core.attachComponent(&_config);
    _core.attachComponent(&_user_config);
    _core.attachComponent(&_server);
#ifdef USE_GPU_ROUTING
    _core.attachComponent(&_cost_analysis);
#endif
    _core.attachComponent(&_routing_cpu);
    _core.attachComponent(&_routing_cpu_dijkstra);
    _core.attachComponent(&_routing_dummy);
#ifdef USE_GPU_ROUTING
    _core.attachComponent(&_routing_gpu);
#endif
    _core.attachComponent(&_renderer);

    _core.attachComponent(this);
    registerArg("DebugDesktopImage", _debug_desktop_image);
    registerArg("DumpScreenshot", _dump_screenshot = 0);

    _core.init();

    LinksRouting::SlotSubscriber subscriber = _core.getSlotSubscriber();
    subscribeSlots(subscriber);

    QSurfaceFormat fmt;
    fmt.setRenderableType(QSurfaceFormat::RenderableType::OpenGL);
    fmt.setProfile(QSurfaceFormat::OpenGLContextProfile::CoreProfile);
    fmt.setAlphaBufferSize(8);

    _offscreen_surface.setFormat(fmt);
    _offscreen_surface.setScreen( QGuiApplication::primaryScreen() );
    _offscreen_surface.create();

    _gl_ctx.setFormat(fmt);
    if( !_gl_ctx.create() )
      qFatal("Failed to create OpenGL context.");
    if( !_gl_ctx.format().hasAlpha() )
      qFatal("Failed to enable alpha blending.");
    if( !_gl_ctx.makeCurrent(&_offscreen_surface) )
      qFatal("Could not activate OpenGL context.");

//    _render_thread =
//      QSharedPointer<RenderThread>(new RenderThread(this, width(), height()));
//    _gl_ctx->moveToThread(_render_thread.data());

    //std::cout << "Is virtual desktop: "
    //          << QApplication::desktop()->isVirtualDesktop()
    //          << std::endl;
  }
Esempio n. 25
0
int main(int argc, char *argv[])
{
    QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts);

    QSurfaceFormat format;
    format.setMajorVersion(4);
    format.setMinorVersion(1);
    format.setProfile(QSurfaceFormat::CoreProfile);
    format.setRenderableType(QSurfaceFormat::OpenGL);
    format.setSwapBehavior(QSurfaceFormat::DoubleBuffer);
    format.setSamples(2);

    // Today I learned: the surface itself doesn't need an alpha channel.
    // When we blend colours in OpenGL, the alpha value passed in with the colour
    // is only used internally by OpenGL in order to calculate the physical RGB
    // to write back into the colour buffer. We don't need to set any alpha on the
    // surface itself, since the RGB values will already have been blended by the
    // time they're written back to the colour buffer. If we do set the alpha, that
    // means we'll actually be able to see through the surface and whatever is behind
    // will be visible. This isn't what we want for the application main window!
    // If we want to create a frame buffer later on where the actual colour buffer
    // output should be translucent, override the default alpha buffer size to 8 bits.

    format.setDepthBufferSize(24);
    format.setRedBufferSize(8);
    format.setGreenBufferSize(8);
    format.setBlueBufferSize(8);
    format.setAlphaBufferSize(0);
    format.setStencilBufferSize(8);

    QSurfaceFormat::setDefaultFormat(format);
    qDebug() << "Set default OpenGL format:" << format;

    QApplication a(argc, argv);
    a.setApplicationName("Calliper");
    a.setApplicationDisplayName("Calliper");
    a.setOrganizationName("Infra");
    a.setOrganizationName("Infra");

    // Initialise the resource manager.
    ResourceManager::initialise();

    // Initialise the renderer.
    OpenGLRenderer::initialise();

    // Initialise the over-arching application.
    Application::initialise(new MainWindow());

    // Set up resources.
    resourceManager()->makeCurrent();
    resourceManager()->setUpOpenGLResources();
    renderer()->setUpOpenGLResources();
    resourceManager()->doneCurrent();

    application()->mainWindow()->show();
    
    int ret = a.exec();

    // Shut down the application.
    Application::shutdown();

    // Shut down the renderer.
    OpenGLRenderer::shutdown();

    // Shut down the resource manager.
    ResourceManager::shutdown();

    return ret;

    return a.exec();
}
Esempio n. 26
0
int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);

    ThreadGetData threadGetData; //thread to get data
    threadGetData.start();
    threadGetData.inputFromSMF("./smf/man.smf");

    /* faces import */
//    vec4 p1 = vec4(-0.5, 0.0, 0.0, 1.0);
//    vec4 p2 = vec4(0.5, 0.0, 0.0, 1.0);
//    vec4 p3 = vec4(0.0, 1.0, 0.0, 1.0);
//    vec4 p4 = vec4(-0.5, 0.5, 0.0, 1.0);
//    list<Triangle> triList;
//    Triangle a1(p1,p2,p3);
//    Triangle a2(p1,p2,p4);
//    triList.push_back(a1);
//    triList.push_back(a2);
//    threadGetData.inputFaces(triList);

    /*points import*/
    Vertex point1 = Vertex( QVector3D( 0.50f, 0.50f, 0.00f), QVector3D(1.0f, 0.0f, 0.0f), QVector3D(0.0f, 0.0f, 0.0f));
    Vertex point2 = Vertex( QVector3D( 0.00f, 0.50f, 0.00f), QVector3D(0.0f, 1.0f, 0.0f), QVector3D(0.0f, 0.0f, 0.0f));
    Vertex point3 = Vertex( QVector3D( 0.50f, 0.00f, 0.00f), QVector3D(1.0f, 0.0f, 0.0f), QVector3D(0.0f, 0.0f, 0.0f));
    Vertex point4 = Vertex( QVector3D( 0.25f, 0.25f, 0.50f), QVector3D(1.0f, 1.0f, 0.0f), QVector3D(0.0f, 0.0f, 0.0f));

    list<Vertex> pointsListTemp;
    pointsListTemp.push_back(point1);
    pointsListTemp.push_back(point2);
    pointsListTemp.push_back(point3);
    pointsListTemp.push_back(point4);

    threadGetData.inputPoints(pointsListTemp);

    /*lines import*/
    Vertex l1 = Vertex( QVector3D( 0.00f, 0.00f, 0.00f), QVector3D(0.0f, 0.0f, 0.0f), QVector3D(0.0f, 0.0f, 0.0f) );
    Vertex l2 = Vertex( QVector3D( 0.50f, 0.70f, 0.50f), QVector3D(0.0f, 0.0f, 0.0f), QVector3D(0.0f, 0.0f, 0.0f) );
    Vertex l3 = Vertex( QVector3D( 0.50f, 0.70f, -0.50f), QVector3D(0.0f, 0.0f, 0.0f), QVector3D(0.0f, 0.0f, 0.0f) );
    Vertex l4 = Vertex( QVector3D( 0.00f, 0.00f, 0.00f), QVector3D(0.0f, 0.0f, 0.0f), QVector3D(0.0f, 0.0f, 0.0f) );
    list<Vertex> linesListTemp;
    linesListTemp.push_back(l1);
    linesListTemp.push_back(l2);
    linesListTemp.push_back(l3);
    linesListTemp.push_back(l4);
    threadGetData.inputLines(linesListTemp);

    QSurfaceFormat format;
    format.setRenderableType(QSurfaceFormat::OpenGL);
    format.setProfile(QSurfaceFormat::CoreProfile);
    format.setDepthBufferSize(100);
    format.setVersion(3, 3);

    // Set the window up
    ObjectWindow objectwindow;
    objectwindow.setFormat(format);
    objectwindow.resize(QSize(800, 600));
    objectwindow.show();
    objectwindow.setAnimating(true);

    return app.exec();
}