Open Nokse22 opened 6 months ago
Interesting! Thank you for sharing. I see nothing wrong in your code. I'll try to reproduce locally to take a closer look and let you know.
Thank you very much!
By default it seems like it's using GLES and I have a blank window. When adding self.gl_area.set_allowed_apis(Gdk.GLAPI.GL)
, GTK seems to complain it cannot create a GL context, any idea?
I got that error only when setting the GLES api and required version above 3.3 with:
self.gl_area.set_allowed_apis(Gdk.GLAPI.GLES)
self.gl_area.set_required_version(4,0)
When setting only GL it never happened
I can confirm it is using GLES, adding print(area.get_api())
in on_render
prints that is using GLES
It's interesting that, as @Nokse22 already pointed out, the image from render_to_image()
is the right size; we can also add print(self.engine.window.size)
to on_render()
to see that the engine does indeed resize with the window.
So the the engine and the context/area/surface do get connected to some extent but then the actual rendering fails?
I got it working but only on X11, the code is the same, I haven't set any preferred API or version for OpenGL and it doesn't crash. I thought it was only the app that didn't support Wayland.
When using an external window type, libf3d does not handle the OpenGL surface so that's definitely a GTK issue. However I'm under X11 and it's not working on my side, but my issue looks unrelated to yours. Anyway, that looks good! Can I borrow your code to add it in the examples?
Also not working on X11 here :( Maybe #1417 will help narrowing it down?
Maybe https://github.com/f3d-app/f3d/pull/1417 will help narrowing it down?
Hopefully so I can also report it properly to GTK
When using an external window type, libf3d does not handle the OpenGL surface so that's definitely a GTK issue.
I will create an issue on GTK
However I'm under X11 and it's not working on my side, but my issue looks unrelated to yours.
That's too bad, I am working on a flatpak, when it's done I'll send it
Anyway, that looks good! Can I borrow your code to add it in the examples?
Of course! While testing I also made one with python and Qt f you want, it also only works in x11:
from PySide6.QtGui import QGuiApplication
from PySide6.QtOpenGL import QOpenGLWindow
import f3d
class F3DWindow(QOpenGLWindow):
def __init__(self):
super().__init__()
self.mEngine = f3d.Engine(f3d.Window.Type.EXTERNAL)
self.mEngine.loader.load_geometry("/path/to/geometry.obj")
def paintGL(self):
self.mEngine.window.render()
print("rendering")
def main():
a = QGuiApplication()
w = F3DWindow()
w.setTitle("F3D QT External Window")
w.resize(300, 300)
w.show()
return a.exec_()
main()
This example with Qt is working perfectly fine on my side (with X11). Thanks again for sharing, I'll also add it to the examples!
I have understood that the library uses GL and not GLES and the errors I got were because it was using GLES, forcing GL api on wayland fixes the errors, but it still doesn't render.
Wayland uses EGL as a backend while x11 uses GXL and this seems to be the issue, in fact using EGL on x11 causes the same issue. Unfortunately you can't use GXL in Wayland.
I still don't know if there is an issue in Gtk or something needs to be updated in the library to be able to use it in Wayland.
Using Gtk debug I was able to get the errors that points to some specific API calls
Here is a summary of all the different error messages:
GL_INVALID_ENUM in glTexImage2DMultisample(internalformat=GL_NONE)
GL_INVALID_VALUE in glTexImage2D(internalFormat=GL_NONE)
FBO incomplete: color attachment incomplete [0]
GL_INVALID_FRAMEBUFFER_OPERATION in glBlitFramebuffer(incomplete draw/read buffers)
GL_INVALID_FRAMEBUFFER_OPERATION in glClear(incomplete framebuffer)
GL_INVALID_VALUE in glUniform1i(invalid sampler/tex unit index for uniform 0)
GL_INVALID_VALUE in glUniform1i(invalid sampler/tex unit index for uniform 1)
GL_INVALID_VALUE in glUniform1i(invalid sampler/tex unit index for uniform 2)
GL_INVALID_FRAMEBUFFER_OPERATION in glDrawArrays
FBO incomplete: color attachment incomplete [0]
GL_INVALID_FRAMEBUFFER_OPERATION in glBlitFramebuffer(incomplete draw/read buffers)
I fixed it compiling all from source and adding VTK_OPENGL_HAS_EGL=ON
that is enabled by default only on android, but Wayland uses EGL, so it was missing.
Compiling it this way, though will cause it to not work with X11 with GXL so I had to force EGL on X11 too. Maybe there is a way to make it work both with EGL and GXL.
From what I've read it's recommended to use EGL on X11 nowadays rather than GLX, e.g. Firefox switched to EGL on X11 a couple years ago or so.
related to: https://github.com/f3d-app/f3d/issues/1375
Maybe there is a way to make it work both with EGL and GXL.
There is now! This will be much more easy with VTK 9.4.0 + F3D 3.0
Describe the bug I tried to use libf3d with python and Gtk, but it doesn't render and it crashes
To Reproduce Steps to reproduce the behavior:
Expected behavior It should render correctly inside the Gtk.GLArea, if I render it outside it works.
System Information:
F3D Information The version of f3d library is 2.4.0 installed with pip
Additional context
This code should show an application window with a button to open a 3d model file and a Gtk.GLArea where to render the 3d model.
Every time it renders it prints this:
And the result of
print(area.get_error())
at line 45 before crashing is:Segmentation fault (core dumped)
Otherwise is
None
I can correctly draw using OpenGL like this and it won't crash:
If I do this:
It will save an image of the same size of the Gtk.GLArea, but all black if no model is loaded or an image like the following one if a geometry is loaded.
With Gtk.GLArea I can set the allowed APIs with:
With only GL it will not crash and it will not print anything, with GLES it will.