Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2013-02

TOpenGLControl: multisampling not working (Linux/GLX)

18 messages · 6 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Reimar Grabowski

Hi,

as the title says multisampling does not work for me. Setting the MultiSampling value to something greater than 1 does nothing. Well, it does something. The multisampling code path in GLGtkGlxContext.pas is executed without any errors (verified by setting a break point and stepping through the code) but no multisampling enabled context is created as querying GL_SAMPLE_BUFFERS and GL_SAMPLES shows. Both are 0. Forcing multisampling via driver settings GL_SAMPLE_BUFFERS is 1 (meaning multisampling is enabled on this context) and GL_SAMPLES is a non 0 value, too (depends on the driver settings, I tested with 4, 8 and 32 and all work correctly). Does multisampling work under Linux/Gtk for anyone?

To test if it works you should query the mentioned enums like so:

var
samples, samplebuffers: integer;
glGetIntegerv(GL_SAMPLE_BUFFERS, @samplebuffers); // should be 1
glGetIntegerv(GL_SAMPLES, @samples); // should be the value of TOpenGLControl.MultiSampling

Thanks for any info
R.

Reply by email

Reimar Grabowski
to Reimar Grabowski
Does multisampling work under Linux/Gtk for anyone?

As no one answered I take this as a no, making it look like this feature was never working (not even for the one who implemented it) and never tested.

So I have to try to get my head around it. I just use this thread (in the vain hope of getting at least some help) to document my process.

1. Multisampling FBConfigs are non-conformant (see glxinfo) so when requesting a multisampled context I add GLX_CONFIG_CAVEAT followed by GLX_NON_CONFORMANT_CONFIG to the attribute list. This reduces the number of FBConfigs returned by glxChooseFBConfig which is a good thing(tm).

2. The implementation then only keeps the first FBConfig and discards the other ones. So I use glXGetFBConfigAttrib to query this config for GLX_SAMPLES(_ARB) and indeed the FBConfig provides the number of samples specified by TOpenGLControl.MultiSampling. Looks good to me.

3. The FBConfig then gets passed to glxCreateNewContext which returns a GLXContext. I get the ID from this context using glxQueryContext with GLX_FBCONFIG_ID. Looking up the ID in glxinfos list of FBConfigs shows that I get a non-conformant context with the specified number of red, green, blue and alpha bits, multisampling enabled and with the specified number of samples. Everything looks fine.

4. Then the GTK/GDK stuff kicks in (which I have not the slightest clue about) and when all is said and done I end up without multisampling in my GL code.

Currently I don't know what to do or where to look. Any help or ideas are highly appreciated.

R.

Reply by email

Chavoux Luyt
to Reimar Grabowski: as the title says multisampling does not work for me. Setting the MultiSampling value to…

Hi Reimar

