int main(int argc, char **argv) { ::testing::InitGoogleTest(&argc, argv); QGuiApplication app(argc, argv); Q_UNUSED(app); QSurfaceFormat format; format.setMajorVersion(3); format.setMinorVersion(0); QOpenGLContext context; context.setFormat(format); context.create(); if (!context.isValid()) return 1; qDebug() << QString::fromLatin1("Context created."); QOffscreenSurface surface; surface.setFormat(format); surface.create(); if(!surface.isValid()) return 2; qDebug() << QString::fromLatin1("Surface created."); context.makeCurrent(&surface); return RUN_ALL_TESTS(); }
void tst_QOpenGL::openGLPaintDevice() { #if defined(Q_OS_LINUX) && defined(Q_CC_GNU) && !defined(__x86_64__) QSKIP("QTBUG-22617"); #endif QFETCH(int, surfaceClass); QScopedPointer<QSurface> surface(createSurface(surfaceClass)); QOpenGLContext ctx; QVERIFY(ctx.create()); QSurfaceFormat format = ctx.format(); if (format.majorVersion() < 2) QSKIP("This test requires at least OpenGL 2.0"); QVERIFY(ctx.makeCurrent(surface.data())); const QSize size(128, 128); QImage image(size, QImage::Format_RGB32); QPainter p(&image); p.fillRect(0, 0, image.width() / 2, image.height() / 2, Qt::red); p.fillRect(image.width() / 2, 0, image.width() / 2, image.height() / 2, Qt::green); p.fillRect(image.width() / 2, image.height() / 2, image.width() / 2, image.height() / 2, Qt::blue); p.fillRect(0, image.height() / 2, image.width() / 2, image.height() / 2, Qt::white); p.end(); QOpenGLFramebufferObject fbo(size); QVERIFY(fbo.bind()); QOpenGLPaintDevice device(size); QVERIFY(p.begin(&device)); p.fillRect(0, 0, image.width() / 2, image.height() / 2, Qt::red); p.fillRect(image.width() / 2, 0, image.width() / 2, image.height() / 2, Qt::green); p.fillRect(image.width() / 2, image.height() / 2, image.width() / 2, image.height() / 2, Qt::blue); p.fillRect(0, image.height() / 2, image.width() / 2, image.height() / 2, Qt::white); p.end(); QImage actual = fbo.toImage().convertToFormat(QImage::Format_RGB32); QCOMPARE(image.size(), actual.size()); QCOMPARE(image, actual); QVERIFY(p.begin(&device)); p.fillRect(0, 0, image.width(), image.height(), Qt::black); p.drawImage(0, 0, image); p.end(); actual = fbo.toImage().convertToFormat(QImage::Format_RGB32); QCOMPARE(image.size(), actual.size()); QCOMPARE(image, actual); QVERIFY(p.begin(&device)); p.fillRect(0, 0, image.width(), image.height(), Qt::black); p.fillRect(0, 0, image.width(), image.height(), QBrush(image)); p.end(); actual = fbo.toImage().convertToFormat(QImage::Format_RGB32); QCOMPARE(image.size(), actual.size()); QCOMPARE(image, actual); }
static bool q_supportsElementIndexUint(QSGRendererInterface::GraphicsApi api) { static bool elementIndexUint = true; #if QT_CONFIG(opengl) if (api == QSGRendererInterface::OpenGL) { static bool elementIndexUintChecked = false; if (!elementIndexUintChecked) { elementIndexUintChecked = true; QOpenGLContext *context = QOpenGLContext::currentContext(); QScopedPointer<QOpenGLContext> dummyContext; QScopedPointer<QOffscreenSurface> dummySurface; bool ok = true; if (!context) { dummyContext.reset(new QOpenGLContext); dummyContext->create(); context = dummyContext.data(); dummySurface.reset(new QOffscreenSurface); dummySurface->setFormat(context->format()); dummySurface->create(); ok = context->makeCurrent(dummySurface.data()); } if (ok) { elementIndexUint = static_cast<QOpenGLExtensions *>(context->functions())->hasOpenGLExtension( QOpenGLExtensions::ElementIndexUint); } } } #else Q_UNUSED(api); #endif return elementIndexUint; }
void tst_QOpenGL::fboSimpleRendering() { QFETCH(int, surfaceClass); QScopedPointer<QSurface> surface(createSurface(surfaceClass)); QOpenGLContext ctx; ctx.create(); ctx.makeCurrent(surface.data()); if (!QOpenGLFramebufferObject::hasOpenGLFramebufferObjects()) QSKIP("QOpenGLFramebufferObject not supported on this platform"); // No multisample with combined depth/stencil attachment: QOpenGLFramebufferObjectFormat fboFormat; fboFormat.setAttachment(QOpenGLFramebufferObject::NoAttachment); QOpenGLFramebufferObject *fbo = new QOpenGLFramebufferObject(200, 100, fboFormat); fbo->bind(); glClearColor(1.0, 0.0, 0.0, 1.0); glClear(GL_COLOR_BUFFER_BIT); glFinish(); QImage fb = fbo->toImage().convertToFormat(QImage::Format_RGB32); QImage reference(fb.size(), QImage::Format_RGB32); reference.fill(0xffff0000); QFUZZY_COMPARE_IMAGES(fb, reference); delete fbo; }
static void *get_proc_address(void *ctx, const char *name) { Q_UNUSED(ctx); QOpenGLContext *glctx = QOpenGLContext::currentContext(); if(!glctx) return nullptr; return (void *)glctx->getProcAddress(QByteArray(name)); }
static void* get_proc_address(void* ctx, const char* name) { Q_UNUSED(ctx); QOpenGLContext* glctx = QOpenGLContext::currentContext(); if (!glctx) return NULL; void *res = (void *)glctx->getProcAddress(QByteArray(name)); if (strcmp(name, "glMPGetNativeDisplay") == 0) { return (void *)&MPGetNativeDisplay; } #ifdef Q_OS_WIN32 // wglGetProcAddress(), which is used by Qt, does not always resolve all // builtin functions with all drivers (only extensions). Qt compensates this // for a degree, but does this only for functions Qt happens to need. So // we need our own falback as well. if (!res) { HMODULE handle = (HMODULE)QOpenGLContext::openGLModuleHandle(); if (handle) res = (void *)GetProcAddress(handle, name); } #endif return res; }
void OculusWin32DisplayPlugin::stop() { _context->makeCurrent(_window); if (_sceneSwapFbo) { delete _sceneSwapFbo; _sceneSwapFbo = nullptr; } if (_mirrorFbo) { delete _mirrorFbo; _mirrorFbo = nullptr; } _context->doneCurrent(); _timer.stop(); _window->deleteLater(); _window = nullptr; _context->deleteLater(); _context = nullptr; if (_hmd) { ovr_Destroy(_hmd); _hmd = nullptr; } ovr_Shutdown(); }
void ShaderEffectSource::bind() { GLint filtering = smooth() ? GL_LINEAR : GL_NEAREST; GLuint hwrap = (m_wrapMode == Repeat || m_wrapMode == RepeatHorizontally) ? GL_REPEAT : GL_CLAMP_TO_EDGE; GLuint vwrap = (m_wrapMode == Repeat || m_wrapMode == RepeatVertically) ? GL_REPEAT : GL_CLAMP_TO_EDGE; QOpenGLContext *context = QOpenGLContext::currentContext(); QOpenGLFunctions *f = context->functions(); if (!context->isOpenGLES()) f->glEnable(GL_TEXTURE_2D); if (m_fbo && m_fbo->isValid()) { f->glBindTexture(GL_TEXTURE_2D, m_fbo->texture()); } else { m_dirtyTexture = true; emit repaintRequired(); markSourceItemDirty(); f->glBindTexture(GL_TEXTURE_2D, 0); } f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filtering); f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, smooth() ? GL_LINEAR : GL_NEAREST); f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, hwrap); f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, vwrap); }
/*! Blits from the \a sourceRect rectangle in the \a source framebuffer object to the \a targetRect rectangle in the \a target framebuffer object. If \a source or \a target is 0, the default framebuffer will be used instead of a framebuffer object as source or target respectively. The \a buffers parameter should be a mask consisting of any combination of \c GL_COLOR_BUFFER_BIT, \c GL_DEPTH_BUFFER_BIT, and \c GL_STENCIL_BUFFER_BIT. Any buffer type that is not present both in the source and target buffers is ignored. The \a sourceRect and \a targetRect rectangles may have different sizes; in this case \a buffers should not contain \c GL_DEPTH_BUFFER_BIT or \c GL_STENCIL_BUFFER_BIT. The \a filter parameter should be set to \c GL_LINEAR or \c GL_NEAREST, and specifies whether linear or nearest interpolation should be used when scaling is performed. If \a source equals \a target a copy is performed within the same buffer. Results are undefined if the source and target rectangles overlap and have different sizes. The sizes must also be the same if any of the framebuffer objects are multisample framebuffers. Note that the scissor test will restrict the blit area if enabled. This function will have no effect unless hasOpenGLFramebufferBlit() returns true. \sa hasOpenGLFramebufferBlit() */ void QOpenGLFramebufferObject::blitFramebuffer(QOpenGLFramebufferObject *target, const QRect &targetRect, QOpenGLFramebufferObject *source, const QRect &sourceRect, GLbitfield buffers, GLenum filter) { QOpenGLContext *ctx = QOpenGLContext::currentContext(); if (!ctx) return; QOpenGLExtensions extensions(ctx); if (!extensions.hasOpenGLExtension(QOpenGLExtensions::FramebufferBlit)) return; const int sx0 = sourceRect.left(); const int sx1 = sourceRect.left() + sourceRect.width(); const int sy0 = sourceRect.top(); const int sy1 = sourceRect.top() + sourceRect.height(); const int tx0 = targetRect.left(); const int tx1 = targetRect.left() + targetRect.width(); const int ty0 = targetRect.top(); const int ty1 = targetRect.top() + targetRect.height(); extensions.glBindFramebuffer(GL_READ_FRAMEBUFFER, source ? source->handle() : 0); extensions.glBindFramebuffer(GL_DRAW_FRAMEBUFFER, target ? target->handle() : 0); extensions.glBlitFramebuffer(sx0, sy0, sx1, sy1, tx0, ty0, tx1, ty1, buffers, filter); extensions.glBindFramebuffer(GL_FRAMEBUFFER, ctx->d_func()->current_fbo); }
QOpenGLConfig::Gpu QOpenGLConfig::Gpu::fromContext() { QOpenGLContext *ctx = QOpenGLContext::currentContext(); QScopedPointer<QOpenGLContext> tmpContext; QScopedPointer<QOffscreenSurface> tmpSurface; if (!ctx) { tmpContext.reset(new QOpenGLContext); if (!tmpContext->create()) { qWarning("QOpenGLConfig::Gpu::fromContext: Failed to create temporary context"); return QOpenGLConfig::Gpu(); } tmpSurface.reset(new QOffscreenSurface); tmpSurface->setFormat(tmpContext->format()); tmpSurface->create(); tmpContext->makeCurrent(tmpSurface.data()); } QOpenGLConfig::Gpu gpu; ctx = QOpenGLContext::currentContext(); const GLubyte *p = ctx->functions()->glGetString(GL_VENDOR); if (p) gpu.glVendor = QByteArray(reinterpret_cast<const char *>(p)); return gpu; }
void GLWidget::initializeGL() { QPalette palette; #ifndef Q_OS_WIN // getProcAddress is not working for me on Windows. if (Settings.playerGPU()) { QOpenGLContext* cx = context()->contextHandle(); if (m_glslManager && cx->hasExtension("GL_ARB_sync")) { ClientWaitSync = (ClientWaitSync_fp) cx->getProcAddress("glClientWaitSync"); } if (!ClientWaitSync) { emit gpuNotSupported(); delete m_glslManager; m_glslManager = 0; } } #endif initializeOpenGLFunctions(); qglClearColor(palette.color(QPalette::Window)); glShadeModel(GL_FLAT); glEnable(GL_TEXTURE_2D); glDisable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); glDisable(GL_LIGHTING); glDisable(GL_DITHER); glDisable(GL_BLEND); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); m_condition.wakeAll(); m_isInitialized = true; }
void PlayerQuickItem::onSynchronize() { if (!m_renderer && m_mpv) { m_renderer = new PlayerRenderer(m_mpv, window()); if (!m_renderer->init()) { delete m_renderer; m_renderer = NULL; emit onFatalError(tr("Could not initialize OpenGL.")); return; } connect(window(), &QQuickWindow::beforeRendering, m_renderer, &PlayerRenderer::render, Qt::DirectConnection); connect(window(), &QQuickWindow::frameSwapped, m_renderer, &PlayerRenderer::swap, Qt::DirectConnection); window()->setPersistentOpenGLContext(true); window()->setPersistentSceneGraph(true); window()->setClearBeforeRendering(false); m_debugInfo = ""; QOpenGLContext* glctx = QOpenGLContext::currentContext(); if (glctx && glctx->isValid()) { m_debugInfo += "\nOpenGL:\n"; int syms[4] = {GL_VENDOR, GL_RENDERER, GL_VERSION, GL_SHADING_LANGUAGE_VERSION}; for (auto sym : syms) { auto s = (char *)glctx->functions()->glGetString(sym); if (s) m_debugInfo += QString(" ") + QString::fromUtf8(s) + "\n"; } m_debugInfo += "\n"; } } if (m_renderer) m_renderer->m_size = window()->size() * window()->devicePixelRatio(); }
int getMaxTextureSize() { int maxSize = 0; // Create a temp context - required if this is called from another thread QOpenGLContext ctx; if ( !ctx.create() ) { // TODO handle the error qDebug() << "No OpenGL context could be created, this is clearly bad..."; exit(-1); } // rather than using a QWindow - which actually dosen't seem to work in this case either! QOffscreenSurface surface; surface.setFormat( ctx.format() ); surface.create(); ctx.makeCurrent(&surface); // Now the call works QOpenGLFunctions glFuncs(QOpenGLContext::currentContext()); glFuncs.glEnable(GL_TEXTURE_2D); glFuncs.glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxSize); return maxSize; }
void swapBuffers() { // If there is a xpixmap, we are on the reading side and do not want to swap any buffers. // The buffers are being switched on the writing side, the reading side just reads // whatever texture the XWindow contains. if (m_xPixmap) return; if (!m_surface->isVisible()) return; // Creating and exposing the surface is asynchronous. Therefore we have to wait here // before swapping the buffers. This should only be the case for the very first frame. while (!m_surface->isExposed()) QCoreApplication::processEvents(); QOpenGLContext* glContext = QOpenGLContext::currentContext(); if (m_surface && glContext) { GLint oldFBO; glGetIntegerv(GL_FRAMEBUFFER_BINDING, &oldFBO); pGlBindFramebuffer(GL_FRAMEBUFFER, glContext->defaultFramebufferObject()); glContext->swapBuffers(m_surface.get()); pGlBindFramebuffer(GL_FRAMEBUFFER, oldFBO); } }
QOpenGLExtensionMatcher::QOpenGLExtensionMatcher() { QOpenGLContext *ctx = QOpenGLContext::currentContext(); QOpenGLFunctions *funcs = ctx->functions(); const char *extensionStr = 0; if (ctx->isOpenGLES() || ctx->format().majorVersion() < 3) extensionStr = reinterpret_cast<const char *>(funcs->glGetString(GL_EXTENSIONS)); if (extensionStr) { QByteArray ba(extensionStr); QList<QByteArray> extensions = ba.split(' '); m_extensions = extensions.toSet(); } else { #ifdef QT_OPENGL_3 // clear error state while (funcs->glGetError()) {} if (ctx) { qt_glGetStringi glGetStringi = (qt_glGetStringi)ctx->getProcAddress("glGetStringi"); if (!glGetStringi) return; GLint numExtensions; funcs->glGetIntegerv(GL_NUM_EXTENSIONS, &numExtensions); for (int i = 0; i < numExtensions; ++i) { const char *str = reinterpret_cast<const char *>(glGetStringi(GL_EXTENSIONS, i)); m_extensions.insert(str); } } #endif // QT_OPENGL_3 } }
void tst_QOpenGL::fboHandleNulledAfterContextDestroyed() { QWindow window; window.setSurfaceType(QWindow::OpenGLSurface); window.setGeometry(0, 0, 10, 10); window.create(); QOpenGLFramebufferObject *fbo = 0; { QOpenGLContext ctx; ctx.create(); ctx.makeCurrent(&window); if (!QOpenGLFramebufferObject::hasOpenGLFramebufferObjects()) QSKIP("QOpenGLFramebufferObject not supported on this platform"); fbo = new QOpenGLFramebufferObject(128, 128); QVERIFY(fbo->handle() != 0); } QCOMPARE(fbo->handle(), 0U); }
void tst_QOpenGL::sharedResourceCleanup() { QFETCH(int, surfaceClass); QScopedPointer<QSurface> surface(createSurface(surfaceClass)); QOpenGLContext *ctx = new QOpenGLContext; ctx->create(); ctx->makeCurrent(surface.data()); SharedResourceTracker tracker; SharedResource *resource = new SharedResource(&tracker); resource->free(); QCOMPARE(tracker.invalidateResourceCalls, 0); QCOMPARE(tracker.freeResourceCalls, 1); QCOMPARE(tracker.destructorCalls, 1); tracker.reset(); resource = new SharedResource(&tracker); QOpenGLContext *ctx2 = new QOpenGLContext; ctx2->setShareContext(ctx); ctx2->create(); delete ctx; resource->free(); // no current context, freeResource() delayed QCOMPARE(tracker.invalidateResourceCalls, 0); QCOMPARE(tracker.freeResourceCalls, 0); QCOMPARE(tracker.destructorCalls, 0); ctx2->makeCurrent(surface.data()); // freeResource() should now have been called QCOMPARE(tracker.invalidateResourceCalls, 0); QCOMPARE(tracker.freeResourceCalls, 1); QCOMPARE(tracker.destructorCalls, 1); tracker.reset(); resource = new SharedResource(&tracker); // this should cause invalidateResource() to be called delete ctx2; QCOMPARE(tracker.invalidateResourceCalls, 1); QCOMPARE(tracker.freeResourceCalls, 0); QCOMPARE(tracker.destructorCalls, 0); // should have no effect other than destroying the resource, // as it has already been invalidated resource->free(); QCOMPARE(tracker.invalidateResourceCalls, 1); QCOMPARE(tracker.freeResourceCalls, 0); QCOMPARE(tracker.destructorCalls, 1); }
void XCompositeGLXClientBufferIntegration::initializeHardware(QtWayland::Display *) { qDebug() << "Initializing GLX integration"; QPlatformNativeInterface *nativeInterface = QGuiApplicationPrivate::platformIntegration()->nativeInterface(); if (nativeInterface) { mDisplay = static_cast<Display *>(nativeInterface->nativeResourceForWindow("Display",m_compositor->window())); if (!mDisplay) qFatal("could not retireve Display from platform integration"); } else { qFatal("Platform integration doesn't have native interface"); } mScreen = XDefaultScreen(mDisplay); mHandler = new XCompositeHandler(m_compositor->handle(), mDisplay); QOpenGLContext *glContext = new QOpenGLContext(); glContext->create(); m_glxBindTexImageEXT = reinterpret_cast<PFNGLXBINDTEXIMAGEEXTPROC>(glContext->getProcAddress("glXBindTexImageEXT")); if (!m_glxBindTexImageEXT) { qDebug() << "Did not find glxBindTexImageExt, everything will FAIL!"; } m_glxReleaseTexImageEXT = reinterpret_cast<PFNGLXRELEASETEXIMAGEEXTPROC>(glContext->getProcAddress("glXReleaseTexImageEXT")); if (!m_glxReleaseTexImageEXT) { qDebug() << "Did not find glxReleaseTexImageExt"; } delete glContext; }
void MapWidget::initializeGL() { initializeOpenGLFunctions(); QString versionString(QLatin1String(reinterpret_cast<const char*>(glGetString(GL_VERSION)))); QOpenGLContext *ctx = QOpenGLContext::currentContext(); Q_UNUSED(ctx); lg = new QOpenGLDebugLogger(context()); lg->initialize(); lg->startLogging(QOpenGLDebugLogger::SynchronousLogging); lg->enableMessages(); connect(lg, SIGNAL(messageLogged(QOpenGLDebugMessage)), this, SLOT(glLog(QOpenGLDebugMessage))); qDebug() << "Driver Version String:" << versionString; qDebug() << "Current Context:" << ctx->format(); //glGetIntegerv(GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX, &gpuTotalMemory); //qDebug() << "total" << gpuTotalMemory; m_renderer = new Renderer(); m_renderer->createStaticResources(); //m_painterOverlay = new PainterOverlay(); }
QPlatformOpenGLContext *EglFSIntegration::createPlatformOpenGLContext(QOpenGLContext *context) const { QPlatformOpenGLContext *pctx = egl_device_integration()->createPlatformOpenGLContext(context); if (pctx) return pctx; // If there is a "root" window into which raster and QOpenGLWidget content is // composited, all other contexts must share with its context. QOpenGLContext *compositingContext = OpenGLCompositor::instance()->context(); EGLDisplay dpy = context->screen() ? static_cast<EglFSScreen *>(context->screen()->handle())->display() : display(); QPlatformOpenGLContext *share = compositingContext ? compositingContext->handle() : context->shareHandle(); QVariant nativeHandle = context->nativeHandle(); EglFSContext *ctx; QSurfaceFormat adjustedFormat = egl_device_integration()->surfaceFormatFor(context->format()); if (nativeHandle.isNull()) { EGLConfig config = EglFSIntegration::chooseConfig(dpy, adjustedFormat); ctx = new EglFSContext(adjustedFormat, share, dpy, &config, QVariant()); } else { ctx = new EglFSContext(adjustedFormat, share, dpy, 0, nativeHandle); } nativeHandle = QVariant::fromValue<QEGLNativeContext>(QEGLNativeContext(ctx->eglContext(), dpy)); context->setNativeHandle(nativeHandle); return ctx; }
QSurfaceFormat::OpenGLContextProfile QSGShaderSourceBuilder::contextProfile() const { QOpenGLContext *context = QOpenGLContext::currentContext(); QSurfaceFormat::OpenGLContextProfile profile = QSurfaceFormat::NoProfile; Q_ASSERT(context); profile = context->format().profile(); return profile; }
void OculusWin32DisplayPlugin::resizedMirror() { auto newSize = qt::toGlm(_window->size()); _context->makeCurrent(_window); if (newSize != _mirrorFbo->size) { _mirrorFbo->Resize(newSize); } _context->doneCurrent(); }
gl::glProc HeadlessBackend::initializeExtension(const char* name) { #if QT_VERSION >= 0x050000 QOpenGLContext* thisContext = QOpenGLContext::currentContext(); return thisContext->getProcAddress(name); #else const QGLContext* thisContext = QGLContext::currentContext(); return reinterpret_cast<mbgl::gl::glProc>(thisContext->getProcAddress(name)); #endif }
QImage ImageBufferDataPrivateAccelerated::toQImage() const { QOpenGLContext *previousContext = QOpenGLContext::currentContext(); GLSharedContext::makeCurrent(); commitChanges(); QImage image = m_fbo->toImage(); previousContext->makeCurrent(previousContext->surface()); return image; }
void withSavedContext(const std::function<void()>& f) { // Save the original GL context, because creating a QML surface will create a new context QOpenGLContext * savedContext = QOpenGLContext::currentContext(); QSurface * savedSurface = savedContext ? savedContext->surface() : nullptr; f(); if (savedContext) { savedContext->makeCurrent(savedSurface); } }
QPlatformOpenGLContext *QEGLPlatformIntegration::createPlatformOpenGLContext(QOpenGLContext *context) const { QEGLPlatformScreen *screen = static_cast<QEGLPlatformScreen *>(context->screen()->handle()); // If there is a "root" window into which raster and QOpenGLWidget content is // composited, all other contexts must share with its context. QOpenGLContext *compositingContext = screen ? screen->compositingContext() : 0; return createContext(context->format(), compositingContext ? compositingContext->handle() : context->shareHandle(), display()); }
/****************************************************************************** * Is called after rendering has finished. ******************************************************************************/ void StandardSceneRenderer::endRender() { QOpenGLFramebufferObject::bindDefault(); QOpenGLContext* ctxt = QOpenGLContext::currentContext(); if(ctxt) ctxt->doneCurrent(); _framebufferObject.reset(); _offscreenContext.reset(); _offscreenSurface.reset(); ViewportSceneRenderer::endRender(); }
void OpenGLRenderPrivate::initialize() { initializeOpenGLFunctions(); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); for (int i = 0; i < 5; ++i){ const char *fShaderCode = nullptr; switch (i){ case 0: case 1: fShaderCode = fShaderI420; break; case 2: fShaderCode = fShaderNV12; break; case 3: fShaderCode = fShaderNV21; break; case 4: fShaderCode = fShaderBGRP; break; } QOpenGLShaderProgram &p = program[i]; p.addShaderFromSourceCode(QOpenGLShader::Vertex, vShaderCode); p.addShaderFromSourceCode(QOpenGLShader::Fragment, fShaderCode); p.bindAttributeLocation("VtxCoord", 0); p.bindAttributeLocation("TexCoord", 1); p.bind(); switch (i){ case 0: p.setUniformValue("SamplerY", 0); p.setUniformValue("SamplerU", 1); p.setUniformValue("SamplerV", 2); break; case 1: p.setUniformValue("SamplerY", 0); p.setUniformValue("SamplerV", 1); p.setUniformValue("SamplerU", 2); break; case 2: case 3: p.setUniformValue("SamplerY", 0); p.setUniformValue("SamplerA", 1); break; case 4: p.setUniformValue("SamplerP", 0); break; } } tex[0] = 0; tex[1] = 0; tex[2] = 1; tex[3] = 0; tex[4] = 0; tex[5] = 1; tex[6] = 1; tex[7] = 1; QOpenGLContext *c = QOpenGLContext::currentContext(); timer.setInterval(c->format().swapInterval() / (double)c->screen()->refreshRate()); }
bool QOpenGLTextureBlitter::create() { QOpenGLContext *currentContext = QOpenGLContext::currentContext(); if (!currentContext) return false; Q_D(QOpenGLTextureBlitter); d->vao->create(); d->vao->bind(); if (d->program) return true; d->program.reset(new QOpenGLShaderProgram()); QSurfaceFormat format = currentContext->format(); if (format.profile() == QSurfaceFormat::CoreProfile && format.version() >= qMakePair(3,2)) { d->program->addShaderFromSourceCode(QOpenGLShader::Vertex, vertex_shader150); d->program->addShaderFromSourceCode(QOpenGLShader::Fragment, fragment_shader150); } else { d->program->addShaderFromSourceCode(QOpenGLShader::Vertex, vertex_shader); d->program->addShaderFromSourceCode(QOpenGLShader::Fragment, fragment_shader); } d->program->link(); if (!d->program->isLinked()) { qWarning() << Q_FUNC_INFO << "Could not link shader program:\n" << d->program->log(); return false; } d->program->bind(); d->vertexBuffer.create(); d->vertexBuffer.bind(); d->vertexBuffer.allocate(vertex_buffer_data, sizeof(vertex_buffer_data)); d->vertexBuffer.release(); d->textureBuffer.create(); d->textureBuffer.bind(); d->textureBuffer.allocate(texture_buffer_data, sizeof(texture_buffer_data)); d->textureBuffer.release(); d->vertexCoordAttribPos = d->program->attributeLocation("vertexCoord"); d->vertexTransformUniformPos = d->program->uniformLocation("vertexTransform"); d->textureCoordAttribPos = d->program->attributeLocation("textureCoord"); d->textureTransformUniformPos = d->program->uniformLocation("textureTransform"); d->swizzleUniformPos = d->program->uniformLocation("swizzle"); d->program->setUniformValue(d->swizzleUniformPos,false); d->vao->release(); return true; }
int QOpenGLTextureGlyphCache::maxTextureHeight() const { QOpenGLContext *ctx = const_cast<QOpenGLContext *>(QOpenGLContext::currentContext()); if (ctx == 0) return QImageTextureGlyphCache::maxTextureHeight(); if (ctx->d_func()->workaround_brokenTexSubImage) return qMin(1024, ctx->d_func()->maxTextureSize()); else return ctx->d_func()->maxTextureSize(); }