lkalif's picture

How to determine if function is available in a specific driver

Some of the users of my app get errors like:

System.EntryPointNotFoundException: Unable to find an entry point named 'glGenBuffers' in DLL 'opengl32.dll'.

I try to determine if I can use VBO by doing this in code:

string glExtensions = GL.GetString(StringName.Extensions);
RenderSettings.UseVBO = glExtensions.Contains("vertex_buffer_object");

But I still get the same error. Is there a way to test if DLL entrypoints exist on a specific machine without resorting to P/Invoking kernel32 or something not platform idependent?


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

It is possible to retrieve the address of an OpenGL function:

IntPtr address = (Context as IGraphicsContextInternal).GetAddress("glGenBuffers");
if (address != IntPtr.Zero)
    ;

However, this will not solve the root of the problem, which is the "vertex_buffer_object" check. This check will be true if the ARB version of the extension is available (GL.Arb.GenBuffers()) rather than the core version (GL.GenBuffers()). The ARB version is more widely supported than the core version, hence the bug reports.

What you need to do is check that OpenGL version is >= 1.5.

lkalif's picture

Thank you very much for that hint. My code will work fine if VBOs are not supported I just didn't know reliable way of detecting it.

Will something like this work: check if the entry point exists for regular version, if it does use that. If it doesn't try checking if ARB extension is present, and if it's not use immediate mode?

Or is this a bad strategy?

the Fiddler's picture

Checking both core and ARB versions would ensure the best compatibility. The best approach would be to check the OpenGL version first (version >= 1.5 guarantees support for the core version), check the ARB extension next (version < 1.5) and use the fallback if neither is present.

lkalif's picture

I implemented it in that way and it works great. Thanks again!