// TODO: set surface/device size here (viewport?) void OpenGLVideo::setOpenGLContext(QOpenGLContext *ctx) { DPTR_D(OpenGLVideo); if (!ctx) { d.resetGL(); return; } #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) d.manager = ctx->findChild<ShaderManager*>(QStringLiteral("__qtav_shader_manager")); QSizeF surfaceSize = QOpenGLContext::currentContext()->surface()->size(); #else d.resetGL(); QSizeF surfaceSize = QSizeF(ctx->device()->width(), ctx->device()->height()); #endif d.ctx = ctx; // Qt4: set to null in resetGL() setProjectionMatrixToRect(QRectF(QPointF(), surfaceSize)); if (d.manager) return; // TODO: what if ctx is delete? d.manager = new ShaderManager(ctx); d.manager->setObjectName(QStringLiteral("__qtav_shader_manager")); #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) QObject::connect(ctx, SIGNAL(aboutToBeDestroyed()), this, SLOT(resetGL()), Qt::DirectConnection); //direct? #endif }
/*! \internal This replaces the standard draw() as used in Item3D. In this instance all drawing carried out using \a painter follows the standard sequence. However, after the transforms for the item have been applied, a QGraphicsBillboardTransform is applied to the model-view matrix. After the current item is drawn the model-view matrix from immediately before the billboard transform being applied will be restored so child items are not affected by it. */ void BillboardItem3D::draw(QGLPainter *painter) { // Bail out if this item and its children have been disabled. if (!isEnabled()) return; if (!isInitialized()) initialize(painter); if (!m_bConnectedToOpenGLContextSignal) { QOpenGLContext* pOpenGLContext = QOpenGLContext::currentContext(); if (pOpenGLContext) { bool Ok = QObject::connect(pOpenGLContext, SIGNAL(aboutToBeDestroyed()), this, SLOT(handleOpenglContextIsAboutToBeDestroyed()), Qt::DirectConnection); Q_UNUSED(Ok); // quell compiler warning Q_ASSERT(Ok); m_bConnectedToOpenGLContextSignal = true; } } //Setup picking int prevId = painter->objectPickId(); painter->setObjectPickId(objectPickId()); //Setup effect (lighting, culling, effects etc) const QGLLightParameters *currentLight = 0; QMatrix4x4 currentLightTransform; drawLightingSetup(painter, currentLight, currentLightTransform); bool viewportBlend, effectBlend; drawEffectSetup(painter, viewportBlend, effectBlend); drawCullSetup(); //Local and Global transforms drawTransformSetup(painter); //After all of the other transforms, apply the billboard transform to //ensure forward facing. painter->modelViewMatrix().push(); QGraphicsBillboardTransform bill; bill.setPreserveUpVector(m_preserveUpVector); bill.applyTo(const_cast<QMatrix4x4 *>(&painter->modelViewMatrix().top())); //Drawing drawItem(painter); //Pop the billboard transform from the model-view matrix stack so that it //is not applied to child items. painter->modelViewMatrix().pop(); //Draw children drawChildren(painter); //Cleanup drawTransformCleanup(painter); drawLightingCleanup(painter, currentLight, currentLightTransform); drawEffectCleanup(painter, viewportBlend, effectBlend); drawCullCleanup(); //Reset pick id. painter->setObjectPickId(prevId); }
GLC_Context::GLC_Context(QOpenGLContext *pOpenGLContext, QSurface *pSurface) : QObject() , m_pOpenGLContext(pOpenGLContext) , m_pSurface(pSurface) , m_ContextSharedData() { connect(m_pOpenGLContext, SIGNAL(aboutToBeDestroyed()), this, SLOT(openGLContextDestroyed()), Qt::DirectConnection); }
void QGLView::setupWindow() { connect(window()->openglContext(), SIGNAL(aboutToBeDestroyed()), this, SLOT(cleanup()), Qt::DirectConnection); QSurfaceFormat format = window()->format(); format.setDepthBufferSize(24); format.setSamples(4); window()->setFormat(format); }
void Scene_c3t3_item::set_data_item(const Scene_item* data_item) { data_item_ = data_item; if (NULL != data_item) { connect(data_item, SIGNAL(aboutToBeDestroyed()), this, SLOT(data_item_destroyed())); } }
// TODO: set surface/device size here (viewport?) void OpenGLVideo::setOpenGLContext(QOpenGLContext *ctx) { DPTR_D(OpenGLVideo); if (d.ctx == ctx) return; d.resetGL(); //TODO: is it ok to destroygl resources in another context? d.ctx = ctx; // Qt4: set to null in resetGL() if (!ctx) { return; } if (d.material) delete d.material; d.material = new VideoMaterial(); #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) d.manager = ctx->findChild<ShaderManager*>(QStringLiteral("__qtav_shader_manager")); QSizeF surfaceSize = QOpenGLContext::currentContext()->surface()->size(); #else QSizeF surfaceSize = QSizeF(ctx->device()->width(), ctx->device()->height()); #endif setProjectionMatrixToRect(QRectF(QPointF(), surfaceSize)); if (d.manager) return; // TODO: what if ctx is delete? d.manager = new ShaderManager(ctx); d.manager->setObjectName(QStringLiteral("__qtav_shader_manager")); #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) QObject::connect(ctx, SIGNAL(aboutToBeDestroyed()), this, SLOT(resetGL()), Qt::DirectConnection); //direct? #endif /// get gl info here because context is current(qt ensure it) //const QByteArray extensions(reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS))); bool hasGLSL = QOpenGLShaderProgram::hasOpenGLShaderPrograms(); qDebug("OpenGL version: %d.%d hasGLSL: %d", ctx->format().majorVersion(), ctx->format().minorVersion(), hasGLSL); static bool sInfo = true; if (sInfo) { sInfo = false; qDebug("GL_VERSION: %s", DYGL(glGetString(GL_VERSION))); qDebug("GL_VENDOR: %s", DYGL(glGetString(GL_VENDOR))); qDebug("GL_RENDERER: %s", DYGL(glGetString(GL_RENDERER))); qDebug("GL_SHADING_LANGUAGE_VERSION: %s", DYGL(glGetString(GL_SHADING_LANGUAGE_VERSION))); /// check here with current context can ensure the right result. If the first check is in VideoShader/VideoMaterial/decoder or somewhere else, the context can be null bool v = OpenGLHelper::isOpenGLES(); qDebug("Is OpenGLES: %d", v); v = OpenGLHelper::isEGL(); qDebug("Is EGL: %d", v); const int glsl_ver = OpenGLHelper::GLSLVersion(); qDebug("GLSL version: %d", glsl_ver); v = OpenGLHelper::isPBOSupported(); qDebug("Has PBO: %d", v); v = OpenGLHelper::has16BitTexture(); qDebug("Has 16bit texture: %d", v); v = OpenGLHelper::hasRG(); qDebug("Has RG texture: %d", v); qDebug() << ctx->format(); } }
Action::~Action() { emit aboutToBeDestroyed(this); // we are real owner of this menu if (menu()) { delete menu(); setMenu(0); } }
void ImageViewer::initializeGL() { initializeOpenGLFunctions(); // to be computed once through the software if (m_lutCalibrator) { m_lutCalibrator->initialize(); connect(context(), SIGNAL(aboutToBeDestroyed()), this, SLOT(onContextAboutToBeDestroyed())); } // glClearColor(1.0,1.0,1.0,1); glClear(GL_COLOR_BUFFER_BIT); }
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 tst_QOpenGL::aboutToBeDestroyed() { QWindow window; window.setSurfaceType(QWindow::OpenGLSurface); window.setGeometry(0, 0, 128, 128); window.create(); QOpenGLContext *context = new QOpenGLContext; QSignalSpy spy(context, SIGNAL(aboutToBeDestroyed())); context->create(); context->makeCurrent(&window); QCOMPARE(spy.size(), 0); delete context; QCOMPARE(spy.size(), 1); }
AbstractColumn::~AbstractColumn() { aboutToBeDestroyed(this); delete m_abstract_column_private; }
void Scene_item::itemAboutToBeDestroyed(Scene_item* item) { if(this == item) Q_EMIT aboutToBeDestroyed(); }
void CGAL::Three::Scene_item::itemAboutToBeDestroyed(CGAL::Three::Scene_item* item) { if(this == item) { Q_EMIT aboutToBeDestroyed(); } }
TOPPASWidget::~TOPPASWidget() { emit aboutToBeDestroyed(window_id_); }
// OpenGL initialization void Engine::initialize() { std::cout << "INITA" << std::endl; /* _GUIContext = _window->openglContext(); _GLContext = new QOpenGLContext(); */ _GUIContext = _window->openglContext(); _GLContext = new QOpenGLContext(); _format = new QSurfaceFormat(); _format->setRenderableType(QSurfaceFormat::RenderableType::OpenGL); _format->setMajorVersion(3); _format->setMinorVersion(3); _format->setProfile(QSurfaceFormat::OpenGLContextProfile::CompatibilityProfile); _GLContext->setFormat(*_format); _GLContext->create(); if(_GLContext->isValid()) std::cout << "_GLContext is valid." << std::endl; else std::cout << "_GLContext is not valid." << std::endl; if(_GLContext->makeCurrent(_window)) std::cout << "Made current: _GLContext" << std::endl; else std::cout << "Didn't make current: _GLContext" << std::endl; _window->openglContext()->format().setRenderableType(QSurfaceFormat::RenderableType::OpenGL); _window->openglContext()->format().setProfile(QSurfaceFormat::OpenGLContextProfile::CompatibilityProfile); _window->openglContext()->format().setMajorVersion(3); _window->openglContext()->format().setMinorVersion(3); std::cout << "GL info: " << glGetString(GL_VERSION) << std::endl; //_GUIContext->makeCurrent(_window); /* QSurfaceFormat f = _window->openglContext()->format(); f.setVersion(3, 3); f.setProfile(QSurfaceFormat::CompatibilityProfile); _window->openglContext()->setFormat(f); */ _GLFunctions = _window->openglContext()->functions(); //GLuint hej; //_qlFunctions->glGenFramebuffers(1, &hej); t = 0; _program = new QOpenGLShaderProgram(); _program->addShaderFromSourceCode(QOpenGLShader::Vertex, vertexShader); _program->addShaderFromSourceCode(QOpenGLShader::Fragment, fragmentShader); _program->bindAttributeLocation("vertices", 0); _program->link(); connect(_window->openglContext(), SIGNAL(aboutToBeDestroyed()), this, SLOT(cleanup()), Qt::DirectConnection); createVolume(1,1,1,1); if(_window->openglContext()->isValid()) std::cout << "_window->openglContext() is valid." << std::endl; else std::cout << "_window->openglContext() is not valid." << std::endl; // GLuint fboHandle; // glGenFramebuffers(1, &fboHandle); // glBindFramebuffer(GL_FRAMEBUFFER, fboHandle); }
TextInfo::~TextInfo() { emit(aboutToBeDestroyed(this)); detach(); delete [] m_arStatistics; }
void Window::initializeGL() { initializeOpenGLFunctions(); connect(context(), SIGNAL(aboutToBeDestroyed()), this, SLOT(teardownGL()), Qt::DirectConnection); printVersionInformation(); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); //Loading, compiling and linking shaders. shaderProgram = new QOpenGLShaderProgram(); shaderProgram->addShaderFromSourceFile(QOpenGLShader::Vertex, ".\\simple.vert"); shaderProgram->addShaderFromSourceFile(QOpenGLShader::Fragment, ".\\simple.frag"); shaderProgram->link(); shaderProgram->bind(); //Creating the VAO vertexArrayObject.create(); vertexArrayObject.bind(); //We now need to combine the data of out mesh and our interator mesh vector<Vertex> combinedVertexBuffer; combinedVertexBuffer.reserve(mesh->getVertexVector().size() + interatorMesh->getVertexVector().size()); combinedVertexBuffer.insert(combinedVertexBuffer.end(), mesh-> getVertexVector().begin(), mesh->getVertexVector().end()); combinedVertexBuffer.insert(combinedVertexBuffer.end(), interatorMesh-> getVertexVector().begin(), interatorMesh->getVertexVector().end()); //Index buffer vector<unsigned int> combinedIndexBuffer; combinedIndexBuffer.reserve(mesh->getIndexVector().size() + interatorMesh-> getIndexVector().size()); combinedIndexBuffer.insert(combinedIndexBuffer.end(), mesh-> getIndexVector().begin(), mesh->getIndexVector().end()); unsigned int vertexVectorSize = static_cast<unsigned int>(mesh-> getVertexVector().size()); for (auto index : interatorMesh->getIndexVector()) { combinedIndexBuffer.push_back(index + vertexVectorSize); } //Creating the VBO for the mesh vertexBuffer.create(); vertexBuffer.bind(); vertexBuffer.setUsagePattern(QOpenGLBuffer::DynamicDraw); vertexBuffer.allocate(combinedVertexBuffer.data(), static_cast<int>(combinedVertexBuffer.size() * sizeof(Vertex))); //Creating IBO for the mesh indexBuffer = QOpenGLBuffer(QOpenGLBuffer::IndexBuffer); indexBuffer.create(); indexBuffer.bind(); indexBuffer.setUsagePattern(QOpenGLBuffer::DynamicDraw); indexBuffer.allocate(combinedIndexBuffer.data(), static_cast<int>(combinedIndexBuffer.size() * sizeof(unsigned int))); //Enabling attribute arrays for vertex, normal and color data. shaderProgram->enableAttributeArray(0); shaderProgram->enableAttributeArray(1); shaderProgram->enableAttributeArray(2); shaderProgram->setAttributeBuffer(0, GL_FLOAT, Vertex::positionOffset(), Vertex::PositionTupleSize, Vertex::stride()); shaderProgram->setAttributeBuffer(1, GL_FLOAT, Vertex::colorOffset(), Vertex::ColorTupleSize, Vertex::stride()); shaderProgram->setAttributeBuffer(2, GL_FLOAT, Vertex::normalOffset(), Vertex::NormalTupleSize, Vertex::stride()); vertexArrayObject.release(); vertexBuffer.release(); indexBuffer.release(); shaderProgram->release(); //Setting up model, view and projection matrices. mvpSetup(); //Creating interator ray interator = new Ray(vec3(0.0f, 0.0f, 0.0f), vec3(0.0f, 0.0f, 1.0f)); //Setting up the collision detector collisionDetector.setMesh(mesh); collisionDetector.setRay(interator); //Initializing haptic device if (hapticsEnabled) { haptic.initializeHL(); haptic.updateHapticWorkspace(); haptic.setInterator(interator); haptic.setCollisionDetector(&collisionDetector); haptic.setCollisionPath(&path); haptic.setMesh(mesh); haptic.setShaderProgram(shaderProgram); haptic.setVAO(&vertexArrayObject); handle = hdScheduleAsynchronous(HapticInterface::mainHapticCallback, &haptic, HD_MAX_SCHEDULER_PRIORITY); hdStartScheduler(); } }
/*! Destructor. */ Place::~Place() { emit aboutToBeDestroyed(); delete mLandmark; }
void HsQMLCanvasBackEnd::doRendering() { if (!mGL) { mGL = mWindow->openglContext(); QObject::connect( mGL, SIGNAL(aboutToBeDestroyed()), this, SLOT(doCleanup())); HsQMLGLCanvasType ctype; QSurfaceFormat format = mGL->format(); switch (format.renderableType()) { case QSurfaceFormat::OpenGL: ctype = HSQML_GL_DESKTOP; break; case QSurfaceFormat::OpenGLES: ctype = HSQML_GL_ES; break; default: setStatus(HsQMLCanvas::BadConfig); return; } mGLViewportFn = reinterpret_cast<GLViewportFn>( mGL->getProcAddress("glViewport")); mGLClearColorFn = reinterpret_cast<GLClearColorFn>( mGL->getProcAddress("glClearColor")); mGLClearFn = reinterpret_cast<GLClearFn>( mGL->getProcAddress("glClear")); if (!mGLViewportFn || !mGLClearColorFn || !mGLClearFn) { setStatus(HsQMLCanvas::BadProcs); return; } mGLCallbacks->mSetupCb( ctype, format.majorVersion(), format.minorVersion()); } // Reset OpenGL state before rendering #if QT_VERSION >= 0x050200 mWindow->resetOpenGLState(); #else #warning Resetting OpenGL state requires Qt 5.2 or later #endif // Clear window if painting below the scenegraph if (mWinInfo.needsBelowClear()) { QColor bg = mWindow->color(); mGLClearColorFn(bg.redF(), bg.greenF(), bg.blueF(), bg.alphaF()); mGLClearFn(GL_COLOR_BUFFER_BIT); } // Setup prior to paint callback QMatrix4x4 matrix; bool inlineMode = HsQMLCanvas::Inline == mDisplayMode; if (inlineMode) { if (!mFBO->bind()) { setStatus(HsQMLCanvas::BadBind); return; } mGLViewportFn(0, 0, qCeil(mCanvasWidth), qCeil(mCanvasHeight)); // Clear FBO to transparent mGLClearColorFn(0, 0, 0, 0); mGLClearFn(GL_COLOR_BUFFER_BIT); } else { // Calculate matrix for non-inline display modes QMatrix4x4 smatrix; QSGNode* node = mTransformNode; while (node) { if (QSGNode::TransformNodeType == node->type()) { QSGTransformNode* tnode = static_cast<QSGTransformNode*>(node); smatrix = tnode->matrix() * smatrix; } node = node->parent(); } matrix.translate(-1, 1); matrix.scale(2.0f/mWindow->width(), -2.0f/mWindow->height()); matrix *= smatrix; matrix.scale(mItemWidth/2.0f, mItemHeight/2.0f); matrix.translate(1, 1); mGLViewportFn(0, 0, mWindow->width(), mWindow->height()); } setStatus(HsQMLCanvas::Okay); mGLCallbacks->mPaintCb(matrix.data(), mItemWidth, mItemHeight); if (inlineMode) { mFBO->release(); } }