Replies: 6 comments 7 replies
-
|
Hi! The problem with shared GL contexts is that VAOs and FBOs are not shared, for whatever strange reason. It probably made sense back when they designed this functionality with the client/server architecture in mind, but definitely doesn't anymore. Thus, if you have a This particular limitation the main reason why I always avoided shared contexts myself. It's possible to render to multiple windows with a single GL context by looping over all windows and for each making it current with a window-specific drawable and drawing there. But it requires extra care when it comes to VSync, as drawing + buffer swap for each window may result in each window waiting for its own VSync and thus the refresh rate going from 60 FPS to 30 to 15, etc. Unfortunately I don't have much experience in this area, and I'm also not sure if Qt allows you to use a single GL context this way. #321 has some more details and links some code for this approach, it's GLFW however, not Qt. |
Beta Was this translation helpful? Give feedback.
-
|
Thanks Vladimír.
That's fine - I'm not sharing any meshes. I mainly wanted a shared context to avoid recompiling shaders with each instance. Is there another way to achieve that?
Unless I'm misunderstanding things, I only ever have one context though. Everything is created while it's activate. It's almost like when I delete the meshes when closing one window, the vertices/indices of meshes from other windows are getting messed with. |
Beta Was this translation helpful? Give feedback.
-
|
Oh, sorry, I misunderstood, apologies in case I attempted to explain something you already know. So you're definitely not sharing any meshes, and it still causes these issues? Interesting. That indeed does look like a driver bug, where it could be accidentally deleting VAOs with the same ID from the other shared GL contexts. Heh. Let's assume there are two shared GL contexts:
Just to rule out some stupid mistake on my end, can you have one Another option to try would be disabling the
Oh, hmm, another idea -- couldn't it be that when deleting the widget, some other GL context from a different window is active, and thus you end up deleting completely different VAOs? I'm not sure how Qt works in this case, but I suspect it might not be making the window's GL context current implicitly during a destructor run, and you have to do that yourself. Maybe this is actually the problem, and it's why it's behaving so random, because it depends on whatever other window got drawn before, and on Qt's internals on different platforms. |
Beta Was this translation helpful? Give feedback.
-
|
Thanks - this gives me hope that I'm just doing it wrong!
I will start by correcting this. I think I misunderstood the docs:
I probably read this as if "multiple OpenGL contexts" means "not using a shared context", but of course that's not what it's saying. So every time I want to do anything with GL calls in the widget, I will want to do something like: QOpenGLWidget::makeCurrent()
Magnum::Platform::GLContext::makeCurrent( &magnumContext );
magnumContext.resetState( Magnum::GL::Context::State::ExitExternal );
// ... do stuff with GL
magnumContext.resetState( Magnum::GL::Context::State::EnterExternal );If fixing the Magnum contexts doesn't fix the issue I will look at disabling VAOs to see if that is a workaround.
This shouldn't happen because I am calling myWidget::~myWidget()
{
makeCurrent();
Magnum::GL::Context::current().resetState( Magnum::GL::Context::State::ExitExternal );
delete mPrivate; // this holds all the Magnum stuff
mPrivate = nullptr;
} |
Beta Was this translation helpful? Give feedback.
-
|
So I started to change things so I have one Magnum context per widget, but then I don't know how to share the shaders so I only compile them once. They need a context to compile (and destruct), so how do I manage that if each widget has their own Magnum context? Do I give the shaders their own Magnum context? Would that work because I'm using a shared GL context underneath everything? |
Beta Was this translation helpful? Give feedback.
-
Oh. There goes my only hope 😅
There's a But, given that the context is shared, I think it should be possible to create the shader just once in some context, and then reuse the same instance with different GL contexts (and If sharing a single shader instance isn't possible for you, I could attempt to add the // create first window, "owning" and compiling all shaders
window1 = ...;
window2.makeCurrent();
// window1.shader is now from another GL context, query just its ID, the
// (to-be-added) wrap() makes it a state-tracked instance in the current context
window2.shader = Shaders::PhongGL::wrap(window1.shader.id(), ...); However, first I'd like to be sure that this path is actually going to fix anything. Could you first try even with the shader instances being duplicated in each widget, to see if it solves the initial problem? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I've been trying to solve an issue for days now and am hoping someone can point me in the right direction.
Background
I have a QOpenGLWidget which renders using Magnum. Qt is set to share OpenGL contexts:
QCoreApplication::setAttribute( Qt::AA_ShareOpenGLContexts );I create one static
Magnum::Platform::GLContextto be shared.I am calling (Qt's)
makeCurrent&Magnum::GL::Context::current().resetState(ExitExternal)before calling into Magnum code (and EnterExternal on the way out).The scenes in this case are static (i.e. I create all the objects programatically and they don't change over the lifetime of the widget).
Problem
On macOS this all works fine.
On Windows running on VMWare:
Magnum::MeshTools::compileand "manually" usingaddVertexBufferandsetIndexBufferand both (sometimes) go wonkyThe problem could be with:
Windows ARM on VMWare is buggy?(happens on VMWare on Intel as well))and I haven't been able to narrow that down.
Any ideas? Where (and how) should I be looking for the problem here?
Thanks for any insights!
Beta Was this translation helpful? Give feedback.
All reactions