Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: Multi-sampling #2

Closed
neurolabusc opened this issue Dec 13, 2019 · 4 comments
Closed

Enhancement: Multi-sampling #2

neurolabusc opened this issue Dec 13, 2019 · 4 comments

Comments

@neurolabusc
Copy link

Is it possible to enable multi-sampling for GTK3 OpenGL images? Thanks to this demo (as well as this one), I have ported some of my GTK2 OpenGL applications to GTK3. However, the edges look very jagged without multis-sampling. The image below shows your GTK3 project on the left and my GTK2 project on the right. My GTK3 projects show the same jagged appearance as yours, as do my GTK2 projects when I turn off multi-sampling. With Ubuntu 19.10 there are a lot of GTK2 issues, and it seems clearly end-of-life. However, at the moment it seems like QT5 allows a better upgrade path fro OpenGL applications as QT5 supports multi-sampling.

gtk3

@aklomp
Copy link
Owner

aklomp commented Dec 16, 2019

Good question. I've been playing around with various promising-sounding calls like glEnable(GL_MULTISAMPLE) and glEnable(GL_POLYGON_SMOOTH), but haven't been able to get multisampling to work so far. None of those options seem to enable multisampling on an already realized context, although some of them look like they do have some effect on how the edges are rendered.

According to the OpenGL wiki on the topic, proper multisampling must be enabled at context creation by supplying an attribute to the creation function. As far as I can tell, GTK/GDK3's context creation doesn't have the necessary sophistication to supply such additional attributes. It seems like your conclusion about GTK not supporting it natively is correct.

I see two avenues that you could try. The first is to dive into the GDK code until you get to the part where the OpenGL context is actually created. I followed the rabbit hole down to gdk_window_create_gl_context(), but it goes even deeper, because that's not where the actual creation happens either. You may find a way to create your own context, and then override the create-context signal on the GtkGLArea. This might let you install a custom-generated OpenGL context.

The second option is to render to an FBO that has multisampling enabled, and blit that FBO to the window after rendering. Probably the less elegant solution, but it would give you more control over rendering options. The OpenGL wiki entry referenced above explains this technique.

As for this project, keep in mind that it is intended as a super simple demo. I'm comfortable with the jagged edges for that purpose.

@neurolabusc
Copy link
Author

Thanks for looking into this. Thanks to your demo, I now have MRIcroGL and Surfice now working with GTK3 on Linux (as well as QT5, GTK2, Cocoa on MacOS and Windows APIs). With Ubuntu 19.10 GTK2 is no longer included in default, and GTK2 apps are poorly supported. While I think it is fine that GTK3 dropped support for legacy OpenGL, dropping simple multisampling seems to be a deal breaker. I really do not want my new software to deliver a worse experience than my previous versions. Until GTK3 matures, I will use QT5 for future releases.

I do think this will be a major issue for other GTK2 tools that use OpenGL. Like you, I tried the obvious ways to enable multi-sampling, and it seems to require being done when the context is created. While well documented, the current GTK3 OpenGL implementation seems to lack this feature.

You are right, I could use a different size FBO, and indeed I do these tricks for screen shots, and I already use FBOs for SSAO. However, in my experience this approach has a big performance penalty. My sense is that multisampling is used for the primary frame buffer some hardware tricks are exploited that are not realised with an upsampled texture.

Feel free to close this issue if you think you have explored it to your content. As you note, this is intended to be a simple demo, and it fulfils that role admirably.

@aklomp
Copy link
Owner

aklomp commented Dec 18, 2019

I spent some time looking at where the GL contexts are actually created in GDK, and ended up tracing through a bunch of platform-specific code. Here is what I think is the code that creates the GL context for X11. It does not enable multisampling. In another part of the file, an X visual supporting multisampling is the least preferred fallback option. I think it's safe to conclude that GDK3 does not make multisampling a priority, at all.

From the little I know about GTK development, I believe that GTK+-3 is now considered stable and feature complete, and that development is focusing on GTK+-4. Perhaps you could consider petitioning the developers about this issue. It could be that they're simply not aware that there is demand for features like this.

Anyway, closing this issue. Best of luck with your projects, it looks very interesting and worthwhile!

@neurolabusc
Copy link
Author

Sounds like the GTK developers are considering this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants