OpenGL 3.2+ and Qt Quick2
-
Ah, then the alternative is to create your own context and do a context switch twice each frame. In my code it looks like this
@
QOpenGLContext* current = QOpenGLContext::currentContext();
Context* context = _item->context();
context->makeCurrent();{ AutoFrameSwitch fs(context); _frame->render(context, [&]() { _item->render(); }); } current->makeCurrent(_item->window());
@
I do the FBO thing but I highly don't recommend doing what I do if you can avoid it. I'm actually in the process of moving my engines rendering out into another thread and getting rid of those context switches. -
That looks a lot like what I've been trying to do, except I haven't been using FBOs. I let the QQuickView create the window, then use its beforeRendering signal to try to render to its QSurface using my own gl 3.2 context. It looks something like this:
@myQuickView->setClearBeforeRendering(false);
QObject::connect(myQuickView, &QQuickWindow::beforeRendering, testrender, Qt::DirectConnection);void testrender()
{
QOpenGLContext* savedContext = QOpenGLContext::currentContext();
myGL32Context->makeCurrent(myQuickView);
glClearColor(1, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT);
savedContext->makeCurrent();
}@The above leaves garbage in the framebuffer though, indicating the glClear isn't having an effect. I'm don't know if having two contexts render into the same QSurface like this is unsupported, or if I'm doing something else wrong.
-
It works fine with the default one, I'll get a cleared red screen with my QML gui on top. I saw the part of the talk you linked where he inherits QQuickView and sets the surface format to a gl 3.3. compatibility profile. Unfortunately this wouldn't work on OS X -- otherwise it's exactly what I'd like to achieve.
-
The context appears to be created successfully. glGetString(GL_VERSION) returns "3.2 ATI-7.32.12". I create it in a class derived from QQuickView, on the render thread. This is the actual code:
@GLWindow::GLWindow(QWindow *parent)
: QQuickView(parent)
, mCustomContext(0)
{
resize(QSize(800, 600));
connect(this, SIGNAL(beforeRendering()), this, SLOT(render()), Qt::DirectConnection);
}void GLWindow::createContext()
{
QSurfaceFormat fmt = format();
fmt.setMajorVersion(3);
fmt.setMinorVersion(2);
fmt.setProfile(QSurfaceFormat::CoreProfile);
mCustomContext = new QOpenGLContext();
mCustomContext->setFormat(fmt);
qDebug() << "create context" << mCustomContext->create();
}void GLWindow::render()
{
if (mCustomContext == 0) createContext();
QOpenGLContext* savedContext = QOpenGLContext::currentContext();
mCustomContext->makeCurrent(this);glViewport(0, 0, width(), height()); glClearColor(1, 0, 0, 1); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); savedContext->makeCurrent(this);
}
@ -
No change unfortunately. It looks like this (I used the openglunderqml example as a starting point). The glClear is doing something, as it will occasionally flash a (corrupted) red buffer.
-
I'm afraid I'm running out of ideas. For reference mine is
@
_context->setScreen(QGuiApplication::primaryScreen());
QSurfaceFormat format;
format.setMajorVersion(4);
format.setMinorVersion(3);
format.setSamples(4);
// format.setProfile(QSurfaceFormat::CoreProfile);
_context->setFormat(format);
_context->setShareContext(share);
_context->create();_window->setFormat(_context->format());
@
I really don't remember why I commented out the setProfile line. Suddenly seems suspicious. If I uncomment it my app crashes at glGenSamplers indicating it isn't giving me a useful context. Probably because I'm trying to share it.