本文整理汇总了C++中QOpenGLContext::makeCurrent方法的典型用法代码示例。如果您正苦于以下问题:C++ QOpenGLContext::makeCurrent方法的具体用法?C++ QOpenGLContext::makeCurrent怎么用?C++ QOpenGLContext::makeCurrent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QOpenGLContext
的用法示例。
在下文中一共展示了QOpenGLContext::makeCurrent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testGLInternal
bool OpenGL2Common::testGL()
{
QOpenGLContext glCtx;
if ((isOK = glCtx.create()))
{
QOffscreenSurface offscreenSurface;
offscreenSurface.create();
if ((isOK = glCtx.makeCurrent(&offscreenSurface)))
testGLInternal();
}
return isOK;
}
示例2: clearThreadRenderObject
void QuickMozView::clearThreadRenderObject()
{
QOpenGLContext* ctx = QOpenGLContext::currentContext();
Q_ASSERT(ctx != NULL && ctx->makeCurrent(ctx->surface()));
if (gSGRenderer != NULL) {
delete gSGRenderer;
gSGRenderer = NULL;
}
QQuickWindow *win = window();
if (!win) return;
connect(win, SIGNAL(beforeSynchronizing()), this, SLOT(createThreadRenderObject()), Qt::DirectConnection);
}
示例3: openGLPaintDevice
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;
ctx.create();
QSurfaceFormat format = ctx.format();
if (format.majorVersion() < 2)
QSKIP("This test requires at least OpenGL 2.0");
ctx.makeCurrent(surface.data());
QImage image(128, 128, 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(128, 128);
fbo.bind();
QOpenGLPaintDevice device(128, 128);
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();
QCOMPARE(image, fbo.toImage().convertToFormat(QImage::Format_RGB32));
p.begin(&device);
p.fillRect(0, 0, image.width(), image.height(), Qt::black);
p.drawImage(0, 0, image);
p.end();
QCOMPARE(image, fbo.toImage().convertToFormat(QImage::Format_RGB32));
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();
QCOMPARE(image, fbo.toImage().convertToFormat(QImage::Format_RGB32));
}
示例4: graphicsSurfaceToken
GraphicsSurfaceToken ImageBufferDataPrivateAccelerated::graphicsSurfaceToken() const
{
if (!m_graphicsSurface) {
QOpenGLContext *previousContext = QOpenGLContext::currentContext();
GLSharedContext::makeCurrent();
m_graphicsSurface = GraphicsSurface::create(m_fbo->size(), graphicsSurfaceFlags(), QOpenGLContext::currentContext());
previousContext->makeCurrent(previousContext->surface());
}
return m_graphicsSurface->exportToken();
}
示例5: copyToGraphicsSurface
uint32_t ImageBufferDataPrivateAccelerated::copyToGraphicsSurface()
{
QOpenGLContext *previousContext = QOpenGLContext::currentContext();
GLSharedContext::makeCurrent();
if (!m_graphicsSurface) {
m_graphicsSurface = GraphicsSurface::create(m_fbo->size(), graphicsSurfaceFlags(), QOpenGLContext::currentContext());
}
commitChanges();
m_graphicsSurface->copyFromTexture(m_fbo->texture(), IntRect(IntPoint(), m_fbo->size()));
previousContext->makeCurrent(previousContext->surface());
return m_graphicsSurface->frontBuffer();
}
示例6: paintToTextureMapper
void ImageBufferDataPrivateAccelerated::paintToTextureMapper(TextureMapper* textureMapper, const FloatRect& targetRect, const TransformationMatrix& matrix, float opacity)
{
if (textureMapper->accelerationMode() != TextureMapper::OpenGLMode) {
return;
}
QOpenGLContext *previousContext = QOpenGLContext::currentContext();
GLSharedContext::makeCurrent();
commitChanges();
previousContext->makeCurrent(previousContext->surface());
static_cast<TextureMapperGL*>(textureMapper)->drawTexture(m_fbo->texture(), TextureMapperGL::ShouldFlipTexture | TextureMapperGL::ShouldBlend, m_fbo->size(), targetRect, matrix, opacity);
}
示例7: buildWebSurface
bool RenderableWebEntityItem::buildWebSurface(EntityTreeRenderer* renderer) {
if (_currentWebCount >= MAX_CONCURRENT_WEB_VIEWS) {
qWarning() << "Too many concurrent web views to create new view";
return false;
}
qDebug() << "Building web surface";
++_currentWebCount;
// Save the original GL context, because creating a QML surface will create a new context
QOpenGLContext * currentContext = QOpenGLContext::currentContext();
QSurface * currentSurface = currentContext->surface();
_webSurface = new OffscreenQmlSurface();
_webSurface->create(currentContext);
_webSurface->setBaseUrl(QUrl::fromLocalFile(PathUtils::resourcesPath() + "/qml/controls/"));
_webSurface->load("WebView.qml");
_webSurface->resume();
_webSurface->getRootItem()->setProperty("url", _sourceUrl);
_webSurface->getRootContext()->setContextProperty("desktop", QVariant());
_connection = QObject::connect(_webSurface, &OffscreenQmlSurface::textureUpdated, [&](GLuint textureId) {
_texture = textureId;
});
// Restore the original GL context
currentContext->makeCurrent(currentSurface);
auto forwardPointerEvent = [=](const EntityItemID& entityItemID, const PointerEvent& event) {
if (entityItemID == getID()) {
handlePointerEvent(event);
}
};
_mousePressConnection = QObject::connect(renderer, &EntityTreeRenderer::mousePressOnEntity, forwardPointerEvent);
_mouseReleaseConnection = QObject::connect(renderer, &EntityTreeRenderer::mouseReleaseOnEntity, forwardPointerEvent);
_mouseMoveConnection = QObject::connect(renderer, &EntityTreeRenderer::mouseMoveOnEntity, forwardPointerEvent);
_hoverLeaveConnection = QObject::connect(renderer, &EntityTreeRenderer::hoverLeaveEntity, [=](const EntityItemID& entityItemID, const PointerEvent& event) {
if (this->_pressed && this->getID() == entityItemID) {
// If the user mouses off the entity while the button is down, simulate a touch end.
QTouchEvent::TouchPoint point;
point.setId(event.getID());
point.setState(Qt::TouchPointReleased);
glm::vec2 windowPos = event.getPos2D() * (METERS_TO_INCHES * _dpi);
QPointF windowPoint(windowPos.x, windowPos.y);
point.setPos(windowPoint);
QList<QTouchEvent::TouchPoint> touchPoints;
touchPoints.push_back(point);
QTouchEvent* touchEvent = new QTouchEvent(QEvent::TouchEnd, nullptr, Qt::NoModifier, Qt::TouchPointReleased, touchPoints);
QCoreApplication::postEvent(_webSurface->getWindow(), touchEvent);
}
});
return true;
}
示例8: openGlContext
QString openGlContext()
{
QString result;
QTextStream str(&result);
QOpenGLContext context;
if (context.create()) {
# ifdef QT_OPENGL_DYNAMIC
str << "Dynamic GL ";
# endif
switch (context.openGLModuleType()) {
case QOpenGLContext::LibGL:
str << "LibGL";
break;
case QOpenGLContext::LibGLES:
str << "LibGLES";
break;
}
QWindow window;
if (QGuiApplication::platformName() == QLatin1String("greenisland"))
window.setFlags(Qt::Desktop);
window.setSurfaceType(QSurface::OpenGLSurface);
//window.setScreen(QGuiApplication::primaryScreen());
window.create();
if (context.makeCurrent(&window)) {
QOpenGLFunctions functions(&context);
str << " Vendor: " << reinterpret_cast<const char *>(functions.glGetString(GL_VENDOR))
<< "\nRenderer: " << reinterpret_cast<const char *>(functions.glGetString(GL_RENDERER))
<< "\nVersion: " << reinterpret_cast<const char *>(functions.glGetString(GL_VERSION))
<< "\nGLSL version: " << reinterpret_cast<const char *>(functions.glGetString(GL_SHADING_LANGUAGE_VERSION))
<< "\nFormat: " << context.format();
QList<QByteArray> extensionList = context.extensions().toList();
std::sort(extensionList.begin(), extensionList.end());
QByteArray extensions = extensionList.join(' ');
str << " \nFound " << extensionList.size() << " extensions:\n";
str << wordWrap(extensions, 78);
context.doneCurrent();
}
window.destroy();
} else {
str << "Unable to create an Open GL context.\n";
}
return result;
}
示例9:
void
WebView::CreateGLContext() {
QOpenGLContext* context = window_->GLContext();
context->makeCurrent(window_);
static bool firstClearDone = false;
if (!firstClearDone) {
QOpenGLFunctions* functions = context->functions();
Q_ASSERT(functions);
functions->glClearColor(1.0, 1.0, 1.0, 0.0);
functions->glClear(GL_COLOR_BUFFER_BIT);
context->swapBuffers(window_);
firstClearDone = true;
}
}
示例10: initGl
void TestWindow::initGl() {
_glContext.setFormat(format());
if (!_glContext.create() || !_glContext.makeCurrent(this)) {
qFatal("Unable to intialize Window GL context");
}
gl::initModuleGl();
_glf.initializeOpenGLFunctions();
_glf.glGenFramebuffers(1, &_fbo);
if (!_sharedContext.create(&_glContext) || !_sharedContext.makeCurrent()) {
qFatal("Unable to intialize Shared GL context");
}
hifi::qml::OffscreenSurface::setSharedContext(_sharedContext.getContext());
_discardLamdba = hifi::qml::OffscreenSurface::getDiscardLambda();
}
示例11: draw
void TestWindow::draw() {
if (_aboutToQuit) {
return;
}
// Attempting to draw before we're visible and have a valid size will
// produce GL errors.
if (!isVisible() || _size.width() <= 0 || _size.height() <= 0) {
return;
}
static std::once_flag once;
std::call_once(once, [&] { initGl(); });
if (!_glContext.makeCurrent(this)) {
return;
}
updateSurfaces();
auto size = this->geometry().size();
auto incrementX = size.width() / DIVISIONS_X;
auto incrementY = size.height() / DIVISIONS_Y;
_glf.glViewport(0, 0, size.width(), size.height());
_glf.glClearColor(1, 0, 0, 1);
_glf.glClear(GL_COLOR_BUFFER_BIT);
for (uint32_t x = 0; x < DIVISIONS_X; ++x) {
for (uint32_t y = 0; y < DIVISIONS_Y; ++y) {
auto& qmlInfo = _surfaces[x][y];
if (!qmlInfo.surface || !qmlInfo.texture) {
continue;
}
_glf.glBindFramebuffer(GL_READ_FRAMEBUFFER, _fbo);
_glf.glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, qmlInfo.texture, 0);
_glf.glBlitFramebuffer(
// src coordinates
0, 0, _qmlSize.width() - 1, _qmlSize.height() - 1,
// dst coordinates
incrementX * x, incrementY * y, incrementX * (x + 1), incrementY * (y + 1),
// blit mask and filter
GL_COLOR_BUFFER_BIT, GL_NEAREST);
}
}
_glf.glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
_glf.glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
_glContext.swapBuffers(this);
}
示例12: fboRendering
// NOTE: This tests that CombinedDepthStencil attachment works by assuming the
// GL2 engine is being used and is implemented the same way as it was when
// this autotest was written. If this is not the case, there may be some
// false-positives: I.e. The test passes when either the depth or stencil
// buffer is actually missing. But that's probably ok anyway.
void tst_QOpenGL::fboRendering()
{
#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());
QVERIFY(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::CombinedDepthStencil);
// Uncomplicate things by using NPOT:
const QSize size(256, 128);
QOpenGLFramebufferObject fbo(size, fboFormat);
if (fbo.attachment() != QOpenGLFramebufferObject::CombinedDepthStencil)
QSKIP("FBOs missing combined depth~stencil support");
QVERIFY(fbo.bind());
QPainter fboPainter;
QOpenGLPaintDevice device(fbo.width(), fbo.height());
bool painterBegun = fboPainter.begin(&device);
QVERIFY(painterBegun);
qt_opengl_draw_test_pattern(&fboPainter, fbo.width(), fbo.height());
fboPainter.end();
const QImage fb = fbo.toImage().convertToFormat(QImage::Format_RGB32);
QCOMPARE(fb.size(), size);
qt_opengl_check_test_pattern(fb);
}
示例13: color
void Web3DOverlay::render(RenderArgs* args) {
if (!_visible || !getParentVisible()) {
return;
}
QOpenGLContext * currentContext = QOpenGLContext::currentContext();
QSurface * currentSurface = currentContext->surface();
if (!_webSurface) {
_webSurface = new OffscreenQmlSurface();
_webSurface->create(currentContext);
_webSurface->setBaseUrl(QUrl::fromLocalFile(PathUtils::resourcesPath() + "/qml/"));
_webSurface->load("WebEntity.qml");
_webSurface->resume();
_webSurface->getRootItem()->setProperty("url", _url);
_webSurface->resize(QSize(_resolution.x, _resolution.y));
_connection = QObject::connect(_webSurface, &OffscreenQmlSurface::textureUpdated, [&](GLuint textureId) {
_texture = textureId;
});
currentContext->makeCurrent(currentSurface);
}
vec2 size = _resolution / _dpi * INCHES_TO_METERS;
vec2 halfSize = size / 2.0f;
vec4 color(toGlm(getColor()), getAlpha());
applyTransformTo(_transform, true);
Transform transform = _transform;
if (glm::length2(getDimensions()) != 1.0f) {
transform.postScale(vec3(getDimensions(), 1.0f));
}
Q_ASSERT(args->_batch);
gpu::Batch& batch = *args->_batch;
if (_texture) {
batch._glActiveBindTexture(GL_TEXTURE0, GL_TEXTURE_2D, _texture);
} else {
batch.setResourceTexture(0, DependencyManager::get<TextureCache>()->getWhiteTexture());
}
batch.setModelTransform(transform);
DependencyManager::get<DeferredLightingEffect>()->bindSimpleProgram(batch, true, false, false, true);
DependencyManager::get<GeometryCache>()->renderQuad(batch, halfSize * -1.0f, halfSize, vec2(0), vec2(1), color);
batch.setResourceTexture(0, args->_whiteTexture); // restore default white color after me
}
示例14: aboutToBeDestroyed
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);
}
示例15: multiGroupSharedResourceCleanup
void tst_QOpenGL::multiGroupSharedResourceCleanup()
{
QFETCH(int, surfaceClass);
QScopedPointer<QSurface> surface(createSurface(surfaceClass));
for (int i = 0; i < 10; ++i) {
QOpenGLContext *gl = new QOpenGLContext();
gl->create();
gl->makeCurrent(surface.data());
{
// Cause QOpenGLMultiGroupSharedResource instantiation.
QOpenGLFunctions func(gl);
}
delete gl;
// Cause context group's deleteLater() to be processed.
QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete);
}
// Shouldn't crash when application exits.
}