Tue, 04/05/2022 - 12:42
Forums:
I tried to replicate this sample: https://github.com/gkv311/occt-samples-gtk/
While the original (which used GTK+-3.0) didn't start due to an old version of GTK+-3.0 being installed, my own implementation (using GTK4) did. However, I can't see anything on the blank GtkGlArea window, and I get:
TKOpenGl | Type: Other | ID: 0 | Severity: Medium | Message: OpenGl_Window::CreateWindow: window Visual is incomplete: no depth buffer, no stencil buffer
... despite having checked that gtk_gl_area_set_has_depth_buffer() and gtk_gl_area_set_has_stencil_buffer() are called. This is my code:
static void viewer_realize_callback(GtkWidget *self, gpointer user_data) {
gtk_gl_area_make_current(GTK_GL_AREA(self));
int width = gtk_widget_get_width(self);
int height = gtk_widget_get_height(self);
int scale_factor = gtk_widget_get_scale_factor(self);
gtk_gl_area_set_has_depth_buffer(GTK_GL_AREA(self), 1);
gtk_gl_area_set_has_stencil_buffer(GTK_GL_AREA(self), 1);
gtk_gl_area_attach_buffers(GTK_GL_AREA(self));
//gtk_gl_area_set_auto_render(GTK_GL_AREA(self), 0);
EGLContext egl_context = eglGetCurrentContext();
if(egl_context != EGL_NO_CONTEXT) {
EGLContext egl_display = eglGetCurrentDisplay();
EGLContext egl_surface = eglGetCurrentSurface(EGL_DRAW);
EGLint egl_config_id = 0;
EGLint num_configs = 0;
eglQuerySurface(egl_display, egl_surface, EGL_CONFIG_ID, &egl_config_id);
const EGLint config_attributes[] = {EGL_CONFIG_ID, egl_config_id, EGL_NONE};
void* egl_config = NULL;
eglChooseConfig(egl_display, config_attributes, &egl_config, 1, &num_configs);
run_at_viewer_realize(
width, height, scale_factor,
(void *) egl_context, (void *) egl_display, (void *) egl_config
);
} else {
GdkGLContext* gdk_gl_context = gdk_gl_context_get_current();
GdkDisplay* display = gdk_gl_context_get_display(gdk_gl_context);
GdkSurface* surface = gdk_gl_context_get_surface(gdk_gl_context);
Display *xdisplay = gdk_x11_display_get_xdisplay(display);
Window gl_window = gdk_x11_surface_get_xid(surface);
run_at_viewer_realize(
width, height, scale_factor,
(void *) NULL, (void *) xdisplay, (void *) gl_window
);
}
}
void backend_init_graphics(void) {
display_connection = new Aspect_DisplayConnection();
viewer_driver = new OpenGl_GraphicDriver(display_connection, false);
viewer_driver->ChangeOptions().buffersNoSwap = true;
viewer_driver->ChangeOptions().buffersOpaqueAlpha = true;
viewer_driver->ChangeOptions().useSystemBuffer = false;
viewer = new V3d_Viewer(viewer_driver);
viewer->SetDefaultBackgroundColor(Quantity_Color(Quantity_NOC_WHEAT));
viewer->SetDefaultLights();
viewer->SetLightOn();
viewer->ActivateGrid(Aspect_GT_Rectangular, Aspect_GDM_Lines);
ais_context = new AIS_InteractiveContext(viewer);
ais_controller = new AIS_ViewController();
view = viewer->CreateView();
view->SetImmediateUpdate(false);
}
void backend_realize_graphics(
int width, int height, int scale_factor,
void *context, void *display, void *config
) {
Graphic3d_Vec2i logical_size(width, height);
Graphic3d_Vec2i view_size = logical_size * scale_factor;
opencascade::handle<OpenGl_Context> gl_context = new OpenGl_Context();
opencascade::handle<OcctGtkWindow> custom_window = dynamic_cast<OcctGtkWindow *>(view.get());
if(context != nullptr) {
if(custom_window.get() == nullptr) {
custom_window = new OcctGtkWindow();
}
opencascade::handle<OpenGl_GraphicDriver> gl_driver =
dynamic_cast<OpenGl_GraphicDriver *>(
ais_context->CurrentViewer()->Driver().get()
)
;
gl_driver->InitEglContext(display, context, config);
custom_window->SetSize(view_size.x(), view_size.y());
custom_window->SetDevicePixelRatio(scale_factor);
view->SetWindow(custom_window, gl_context->RenderingContext());
} else {
opencascade::handle<OpenGl_GraphicDriver> gl_driver =
dynamic_cast<OpenGl_GraphicDriver *>(
ais_context->CurrentViewer()->Driver().get()
)
;
//gl_driver.get()->GetDisplayConnection().get()->Init((Aspect_XDisplay *) display);
//custom_window->SetNativeHandle((Aspect_Drawable) config);
opencascade::handle<Xw_Window> xw_window =
new Xw_Window(display_connection, (Aspect_Drawable) config);
view->SetWindow(xw_window, gl_context->RenderingContext());
}
// initPixelScaleRatio();
view->ChangeRenderingParams().Resolution = (unsigned int )(96.0 * scale_factor + 0.5);
ais_context->SetPixelTolerance(int(scale_factor * 6.0));
/*TopoDS_Solid *undef_solid = new TopoDS_Solid();
opencascade::handle<AIS_Shape> interactive_shape =
opencascade::handle<AIS_Shape>(new AIS_Shape(*undef_solid));
ais_context->Display(interactive_shape, 0);*/
}
Any ideas on what could be going wrong?
Tue, 04/05/2022 - 13:05
This is a warning message not an error. It usually doesn't lead to rendering issues.
Please use "Insert Code Snippet" (HTML editor) or ``` Markdown syntax while pasting code snippets - they are difficult to read.
Tue, 04/05/2022 - 13:33
Sorry, I wasn't aware I could use Markdown. The fact is, it doesn't work, and I'm not entirely sure why...
Tue, 04/05/2022 - 14:05
libgtk-4-dev isn’t available in Ubuntu 20.04 as far as I know. How did you installed it?
Tue, 04/05/2022 - 14:16
From source. Most of its dependencies are already there, so just a matter of compiling and installing. Same for OCCT (bc no debug symbols apparently).
Tue, 04/05/2022 - 14:58
Have you been able to build / run any GLArea samples using GTK4?
Tue, 04/05/2022 - 15:47
Haven't tried... Where can I get them? Are they bundled with the GTK4 sources?
Tue, 04/05/2022 - 19:02
Confirmed. All of the GTK4 demos build and run perfectly. Is there any way to build your code to run with gtkmm4? CMake only seems to accept gtkmm3... That way I'd be able to test! (well, it doesn't work with GTK+-3.0, because of the implementation bugs you mention, I assume).
Tue, 04/05/2022 - 20:01
You need to change gtkmm version in CMakeLists.txt and update sample based on changes in GTK API. Don't know if they have any dedicated upgrade guide describing these changes.
Tue, 04/05/2022 - 22:56
Unfortunately I can't manage to build it on my system :(
I'm getting some interesting messages though, it looks like a
GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT
is being produced somewhere... Probably unrelated, but anyway.Wed, 04/06/2022 - 23:57
This may be an old thread, but while looking at this I found a possible bug (as in, a concrete piece of code that appears to be wrong) in
OpenGl_TextureFormat.hxx
. I'll try a fix and see if this GTK4 issue gets fixed as well.Basically, it's an instance where pixel formats like
GL_RGBA
are getting mixed up with internal formats likeGL_RGBA8
, which are constants defined with different numerical values.Edit:
OpenGl_TextureFormat.cxx
has another instance of this, but I believe that one isn't the cause.Tue, 05/23/2023 - 13:20
I ran into the same issue with
gtkmm-4.0
so I started investigating a bit and there seems to be difference between v3.0 and v4.0 wheregtkmm-4.0
doesn't fully prepareGLArea
in the realize callback. Or I'm not sure how to put it in words.Here's what I did:
GLArea
example from the GNOME repo and isolated it to test out some things.epoxy
dependency and went back to "regular"libgl-dev
(I use Linux). I'm usingmeson
cause I find it easier thancmake
, but I hope we can investigate together to figure out a solution so if there's anything anyone needs to collaborate on figuring out this stuff let me know... unless it's about Windows, I have no idea how to set stuff up on Windows.GLArea->get_width()
&GLArea->get_height()
and here's that I found that they're set to 0 in the realize callback. I would have expected them to have some size > 0 at this point. This is different fromgtkmm-3.0
.I assume that somehow we're using the realize callback incorrectly, but I literally started programming
gtkmm-4.0
andOpenCASCADE
yesterday so I don't understand what's happening just yet.I forked the
occt-samples-gtk
repo and made a branch with the example if anyone wants to check it out: https://github.com/razcore-rad/occt-gtk/tree/official-gtk. The file to look at issrc/example_glarea.cpp
. This branch is just the isolatedgtkmm-4.0
example with noOpenCASCADE
.They also don't seem to have any OpenGL context initialization code in the example, I'm not sure how that ties in with
OpenCASCADE
OpenGl_Context::Init()
function.For
meson
you can compile and run with:Where
--wipe
is like clear everything and start over. Only relevant after once runningmeson setup build
, otherwise it gives an error.Once
meson setup build
is ran, you can just doWed, 05/24/2023 - 07:17
This might be relevant: https://gitlab.gnome.org/GNOME/gtk/-/issues/4950. I did some more tests and with a sample code I found on stackoverflow I can confirm that
gl-egl
fails and I'm on NVidia as the user from the GNOME issue.I have no idea what the implications would be with the OpenCASCADE
Init()
call though, because the stackoverflow test app runs fine withoutglewInit()
. I haven't done any OpenGL development though so I don't understand what happens here.I also compiled some of the info I found on the issue on the GNOME forum.
That said, this seems to be unrelated with the size issue.
Wed, 05/24/2023 - 08:14
I had a chat with a GNOME developer in the Matrix chat and this is my conclusion:
GtkGlArea
size is0 x 0
in the realize callback and this is correct since GTK4 follows Wayland which sets the size only on the first render.GDK_DEBUG=gl-glx
(probably).With that I think we have a starting point.
For future reference I'm including the chat log from Matrix: