SystemCompositor::SystemCompositor() : VCompositor(this) , m_currentSurface(0) { // Enable the subsurface extension enableSubSurfaceExtension(); // System compositor protocol m_protocol = new SystemCompositorServer(this, QWaylandCompositor::handle()); // Allow QML to access this compositor rootContext()->setContextProperty("compositor", this); // All the screen is initially available m_availableGeometry = screen()->availableGeometry(); connect(screen(), SIGNAL(virtualGeometryChanged(QRect)), this, SIGNAL(screenGeometryChanged())); // Load the QML code setSource(QUrl("qrc:///qml/Compositor.qml")); setResizeMode(QQuickView::SizeRootObjectToView); setColor(Qt::black); winId(); connect(this, SIGNAL(windowAdded(QVariant)), rootObject(), SLOT(windowAdded(QVariant))); connect(this, SIGNAL(windowDestroyed(QVariant)), rootObject(), SLOT(windowDestroyed(QVariant))); connect(this, SIGNAL(windowResized(QVariant)), rootObject(), SLOT(windowResized(QVariant))); connect(this, SIGNAL(sceneGraphInitialized()), this, SLOT(sceneGraphInitialized()), Qt::DirectConnection); connect(this, SIGNAL(frameSwapped()), this, SLOT(frameSwapped())); }
HsQMLCanvasBackEnd::HsQMLCanvasBackEnd( QQuickWindow* win, const HsQMLGLDelegate::CallbacksRef& cbs, HsQMLCanvas::DisplayMode mode) : mWindow(win) , mWinInfo(HsQMLWindowInfo::getWindowInfo(win)) , mGLCallbacks(cbs) , mGL(NULL) , mStatus(HsQMLCanvas::Okay) , mDisplayMode(mode) , mItemWidth(0) , mItemHeight(0) , mTransformNode(NULL) , mCanvasWidth(0) , mCanvasHeight(0) { if (HsQMLCanvas::Above == mDisplayMode) { QObject::connect( win, SIGNAL(afterRendering()), this, SLOT(doRendering())); } else { QObject::connect( win, SIGNAL(beforeRendering()), this, SLOT(doRendering())); if (HsQMLCanvas::Below == mDisplayMode) { mWinInfo.addBelow(); QObject::connect( win, SIGNAL(frameSwapped()), this, SLOT(doEndFrame())); } } }
void MainWidget::initializeGL() { initializeOpenGLFunctions(); connect(this, SIGNAL(frameSwapped()), this, SLOT(update())); //animationTimer.setSingleShot(true); //connect(&animationTimer, SIGNAL(timeout()), this, SLOT(animate())); distance = -4; trackball = TrackBall(0.0f, QVector3D(0, 1, 0), TrackBall::Sphere); glClearColor(0.05, 0.05, 0.05, 1); // Enable depth buffer glEnable(GL_DEPTH_TEST); // Enable back face culling glEnable(GL_CULL_FACE); glFrontFace(GL_CCW); glCullFace(GL_BACK); initShaders(); initTextures(); geometries = new GeometryEngine(&programearth, &programearthnobump); gshhs = new gshhsData(&programgshhs); skybox = new SkyBox(&programskybox); }
LipstickCompositor::LipstickCompositor() : QWaylandCompositor(this), m_totalWindowCount(0), m_nextWindowId(1), m_homeActive(true), m_shaderEffect(0), m_fullscreenSurface(0), m_directRenderingActive(false), m_topmostWindowId(0), m_screenOrientation(Qt::PrimaryOrientation), m_displayState(new MeeGo::QmDisplayState(this)), m_retainedSelection(0) { setColor(Qt::black); setRetainedSelectionEnabled(true); if (m_instance) qFatal("LipstickCompositor: Only one compositor instance per process is supported"); m_instance = this; QObject::connect(this, SIGNAL(frameSwapped()), this, SLOT(windowSwapped())); QObject::connect(this, SIGNAL(beforeSynchronizing()), this, SLOT(clearUpdateRequest())); connect(m_displayState, SIGNAL(displayStateChanged(MeeGo::QmDisplayState::DisplayState)), this, SLOT(reactOnDisplayStateChanges(MeeGo::QmDisplayState::DisplayState))); QObject::connect(HomeApplication::instance(), SIGNAL(aboutToDestroy()), this, SLOT(homeApplicationAboutToDestroy())); m_orientationSensor = new QOrientationSensor(this); QObject::connect(m_orientationSensor, SIGNAL(readingChanged()), this, SLOT(setScreenOrientationFromSensor())); if (!m_orientationSensor->connectToBackend()) { qWarning() << "Could not connect to the orientation sensor backend"; } else { if (!m_orientationSensor->start()) qWarning() << "Could not start the orientation sensor"; } emit HomeApplication::instance()->homeActiveChanged(); QDesktopServices::setUrlHandler("http", this, "openUrl"); QDesktopServices::setUrlHandler("https", this, "openUrl"); QDesktopServices::setUrlHandler("mailto", this, "openUrl"); connect(QGuiApplication::clipboard(), SIGNAL(dataChanged()), SLOT(clipboardDataChanged())); }
VideoPlayer::VideoPlayer(QWidget *parent, Qt::WindowFlags f) : QOpenGLWidget(parent, f), //PosUpdateTimer(this) PosUpdate(mpv) { mpv = mpv::qt::Handle::FromRawHandle(mpv_create()); if(!mpv) throw std::runtime_error("could not create mpv context"); //mpv_set_option_string(mpv, "terminal", "yes"); //mpv_set_option_string(mpv, "msg-level", "all=v"); if(mpv_initialize(mpv) < 0) throw std::runtime_error("could not initialize mpv context"); mpv::qt::set_option_variant(mpv, "vo", "opengl-cb"); mpv_gl = (mpv_opengl_cb_context *)mpv_get_sub_api(mpv, MPV_SUB_API_OPENGL_CB); if(!mpv_gl) throw std::runtime_error("OpenGL not compiled in"); mpv_opengl_cb_set_update_callback(mpv_gl, VideoPlayer::on_update, (void*)this); connect(this, SIGNAL(frameSwapped()), SLOT(swapped())); //mpv_observe_property(mpv, 0, "time-pos", MPV_FORMAT_DOUBLE); mpv_set_wakeup_callback(mpv, wakeup, this); pause(); TimePosition = 0; connect(&PosUpdate, SIGNAL(timeChanged(int)), this, SLOT(timeChange(int))); //connect(&PosUpdateTimer, SIGNAL(timeout()), this, SLOT(updateTime())); //PosUpdateTimer.start(40); }
MpvWidget::MpvWidget(QWidget *parent, Qt::WindowFlags f) : QOpenGLWidget(parent, f) { mpv = mpv::qt::Handle::FromRawHandle(mpv_create()); if (!mpv) throw std::runtime_error("could not create mpv context"); mpv_set_option_string(mpv, "terminal", "yes"); mpv_set_option_string(mpv, "msg-level", "all=v"); if (mpv_initialize(mpv) < 0) throw std::runtime_error("could not initialize mpv context"); // Make use of the MPV_SUB_API_OPENGL_CB API. mpv::qt::set_option_variant(mpv, "vo", "opengl-cb"); // Request hw decoding, just for testing. mpv::qt::set_option_variant(mpv, "hwdec", "auto"); mpv_gl = (mpv_opengl_cb_context *)mpv_get_sub_api(mpv, MPV_SUB_API_OPENGL_CB); if (!mpv_gl) throw std::runtime_error("OpenGL not compiled in"); mpv_opengl_cb_set_update_callback(mpv_gl, MpvWidget::on_update, (void *)this); connect(this, SIGNAL(frameSwapped()), SLOT(swapped())); mpv_observe_property(mpv, 0, "duration", MPV_FORMAT_DOUBLE); mpv_observe_property(mpv, 0, "time-pos", MPV_FORMAT_DOUBLE); mpv_set_wakeup_callback(mpv, wakeup, this); }
void tst_QOpenGLWidget::createNonTopLevel() { QWidget w; ClearWidget *glw = new ClearWidget(&w, 600, 700); QSignalSpy frameSwappedSpy(glw, SIGNAL(frameSwapped())); w.resize(400, 400); w.show(); QTest::qWaitForWindowExposed(&w); QVERIFY(frameSwappedSpy.count() > 0); QVERIFY(glw->m_resizeCalled); glw->m_resizeCalled = false; QVERIFY(!glw->m_resizeOk); glw->resize(600, 700); QVERIFY(glw->m_initCalled); QVERIFY(glw->m_resizeCalled); QVERIFY(glw->m_resizeOk); QVERIFY(glw->m_paintCalled); QImage image = glw->grabFramebuffer(); QVERIFY(!image.isNull()); QCOMPARE(image.width(), glw->width()); QCOMPARE(image.height(), glw->height()); QVERIFY(image.pixel(30, 40) == qRgb(255, 0, 0)); glw->doneCurrent(); QVERIFY(!QOpenGLContext::currentContext()); glw->makeCurrent(); QVERIFY(QOpenGLContext::currentContext() == glw->context() && glw->context()); }
void GLWindow::initializeGL() { initializeOpenGLFunctions(); printContext(); glClearColor(0.0f,0.9f,1.0f,10.f); shader.compile("../Renderer/shader.vert","../Renderer/shader.frag"); connect(this,SIGNAL(frameSwapped()),this,SLOT(update())); }
void ModelRenderer::windowChanged(QQuickWindow *window) { LOG_ENTER(); if( window != nullptr && window != m_window ){ window->setClearBeforeRendering(false); connect( window, SIGNAL(afterAnimating()), this, SLOT(afterAnimating()), Qt::DirectConnection ); connect( window, SIGNAL(afterRendering()), this, SLOT(afterRendering()), Qt::DirectConnection ); connect( window, SIGNAL(afterSynchronizing()), this, SLOT(afterSynchronizing()), Qt::DirectConnection ); connect( window, SIGNAL(beforeRendering()), this, SLOT(beforeRendering()), Qt::DirectConnection ); connect( window, SIGNAL(beforeSynchronizing()), this, SLOT(beforeSynchronizing()), Qt::DirectConnection ); connect( window, SIGNAL(frameSwapped()), this, SLOT(frameSwapped()), Qt::DirectConnection ); connect( window, SIGNAL(openglContextCreated(QOpenGLContext*)), this, SLOT(openglContextCreated(QOpenGLContext*)), Qt::DirectConnection ); connect( window, SIGNAL(sceneGraphError(QQuickWindow::SceneGraphError,QString)), this, SLOT(sceneGraphError(QQuickWindow::SceneGraphError,QString)), Qt::DirectConnection ); connect( window, SIGNAL(sceneGraphInitialized()), this, SLOT(sceneGraphInitialized()), Qt::DirectConnection ); connect( window, SIGNAL(sceneGraphInvalidated()), this, SLOT(sceneGraphInvalidated()),Qt::DirectConnection ); }
void HomeApplication::sendHomeReadySignalIfNotAlreadySent() { if (!homeReadySent) { homeReadySent = true; disconnect(LipstickCompositor::instance(), SIGNAL(frameSwapped()), this, SLOT(sendHomeReadySignalIfNotAlreadySent())); emit homeReady(); } }
GLWidget::GLWidget() { // Update the Widget after a frameswap connect( this, SIGNAL( frameSwapped() ), this, SLOT( update() ) ); // Exit the application connect( this, SIGNAL( exitFlag() ), QApplication::instance(), SLOT( quit() ) ); // Rotate Clockwise connect( this, SIGNAL( rotateClockwise( bool ) ), this, SLOT( set_rotate_cw( bool ) ) ); connect( this, SIGNAL( rotateClockwiseMoon( bool ) ), this, SLOT( set_rotate_cw_moon( bool ) ) ); // Translate Clockwise connect( this, SIGNAL( translateClockwise( bool ) ), this, SLOT( set_translate_cw( bool ) ) ); connect( this, SIGNAL( translateClockwiseMoon( bool ) ), this, SLOT( set_translate_cw_moon( bool ) ) ); // Context Menu context_menu = new QMenu(); setContextMenuPolicy(Qt::CustomContextMenu); action_pause = context_menu->addAction("Unpause All"); action_exit = context_menu->addAction("Exit Program"); // Context Menu Request connect( this, SIGNAL( customContextMenuRequested( const QPoint ) ), this, SLOT( contextMenuRequested( QPoint ) ) ); // Context Menu Pause All connect( action_pause, SIGNAL( triggered() ), this, SLOT( pause() ) ); // Context Menu Quit connect( action_exit, SIGNAL( triggered() ), QApplication::instance(), SLOT( quit() ) ); // Set the initial scene transform3d.setTranslation( 3.0 * sin( 0.0f ), 0, 3.0 * cos( 0.0f ) ); transform3d.translate( 0.0f, 0.0f, -10.0f ); transform3d_2.scale( 0.5f ); transform3d_2.setTranslation( transform3d.translation().x() + 2.0f * sin( 0.0f ), transform3d.translation().y(), transform3d.translation().z() + 2.0f * cos( 0.0f ) ); camera3d.rotate( -25.0f, 1.0f, 0.0f, 0.0f ); camera3d.translate( 0.0f, 3.5f, 0.0f ); // Initialize planet system helper variables is_paused = true; rotate_cw = false; translate_cw = true; rotate_cw_moon = true; translate_cw_moon = false; setOrbitString(); }
void tst_QOpenGLWidget::create() { QScopedPointer<QOpenGLWidget> w(new QOpenGLWidget); QVERIFY(!w->isValid()); QSignalSpy frameSwappedSpy(w.data(), SIGNAL(frameSwapped())); w->show(); QTest::qWaitForWindowExposed(w.data()); QVERIFY(frameSwappedSpy.count() > 0); QVERIFY(w->isValid()); QVERIFY(w->context()); QCOMPARE(w->context()->format(), w->format()); QVERIFY(w->defaultFramebufferObject() != 0); }
void Window::initializeGL() { // Initialize OpenGL Backend initializeOpenGLFunctions(); connect(context(), SIGNAL(aboutToBeDestroyed()), this, SLOT(teardownGL()), Qt::DirectConnection); connect(this, SIGNAL(frameSwapped()), this, SLOT(update())); printVersionInformation(); // Set global information glEnable(GL_CULL_FACE); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Application-specific initialization { // Create Shader (Do not release until VAO is created) m_program = new QOpenGLShaderProgram(); m_program->addShaderFromSourceFile(QOpenGLShader::Vertex, ":/shaders/simple.vert"); m_program->addShaderFromSourceFile(QOpenGLShader::Fragment, ":/shaders/simple.frag"); m_program->link(); m_program->bind(); // Cache Uniform Locations u_modelToWorld = m_program->uniformLocation("modelToWorld"); u_worldToCamera = m_program->uniformLocation("worldToCamera"); u_cameraToView = m_program->uniformLocation("cameraToView"); // Create Buffer (Do not release until VAO is created) m_vertex.create(); m_vertex.bind(); m_vertex.setUsagePattern(QOpenGLBuffer::StaticDraw); m_vertex.allocate(sg_vertexes, sizeof(sg_vertexes)); // Create Vertex Array Object m_object.create(); m_object.bind(); m_program->enableAttributeArray(0); m_program->enableAttributeArray(1); m_program->setAttributeBuffer(0, GL_FLOAT, Vertex::positionOffset(), Vertex::PositionTupleSize, Vertex::stride()); m_program->setAttributeBuffer(1, GL_FLOAT, Vertex::colorOffset(), Vertex::ColorTupleSize, Vertex::stride()); // Release (unbind) all m_object.release(); m_vertex.release(); m_program->release(); } }
void VideoItem::handleWindowChanged(QQuickWindow *win) { if (win) { // Connect the beforeRendering signal to our paint function. // Since this call is executed on the rendering thread it must be // a Qt::DirectConnection setFlag(QQuickItem::ItemHasContents, true); connect(win, SIGNAL(frameSwapped()), this, SLOT(update())); connect(win, SIGNAL(widthChanged(int)), this, SLOT(handleGeometryChanged(int))); connect(win, SIGNAL(heightChanged(int)), this, SLOT(handleGeometryChanged(int))); connect(win, SIGNAL(sceneGraphInitialized()), this, SLOT(handleSceneGraphInitialized())); // If we allow QML to do the clearing, they would clear what we paint // and nothing would show. //win->setClearBeforeRendering(false); } }
void MainWidget::initializeGL() { initializeOpenGLFunctions(); connect(this, SIGNAL(frameSwapped()), this, SLOT(update())); glClearColor(1.0f, 0.0f, 0.0f, 1.0f); // Enable depth buffer //glEnable(GL_DEPTH_TEST); // Enable back face culling //glEnable(GL_CULL_FACE); initShaders(); initTextures(); initFrameBuffers(); }
LipstickCompositor::LipstickCompositor() : QWaylandCompositor(this), m_totalWindowCount(0), m_nextWindowId(1), m_homeActive(true), m_shaderEffect(0), m_fullscreenSurface(0), m_directRenderingActive(false), m_topmostWindowId(0), m_screenOrientation(Qt::PrimaryOrientation), m_displayState(new MeeGo::QmDisplayState(this)) { setColor(Qt::black); if (m_instance) qFatal("LipstickCompositor: Only one compositor instance per process is supported"); m_instance = this; QObject::connect(this, SIGNAL(frameSwapped()), this, SLOT(windowSwapped())); QObject::connect(this, SIGNAL(beforeSynchronizing()), this, SLOT(clearUpdateRequest())); connect(m_displayState, SIGNAL(displayStateChanged(MeeGo::QmDisplayState::DisplayState)), this, SLOT(reactOnDisplayStateChanges(MeeGo::QmDisplayState::DisplayState))); emit HomeApplication::instance()->homeActiveChanged(); QDesktopServices::setUrlHandler("http", this, "openUrl"); QDesktopServices::setUrlHandler("https", this, "openUrl"); QDesktopServices::setUrlHandler("mailto", this, "openUrl"); }
/** * @brief Default constructor for OGLWidget. */ OGLWidget::OGLWidget() { // Update the widget after a frameswap connect( this, SIGNAL( frameSwapped() ), this, SLOT( update() ) ); // Allows keyboard input to fall through setFocusPolicy( Qt::ClickFocus ); // Default camera view camera.rotate( -25.0f, 1.0f, 0.0f, 0.0f ); camera.translate( 0.0f, 8.0f, 15.0f ); renderables["Cube"] = new Cube(); renderables["Cylindar"] = new Cylindar(); ((BaseEntity*)renderables["Cylindar"])->Transform.translate( -3, 3, 0 ); renderables["Sphere"] = new Sphere(); ((BaseEntity*)renderables["Sphere"])->Transform.translate( 3, 3, 0 ); renderables["Board"] = new Board(); }
MainGui::MainGui(QWidget *parent) : QMainWindow(parent) { mainWidget = new QWidget(this); mainLayout = new QGridLayout(mainWidget); mainWidget->setLayout(mainLayout); setCentralWidget(mainWidget); mainLayout->setColumnStretch(0, 4); mainLayout->setColumnStretch(1, 1); view = new OpenGLViewer(this); mainLayout->addWidget(view, 0, 0); ui = new Ui(this); mainLayout->addWidget(ui, 0, 1); connect(view, SIGNAL(frameSwapped()), this, SLOT(OnFrameSwapped())); connect(ui->radioGroup, SIGNAL(selectionChanged(int)), this, SLOT(OnAlgorithmChanged(int))); connect(ui->esmCoeffSlider, SIGNAL(valueChanged(double)), this, SLOT(OnParamChanged(double))); connect(ui->ksizeSlider, SIGNAL(valueChanged(double)), this, SLOT(OnParamChanged(double))); connect(ui->darknessSlider, SIGNAL(valueChanged(double)), this, SLOT(OnParamChanged(double))); }
void HomeApplication::connectFrameSwappedSignal(bool mainWindowVisible) { if (!homeReadySent && mainWindowVisible) { connect(LipstickCompositor::instance(), SIGNAL(frameSwapped()), this, SLOT(sendHomeReadySignalIfNotAlreadySent())); } }
void Window::initializeGL() { // Initialize OpenGL Backend initializeOpenGLFunctions(); //This is equivalent to register an IDLE function callback for animation //We don't control the frame rate is as fast as the system is available //Maybe using the vsync connect(this, SIGNAL(frameSwapped()), this, SLOT(update())); printVersionInformation(); //Global GL configurations glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glClearColor(0.15f, 0.15f, 0.15f, 1.0f); // Application-specific initialization { // Create Shader (Do not release until VAO is created) m_program_ptr = new QOpenGLShaderProgram(); m_program_ptr->addShaderFromSourceFile(QOpenGLShader::Vertex, "Resources/shaders/simpleVertex.glsl"); m_program_ptr->addShaderFromSourceFile(QOpenGLShader::Fragment, "Resources/shaders/simpleFragment.glsl"); m_program_ptr->link(); m_program_ptr->bind(); //Fill the arrays with date in CPU side createGeomerty(); // Create Vertex Array Object (Remember this needs to be done BEFORE binding the vertex) m_vao.create(); m_vao.bind(); // Create Buffers (Do not release until VAO is created) m_vertex_buffer = QOpenGLBuffer(QOpenGLBuffer::VertexBuffer); m_vertex_buffer.create(); m_vertex_buffer.bind(); m_vertex_buffer.setUsagePattern(QOpenGLBuffer::StaticDraw); m_vertex_buffer.allocate(m_vertices.constData(), m_vertices.size() * sizeof(Vertex)); m_index_buffer = QOpenGLBuffer(QOpenGLBuffer::IndexBuffer); m_index_buffer.create(); m_index_buffer.bind(); m_index_buffer.setUsagePattern(QOpenGLBuffer::StaticDraw); m_index_buffer.allocate(m_indexes.constData(), m_indexes.size() * sizeof(unsigned int)); m_program_ptr->enableAttributeArray(0); m_program_ptr->enableAttributeArray(1); m_program_ptr->setAttributeBuffer(0, GL_FLOAT, Vertex::positionOffset(), Vertex::PositionTupleSize, Vertex::stride()); m_program_ptr->setAttributeBuffer(1, GL_FLOAT, Vertex::colorOffset(), Vertex::ColorTupleSize, Vertex::stride()); // Release (unbind) all m_vao.release(); m_index_buffer.release(); m_index_buffer.release(); m_program_ptr->release(); //Once we have a copy in the GPU there is no need to keep a CPU copy (unless yopu want to) m_indexes.clear(); m_vertices.clear(); } //Program main logic //Camera start with no rotation m_new_rotation = m_base_rotation = QQuaternion(1.0f, QVector3D(0.0f, 0.0f, 0.0f)); m_mouse_draging = false; m_fovy_y = 45.0f; }