comp.lang.ada
 help / color / mirror / Atom feed
* Xlib, (GLX or EGL), OpenGL. Stuck at double buffering not working properly.
@ 2020-05-12 23:15 Olivier Henley
  2020-05-14 18:40 ` onox
  0 siblings, 1 reply; 4+ messages in thread
From: Olivier Henley @ 2020-05-12 23:15 UTC (permalink / raw)


Hi to all,

In my spare time I am working on a cross-platform windowing lib for OpenGL in Ada. 

In a nutshell, a GLFW replacement.

I come to you because on Linux, wrapping, and driving Xlib with GLX or EGL in Ada, I am failing to get double buffering to work. 

Generally its working, eg. I get sample code from OpenGLAda rendering fine in the window but if I try to resize a window rapidly, I get black tearing and sometimes dropped frames. I did fix this problem on windows by threading the rendering out of the window message pump, but for Linux, threading over X11 makes things explode. I looked into XInitThread but the documentation leave me cold.

I tried two other Ada projects that paint some OpenGL in a native Linux window using (Xlib and GLX) namely Globe3D and AdaOGL. Both suffer from the same tearing and/or dropped frame when resizing the window.

Now if I compile an equivalent simple GLFW C example code, it works like a charm, no dropped frame, no tearing. I looked at their code and they do not seem to make much more than I do. I also found, compiled, and tried a really simple C source code file using Xlib/GLX and it works. (http://andrewd.ces.clemson.edu/courses/graphics/examples/glx-simple/glxsimple.c)

Anyone is aware of what is going on here? Something special about the Ada runtime that I should know about or is it just me that does not handle the Xlib window message pump incorrectly?

Any insights welcome.

Thanks,

Olivier 

Note: Now because the threading problem over X11 looks like mostly coming from the whole needed 'same thread context for window and GL' I was thinking rendering GL to a double buffer of Pixmaps/pBuffer (XLib off-screen render targets) from a separate thread and then just blit myself to the window at the 'Expose' events. Make sense, any thoughts on that?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Xlib, (GLX or EGL), OpenGL. Stuck at double buffering not working properly.
  2020-05-12 23:15 Xlib, (GLX or EGL), OpenGL. Stuck at double buffering not working properly Olivier Henley
@ 2020-05-14 18:40 ` onox
  2020-05-15 20:00   ` Olivier Henley
  0 siblings, 1 reply; 4+ messages in thread
From: onox @ 2020-05-14 18:40 UTC (permalink / raw)


On Wednesday, May 13, 2020 at 1:15:10 AM UTC+2, Olivier Henley wrote:
> Hi to all,
> 
> In my spare time I am working on a cross-platform windowing lib for OpenGL in Ada. 
> 
> In a nutshell, a GLFW replacement.
> 
> I come to you because on Linux, wrapping, and driving Xlib with GLX or EGL in Ada, I am failing to get double buffering to work. 
> 
> Generally its working, eg. I get sample code from OpenGLAda rendering fine in the window but if I try to resize a window rapidly, I get black tearing and sometimes dropped frames. I did fix this problem on windows by threading the rendering out of the window message pump, but for Linux, threading over X11 makes things explode. I looked into XInitThread but the documentation leave me cold.
> 
> I tried two other Ada projects that paint some OpenGL in a native Linux window using (Xlib and GLX) namely Globe3D and AdaOGL. Both suffer from the same tearing and/or dropped frame when resizing the window.
> 
> Now if I compile an equivalent simple GLFW C example code, it works like a charm, no dropped frame, no tearing. I looked at their code and they do not seem to make much more than I do. I also found, compiled, and tried a really simple C source code file using Xlib/GLX and it works. (http://andrewd.ces.clemson.edu/courses/graphics/examples/glx-simple/glxsimple.c)
> 
> Anyone is aware of what is going on here? Something special about the Ada runtime that I should know about or is it just me that does not handle the Xlib window message pump incorrectly?
> 
> Any insights welcome.
> 
> Thanks,
> 
> Olivier 
> 
> Note: Now because the threading problem over X11 looks like mostly coming from the whole needed 'same thread context for window and GL' I was thinking rendering GL to a double buffer of Pixmaps/pBuffer (XLib off-screen render targets) from a separate thread and then just blit myself to the window at the 'Expose' events. Make sense, any thoughts on that?

X11 seems to have a single event queue so event processing can occur on any task. The GLFW maintainer explains a bit how all the platform do their event and window management in #5 at https://discourse.glfw.org/t/multithreading-glfw/573/5

I'm not sure how you can get tearing. Do you still get it when you explicitly set swap interval to 1?

Is there a particular reason you're trying this on X11? I've been thinking a lot about a GLFW replacement written in Ada, because GLFW tries to maintain too many backends (X11 and macOS are dead platforms for gaming/3D IMO) and development is slow. A replacement that just supports WGL+win32 and Wayland+EGL would be nice and feasible. Also I would like to have more control over the frame latency via accurate frame presentation feedback (presentation-time Wayland protocol)

Have you considered putting your code under some OSS license? (Preferably Apache License 2.0 or MIT license) It would be nice if we could team up to make this happen :)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Xlib, (GLX or EGL), OpenGL. Stuck at double buffering not working properly.
  2020-05-14 18:40 ` onox
