// 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 }
// 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(); } }
void QSGRenderer::setProjectionMatrixToDeviceRect() { setProjectionMatrixToRect(m_device_rect); }