It seems the original author had a problem with GDK... should that not be cairo? I though GDK was deprecated (http://developer.gnome.org/gdk/).

Don't know if this helps at all!

Cheers
Chavoux
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130225/e4df1a14/attachment.html>

Reply by email

Michalis Kamburelis
to Reimar Grabowski: as the title says multisampling does not work for me. Setting the MultiSampling value to…
Reimar Grabowski wrote
Hi, as the title says multisampling does not work for me.

I was testing TOpenGLControl.MultiSampling on Linux (with Radeon GPU), it worked fine for me.

Note that there is a fallback (documented in TCustomOpenGLControl interface): if the requested MultiSampling is not available, we fallback to non-multisampled context (that's because for most applications anti-aliasing can be just an optional feature). I guess you already checked that this didn't happen in your case?

The code is pretty straightforward, in glgtkglxcontext.pas LOpenGLCreateContextCore gets called with given MultiSampling value, and then CreateOpenGLContextAttrList adds to the attributes this:

       Add(GLX_SAMPLE_BUFFERS_ARB); Add(1);
       Add(GLX_SAMPLES_ARB); Add(MultiSampling);

The GLX_SAMPLES_ARB is the minimal required value (as http://www.opengl.org/registry/specs/ARB/multisample.txt says "...accepts GLX_SAMPLES_ARB in <attribList>, followed by the minimum number of samples that can be accepted in the multisample buffer"). So it should work... Well, unless GLX is just lying to us.

Can you check what list was created in your case by CreateOpenGLContextAttrList, did it contain appropriate GLX_SAMPLES_ARB and MultiSampling items?

Michalis

Reply by email

Michalis Kamburelis
to Reimar Grabowski: as the title says multisampling does not work for me. Setting the MultiSampling value to…
I was testing TOpenGLControl.MultiSampling on Linux (with Radeon GPU), it worked fine for me.

I just did some more testing, and things look a little weird. TOpenGLControl.MultiSampling works fine for Radeon GPU, but silently fails with NVidia GPU (GeForce GTS 450 with propriatary NVidia OpenGL). On NVidia GLX behaves like we have multi-sampling config, but the actual context doesn't have multi-sampling. Both systems (Radeon and NVidia) run Linux (recent Debian testing version).

What is weirder is that I can get multi-sampling on both these systems (both Radeon and NVidia) with a very similar multi-sampling code inside my Castle Game Engine TCastleWindow class (that directly uses GTK and GTKGlExt, without Lazarus TOpenGLControl, to create window with OpenGL context). Seems like there is something specific in Lazarus/TOpenGLControl that causes (some?) drivers to just ignore multi-sampling (even though glx seems to behave like we found multi-sampling context correctly, just like Reimar describes).

Not really sure what is wrong at this point.

Michalis

Reply by email

Mattias Gaertner
to Michalis Kamburelis: I was testing TOpenGLControl.MultiSampling on Linux (with Radeon GPU), it worked fine for…
Show quoted text 13 lines
Reimar Grabowski wrote: > Hi, > > as the title says multisampling does not work for me. I was testing TOpenGLControl.MultiSampling on Linux (with Radeon GPU), it worked fine for me. Note that there is a fallback (documented in TCustomOpenGLControl interface): if the requested MultiSampling is not available, we fallback to non-multisampled context (that's because for most applications anti-aliasing can be just an optional feature). I guess you already checked that this didn't happen in your case?

I checked: There is no error, so the fallback is not called.

Show quoted text 16 lines
The code is pretty straightforward, in glgtkglxcontext.pas LOpenGLCreateContextCore gets called with given MultiSampling value, and then CreateOpenGLContextAttrList adds to the attributes this: Add(GLX_SAMPLE_BUFFERS_ARB); Add(1); Add(GLX_SAMPLES_ARB); Add(MultiSampling); The GLX_SAMPLES_ARB is the minimal required value (as http://www.opengl.org/registry/specs/ARB/multisample.txt says "...accepts GLX_SAMPLES_ARB in <attribList>, followed by the minimum number of samples that can be accepted in the multisample buffer"). So it should work... Well, unless GLX is just lying to us. Can you check what list was created in your case by CreateOpenGLContextAttrList, did it contain appropriate GLX_SAMPLES_ARB and MultiSampling items?

Yes, it does and the copy contains them too.

Mattias

Reply by email

Mattias Gaertner
to Reimar Grabowski: On Fri, 15 Feb 2013 07:43:27 +0100 As no one answered I take this as a no, making it look…
[...] 3. The FBConfig then gets passed to glxCreateNewContext which returns a GLXContext. I get the ID from this context using glxQueryContext with GLX_FBCONFIG_ID. Looking up the ID in glxinfos list of FBConfigs shows that I get a non-conformant context with the specified number of red, green, blue and alpha bits, multisampling enabled and with the specified number of samples. Everything looks fine. 4. Then the GTK/GDK stuff kicks in (which I have not the slightest clue about) and when all is said and done I end up without multisampling in my GL code.

Querying the GLX_FBCONFIG_ID later still shows the same config *with* sample buffers and GL_MULTISAMPLE is enabled.
Maybe some drivers need an explicit activation or more parameters?

Mattias

Reply by email

Reimar Grabowski
to Michalis Kamburelis: I just did some more testing, and things look a little weird.…
Show quoted text 5 lines
What is weirder is that I can get multi-sampling on both these systems (both Radeon and NVidia) with a very similar multi-sampling code inside my Castle Game Engine TCastleWindow class (that directly uses GTK and GTKGlExt, without Lazarus TOpenGLControl, to create window with OpenGL context)

GTKGLExt may be the thing making it work. I don't have enough details but searching around the net showed that GTKGLArea does not support multisampling. AFAIR TOpenGLControls code is based on this. The lazarus forum post I linked to in another mail showed multisampling did work for the OpenGL examples that come with FPC. Multisampling does work with GTKGLExt as your engine shows. So I still think it is a problem with GDK but that is just a gut feeling. Perhaps TOpenGLControl can be rewritten to use GTKGLExt following your code if your license permits it. It's a shame that the GTK guys did not get their act together and don't offer a standard way of context creation like virtually every other widgetset does since years.

R.

Reply by email

Mattias Gaertner
to Reimar Grabowski
Show quoted text 9 lines
On Tue, 26 Feb 2013 06:17:04 +0100 Michalis Kamburelis wrote: > What is weirder is that I can get multi-sampling on both these systems > (both Radeon and NVidia) with a very similar multi-sampling code inside > my Castle Game Engine TCastleWindow class (that directly uses GTK and > GTKGlExt, without Lazarus TOpenGLControl, to create window with OpenGL > context) GTKGLExt may be the thing making it work.

A quick look at the gtkglext-1.2.0 sources didn't reveal anything special about multisampling.
The first noticeable thing of gtkglext code is the special color map.

I don't have enough details but searching around the net showed that GTKGLArea does not support multisampling. AFAIR TOpenGLControls code is based on this.

Yes.

The lazarus forum post I linked to in another mail showed multisampling did work for the OpenGL examples that come with FPC. Multisampling does work with GTKGLExt as your engine shows. So I still think it is a problem with GDK but that is just a gut feeling.

The GLGtkGlxContext only uses the gdk function gdk_colormap_new. And it let the gtk create the XWindow. It seems gtkglext does not create the XWindow too.

Perhaps TOpenGLControl can be rewritten to use GTKGLExt following your code if your license permits it. It's a shame that the GTK guys did not get their act together and don't offer a standard way of context creation like virtually every other widgetset does since years.

Indeed. And the last release of gtkglext is 1.2.0 from 2006.

Mattias

Reply by email

Reimar Grabowski
to Mattias Gaertner
A quick look at the gtkglext-1.2.0 sources didn't reveal anything special about multisampling.

It is very possible that no 'special' support is needed.

The first noticeable thing of gtkglext code is the special color map.

This could be the difference as multisampling in GLX is handled the same as for example alpha bits or color bits.

And the last release of gtkglext is 1.2.0 from 2006.

It is not part of GTK and OpenGL context creation never was unlike for example QT where the OpenGL widget is a first class citizen. AFAIR GLX 1.3 was released around 1998.

R.

Reply by email

Mattias Gaertner
to Reimar Grabowski
Show quoted text 9 lines
On Tue, 26 Feb 2013 16:53:25 +0100 Mattias Gaertner wrote: > A quick look at the gtkglext-1.2.0 sources didn't reveal anything > special about multisampling. It is very possible that no 'special' support is needed. > The first noticeable thing of gtkglext code is the special color map. This could be the difference as multisampling in GLX is handled the same as for example alpha bits or color bits.

The color map functions are in gdk/x11/gdkglconfig-x11.c. The C looks simple, but I guess it needs some time to understand all the X calls and flags.

> And the last release of gtkglext is 1.2.0 from 2006. It is not part of GTK and OpenGL context creation never was unlike for example QT where the OpenGL widget is a first class citizen.

There is still no opengl widget for LCL QT. AFAIK it requires a QT expert.

AFAIR GLX 1.3 was released around 1998.

Mattias

Reply by email

Mattias Gaertner
to Mattias Gaertner: On Tue, 26 Feb 2013 19:10:53 +0100 The color map functions are in…
Show quoted text 16 lines
On Tue, 26 Feb 2013 19:10:53 +0100 Reimar Grabowski wrote: > On Tue, 26 Feb 2013 16:53:25 +0100 > Mattias Gaertner wrote: > > > A quick look at the gtkglext-1.2.0 sources didn't reveal anything > > special about multisampling. > It is very possible that no 'special' support is needed. > > > The first noticeable thing of gtkglext code is the special color map. > This could be the difference as multisampling in GLX is handled the same as for example alpha bits or color bits. The color map functions are in gdk/x11/gdkglconfig-x11.c. The C looks simple, but I guess it needs some time to understand all the X calls and flags.

Reimar sent me a patch that allocates a simple colormap, instead of the "sophisticated" gtkglext colormap. That seems to be enough for multisampling. :)

Mattias

Reply by email

Michalis Kamburelis
to Mattias Gaertner
Mattias Gaertner wrote
Reimar sent me a patch that allocates a simple colormap, instead of the "sophisticated" gtkglext colormap. That seems to be enough for multisampling. :)

I can confirm that it also fixes the issue for me: now I can get multisampling in TOpenGLContext on both Radeon and NVidia on Linux (previously only Radeon was working for me).

Thank you!,
Michalis

Reply by email