@ 2020-05-15 20:00   ` Olivier Henley
  2020-05-16  5:51     ` onox
  0 siblings, 1 reply; 4+ messages in thread
From: Olivier Henley @ 2020-05-15 20:00 UTC (permalink / raw)


> X11 seems to have a single event queue so event processing can occur on any task. 

ok. I will investigate the possibilities.

> The GLFW maintainer explains a bit how all the platform do their event and window management in #5 at https://discourse.glfw.org/t/multithreading-glfw/573/5

Thank you for this nice discussion. The OP is quite in line with what I was envisioning for an Ada replacement. 

> I'm not sure how you can get tearing. Do you still get it when you explicitly set swap interval to 1?

No, it's not tearing per se. I wanted to picture a frame, rendered, but with different black damaged portions. I either get that of full black frames.

> Is there a particular reason you're trying this on X11?

- It's still ubiquitous
- Ubuntu 18.04 LTS has it by default
- Low hanging fruit. Many code examples here and there around the web.

> I've been thinking a lot about a GLFW replacement written in Ada, because GLFW tries to maintain too many backends (X11 and macOS are dead platforms for gaming/3D IMO) and development is slow. 

Not just that, installing for Ada, on Windows is tricky and quite frustrating.

> A replacement that just supports WGL+win32 and Wayland+EGL would be nice and feasible. 

Nice to know you would be satisfied with just that. I was wondering about Apple dropping OpenGL. If you say, we do not care, for now at least, it reassures me.

> Also, I would like to have more control over the frame latency via accurate frame presentation feedback (presentation-time Wayland protocol)

Could you elaborate? I bought the Wayland online book and I am almost done but never 'touched' any code yet. Do you mean that using Wayland, we can 'drive' precise refresh presentation with guaranteed full-frames?

> Have you considered putting your code under some OSS license? 

Will do.

> It would be nice if we could team up to make this happen :)

That is perfect because Orka was exactly the client I wanted to fulfill the needs. I'll get in touch then.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Xlib, (GLX or EGL), OpenGL. Stuck at double buffering not working properly.
  2020-05-15 20:00   ` Olivier Henley
@ 2020-05-16  5:51     ` onox
  0 siblings, 0 replies; 4+ messages in thread
From: onox @ 2020-05-16  5:51 UTC (permalink / raw)


On Friday, May 15, 2020 at 10:00:52 PM UTC+2, Olivier Henley wrote:
> > Also, I would like to have more control over the frame latency via accurate frame presentation feedback (presentation-time Wayland protocol)
> 
> Could you elaborate? I bought the Wayland online book and I am almost done but never 'touched' any code yet. Do you mean that using Wayland, we can 'drive' precise refresh presentation with guaranteed full-frames?

I meant that you can get feedback about when a frame was presented to the screen so you can sync with the display refresh. See https://github.com/glfw/glfw/issues/1350#issuecomment-447534605. X11 has a similar extension called PresentCompleteNotify (see https://stackoverflow.com/questions/48424320/precision-timing-of-gdk3-gtk3-window-update)

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-05-16  5:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-12 23:15 Xlib, (GLX or EGL), OpenGL. Stuck at double buffering not working properly Olivier Henley
2020-05-14 18:40 ` onox
2020-05-15 20:00   ` Olivier Henley
2020-05-16  5:51     ` onox

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox